MauiMan

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

KDE's Doxygen guidelines are available online.