NDEVR
API Documentation
Toggle.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: Toggle
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Button.h>
34#include "DLLInfo.h"
35class QPropertyAnimation;
36class QLabel;
37class QCheckBox;
38namespace NDEVR
39{
40 template<class t_type>
41 class Resource;
42
43 class ResourceListener;
49 class NDEVR_WIDGETS_API Toggle : public Button
50 {
51 Q_OBJECT
52 Q_PROPERTY(float offset READ offset WRITE setOffset)
53
54 public:
57 Toggle(QWidget* parent = nullptr);
60 Toggle(const std::function<void(Button*)>& on_click);
64 Toggle(const TranslatedString& name, const std::function<void(Button*)>& on_click);
69 Toggle(const TranslatedString& name, const StringView& icon, const std::function<void(Button*)>& on_click);
74 Toggle(const TranslatedString& name, const StringView& icon, Resource<bool>& on_click);
75 ~Toggle();
78 QSize sizeHint() const override;
81 QSize minimumSizeHint() const override;
84 float offset() const {
85 return _x;
86 }
87
89 void setOffset(float o) {
90 _x = o;
91 update();
92 }
93 protected:
97 void paintEvent(QPaintEvent*) override;
99 void mouseReleaseEvent(QMouseEvent*) override;
102 int sliderWidth() const;
105 int sliderHeight() const;
108 int spacing() const;
111 QRect sliderRect() const;
112 protected slots:
115 void onChecked(bool checked);
116 private:
117 qreal _opacity;
118 float _x;
119 QLabel* m_label;
120 QCheckBox* m_combo;
121 QPropertyAnimation* _anim = nullptr;
122 };
123}
Button(QWidget *parent=nullptr)
Constructs a Button with an optional parent widget.
A class that can subscribe to any number of Resources which will get updates when the Resource(s) hav...
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
The core String View class for the NDEVR API.
Definition StringView.h:58
QSize sizeHint() const override
Returns the recommended size for the toggle widget.
QSize minimumSizeHint() const override
Returns the minimum recommended size for the toggle widget.
Toggle(QWidget *parent=nullptr)
Constructs a Toggle with an optional parent widget.
int sliderWidth() const
Returns the width of the slider track in pixels.
Toggle(const TranslatedString &name, const std::function< void(Button *)> &on_click)
Constructs a Toggle with a label and click callback.
Toggle(const std::function< void(Button *)> &on_click)
Constructs a Toggle with a click callback.
void mouseReleaseEvent(QMouseEvent *) override
Handles mouse release to toggle the checked state.
void setOffset(float o)
Sets the horizontal offset of the slider knob and triggers a repaint.
Definition Toggle.h:89
void paintEvent(QPaintEvent *) override
Custom paint handler that draws the toggle slider in touch mode.
Toggle(const TranslatedString &name, const StringView &icon, Resource< bool > &on_click)
Constructs a Toggle bound to a boolean Resource.
Toggle(const TranslatedString &name, const StringView &icon, const std::function< void(Button *)> &on_click)
Constructs a Toggle with a label, icon, and click callback.
void setupToggle()
Performs initial configuration of the toggle appearance and behavior.
int spacing() const
Returns the spacing between the slider and the label in pixels.
float offset() const
Returns the current horizontal offset of the slider knob.
Definition Toggle.h:84
int sliderHeight() const
Returns the height of the slider track in pixels.
QRect sliderRect() const
Returns the bounding rectangle of the slider knob.
void onChecked(bool checked)
Slot invoked when the checked state changes, triggers the slide animation.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.