NDEVR
API Documentation
QCustomDial.h
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{
43 struct DialIcon
44 {
46 QPixmap pixmap;
47 QPixmap scaled_pixmap;
48 bool fullsize = false;
49 bool rotate = false;
50 bool make_shadow = false;
52 fltp08 size = 1.0;
57 void setImageID(const StringView& id)
58 {
59 image_id = id;
60 pixmap = QPixmap();
61 scaled_pixmap = QPixmap();
62 }
63 };
64 class QCustomLineEdit;
75 class NDEVR_WIDGETS_API QCustomDial : public QDial
76 {
77 Q_OBJECT
78 public:
83 QCustomDial(QWidget* parent = nullptr);
88
93 //based on the implementation of QLabel::paintEvent
94 void paintEvent(QPaintEvent *event) override;
100 int heightForWidth(int w) const override { return w; }
105 void mouseMoveEvent(QMouseEvent *event) override;
110 void mouseReleaseEvent(QMouseEvent *event) override;
115 void mousePressEvent(QMouseEvent *event) override;
120 void keyPressEvent(QKeyEvent* event) override;
125 void wheelEvent(QWheelEvent* e) override;
130 void resizeEvent(QResizeEvent *event) override;
137 void setIcon(const QPixmap& map, bool show_full_icon, bool rotate_icon);
144 void addIcon(const String& icon, bool show_full_icon, bool rotate_icon);
149 void addIcon(const DialIcon& icon);
154 const Buffer<DialIcon>& icons() const { return m_icons; };
168 void setColor(const RGBColor& color);
174 bool event(QEvent* event) override;
179 QSize sizeHint() const override;
184 QSize minimumSizeHint() const override;
189 void setGrip(fltp04 grip_size)
190 {
191 m_grip_size = grip_size;
192 }
193
207 void showLineEdit(bool show);
213 void tieToLineEdit(QCustomLineEdit* edit, bool is_offset = false);
224 protected slots:
229 public slots:
234 void setValue(fltp08 value);
235 signals:
239 void edited();
240 private:
246 void _setValue(fltp08 value, bool emit_edit = false);
250 void updateCenterLineEditLocation();
256 fltp08 pixSize(const DialIcon& icon) const;
261 void cacheScaledPixmap(DialIcon& icon);
262 private:
263 Buffer<DialIcon> m_icons;
264 fltp08 m_grip_size;
265 QCustomLineEdit* m_center_edit;
266
267 fltp08 m_max_value;
268 fltp08 m_min_value;
269 qint64 cacheKey{ 0 };
270 RGBColor m_color;
271 bool m_is_editing;
272 bool m_has_user_focus;
277 void modifyValue(QMouseEvent* event);
278 };
279}
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
Definition Angle.h:83
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
void keyPressEvent(QKeyEvent *event) override
Handles key press events for keyboard-based dial control.
void setMinValue(fltp08 min)
Sets the minimum value of the dial range.
void setValue(fltp08 value)
Sets the dial to the given floating-point value.
QCustomLineEdit * centerLineEdit()
Returns the center line edit widget, creating one if it does not exist.
const Buffer< DialIcon > & icons() const
Returns the list of icons currently displayed on the dial.
bool event(QEvent *event) override
Handles generic events such as tooltip and theme updates.
void setGrip(fltp04 grip_size)
Sets the size of the grip indicator on the dial.
void showLineEdit(bool show)
Shows or hides the center line edit overlay.
~QCustomDial()
Destroys the dial and its resources.
void addIcon(const DialIcon &icon)
Adds a fully configured DialIcon to the dial.
void tieToLineEdit(QCustomLineEdit *edit, bool is_offset=false)
Ties a QCustomLineEdit to this dial so they stay synchronized.
void setMaxValue(fltp08 max)
Sets the maximum value of the dial range.
void mouseMoveEvent(QMouseEvent *event) override
Handles mouse movement for interactive dial rotation.
QSize minimumSizeHint() const override
Returns the minimum size hint for layout purposes.
void onValueChanged()
Slot invoked when the underlying QDial value changes.
void resizeEvent(QResizeEvent *event) override
Handles resize events and updates icon caches accordingly.
void setIcon(const QPixmap &map, bool show_full_icon, bool rotate_icon)
Sets the dial icon from a pixmap with display options.
void setColor(const RGBColor &color)
Sets the color of the dial track and grip indicator.
void clearIcons()
Removes all icons from the dial.
void paintEvent(QPaintEvent *event) override
Paints the dial including any overlay icons.
QSize sizeHint() const override
Returns the recommended size for the dial.
void edited()
Emitted when the user interactively edits the dial value.
void addIcon(const String &icon, bool show_full_icon, bool rotate_icon)
Adds an icon to the dial by resource name.
fltp08 getValue()
Returns the current dial value as a floating-point number.
void mouseReleaseEvent(QMouseEvent *event) override
Handles mouse release to finalize dial value changes.
void wheelEvent(QWheelEvent *e) override
Handles mouse wheel events for scrolling the dial value.
void setIcons(const Buffer< DialIcon > &icons)
Replaces all icons with the given buffer.
QCustomDial(QWidget *parent=nullptr)
Constructs a QCustomDial with the given parent widget.
int heightForWidth(int w) const override
Returns the height for a given width, maintaining a square aspect ratio.
void mousePressEvent(QMouseEvent *event) override
Handles mouse press to begin interactive dial rotation.
A line edit allows users to enter and edit a single line of plain text with useful editing functions,...
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
double fltp08
Defines an alias representing an 8 byte floating-point number.
An icon along with defined behavior describing how that icon should interact with a parent QCustomDia...
Definition QCustomDial.h:44
Angle< fltp08 > rotation_offset
An angular offset applied to the icon rotation.
Definition QCustomDial.h:51
void setImageID(const StringView &id)
Sets the icon image by resource ID and clears cached pixmaps.
Definition QCustomDial.h:57
QPixmap pixmap
The loaded pixmap for the icon.
Definition QCustomDial.h:46
bool make_shadow
Whether to render a drop shadow behind the icon.
Definition QCustomDial.h:50
String image_id
The resource identifier for the icon image.
Definition QCustomDial.h:45
QPixmap scaled_pixmap
Cached scaled pixmap to avoid redundant scaling when size has not changed.
Definition QCustomDial.h:47
bool rotate
Whether the icon should rotate with the dial value.
Definition QCustomDial.h:49
fltp08 size
A size multiplier for the icon relative to the dial.
Definition QCustomDial.h:52
bool fullsize
Whether the icon should fill the entire dial area.
Definition QCustomDial.h:48