MauiKit Controls

controls.h
1
2
3#pragma once
4
5#include <QObject>
6#include <QQmlEngine>
7#include <QQmlComponent>
8#include <QQuickItem>
9
10/**
11 * @brief The Controls class.
12 *
13 * This object exposes a series of attached properties useful for the MauiKit controls as a sort of common set of metadata.
14 *
15 * @note This is mean to be used as an attached property. It can be consumed as `Maui.Controls`, for example, `Maui.Controls.showCSD`
16 */
17class Controls : public QObject
18{
20 QML_ELEMENT
21 QML_ATTACHED(Controls)
22 QML_UNCREATABLE("Cannot be created. Controls object is a set of metadata information to be attached")
23
24 /**
25 * A title text that can be attached to any control.
26 * @note Some controls depend on this property to be set in order show revelant information. For example, for the SplitViewItem, when requesting to close a view, the view can be referenced by the given title.
27 *
28 *
29 */
30 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
31
32 /**
33 * A subtitle text that can be attached to any control.
34 * This property can be used in the Menu type to set the subtitle in the header information.
35 *
36 * @image html controls_subtitle_menu.png "Menu with header information: title, subtitle and icon source"
37 */
38 Q_PROPERTY(QString subtitle READ subtitle WRITE setSubtitle NOTIFY subtitleChanged)
39
40 /**
41 * The icon name to be used in or by the widget.
42 */
43 Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged)
44
45 /**
46 * The text to be used as a badge for notification purposes.
47 * If this is left empty, then not badge will be shown.
48 *
49 * @image html controls_badge.png "Badge text notification on a few controls"
50 *
51 * Some of the controls that support this attached property include:
52 * - ToolButton
53 * - Button
54 * - ListBrowser
55 * - GridBrowser
56 * - SplitViewItem
57 * - TextField
58 * - TabButton
59 */
60 Q_PROPERTY(QString badgeText READ badgeText WRITE setBadgeText NOTIFY badgeTextChanged)
61
62 /**
63 * The color to be used as an indicator in the supported widgets.
64 * Supported widgets include:
65 * - TabButton
66 * - Button
67 * - Page
68 * - Badge
69 */
70 Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
71
72 /**
73 * The text to be shown in the tool-tip when hovering over the tab button representing the view.
74 */
75 Q_PROPERTY(QString toolTipText READ toolTipText WRITE setToolTipText NOTIFY toolTipTextChanged)
76
77 /**
78 * Whether a supported MauiKit control should display the window control buttons when using client side decorations.
79 * Some of the supported controls include:
80 * - Page
81 * - PageLayout
82 * - TabView
83 * - ToolBar
84 */
85 Q_PROPERTY(bool showCSD READ showCSD WRITE setShowCSD NOTIFY showCSDChanged)
86
87 /**
88 * Set a UI element hierarchy level. For example, in a page with two toolbars one could be `Level::Primary`, and the other one `Level::Secondary`, this will allow to better style the toolbars for differentiation.
89 * By default `Level::Primary` is assumed.
90 * @see Level
91 *
92 * @image html controls_level_toolbar.png "A primary and secondary toolbar"
93 *
94 * @code
95 * import QtQuick
96 import QtQuick.Controls
97 import org.mauikit.controls as Maui
98
99 Maui.ApplicationWindow
100 {
101 Maui.Page
102 {
103 anchors.fill: parent
104
105 Maui.Controls.showCSD: true
106 headBar.leftContent: Label
107 {
108 text: "Primary"
109 }
110
111 headerColumn: Maui.ToolBar
112 {
113 width: parent.width
114 Maui.Controls.level: Maui.Controls.Secondary
115
116 Label
117 {
118 text: "Secondary"
119 }
120 }
121 }
122 }
123 @endcode
124**/
125 Q_PROPERTY(Level level READ level WRITE setLevel NOTIFY levelChanged)
126
127 /**
128 * A property hint for UI elements to be styled as a flat surface, for example, without a background.
129 * Although some controls have this property implicitly available, some other controls do not, and thus this is the way to set it.
130 * By default this is set to false.
131 */
132 Q_PROPERTY(bool flat READ flat WRITE setFlat NOTIFY flatChanged)
133
134 /**
135 * Mark the supported widget in one of the given status, which will alterate its look.
136 * This can serve as a visual clue of an important state or action.
137 * @see Status
138 *
139 * Suported widgets include:
140 * - Button
141 * - MenuItem
142 *
143 * @image html controls_status.png "Button with different status"
144 *
145 * @code
146 * import QtQuick
147 import QtQuick.Controls
148 import org.mauikit.controls as Maui
149
150 Maui.ApplicationWindow
151 {
152
153 Maui.Page
154 {
155 anchors.fill: parent
156
157 Column
158 {
159 anchors.centerIn: parent
160 spacing: Maui.Style.space.big
161
162 Button
163 {
164 text: "Normal"
165 Maui.Controls.status: Maui.Controls.Normal
166 }
167
168 Button
169 {
170 text: "Positive"
171 Maui.Controls.status: Maui.Controls.Positive
172 }
173
174 Button
175 {
176 text: "Neutral"
177 Maui.Controls.status: Maui.Controls.Neutral
178 }
179
180 Button
181 {
182 text: "Negative"
183 Maui.Controls.status: Maui.Controls.Negative
184 }
185 }
186 }
187 }
188 * @endcode
189 **/
190 Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged)
191
192 /**
193 * Some controls might depend of a custom Component to be rendered. Some of those controls include:
194 * - Menu
195 * - ToolBar
196 *
197 * @note The Menu control depends on this custom property to set a custom menu header, instead of the default one that relies on a title, subtitle, and icon source.
198 *
199 * @image html controls_item_menu_header.png "A Menu with a custom header via `Maui.Controls.component` attached property"
200 */
201 Q_PROPERTY(QQmlComponent *component READ component WRITE setComponent NOTIFY componentChanged)
202 Q_PROPERTY(QQuickItem *item READ item WRITE setItem NOTIFY itemChanged)
203
204public:
205
206 enum Level
207 {
208 Undefined,
209 Primary,
210 Secondary
211 }; Q_ENUM(Level)
212
213 enum Status
214 {
215 Normal,
216 Positive,
217 Negative,
218 Neutral
219 }; Q_ENUM(Status)
220
221 explicit Controls(QObject *parent = nullptr);
222
223 static Controls *qmlAttachedProperties(QObject *object);
224
225 bool showCSD() const;
226 void setShowCSD(bool newShowCSD);
227
228 QString title() const;
229 void setTitle(const QString &title);
230
231 QString subtitle() const;
232 void setSubtitle(const QString &subtitle);
233
234 QString iconName() const;
235 void setIconName(const QString &newIconName);
236
237 QString badgeText() const;
238 void setBadgeText(const QString &newBadgeText);
239
240 QString toolTipText() const;
241 void setToolTipText(const QString &newToolTipText);
242
243 QString color() const;
244 void setColor(const QString &newColor);
245
246 Controls::Level level() const;
247 void setLevel(Level level);
248
249 bool flat() const;
250 void setFlat(bool value);
251
252 Controls::Status status() const;
253 void setStatus(Controls::Status status);
254
255 QQmlComponent *component() const;
256 void setComponent(QQmlComponent *component);
257
258 QQuickItem *item() const;
259 void setItem(QQuickItem *item);
260
262 void titleChanged();
263 void subtitleChanged();
264 void showCSDChanged();
265 void iconNameChanged();
266 void badgeTextChanged();
267 void toolTipTextChanged();
268 void colorChanged();
269 void levelChanged();
270 void flatChanged();
271 void statusChanged();
272 void itemChanged();
273 void componentChanged();
274
275private:
276 bool m_showCSD;
277 QString m_title;
278 QString m_subtitle;
279 QString m_iconName;
280 QString m_badgeText;
281 QString m_toolTipText;
282 QString m_color;
283 Controls::Level m_level = Controls::Level::Undefined;
284 bool m_flat;
285 Controls::Status m_status = Controls::Status::Normal;
286 QQuickItem *m_item = nullptr;
287 QQmlComponent *m_component = nullptr;
288};
289
290QML_DECLARE_TYPEINFO(Controls, QML_HAS_ATTACHED_PROPERTIES)
The Controls class.
Definition controls.h:18
QQmlComponent * component
Some controls might depend of a custom Component to be rendered.
Definition controls.h:201
QString toolTipText
The text to be shown in the tool-tip when hovering over the tab button representing the view.
Definition controls.h:75
QML_ELEMENTQString title
A title text that can be attached to any control.
Definition controls.h:30
QString iconName
The icon name to be used in or by the widget.
Definition controls.h:43
QString badgeText
The text to be used as a badge for notification purposes.
Definition controls.h:60
Status status
Mark the supported widget in one of the given status, which will alterate its look.
Definition controls.h:190
QString color
The color to be used as an indicator in the supported widgets.
Definition controls.h:70
QString subtitle
A subtitle text that can be attached to any control.
Definition controls.h:38
bool showCSD
Whether a supported MauiKit control should display the window control buttons when using client side ...
Definition controls.h:85
Level level
Set a UI element hierarchy level.
Definition controls.h:125
bool flat
A property hint for UI elements to be styled as a flat surface, for example, without a background.
Definition controls.h:132
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:17:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.