API Documentation
Loading...
Searching...
No Matches
QCustomDial.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: QCustomDial
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/String.h>
35#include <NDEVR/RGBColor.h>
36#include <QDial>
37namespace NDEVR
38{
39 /**--------------------------------------------------------------------------------------------------
40 \brief An icon along with defined behavior describing how that icon should interact with a parent
41 QCustomDial object.
42 **/
43 struct DialIcon
44 {
46 QPixmap pixmap;
47 QPixmap scaled_pixmap;//used to cache the last scaled pixmap to avoid calling scale again when the size is still at the same
48 bool fullsize = false;
49 bool rotate = false;
50 bool make_shadow = false;
52 fltp08 size = 1.0;
53 void setImageID(const String& id)
54 {
55 image_id = id;
56 pixmap = QPixmap();
57 scaled_pixmap = QPixmap();
58 }
59 };
60 class QCustomLineEdit;
61 /**--------------------------------------------------------------------------------------------------
62 \brief Provides a rounded range control (like a speedometer or potentiometer).
63
64 QCustomDial is used when the user needs to control a value within a program-definable range,
65 and the range either wraps around (for example, with angles measured from 0 to 359 degrees)
66 or the dialog layout needs a square widget.
67
68 Contains logic for adding one or more images to the dial that may or may not rotate with the dial.
69 **/
70 class NDEVR_WIDGETS_API QCustomDial : public QDial
71 {
72 Q_OBJECT
73 public:
74 QCustomDial(QWidget* parent = nullptr);
76
77 //based on the implementation of QLabel::paintEvent
78 void paintEvent(QPaintEvent *event) override;
79 int heightForWidth(int w) const override { return w; }
80 void mouseMoveEvent(QMouseEvent *event) override;
81 void mouseReleaseEvent(QMouseEvent *event) override;
82 void mousePressEvent(QMouseEvent *event) override;
83 void keyPressEvent(QKeyEvent* event) override;
84 void wheelEvent(QWheelEvent* e) override;
85 void resizeEvent(QResizeEvent *event) override;
86 void setIcon(const QPixmap& map, bool show_full_icon, bool rotate_icon);
87 void addIcon(const String& icon, bool show_full_icon, bool rotate_icon);
88 void addIcon(const DialIcon& icon);
89 const Buffer<DialIcon>& icons() const { return m_icons; };
90 void setIcons(const Buffer<DialIcon>& icons);
91 void clearIcons();
92 void setColor(const RGBColor& color);
93 bool event(QEvent* event) override;
94 QSize sizeHint() const override;
95 QSize minimumSizeHint() const override;
96 void setGrip(fltp04 grip_size)
97 {
98 m_grip_size = grip_size;
99 }
102 void showLineEdit(bool show);
103 void tieToLineEdit(QCustomLineEdit* edit, bool is_offset = false);
106 protected slots:
108 public slots:
109 void setValue(fltp08 value);
110 signals:
111 void edited();
112 private:
113 void _setValue(fltp08 value, bool emit_edit = false);
114 void updateCenterLineEditLocation();
115 fltp08 pixSize(const DialIcon& icon) const;
116 void cacheScaledPixmap(DialIcon& icon);
117 private:
118 Buffer<DialIcon> m_icons;
119 fltp08 m_grip_size;
120 QCustomLineEdit* m_center_edit;
121
122 fltp08 m_max_value;
123 fltp08 m_min_value;
124 //key for the currently cached QImage and QPixmap
125 //used to make sure the label was not set to another QPixmap
126 qint64 cacheKey{ 0 };
127 RGBColor m_color;
128 bool m_is_editing;
129 bool m_has_user_focus;
130 void modifyValue(QMouseEvent* event);
131 };
132}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:59
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Provides a rounded range control (like a speedometer or potentiometer).
Definition QCustomDial.h:71
QSize minimumSizeHint() const override
QSize sizeHint() const override
void mouseReleaseEvent(QMouseEvent *event) override
void tieToLineEdit(QCustomLineEdit *edit, bool is_offset=false)
const Buffer< DialIcon > & icons() const
Definition QCustomDial.h:89
void setMinValue(fltp08 min)
int heightForWidth(int w) const override
Definition QCustomDial.h:79
void mouseMoveEvent(QMouseEvent *event) override
void setColor(const RGBColor &color)
bool event(QEvent *event) override
void keyPressEvent(QKeyEvent *event) override
void setIcon(const QPixmap &map, bool show_full_icon, bool rotate_icon)
void mousePressEvent(QMouseEvent *event) override
void wheelEvent(QWheelEvent *e) override
void setValue(fltp08 value)
void resizeEvent(QResizeEvent *event) override
void setMaxValue(fltp08 max)
void paintEvent(QPaintEvent *event) override
void addIcon(const DialIcon &icon)
QCustomLineEdit * centerLineEdit()
void addIcon(const String &icon, bool show_full_icon, bool rotate_icon)
void setGrip(fltp04 grip_size)
Definition QCustomDial.h:96
void setIcons(const Buffer< DialIcon > &icons)
void showLineEdit(bool show)
QCustomDial(QWidget *parent=nullptr)
A line edit allows users to enter and edit a single line of plain text with useful editing functions,...
Definition QCustomLineEdit.h:56
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
The core String class for the NDEVR API.
Definition String.h:69
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
An icon along with defined behavior describing how that icon should interact with a parent QCustomDia...
Definition QCustomDial.h:44
QPixmap scaled_pixmap
Definition QCustomDial.h:47
bool rotate
Definition QCustomDial.h:49
fltp08 size
Definition QCustomDial.h:52
String image_id
Definition QCustomDial.h:45
QPixmap pixmap
Definition QCustomDial.h:46
bool make_shadow
Definition QCustomDial.h:50
void setImageID(const String &id)
Definition QCustomDial.h:53
Angle< fltp08 > rotation_offset
Definition QCustomDial.h:51
bool fullsize
Definition QCustomDial.h:48