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
204 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
205
206public:
207
208 enum Level
209 {
210 Undefined,
211 Primary,
212 Secondary
213 }; Q_ENUM(Level)
214
215 enum Status
216 {
217 Normal,
218 Positive,
219 Negative,
220 Neutral
221 }; Q_ENUM(Status)
222
223 explicit Controls(QObject *parent = nullptr);
224
225 static Controls *qmlAttachedProperties(QObject *object);
226
227 bool showCSD() const;
228 void setShowCSD(bool newShowCSD);
229
230 QString title() const;
231 void setTitle(const QString &title);
232
233 QString subtitle() const;
234 void setSubtitle(const QString &subtitle);
235
236 QString iconName() const;
237 void setIconName(const QString &newIconName);
238
239 QString badgeText() const;
240 void setBadgeText(const QString &newBadgeText);
241
242 QString toolTipText() const;
243 void setToolTipText(const QString &newToolTipText);
244
245 QString color() const;
246 void setColor(const QString &newColor);
247
248 Controls::Level level() const;
249 void setLevel(Level level);
250
251 bool flat() const;
252 void setFlat(bool value);
253
254 Controls::Status status() const;
255 void setStatus(Controls::Status status);
256
257 QQmlComponent *component() const;
258 void setComponent(QQmlComponent *component);
259
260 QQuickItem *item() const;
261 void setItem(QQuickItem *item);
262
263 void setOrientation(Qt::Orientation orientation);
264 Qt::Orientation orientation() const;
265
267 void titleChanged();
268 void subtitleChanged();
269 void showCSDChanged();
270 void iconNameChanged();
271 void badgeTextChanged();
272 void toolTipTextChanged();
273 void colorChanged();
274 void levelChanged();
275 void flatChanged();
276 void statusChanged();
277 void itemChanged();
278 void componentChanged();
279 void orientationChanged();
280
281private:
282 bool m_showCSD;
283 QString m_title;
284 QString m_subtitle;
285 QString m_iconName;
286 QString m_badgeText;
287 QString m_toolTipText;
288 QString m_color;
289 Controls::Level m_level = Controls::Level::Undefined;
290 bool m_flat;
291 Controls::Status m_status = Controls::Status::Normal;
292 QQuickItem *m_item = nullptr;
293 QQmlComponent *m_component = nullptr;
294 Qt::Orientation m_orientation = Qt::Orientation::Vertical;
295};
296
297QML_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
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 31 2025 12:11:16 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.