API Documentation
Loading...
Searching...
No Matches
Button.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: Button
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/TranslatedString.h>
35#include <NDEVR/RGBColor.h>
36#include <NDEVR/TimeSpan.h>
37#include <QToolButton>
38#include <functional>
39#include <QEvent>
40#include <QPointer>
41#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
42typedef QEvent ButtonEnterEvent;
43#else
44typedef QEnterEvent ButtonEnterEvent;
45#endif
46class QStylePainter;
47class QStyleOptionToolButton;
48class QPushButton;
49namespace NDEVR
50{
51 class ButtonDialog;
52 class QTResourceListener;
53 enum class TooltipType;
54 template<class t_type>
55 class Resource;
56 template<class t_type>
58 struct GenericOption;
59 class NDEVR_WIDGETS_API Button : public QToolButton
60 {
61 friend class HoverButtonIconWatch;
62 Q_OBJECT
63 public:
65 {
66 e_large
67 , e_medium
68 , e_medium_centered
69 , e_small
70 , e_circular
71 , e_circular_small
72 , e_push_button
74 };
75 public:
76 Button(QWidget* parent = nullptr);
77 Button(ButtonState state, QWidget* parent = nullptr);
78 Button(const TranslatedString& name, const String& icon = "", QWidget* parent = nullptr);
79 Button(const std::function<void(Button*)>& on_click, QWidget* parent = nullptr);
80 Button(const TranslatedString& name, const std::function<void(Button*)>& on_click, QWidget* parent = nullptr);
81 Button(const TranslatedString& name, const String& icon, const std::function<void(Button*)>& on_click, QWidget* parent = nullptr);
82 Button(const TranslatedString& name, const String& icon, TooltipType tooltip, const std::function<void(Button*)>& on_click, QWidget* parent = nullptr);
83 ~Button();
84 void paintEvent(QPaintEvent *event) override;
85 void setAlignment(Qt::Alignment m_alignment);
86 void setup(const TranslatedString& name, const String& icon, const std::function<void(Button*)>& on_click);
87 void setup(const TranslatedString& name, const String& icon, TooltipType tooltip, const std::function<void(Button*)>& on_click);
88 void setup(const TranslatedString& name, const String& icon, Resource<bool>& checked_var);
89 void setup(GenericOption& checked_var);
90 void setup(ApplicationOption<bool>& checked_var);
91 void setup(const TranslatedString& name, const String& icon, ApplicationOption<bool>& checked_var);
92 int styleDefaultIconSize() const;
93 int scaledIconSize() const;
94 void setToolTip(TooltipType type);
95 void setToolTip(const QString& tip);
96 void setButtonState(ButtonState state);
97 void showPopupMenu(QWidget* widget, bool is_popup = true);
98 bool requestButtonState(ButtonState state);
99 void requestFixedState(bool fixed_state);
100 ButtonState buttonState() const { return m_state; }
101 void setFunction(const std::function<void(Button*)>& on_click) { m_on_click = on_click; }
102 void setHoverFunction(const std::function<void(Button*, bool hovering)>& on_hover) { m_on_hover = on_hover; }
103 void setPressFunction(const std::function<void(Button*, bool hovering)>& on_press) { m_on_press = on_press; }
104 void enterEvent(ButtonEnterEvent* e) override;
105 void leaveEvent(QEvent* e) override;
106 void setMargin(uint04 margin);
107 void setIconSize(int size);
108 void setProgressPercent(fltp04 progress);
109 bool event(QEvent* e) override;
110 void setIconSizeMultiplier(fltp04 icon_size_multiplier);
111 void setHoverIconSizeMultiplier(fltp04 icon_size_multiplier);
112 void setTitle(const TranslatedString& title);
113 void setText(const QString &text);
114 const TranslatedString& title() const;
115 const String& iconName() const;
116 void setIconName(const String& icon);
117 void setIcon(const QIcon& icon);
118 void setHoverIconName(const String& icon);
119 void setCheckedIconName(const String& icon);
120 bool eventFilter(QObject* watched, QEvent* event) override;
121 void setToolTip(const TranslatedString& tooltip);
122 void setDisabledToolTip(const TranslatedString& tooltip);
123 void setToolTip(const TranslatedString& enabled_tooltip, const TranslatedString& disabled_tooltip);
124 void setFlat(bool is_flat);
125 void setButtonDialog(ButtonDialog* dialog);
126 void setSound(const String& sound);
127 void setIgnoreClicks(bool ignore_clicks) { m_ignore_clicks = ignore_clicks; }
128 void copyButtonFrom(Button* button);
129 void setBackgroundOpacity(fltp04 background_opacity);
130 void setMenuDialog(QWidget* widget);
131 void setIconColor(const RGBColor& color);
132 void setBackgroundColor(const RGBColor& color, bool update_foreground = true);
133 void clearBackgroundColor();
134 void setFocusOnPress(bool focus_on_press);
135 void setAutoDefault(bool is_auto_default);
136 void setDefault(bool is_default);
137 void setCheckable(bool checkable);
138 void setChecked(bool checked);
139 QSize sizeHint() const override;
140 QSize minimumSizeHint() const override;
141 void virtualMouseEvent(QEvent::Type event);
142 void setFontMultiplier(fltp04 font_multiplier);
143 void setBold(bool is_bold);
144 void setMenu(QMenu* menu);
145 void setClickCooldown(const TimeSpan& span);
146 QMenu* menu() const;
147 protected slots:
148 void onButtonClickSlot();
149 void onButtonPressSlot();
150 void onButtonReleaseSlot();
151 protected:
152 QString autoWrapText(const QFontMetrics& metrics);
153 void updateTooltip();
154 void updateText();
155 void mouseReleaseEvent(QMouseEvent*) override;
156 void mousePressEvent(QMouseEvent*) override;
157 bool ignorePress() const;
158 void setup();
159 void _setIcon(const String & icon, bool force = false);
160 void updateFont();
161 void _defaultRender(QStylePainter* p, QStyleOptionToolButton* tool_button, QIcon::State state, QIcon::Mode mode, bool draw_backgound, bool is_default);
162 protected:
163 std::function<void(Button*)> m_on_click = nullptr;
164 std::function<void(Button*, bool hovering)> m_on_hover = nullptr;
165 std::function<void(Button*, bool pressing)> m_on_press = nullptr;
166 QTResourceListener* m_icon_theme_listener = nullptr;
167 ButtonDialog* m_dialog = nullptr;
168 QPointer<QWidget> m_menu_dialog = nullptr;
177 Time m_last_click_time = Time(0);
178 TimeSpan m_click_cooldown = TimeSpan(0.1);
179 fltp04 m_icon_size_multiplier = 1.0f;
181 fltp04 m_hover_icon_size_multiplier = Constant<fltp04>::NaN;
183 fltp04 m_background_opacity = 1.0f;
184 ButtonState m_state = ButtonState::e_large;
185 bool m_ignore_clicks = false;
186 bool m_fixed_state_requested = false;
187 bool m_has_custom_background_color = false;
188 bool m_focus_on_press = true;
189 Qt::Alignment m_alignment;
191
192 QPushButton* m_push_button = nullptr;
193 bool m_is_default_button = false;
194 bool m_is_auto_default_button = false;
195 fltp04 m_font_multiplier = 1.0f;
196 bool m_is_bold = false;
197 public:
199 };
200}
QEnterEvent ButtonEnterEvent
Definition Button.h:44
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:81
The default object to store data of any type that should persist through sessions of the application.
Definition Button.h:57
Definition ButtonDialog.h:41
Definition Button.h:60
RGBColor m_icon_color
Definition Button.h:190
void setFunction(const std::function< void(Button *)> &on_click)
Definition Button.h:101
TranslatedString m_enabled_tooltip
Definition Button.h:171
String m_hover_icon
Definition Button.h:174
Qt::Alignment m_alignment
Definition Button.h:189
TranslatedString m_title
Definition Button.h:169
String m_icon
Definition Button.h:172
void setPressFunction(const std::function< void(Button *, bool hovering)> &on_press)
Definition Button.h:103
void setIgnoreClicks(bool ignore_clicks)
Definition Button.h:127
String m_checked_icon
Definition Button.h:175
void setHoverFunction(const std::function< void(Button *, bool hovering)> &on_hover)
Definition Button.h:102
ButtonState buttonState() const
Definition Button.h:100
ButtonState
Definition Button.h:65
TranslatedString m_disabled_tooltip
Definition Button.h:170
static String s_default_sound
Definition Button.h:198
String m_current_icon
Definition Button.h:173
String m_sound
Definition Button.h:176
Definition QTTools.h:183
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
Definition Toggle.h:41
Definition String.h:40
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition TimeSpan.h:40
Definition TranslatedString.h:9
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
TooltipType
Definition TooltipTextManager.h:41
Definition BaseValues.hpp:272
Definition GenericOptions.h:53