API Documentation
Loading...
Searching...
No Matches
Toggle.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: 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;
44 /**--------------------------------------------------------------------------------------------------
45 \brief A Button that toggles between on and off. In desktop mode this looks like a checkbox and in
46 touch mode has a distinct look and feel.
47 **/
49 {
50 Q_OBJECT
51 Q_PROPERTY(float offset READ offset WRITE setOffset)
52
53 public:
54 Toggle(QWidget* parent = nullptr);
55 Toggle(const std::function<void(Button*)>& on_click);
56 Toggle(const TranslatedString& name, const std::function<void(Button*)>& on_click);
57 Toggle(const TranslatedString& name, const String& icon, const std::function<void(Button*)>& on_click);
58 Toggle(const TranslatedString& name, const String& icon, Resource<bool>& on_click);
60 QSize sizeHint() const override;
61 QSize minimumSizeHint() const override;
62 float offset() const {
63 return _x;
64 }
65 void setOffset(float o) {
66 _x = o;
67 update();
68 }
69 protected:
71 void paintEvent(QPaintEvent*) override;
72 void mouseReleaseEvent(QMouseEvent*) override;
73 int sliderWidth() const;
74 int sliderHeight() const;
75 int spacing() const;
76 QRect sliderRect() const;
77 protected slots:
78 void onChecked(bool checked);
79 private:
80 qreal _opacity;
81 float _x;
82 QLabel* m_label;
83 QCheckBox* m_combo;
84 QPropertyAnimation* _anim = nullptr;
85 };
86}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:59
A core widget that allows the user to click one of many button types.
Definition Button.h:66
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
A class that can subscribe to any number of Resources which will get updates when the Resource(s) hav...
Definition ResourceListener.h:62
The core String class for the NDEVR API.
Definition String.h:69
A Button that toggles between on and off. In desktop mode this looks like a checkbox and in touch mod...
Definition Toggle.h:49
Toggle(const TranslatedString &name, const String &icon, Resource< bool > &on_click)
QRect sliderRect() const
Toggle(const TranslatedString &name, const String &icon, const std::function< void(Button *)> &on_click)
void setupToggle()
QSize minimumSizeHint() const override
void paintEvent(QPaintEvent *) override
int sliderHeight() const
QSize sizeHint() const override
Toggle(QWidget *parent=nullptr)
void onChecked(bool checked)
int sliderWidth() const
void setOffset(float o)
Definition Toggle.h:65
float offset() const
Definition Toggle.h:62
Toggle(const TranslatedString &name, const std::function< void(Button *)> &on_click)
void mouseReleaseEvent(QMouseEvent *) override
int spacing() const
Toggle(const std::function< void(Button *)> &on_click)
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Definition ACIColor.h:37