File indexing completed on 2024-10-27 04:24:10

0001 #pragma once
0002 
0003 #include <QObject>
0004 #include <QString>
0005 #include <QFont>
0006 
0007 #if !defined Q_OS_ANDROID
0008 #include <QDBusInterface>
0009 #endif
0010 
0011 #include "mauiman_export.h"
0012 #include "mauimanutils.h"
0013 
0014 /**
0015  * @brief The MauiMan name-space contains all of the available modules for configuring the Maui Applications and Shell properties.
0016  * The properties are exposed for the user, developer and distributor to tweak.
0017  */
0018 namespace MauiMan
0019 {
0020     
0021     class SettingsStore;
0022     
0023     /**
0024      * @brief The ThemeManager class
0025      * Helpful for third parties to connect to property changes from the Theme module setting changes.
0026      * 
0027      * @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.
0028      * 
0029      * 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.
0030      */
0031     class MAUIMAN_EXPORT ThemeManager : public QObject
0032     {
0033         Q_OBJECT
0034         /**
0035          * The style type for the color scheme. The possible values are:
0036          * - 0 Light
0037          * - 1 Dark
0038          * - 2 Adaptive
0039          * - 3 Custom (from the plasma color-scheme file preferences)
0040          * - 4 True Black
0041          * - 5 Inverted (True White)
0042          */
0043         Q_PROPERTY(int styleType READ styleType WRITE setStyleType NOTIFY styleTypeChanged)
0044         
0045         /**
0046          * The preferred accent color used for the highlighted and checked states.
0047          */
0048         Q_PROPERTY(QString accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged RESET resetAccentColor)
0049         
0050         /**
0051          * The preferred icon theme. This preference is only valid when using the Maui Shell session.
0052          */
0053         Q_PROPERTY(QString iconTheme READ iconTheme WRITE setIconTheme NOTIFY iconThemeChanged)
0054         
0055         /**
0056          * 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.
0057          */
0058         Q_PROPERTY(QString windowControlsTheme READ windowControlsTheme WRITE setWindowControlsTheme NOTIFY windowControlsThemeChanged)
0059         
0060         /**
0061          * Whether to use client side decorations (CSD) for the applications.
0062          * By default this is set to `true`
0063          */
0064         Q_PROPERTY(bool enableCSD READ enableCSD WRITE setEnableCSD NOTIFY enableCSDChanged)
0065         
0066         /**
0067          * The corner border radius of the UI elements, also affects the radius of the CSD window corners.
0068          */
0069         Q_PROPERTY(uint borderRadius READ borderRadius WRITE setBorderRadius NOTIFY borderRadiusChanged RESET resetBorderRadius)
0070         
0071         /**
0072          * The preferred size of the icons in the buttons, menu entries and other elements.
0073          */
0074         Q_PROPERTY(uint iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged RESET resetIconSize)
0075         
0076         /**
0077          * The preferred padding size for the UI elements, such as buttons, tool bars, menu entries, etc.
0078          */
0079         Q_PROPERTY(uint paddingSize READ paddingSize WRITE setPaddingSize NOTIFY paddingSizeChanged RESET resetPaddingSize)
0080         
0081         /**
0082          * The preferred margin size around views.
0083          */
0084         Q_PROPERTY(uint marginSize READ marginSize WRITE setMarginSize NOTIFY marginSizeChanged RESET resetMarginSize)
0085         
0086         /**
0087          * The preferred spacing size between elements in a row or column, such as lists or browsing elements.
0088          */
0089         Q_PROPERTY(uint spacingSize READ spacingSize WRITE setSpacingSize NOTIFY spacingSizeChanged RESET resetSPacingSize)
0090         
0091         /**
0092          * Whether the user prefers for the system to have visual effects, such as animations, blur, etc.
0093          */
0094         Q_PROPERTY(bool enableEffects READ enableEffects WRITE setEnableEffects NOTIFY enableEffectsChanged)
0095         
0096         /**
0097          * The preferred default font, for most part of the UI.
0098          */
0099         Q_PROPERTY(QString defaultFont READ defaultFont WRITE setDefaultFont NOTIFY defaultFontChanged RESET resetDefaultFont)
0100         
0101         /**
0102          * The preferred small font, for details.
0103          */
0104         Q_PROPERTY(QString smallFont READ smallFont WRITE setSmallFont NOTIFY smallFontChanged RESET resetSmallFont)
0105         
0106         /**
0107          * The preferred mono spaced font, for example the one used in console terminals, or in text editors.
0108          */
0109         Q_PROPERTY(QString monospacedFont READ monospacedFont WRITE setMonospacedFont NOTIFY monospacedFontChanged RESET resetMonospacedFont)
0110         
0111         /**
0112          * The preferred color scheme to be used when the `styleType` is set to Custom.
0113          */
0114         Q_PROPERTY(QString customColorScheme READ customColorScheme WRITE setCustomColorScheme NOTIFY customColorSchemeChanged)
0115         
0116     public:
0117         
0118         /**
0119          * @brief The Theme module default values
0120          */
0121         struct DefaultValues
0122         {
0123             /**
0124              * @private
0125              */
0126             static int preferredStyleType()
0127             {
0128                 
0129                 #ifdef Q_OS_ANDROID
0130                 return 1;
0131                 #endif
0132                 #ifdef Q_OS_LINUX
0133                 if(!MauiManUtils::isMauiSession())
0134                 {
0135                     return 3; //if it is plasma or other session use the system color scheme by setting the style to 3=auto
0136                 }
0137                 #endif
0138                 return 0;
0139             }
0140             
0141             /**
0142              * @private
0143              */
0144             static QString getDefaultFont()
0145             {
0146                 QFont font {QStringLiteral("Noto Sans"), 10, QFont::Normal};
0147                 font.setStyleHint(QFont::SansSerif);
0148                 font.setStyle(QFont::StyleNormal);
0149                 font.setStyleName(QStringLiteral("Regular"));
0150                 return font.toString();
0151             }
0152             
0153             /**
0154              * @private
0155              */
0156             static QString getSmallFont()
0157             {
0158                 QFont font {QStringLiteral("Noto Sans"), 8, QFont::Normal};
0159                 font.setStyleHint(QFont::SansSerif);
0160                 font.setStyle(QFont::StyleNormal);
0161                 font.setStyleName(QStringLiteral("Regular"));
0162                 
0163                 return font.toString();
0164             }
0165             
0166             /**
0167              * @private
0168              */
0169             static QString getMonospacedFont()
0170             {
0171                 QFont font {QStringLiteral("Hack"), 10, QFont::Normal};
0172                 font.setStyleHint(QFont::Monospace);
0173                 font.setStyle(QFont::StyleNormal);
0174                 font.setStyleName(QStringLiteral("Regular"));
0175                 
0176                 return font.toString();
0177             }
0178             
0179             static inline const int styleType = ThemeManager::DefaultValues::preferredStyleType();
0180             static inline const QString accentColor = QStringLiteral("#26c6da");
0181             static inline const QString iconTheme = QStringLiteral("Luv");
0182             static inline const QString windowControlsTheme = QStringLiteral("Nitrux");
0183             static inline const bool enableCSD = true;
0184             static inline const uint borderRadius = 6;
0185             static inline const uint iconSize = 16;
0186             static inline const bool enableEffects = true;
0187             static inline const uint paddingSize = 6;
0188             static inline const uint marginSize = 6;
0189             static inline const uint spacingSize = 6;
0190             static inline const QString defaultFont = getDefaultFont();
0191             static inline const QString smallFont = getSmallFont();
0192             static inline const QString monospacedFont = getMonospacedFont();
0193             static inline const QString customColorScheme = QStringLiteral("Nitrux");
0194         };
0195         
0196         explicit ThemeManager(QObject * parent = nullptr);
0197         
0198         int styleType() const;
0199         void setStyleType(int newStyleType);
0200         
0201         const QString &accentColor() const;
0202         void setAccentColor(const QString &newAccentColor);
0203         void resetAccentColor();
0204         
0205         const QString &iconTheme() const;
0206         void setIconTheme(const QString &newIconTheme);
0207         
0208         const QString &windowControlsTheme() const;
0209         void setWindowControlsTheme(const QString &newWindowControlsTheme);
0210         
0211         bool enableCSD() const;
0212         void setEnableCSD(bool enableCSD);
0213         
0214         uint borderRadius() const;
0215         void setBorderRadius(uint newBorderRadius);
0216         void resetBorderRadius();
0217         
0218         uint iconSize() const;
0219         void setIconSize(uint newIconSize);
0220         void resetIconSize();
0221         
0222         bool enableEffects() const;
0223         void setEnableEffects(bool enableEffects);
0224         
0225         uint paddingSize() const;
0226         void setPaddingSize(uint paddingSize);
0227         void resetPaddingSize();
0228         
0229         uint marginSize() const;
0230         void setMarginSize(uint marginSize);
0231         void resetMarginSize();
0232         
0233         uint spacingSize() const;
0234         void setSpacingSize(uint spacingSize);
0235         void resetSPacingSize();
0236         
0237         QString defaultFont() const;
0238         void setDefaultFont(const QString &defaultFont);
0239         void resetDefaultFont();
0240         
0241         QString smallFont() const;
0242         void setSmallFont(const QString &smallFont);
0243         void resetSmallFont();
0244         
0245         QString monospacedFont() const;
0246         void setMonospacedFont(const QString &monospacedFont);
0247         void resetMonospacedFont();
0248         
0249         QString customColorScheme() const;
0250         void setCustomColorScheme(const QString &customColorScheme);
0251         
0252     private Q_SLOTS:
0253         void onStyleTypeChanged(const int &newStyleType);
0254         void onAccentColorChanged(const QString &newAccentColor);
0255         void onWindowControlsThemeChanged(const QString &newWindowControlsTheme);
0256         void onIconThemeChanged(const QString &newIconTheme);
0257         void onEnableCSDChanged(const bool &enableCSD);
0258         void onBorderRadiusChanged(const uint &radius);
0259         void onIconSizeChanged(const uint &size);
0260         void onPaddingSizeChanged(const uint &paddingSize);
0261         void onMarginSizeChanged(const uint &marginSize);
0262         void onSpacingSizeChanged(const uint &spacingSize);
0263         void onEnableEffectsChanged(bool enableEffects);
0264         void onDefaultFontChanged(const QString &font);
0265         void onSmallFontChanged(const QString &font);
0266         void onMonospacedFontChanged(const QString &font);
0267         void onCustomColorSchemeChanged(const QString &scheme);
0268         
0269     Q_SIGNALS:
0270         void styleTypeChanged(int styleType);
0271         void accentColorChanged(QString accentColor);
0272         void iconThemeChanged(QString iconTheme);
0273         void windowControlsThemeChanged(QString windowControlsTheme);
0274         void enableCSDChanged(bool enableCSD);
0275         void borderRadiusChanged(uint radius);
0276         void iconSizeChanged(uint size);
0277         void enableEffectsChanged(bool enableEffects);
0278         void paddingSizeChanged(uint paddingSize);
0279         void marginSizeChanged(uint marginSize);
0280         void spacingSizeChanged(uint spacingSize);
0281         void defaultFontChanged(QString defaultFont);
0282         void smallFontChanged(QString smallFont);
0283         void monospacedFontChanged(QString monospacedFont);    
0284         void customColorSchemeChanged(QString customColorScheme);
0285         
0286     private:
0287         #if !defined Q_OS_ANDROID
0288         QDBusInterface *m_interface = nullptr;
0289         #endif
0290         
0291         MauiMan::SettingsStore *m_settings;
0292         
0293         int m_styleType = ThemeManager::DefaultValues::styleType;
0294         QString m_accentColor = ThemeManager::DefaultValues::accentColor;
0295         QString m_iconTheme = ThemeManager::DefaultValues::iconTheme;
0296         QString m_windowControlsTheme = ThemeManager::DefaultValues::windowControlsTheme;
0297         bool m_enableCSD = ThemeManager::DefaultValues::enableCSD;
0298         uint m_borderRadius = ThemeManager::DefaultValues::borderRadius;
0299         uint m_iconSize = ThemeManager::DefaultValues::iconSize;
0300         uint m_paddingSize = ThemeManager::DefaultValues::paddingSize;
0301         uint m_marginSize = ThemeManager::DefaultValues::marginSize;
0302         uint m_spacingSize = ThemeManager::DefaultValues::spacingSize;
0303         bool m_enableEffects = ThemeManager::DefaultValues::enableEffects;
0304         QString m_defaultFont = MauiMan::ThemeManager::DefaultValues::defaultFont;
0305         QString m_smallFont = MauiMan::ThemeManager::DefaultValues::smallFont;
0306         QString m_monospacedFont = MauiMan::ThemeManager::DefaultValues::monospacedFont;
0307         QString m_customColorScheme = MauiMan::ThemeManager::DefaultValues::customColorScheme;
0308         
0309         void sync(const QString &key, const QVariant &value);
0310         void setConnections();
0311         void loadSettings();
0312         
0313     };
0314 }
0315