MauiMan

thememanager.h
1#pragma once
2
3#include <QObject>
4#include <QString>
5#include <QFont>
6
7#include "mauiman_export.h"
8#include "mauimanutils.h"
9
10class QDBusInterface;
11
12/**
13 * @brief The MauiMan name-space contains all of the available modules for configuring the Maui Applications and Shell properties.
14 * The properties are exposed for the user, developer and distributor to tweak.
15 */
16namespace MauiMan
17{
18
19 class SettingsStore;
20
21 /**
22 * @brief The ThemeManager class
23 * Helpful for third parties to connect to property changes from the Theme module setting changes.
24 *
25 * @note Note that the properties can be reset back to their default values by using the `undefined` value from QML, or using the reset methods accordingly.
26 *
27 * The preferences have a set of default values, however the values used will be the ones present in the conf file. When a property is reset, then the default value will be written to the conf file.
28 */
29 class MAUIMAN_EXPORT ThemeManager : public QObject
30 {
32 /**
33 * The style type for the color scheme. The possible values are:
34 * - 0 Light
35 * - 1 Dark
36 * - 2 Adaptive
37 * - 3 Custom (from the plasma color-scheme file preferences)
38 * - 4 True Black
39 * - 5 Inverted (True White)
40 */
41 Q_PROPERTY(int styleType READ styleType WRITE setStyleType NOTIFY styleTypeChanged)
42
43 /**
44 * The preferred accent color used for the highlighted and checked states.
45 */
46 Q_PROPERTY(QString accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged RESET resetAccentColor)
47
48 /**
49 * The preferred icon theme. This preference is only valid when using the Maui Shell session.
50 */
51 Q_PROPERTY(QString iconTheme READ iconTheme WRITE setIconTheme NOTIFY iconThemeChanged)
52
53 /**
54 * The preferred theme for the CSD window control buttons. The list of available options depends on the installed themes. For more information on this refer to the MauiKit CSDControls documentation.
55 */
56 Q_PROPERTY(QString windowControlsTheme READ windowControlsTheme WRITE setWindowControlsTheme NOTIFY windowControlsThemeChanged)
57
58 /**
59 * Whether to use client side decorations (CSD) for the applications.
60 * By default this is set to `true`
61 */
62 Q_PROPERTY(bool enableCSD READ enableCSD WRITE setEnableCSD NOTIFY enableCSDChanged)
63
64 /**
65 * The corner border radius of the UI elements, also affects the radius of the CSD window corners.
66 */
67 Q_PROPERTY(uint borderRadius READ borderRadius WRITE setBorderRadius NOTIFY borderRadiusChanged RESET resetBorderRadius)
68
69 /**
70 * The preferred size of the icons in the buttons, menu entries and other elements.
71 */
72 Q_PROPERTY(uint iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged RESET resetIconSize)
73
74 /**
75 * The preferred padding size for the UI elements, such as buttons, tool bars, menu entries, etc.
76 */
77 Q_PROPERTY(uint paddingSize READ paddingSize WRITE setPaddingSize NOTIFY paddingSizeChanged RESET resetPaddingSize)
78
79 /**
80 * The preferred margin size around views.
81 */
82 Q_PROPERTY(uint marginSize READ marginSize WRITE setMarginSize NOTIFY marginSizeChanged RESET resetMarginSize)
83
84 /**
85 * The preferred spacing size between elements in a row or column, such as lists or browsing elements.
86 */
87 Q_PROPERTY(uint spacingSize READ spacingSize WRITE setSpacingSize NOTIFY spacingSizeChanged RESET resetSPacingSize)
88
89 /**
90 * Whether the user prefers for the system to have visual effects, such as animations, blur, etc.
91 */
92 Q_PROPERTY(bool enableEffects READ enableEffects WRITE setEnableEffects NOTIFY enableEffectsChanged)
93
94 /**
95 * The preferred default font, for most part of the UI.
96 */
97 Q_PROPERTY(QString defaultFont READ defaultFont WRITE setDefaultFont NOTIFY defaultFontChanged RESET resetDefaultFont)
98
99 /**
100 * The preferred small font, for details.
101 */
102 Q_PROPERTY(QString smallFont READ smallFont WRITE setSmallFont NOTIFY smallFontChanged RESET resetSmallFont)
103
104 /**
105 * The preferred mono spaced font, for example the one used in console terminals, or in text editors.
106 */
107 Q_PROPERTY(QString monospacedFont READ monospacedFont WRITE setMonospacedFont NOTIFY monospacedFontChanged RESET resetMonospacedFont)
108
109 /**
110 * The preferred color scheme to be used when the `styleType` is set to Custom.
111 */
112 Q_PROPERTY(QString customColorScheme READ customColorScheme WRITE setCustomColorScheme NOTIFY customColorSchemeChanged)
113
114 /**
115 * Allow third party styles for QtQiUickControls. By default this is set to `false`. MauiKit-Style is the best fitted style to be used with Maui Apps, if you want to use a custom style, this needs to be dedicated, since existing styles won't look good with the MauiKit custom controls.
116 */
117 Q_PROPERTY(bool allowCustomStyling READ allowCustomStyling WRITE setAllowCustomStyling NOTIFY allowCustomStylingChanged)
118
119 public:
120
121 /**
122 * @brief The Theme module default values
123 */
125 {
126 /**
127 * @private
128 */
129 static int preferredStyleType()
130 {
131
132 #ifdef Q_OS_ANDROID
133 return 1;
134 #endif
135 #ifdef Q_OS_LINUX
137 {
138 return 3; //if it is plasma or other session use the system color scheme by setting the style to 3=auto
139 }
140 #endif
141 return 0;
142 }
143
144 /**
145 * @private
146 */
147 static QString getDefaultFont()
148 {
149 QFont font {QStringLiteral("Noto Sans"), 10, QFont::Normal};
151 font.setStyle(QFont::StyleNormal);
152 font.setStyleName(QStringLiteral("Regular"));
153 return font.toString();
154 }
155
156 /**
157 * @private
158 */
159 static QString getSmallFont()
160 {
161 QFont font {QStringLiteral("Noto Sans"), 8, QFont::Normal};
163 font.setStyle(QFont::StyleNormal);
164 font.setStyleName(QStringLiteral("Regular"));
165
166 return font.toString();
167 }
168
169 /**
170 * @private
171 */
172 static QString getMonospacedFont()
173 {
174 QFont font {QStringLiteral("Hack"), 10, QFont::Normal};
176 font.setStyle(QFont::StyleNormal);
177 font.setStyleName(QStringLiteral("Regular"));
178
179 return font.toString();
180 }
181
182 static inline const int styleType = ThemeManager::DefaultValues::preferredStyleType();
183 static inline const QString accentColor = QStringLiteral("#26c6da");
184 static inline const QString iconTheme = QStringLiteral("Luv");
185 static inline const QString windowControlsTheme = QStringLiteral("Nitrux");
186 static inline const bool enableCSD = true;
187 static inline const uint borderRadius = 6;
188 static inline const uint iconSize = 16;
189 static inline const bool enableEffects = true;
190 static inline const uint paddingSize = 6;
191 static inline const uint marginSize = 6;
192 static inline const uint spacingSize = 6;
193 static inline const QString defaultFont = getDefaultFont();
194 static inline const QString smallFont = getSmallFont();
195 static inline const QString monospacedFont = getMonospacedFont();
196 static inline const QString customColorScheme = QStringLiteral("Nitrux");
197 static inline const bool allowCustomStyling = false;
198 };
199
200 explicit ThemeManager(QObject * parent = nullptr);
201
202 int styleType() const;
203 void setStyleType(int newStyleType);
204
205 const QString &accentColor() const;
206 void setAccentColor(const QString &newAccentColor);
207 void resetAccentColor();
208
209 const QString &iconTheme() const;
210 void setIconTheme(const QString &newIconTheme);
211
212 const QString &windowControlsTheme() const;
213 void setWindowControlsTheme(const QString &newWindowControlsTheme);
214
215 bool enableCSD() const;
216 void setEnableCSD(bool enableCSD);
217
218 uint borderRadius() const;
219 void setBorderRadius(uint newBorderRadius);
220 void resetBorderRadius();
221
222 uint iconSize() const;
223 void setIconSize(uint newIconSize);
224 void resetIconSize();
225
226 bool enableEffects() const;
227 void setEnableEffects(bool enableEffects);
228
229 uint paddingSize() const;
230 void setPaddingSize(uint paddingSize);
231 void resetPaddingSize();
232
233 uint marginSize() const;
234 void setMarginSize(uint marginSize);
235 void resetMarginSize();
236
237 uint spacingSize() const;
238 void setSpacingSize(uint spacingSize);
239 void resetSPacingSize();
240
241 QString defaultFont() const;
242 void setDefaultFont(const QString &defaultFont);
243 void resetDefaultFont();
244
245 QString smallFont() const;
246 void setSmallFont(const QString &smallFont);
247 void resetSmallFont();
248
249 QString monospacedFont() const;
250 void setMonospacedFont(const QString &monospacedFont);
251 void resetMonospacedFont();
252
254 void setCustomColorScheme(const QString &customColorScheme);
255
256 bool allowCustomStyling() const;
257 void setAllowCustomStyling(bool value);
258
259 private Q_SLOTS:
260 void onStyleTypeChanged(const int &newStyleType);
261 void onAccentColorChanged(const QString &newAccentColor);
262 void onWindowControlsThemeChanged(const QString &newWindowControlsTheme);
263 void onIconThemeChanged(const QString &newIconTheme);
264 void onEnableCSDChanged(const bool &enableCSD);
265 void onBorderRadiusChanged(const uint &radius);
266 void onIconSizeChanged(const uint &size);
267 void onPaddingSizeChanged(const uint &paddingSize);
268 void onMarginSizeChanged(const uint &marginSize);
269 void onSpacingSizeChanged(const uint &spacingSize);
270 void onEnableEffectsChanged(bool enableEffects);
271 void onDefaultFontChanged(const QString &font);
272 void onSmallFontChanged(const QString &font);
273 void onMonospacedFontChanged(const QString &font);
274 void onCustomColorSchemeChanged(const QString &scheme);
275
276 Q_SIGNALS:
277 void styleTypeChanged(int styleType);
278 void accentColorChanged(QString accentColor);
279 void iconThemeChanged(QString iconTheme);
280 void windowControlsThemeChanged(QString windowControlsTheme);
281 void enableCSDChanged(bool enableCSD);
282 void borderRadiusChanged(uint radius);
283 void iconSizeChanged(uint size);
284 void enableEffectsChanged(bool enableEffects);
285 void paddingSizeChanged(uint paddingSize);
286 void marginSizeChanged(uint marginSize);
287 void spacingSizeChanged(uint spacingSize);
288 void defaultFontChanged(QString defaultFont);
289 void smallFontChanged(QString smallFont);
290 void monospacedFontChanged(QString monospacedFont);
291 void customColorSchemeChanged(QString customColorScheme);
292 void allowCustomStyling(bool customStyling);
293
294 private:
295 #if !defined Q_OS_ANDROID
296 QDBusInterface *m_interface = nullptr;
297 #endif
298
299 MauiMan::SettingsStore *m_settings;
300
301 int m_styleType = ThemeManager::DefaultValues::styleType;
302 QString m_accentColor = ThemeManager::DefaultValues::accentColor;
303 QString m_iconTheme = ThemeManager::DefaultValues::iconTheme;
304 QString m_windowControlsTheme = ThemeManager::DefaultValues::windowControlsTheme;
305 bool m_enableCSD = ThemeManager::DefaultValues::enableCSD;
306 uint m_borderRadius = ThemeManager::DefaultValues::borderRadius;
307 uint m_iconSize = ThemeManager::DefaultValues::iconSize;
308 uint m_paddingSize = ThemeManager::DefaultValues::paddingSize;
309 uint m_marginSize = ThemeManager::DefaultValues::marginSize;
310 uint m_spacingSize = ThemeManager::DefaultValues::spacingSize;
311 bool m_enableEffects = ThemeManager::DefaultValues::enableEffects;
312 QString m_defaultFont = MauiMan::ThemeManager::DefaultValues::defaultFont;
313 QString m_smallFont = MauiMan::ThemeManager::DefaultValues::smallFont;
314 QString m_monospacedFont = MauiMan::ThemeManager::DefaultValues::monospacedFont;
315 QString m_customColorScheme = MauiMan::ThemeManager::DefaultValues::customColorScheme;
316 bool m_allowCustomStyling = MauiMan::ThemeManager::DefaultValues::allowCustomStyling;
317
318 void sync(const QString &key, const QVariant &value);
319 void setConnections();
320 void loadSettings();
321
322 };
323}
324
static bool isMauiSession()
Whether the current desktop environment session is running Maui Shell.
The SettingsStore class Allows to store and read settings for MauiMan from the local conf file.
bool allowCustomStyling
Allow third party styles for QtQiUickControls.
QString monospacedFont
The preferred mono spaced font, for example the one used in console terminals, or in text editors.
QString iconTheme
The preferred icon theme.
uint borderRadius
The corner border radius of the UI elements, also affects the radius of the CSD window corners.
QString smallFont
The preferred small font, for details.
bool enableEffects
Whether the user prefers for the system to have visual effects, such as animations,...
QString accentColor
The preferred accent color used for the highlighted and checked states.
QString defaultFont
The preferred default font, for most part of the UI.
uint paddingSize
The preferred padding size for the UI elements, such as buttons, tool bars, menu entries,...
uint marginSize
The preferred margin size around views.
int styleType
The style type for the color scheme.
QString windowControlsTheme
The preferred theme for the CSD window control buttons.
QString customColorScheme
The preferred color scheme to be used when the styleType is set to Custom.
bool enableCSD
Whether to use client side decorations (CSD) for the applications.
uint spacingSize
The preferred spacing size between elements in a row or column, such as lists or browsing elements.
uint iconSize
The preferred size of the icons in the buttons, menu entries and other elements.
The MauiMan name-space contains all of the available modules for configuring the Maui Applications an...
void setStyleHint(StyleHint hint, StyleStrategy strategy)
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
The Theme module default values.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 11:58:12 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.