MauiKit Controls

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

KDE's Doxygen guidelines are available online.