MauiKit Controls

style.h
1#pragma once
2
3#include <QObject>
4#include <QFont>
5#include <QColor>
6#include <QVariant>
7#include <QQmlEngine>
8#include <QFontMetrics>
9
10namespace MauiMan
11{
12class ThemeManager;
13class BackgroundManager;
14class AccessibilityManager;
15}
16
17/**
18 * @brief The Unit group properties.
19 * These properties are standard values meant to be used across the UI elements for a cohesive look and feel.
20 *
21 * @note This object can not be instantiated. It only exists as part of the Style::units implementation, which ca be accessed via the global Style singleton.
22 */
23class Units : public QObject
24{
26 Q_PROPERTY(uint gridUnit MEMBER m_gridUnit CONSTANT FINAL)
27 Q_PROPERTY(uint veryLongDuration MEMBER m_veryLongDuration CONSTANT FINAL)
28 Q_PROPERTY(uint longDuration MEMBER m_longDuration CONSTANT FINAL)
29 Q_PROPERTY(uint shortDuration MEMBER m_shortDuration CONSTANT FINAL)
30 Q_PROPERTY(uint veryShortDuration MEMBER m_veryShortDuration CONSTANT FINAL)
31 Q_PROPERTY(uint humanMoment MEMBER m_humanMoment CONSTANT FINAL)
32 Q_PROPERTY(uint toolTipDelay MEMBER m_toolTipDelay CONSTANT FINAL)
33
34public:
35 explicit Units(QObject *parent = nullptr);
36
37private:
38 QFontMetricsF m_fontMetrics;
39 uint m_gridUnit;
40 uint m_veryLongDuration;
41 uint m_longDuration;
42 uint m_shortDuration;
43 uint m_veryShortDuration;
44 uint m_humanMoment;
45 uint m_toolTipDelay;
46};
47
48/**
49 * @brief The sizes group for some Style properties, such as Style::iconSize, Style::space, etc.
50 *
51 * @note This object can not be instantiated. It only exists as part of some of the Style property implementations, which ca be accessed via the global Style singleton.
52 */
53class GroupSizes : public QObject
54{
56 Q_PROPERTY(uint tiny MEMBER m_tiny NOTIFY sizesChanged FINAL)
57 Q_PROPERTY(uint small MEMBER m_small NOTIFY sizesChanged FINAL)
58 Q_PROPERTY(uint medium MEMBER m_medium NOTIFY sizesChanged FINAL)
59 Q_PROPERTY(uint big MEMBER m_big NOTIFY sizesChanged FINAL)
60 Q_PROPERTY(uint large MEMBER m_large NOTIFY sizesChanged FINAL)
61 Q_PROPERTY(uint huge MEMBER m_huge NOTIFY sizesChanged FINAL)
62 Q_PROPERTY(uint enormous MEMBER m_enormous NOTIFY sizesChanged FINAL)
63
64public:
65 explicit GroupSizes(const uint tiny,const uint small, const uint medium, const uint big, const uint large, const uint huge, const uint enormous, QObject *parent = nullptr);
66 GroupSizes(QObject *parent = nullptr);
67
68 uint m_tiny;
69 uint m_small;
70 uint m_medium;
71 uint m_big;
72 uint m_large;
73 uint m_huge;
74 uint m_enormous;
75
77 void sizesChanged();
78};
79
80/**
81 * @brief The MauiKit Style preferences singleton object.
82 *
83 */
84class Style : public QObject
85{
87 QML_ELEMENT
88 QML_ATTACHED(Style)
89 QML_UNCREATABLE("Cannot be created Style")
90 Q_DISABLE_COPY(Style)
91
92 /**
93 * The standard height size for the toolbars, such as ToolBar, TabBar, etc. Usually this is used as the minimum height fo those bars.
94 * @note This property is read only.
95 */
96 Q_PROPERTY(uint toolBarHeight MEMBER m_toolBarHeight CONSTANT FINAL)
97
98 /**
99 * An alternative size for the tab bars, this is a bit smaller then the `toolBarHeight`.
100 * @see toolBarHeight
101 *
102 */
103 Q_PROPERTY(uint toolBarHeightAlt MEMBER m_toolBarHeightAlt CONSTANT FINAL)
104
105 /**
106 * The preferred radius for the border corners of the UI elements.
107 * @note This property is read only. It can only be modified from the MauiMan global preferences.
108 */
109 Q_PROPERTY(uint radiusV MEMBER m_radiusV NOTIFY radiusVChanged FINAL)
110
111 /**
112 * The preferred size for painting the icons in places, such as menus, buttons and delegates.
113 * @note This property is read only. It can only be modified from the MauiMan global preferences.
114 */
115 Q_PROPERTY(uint iconSize READ iconSize NOTIFY iconSizeChanged FINAL)
116
117 /**
118 * The standard size for the height of elements represented as a row. Such as items in lists.
119 * This can be used for keeping a coherent look, when an implicit height is not desired, or as the minimum height.
120 */
121 Q_PROPERTY(uint rowHeight MEMBER m_rowHeight CONSTANT FINAL)
122
123 /**
124 * An alternative height to the `rowHeight`, this size is a bit smaller.
125 */
126 Q_PROPERTY(uint rowHeightAlt MEMBER m_rowHeightAlt CONSTANT FINAL)
127
128 /**
129 * The preferred size for the margins in the browsing views, such as the ListBrowser and GridBrowser, but also for the margins in menus.
130 * @note This property is read only. It can only be modified from the MauiMan global preferences.
131 */
132 Q_PROPERTY(uint contentMargins MEMBER m_contentMargins NOTIFY contentMarginsChanged)
133
134 /**
135 * The preferred font size for the text labels in the UI elements.
136 * @note This property is read only. It can only be modified from the MauiMan global preferences.
137 */
138 Q_PROPERTY(uint defaultFontSize MEMBER m_defaultFontSize CONSTANT FINAL)
139
140 /**
141 * The preferred padding size for the UI elements, such a menu entries, buttons, bars, etc.
142 * The padding refers to the outer-space around the visible background area of the elements.
143 * @note This property is read only. It can only be modified from the MauiMan global preferences.
144 */
145 Q_PROPERTY(uint defaultPadding MEMBER m_defaultPadding NOTIFY defaultPaddingChanged)
146
147 /**
148 * The preferred spacing size between elements in rows or columns, etc.
149 * @note This property is read only. It can only be modified from the MauiMan global preferences.
150 */
151 Q_PROPERTY(uint defaultSpacing MEMBER m_defaultSpacing NOTIFY defaultSpacingChanged)
152
153 /**
154 * The preferred font for the text in labels.
155 * @note This property is read only. It can only be modified from the MauiMan global preferences.
156 */
157 Q_PROPERTY(QFont defaultFont MEMBER m_defaultFont NOTIFY defaultFontChanged)
158
159 /**
160 * The preferred font for titles and headers.
161 */
162 Q_PROPERTY(QFont h1Font MEMBER m_h1Font NOTIFY h1FontChanged)
163
164 /**
165 * The preferred font for subtitles.
166 */
167 Q_PROPERTY(QFont h2Font MEMBER m_h2Font NOTIFY h2FontChanged)
168
169 /**
170 * The preferred mono spaced font.
171 * @note This property is read only. It can only be modified from the MauiMan global preferences.
172 */
173 Q_PROPERTY(QFont monospacedFont MEMBER m_monospacedFont NOTIFY monospacedFontChanged)
174
175 /**
176 * The group of different standard font sizes for the MauiKit applications.
177 * @see GroupSizes
178 */
179 Q_PROPERTY(GroupSizes *fontSizes MEMBER m_fontSizes NOTIFY fontSizesChanged)
180
181 /**
182 * The group of different standard spacing values for consistency in the MauiKit apps.
183 * @see GroupSizes
184 */
185 Q_PROPERTY(GroupSizes *space MEMBER m_space CONSTANT FINAL)
186
187 /**
188 * The group of different standard icon sizes for consistency in the MauiKit apps.
189 * @see GroupSizes
190 * Values are the standard: 16, 22, 32 ,48, 64, 128 [pixels]
191 */
192 Q_PROPERTY(GroupSizes *iconSizes MEMBER m_iconSizes CONSTANT FINAL)
193
194 /**
195 * The standard units group. See the Units documentation for more information.
196 */
197 Q_PROPERTY(Units *units MEMBER m_units CONSTANT FINAL)
198
199 /**
200 * Sets the color to be used for highlighted, active, checked and such states of the UI elements.
201 * By default this color is set to the global preferences via MauiMan.
202 * This can be overridden by each application to a custom color. To reset it back to the system preference set the property to `undefined`.
203 */
204 Q_PROPERTY(QColor accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged FINAL RESET unsetAccentColor)
205
206 /**
207 * The source for picking up the application color palette when the style type is set to Style.Adaptive.
208 * The source can be an image URL, and QQC2 Image, or a QQC2 Item, or even an icon name.
209 * By default the source for this is set to the MauiMan wallpaper source preference.
210 */
211 Q_PROPERTY(QVariant adaptiveColorSchemeSource READ adaptiveColorSchemeSource WRITE setAdaptiveColorSchemeSource NOTIFY adaptiveColorSchemeSourceChanged RESET unsetAdaptiveColorSchemeSource)
212
213 /**
214 * The preferred style type for setting the color scheme of the application.
215 * @see StyleType
216 * By default this is set to the MauiMan global preference.
217 * It can be overridden by the application, and to reset it - back to the original system preference - by setting this to `undefined`.
218 */
219 Q_PROPERTY(StyleType styleType READ styleType WRITE setStyleType NOTIFY styleTypeChanged RESET unsetStyeType)
220
221 /**
222 * Whether special effects are desired. This can be tweaked in the MauiMan system preferences in cases where the resources need to be preserved.
223 * Consider using this property when using special effects in your applications.
224 * @note This property is read-only. It can only be modified from the MauiMan global preferences.
225 */
226 Q_PROPERTY(bool enableEffects READ enableEffects NOTIFY enableEffectsChanged FINAL)
227
228 /**
229 * The current system icon theme picked up by the user.
230 * @note This property is read-only. It can only be modified from the MauiMan global preferences.
231 * @warning This only works when using the Maui Shell ecosystem. There is not support for Plasma or GNOME desktops.
232 */
233 Q_PROPERTY(QString currentIconTheme READ currentIconTheme NOTIFY currentIconThemeChanged)
234
235 /**
236 * Whether the menu entries should display the icon image.
237 * @note This property is read-only. This is picked by from the QPA Qt Theme integration platform, so its default value will depend on the desktop shell being used.
238 */
239 Q_PROPERTY(bool menusHaveIcons READ menusHaveIcons CONSTANT FINAL)
240
241 /**
242 * The preferred scroll bars policy for displaying them or not.
243 * @note This property is read-only. This is picked by from the QPA Qt Theme integration platform, so its default value will depend on the desktop shell being used.
244 */
245 Q_PROPERTY(uint scrollBarPolicy READ scrollBarPolicy NOTIFY scrollBarPolicyChanged FINAL)
246
247 /**
248 * Whether the user desires for the application to play sounds or not.
249 * @note This property is read-only. It can only be modified from the MauiMan global preferences.
250 */
251 Q_PROPERTY(bool playSounds READ playSounds NOTIFY playSoundsChanged FINAL)
252
253 /**
254 * Whether the application window surface should be transparent and request the compositor to blur the background area of the window surface.
255 * By default this is set to `false`.
256 */
257 Q_PROPERTY(bool translucencyAvailable READ translucencyAvailable NOTIFY translucencyAvailableChanged)
258
259public:
260
261 /**
262 * @private
263 */
264 explicit Style(QObject *parent = nullptr);
265
266 /**
267 * @brief The different options for the color scheme style.
268 */
269 enum StyleType : uint
270 {
271 /**
272 * A light variant designed for Maui.
273 */
274 Light = 0,
275
276 /**
277 * A dark variant designed for Maui.
278 */
280
281 /**
282 * Picks the color scheme based on an source input, such as an image. The generated color palette determines if it is a dark or light scheme, and also its accent color.
283 */
285
286 /**
287 * Picks the colors from the system palette, usually from Plasma color-scheme files.
288 * @note Use this type when mixing MauiKit with Kirigami controls, so both frameworks pick up the color palette from the same source.
289 */
291
292 /**
293 * A fully black color palette with a full white accent color. This is might be useful as a accessibility enhance or for performance on E-Ink and AMOLED displays.
294 */
296
297 /**
298 * A fully white color palette with a true black accent color. This is the inverted version of the TrueBlack type.
299 */
301 }; Q_ENUM(StyleType)
302
303 /**
304 * @brief The possible scrollbar values
305 * The policy for showing the scroll bars. The possible values are:
306 * - 0 Always visible
307 * - 1 Visible when needed
308 * - 2 Auto Hide
309 * - 3 Always hidden
310 */
311 enum ScrollBarPolicy : uint
312 {
313 AlwaysOn =0,
314 AsNeeded,
315 AutoHide,
316 AlwaysOff
317}; Q_ENUM(ScrollBarPolicy)
318
319 /**
320 * @private
321 */
322 static Style *qmlAttachedProperties(QObject *object);
323
324 /**
325 * @private
326 */
327 static Style *instance();
328
329 /**
330 * @private
331 */
332 static QObject * qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine) {
333 Q_UNUSED(engine);
334 Q_UNUSED(scriptEngine);
335
336 return Style::instance();
337 }
338
340 void setAdaptiveColorSchemeSource(const QVariant &source);
341 void unsetAdaptiveColorSchemeSource();
342
343 QColor accentColor() const;
344 void setAccentColor(const QColor &color);
345 void unsetAccentColor();
346
347 StyleType styleType() const;
348 void setStyleType(const StyleType &type);
349 void unsetStyeType();
350
351 void setRadiusV(const uint &radius);
352
353 bool enableEffects() const;
354
355 uint iconSize() const;
356
358
359 bool menusHaveIcons() const;
360 bool playSounds() const;
361 uint scrollBarPolicy() const;
362
363 bool translucencyAvailable() const;
364 void setTranslucencyAvailable(const bool &value);
365
366public Q_SLOTS:
367 /**
368 * @brief Given a `size` as argument this function will return the best fitted icon size from the standard icon sizes.
369 * For example for the a size of 36, this function should return a size of 32.
370 */
371 int mapToIconSizes(const int &size);
372
373private:
374
375 QFont m_defaultFont;
376 QFont m_h1Font = QFont {};
377 QFont m_h2Font = QFont {};
378 QFont m_monospacedFont = QFont {};
379
380 GroupSizes *m_iconSizes;
381 GroupSizes *m_space;
382 GroupSizes *m_fontSizes;
383 Units *m_units;
384
385 uint m_defaultFontSize;
386
387 uint m_toolBarHeight = 42;
388 uint m_toolBarHeightAlt = 38;
389 uint m_radiusV = 4;
390 uint m_iconSize = 22;
391 uint m_rowHeight = 32;
392 uint m_rowHeightAlt = 28;
393
394 uint m_contentMargins;
395 uint m_defaultPadding;
396 uint m_defaultSpacing;
397
398 QColor m_accentColor;
399 bool m_accentColor_blocked = false;
400
401 QVariant m_adaptiveColorSchemeSource;
402 bool m_adaptiveColorSchemeSource_blocked = false;
403
404 StyleType m_styleType;
405 bool m_styleType_blocked = false;
406
407 MauiMan::ThemeManager *m_themeSettings;
408 MauiMan::BackgroundManager *m_backgroundSettings;
409 MauiMan::AccessibilityManager *m_accessibilitySettings;
410
411 bool m_enableEffects = true;
412 bool m_translucencyAvailable = false;
413
414 QString m_currentIconTheme;
415
416 void setFontSizes();
417 void styleChanged();
418
420 void defaultFontChanged();
421 void h1FontChanged();
422 void h2FontChanged();
423 void monospacedFontChanged();
424 void fontSizesChanged();
425
426 void adaptiveColorSchemeSourceChanged(QVariant source);
427 void accentColorChanged(QColor color);
428 void colorSchemeChanged();
429 void styleTypeChanged(StyleType type);
430 void radiusVChanged(uint radius);
431 void iconSizeChanged(uint size);
432 void enableEffectsChanged(bool enableEffects);
433 void defaultPaddingChanged();
434 void contentMarginsChanged();
435 void currentIconThemeChanged(QString currentIconTheme);
436 void defaultSpacingChanged();
437 void scrollBarPolicyChanged(uint);
438 void playSoundsChanged(bool);
439 void translucencyAvailableChanged(bool translucencyAvailable);
440};
441
442// QML_DECLARE_TYPEINFO(Style, QML_HAS_ATTACHED_PROPERTIES)
443
The sizes group for some Style properties, such as Style::iconSize, Style::space, etc.
Definition style.h:54
The MauiKit Style preferences singleton object.
Definition style.h:85
QFont defaultFont
The preferred font for the text in labels.
Definition style.h:157
QString currentIconTheme
The current system icon theme picked up by the user.
Definition style.h:233
uint rowHeight
The standard size for the height of elements represented as a row.
Definition style.h:121
uint rowHeightAlt
An alternative height to the rowHeight, this size is a bit smaller.
Definition style.h:126
QVariant adaptiveColorSchemeSource
The source for picking up the application color palette when the style type is set to Style....
Definition style.h:211
QFont h2Font
The preferred font for subtitles.
Definition style.h:167
uint iconSize
The preferred size for painting the icons in places, such as menus, buttons and delegates.
Definition style.h:115
uint radiusV
The preferred radius for the border corners of the UI elements.
Definition style.h:109
bool menusHaveIcons
Whether the menu entries should display the icon image.
Definition style.h:239
bool playSounds
Whether the user desires for the application to play sounds or not.
Definition style.h:251
bool enableEffects
Whether special effects are desired.
Definition style.h:226
uint contentMargins
The preferred size for the margins in the browsing views, such as the ListBrowser and GridBrowser,...
Definition style.h:132
uint defaultSpacing
The preferred spacing size between elements in rows or columns, etc.
Definition style.h:151
uint toolBarHeightAlt
An alternative size for the tab bars, this is a bit smaller then the toolBarHeight.
Definition style.h:103
GroupSizes * fontSizes
The group of different standard font sizes for the MauiKit applications.
Definition style.h:179
StyleType
The different options for the color scheme style.
Definition style.h:270
@ TrueBlack
A fully black color palette with a full white accent color.
Definition style.h:295
@ Inverted
A fully white color palette with a true black accent color.
Definition style.h:300
@ Light
A light variant designed for Maui.
Definition style.h:274
@ Dark
A dark variant designed for Maui.
Definition style.h:279
@ Auto
Picks the colors from the system palette, usually from Plasma color-scheme files.
Definition style.h:290
@ Adaptive
Picks the color scheme based on an source input, such as an image.
Definition style.h:284
Units * units
The standard units group.
Definition style.h:197
uint scrollBarPolicy
The preferred scroll bars policy for displaying them or not.
Definition style.h:245
QFont monospacedFont
The preferred mono spaced font.
Definition style.h:173
QML_ELEMENTuint toolBarHeight
The standard height size for the toolbars, such as ToolBar, TabBar, etc.
Definition style.h:96
int mapToIconSizes(const int &size)
Given a size as argument this function will return the best fitted icon size from the standard icon s...
Definition style.cpp:375
QFont h1Font
The preferred font for titles and headers.
Definition style.h:162
GroupSizes * iconSizes
The group of different standard icon sizes for consistency in the MauiKit apps.
Definition style.h:192
uint defaultFontSize
The preferred font size for the text labels in the UI elements.
Definition style.h:138
uint defaultPadding
The preferred padding size for the UI elements, such a menu entries, buttons, bars,...
Definition style.h:145
GroupSizes * space
The group of different standard spacing values for consistency in the MauiKit apps.
Definition style.h:185
StyleType styleType
The preferred style type for setting the color scheme of the application.
Definition style.h:219
bool translucencyAvailable
Whether the application window surface should be transparent and request the compositor to blur the b...
Definition style.h:257
QColor accentColor
Sets the color to be used for highlighted, active, checked and such states of the UI elements.
Definition style.h:204
The Unit group properties.
Definition style.h:24
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:19 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.