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 {
31 Q_OBJECT
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 public:
115
116 /**
117 * @brief The Theme module default values
118 */
120 {
121 /**
122 * @private
123 */
124 static int preferredStyleType()
125 {
126
127 #ifdef Q_OS_ANDROID
128 return 1;
129 #endif
130 #ifdef Q_OS_LINUX
132 {
133 return 3; //if it is plasma or other session use the system color scheme by setting the style to 3=auto
134 }
135 #endif
136 return 0;
137 }
138
139 /**
140 * @private
141 */
142 static QString getDefaultFont()
143 {
144 QFont font {QStringLiteral("Noto Sans"), 10, QFont::Normal};
146 font.setStyle(QFont::StyleNormal);
147 font.setStyleName(QStringLiteral("Regular"));
148 return font.toString();
149 }
150
151 /**
152 * @private
153 */
154 static QString getSmallFont()
155 {
156 QFont font {QStringLiteral("Noto Sans"), 8, QFont::Normal};
158 font.setStyle(QFont::StyleNormal);
159 font.setStyleName(QStringLiteral("Regular"));
160
161 return font.toString();
162 }
163
164 /**
165 * @private
166 */
167 static QString getMonospacedFont()
168 {
169 QFont font {QStringLiteral("Hack"), 10, QFont::Normal};
171 font.setStyle(QFont::StyleNormal);
172 font.setStyleName(QStringLiteral("Regular"));
173
174 return font.toString();
175 }
176
177 static inline const int styleType = ThemeManager::DefaultValues::preferredStyleType();
178 static inline const QString accentColor = QStringLiteral("#26c6da");
179 static inline const QString iconTheme = QStringLiteral("Luv");
180 static inline const QString windowControlsTheme = QStringLiteral("Nitrux");
181 static inline const bool enableCSD = true;
182 static inline const uint borderRadius = 6;
183 static inline const uint iconSize = 16;
184 static inline const bool enableEffects = true;
185 static inline const uint paddingSize = 6;
186 static inline const uint marginSize = 6;
187 static inline const uint spacingSize = 6;
188 static inline const QString defaultFont = getDefaultFont();
189 static inline const QString smallFont = getSmallFont();
190 static inline const QString monospacedFont = getMonospacedFont();
191 static inline const QString customColorScheme = QStringLiteral("Nitrux");
192 };
193
194 explicit ThemeManager(QObject * parent = nullptr);
195
196 int styleType() const;
197 void setStyleType(int newStyleType);
198
199 const QString &accentColor() const;
200 void setAccentColor(const QString &newAccentColor);
201 void resetAccentColor();
202
203 const QString &iconTheme() const;
204 void setIconTheme(const QString &newIconTheme);
205
206 const QString &windowControlsTheme() const;
207 void setWindowControlsTheme(const QString &newWindowControlsTheme);
208
209 bool enableCSD() const;
210 void setEnableCSD(bool enableCSD);
211
212 uint borderRadius() const;
213 void setBorderRadius(uint newBorderRadius);
214 void resetBorderRadius();
215
216 uint iconSize() const;
217 void setIconSize(uint newIconSize);
218 void resetIconSize();
219
220 bool enableEffects() const;
221 void setEnableEffects(bool enableEffects);
222
223 uint paddingSize() const;
224 void setPaddingSize(uint paddingSize);
225 void resetPaddingSize();
226
227 uint marginSize() const;
228 void setMarginSize(uint marginSize);
229 void resetMarginSize();
230
231 uint spacingSize() const;
232 void setSpacingSize(uint spacingSize);
233 void resetSPacingSize();
234
235 QString defaultFont() const;
236 void setDefaultFont(const QString &defaultFont);
237 void resetDefaultFont();
238
239 QString smallFont() const;
240 void setSmallFont(const QString &smallFont);
241 void resetSmallFont();
242
243 QString monospacedFont() const;
244 void setMonospacedFont(const QString &monospacedFont);
245 void resetMonospacedFont();
246
247 QString customColorScheme() const;
248 void setCustomColorScheme(const QString &customColorScheme);
249
250 private Q_SLOTS:
251 void onStyleTypeChanged(const int &newStyleType);
252 void onAccentColorChanged(const QString &newAccentColor);
253 void onWindowControlsThemeChanged(const QString &newWindowControlsTheme);
254 void onIconThemeChanged(const QString &newIconTheme);
255 void onEnableCSDChanged(const bool &enableCSD);
256 void onBorderRadiusChanged(const uint &radius);
257 void onIconSizeChanged(const uint &size);
258 void onPaddingSizeChanged(const uint &paddingSize);
259 void onMarginSizeChanged(const uint &marginSize);
260 void onSpacingSizeChanged(const uint &spacingSize);
261 void onEnableEffectsChanged(bool enableEffects);
262 void onDefaultFontChanged(const QString &font);
263 void onSmallFontChanged(const QString &font);
264 void onMonospacedFontChanged(const QString &font);
265 void onCustomColorSchemeChanged(const QString &scheme);
266
267 Q_SIGNALS:
268 void styleTypeChanged(int styleType);
269 void accentColorChanged(QString accentColor);
270 void iconThemeChanged(QString iconTheme);
271 void windowControlsThemeChanged(QString windowControlsTheme);
272 void enableCSDChanged(bool enableCSD);
273 void borderRadiusChanged(uint radius);
274 void iconSizeChanged(uint size);
275 void enableEffectsChanged(bool enableEffects);
276 void paddingSizeChanged(uint paddingSize);
277 void marginSizeChanged(uint marginSize);
278 void spacingSizeChanged(uint spacingSize);
279 void defaultFontChanged(QString defaultFont);
280 void smallFontChanged(QString smallFont);
281 void monospacedFontChanged(QString monospacedFont);
282 void customColorSchemeChanged(QString customColorScheme);
283
284 private:
285 #if !defined Q_OS_ANDROID
286 QDBusInterface *m_interface = nullptr;
287 #endif
288
289 MauiMan::SettingsStore *m_settings;
290
291 int m_styleType = ThemeManager::DefaultValues::styleType;
292 QString m_accentColor = ThemeManager::DefaultValues::accentColor;
293 QString m_iconTheme = ThemeManager::DefaultValues::iconTheme;
294 QString m_windowControlsTheme = ThemeManager::DefaultValues::windowControlsTheme;
295 bool m_enableCSD = ThemeManager::DefaultValues::enableCSD;
296 uint m_borderRadius = ThemeManager::DefaultValues::borderRadius;
297 uint m_iconSize = ThemeManager::DefaultValues::iconSize;
298 uint m_paddingSize = ThemeManager::DefaultValues::paddingSize;
299 uint m_marginSize = ThemeManager::DefaultValues::marginSize;
300 uint m_spacingSize = ThemeManager::DefaultValues::spacingSize;
301 bool m_enableEffects = ThemeManager::DefaultValues::enableEffects;
302 QString m_defaultFont = MauiMan::ThemeManager::DefaultValues::defaultFont;
303 QString m_smallFont = MauiMan::ThemeManager::DefaultValues::smallFont;
304 QString m_monospacedFont = MauiMan::ThemeManager::DefaultValues::monospacedFont;
305 QString m_customColorScheme = MauiMan::ThemeManager::DefaultValues::customColorScheme;
306
307 void sync(const QString &key, const QVariant &value);
308 void setConnections();
309 void loadSettings();
310
311 };
312}
313
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 Mon Nov 18 2024 12:14:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.