1 /* 2 SPDX-FileCopyrightText: 2018 Michail Vourlakos <mvourlakos@gmail.com> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #ifndef PLASMATHEMEEXTENDED_H 7 #define PLASMATHEMEEXTENDED_H 8 9 // C++ 10 #include <array> 11 12 // Qt 13 #include <QObject> 14 #include <QHash> 15 #include <QTemporaryDir> 16 17 // KDE 18 #include <KConfigGroup> 19 #include <KSharedConfig> 20 21 // Plasma 22 #include <Plasma/FrameSvg> 23 #include <Plasma/Theme> 24 25 namespace Latte { 26 class Corona; 27 namespace WindowSystem { 28 class SchemeColors; 29 } 30 } 31 32 namespace Latte { 33 namespace PlasmaExtended { 34 class PanelBackground; 35 } 36 } 37 38 namespace Latte { 39 namespace PlasmaExtended { 40 41 struct CornerRegions { 42 QRegion topLeft; 43 QRegion topRight; 44 QRegion bottomLeft; 45 QRegion bottomRight; 46 }; 47 48 class Theme: public QObject 49 { 50 Q_OBJECT 51 Q_PROPERTY(bool hasShadow READ hasShadow NOTIFY hasShadowChanged) 52 Q_PROPERTY(bool isLightTheme READ isLightTheme NOTIFY themeChanged) 53 Q_PROPERTY(bool isDarkTheme READ isDarkTheme NOTIFY themeChanged) 54 55 Q_PROPERTY(int outlineWidth READ outlineWidth NOTIFY outlineWidthChanged) 56 57 Q_PROPERTY(int marginsAreaTop READ marginsAreaTop NOTIFY marginsAreaChanged) 58 Q_PROPERTY(int marginsAreaLeft READ marginsAreaLeft NOTIFY marginsAreaChanged) 59 Q_PROPERTY(int marginsAreaBottom READ marginsAreaBottom NOTIFY marginsAreaChanged) 60 Q_PROPERTY(int marginsAreaRight READ marginsAreaRight NOTIFY marginsAreaChanged) 61 62 Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundTopEdge READ backgroundTopEdge NOTIFY backgroundsChanged) 63 Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundLeftEdge READ backgroundLeftEdge NOTIFY backgroundsChanged) 64 Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundBottomEdge READ backgroundBottomEdge NOTIFY backgroundsChanged) 65 Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundRightEdge READ backgroundRightEdge NOTIFY backgroundsChanged) 66 67 Q_PROPERTY(Latte::WindowSystem::SchemeColors *defaultTheme READ defaultTheme NOTIFY themeChanged) 68 Q_PROPERTY(Latte::WindowSystem::SchemeColors *lightTheme READ lightTheme NOTIFY themeChanged) 69 Q_PROPERTY(Latte::WindowSystem::SchemeColors *darkTheme READ darkTheme NOTIFY themeChanged) 70 71 public: 72 Theme(KSharedConfig::Ptr config, QObject *parent); 73 ~Theme() override;; 74 75 bool hasShadow() const; 76 bool isLightTheme() const; 77 bool isDarkTheme() const; 78 79 int outlineWidth() const; 80 void setOutlineWidth(int width); 81 82 int marginsAreaTop() const; 83 int marginsAreaLeft() const; 84 int marginsAreaBottom() const; 85 int marginsAreaRight() const; 86 87 PanelBackground *backgroundTopEdge() const; 88 PanelBackground *backgroundLeftEdge() const; 89 PanelBackground *backgroundBottomEdge() const; 90 PanelBackground *backgroundRightEdge() const; 91 92 WindowSystem::SchemeColors *defaultTheme() const; 93 WindowSystem::SchemeColors *lightTheme() const; 94 WindowSystem::SchemeColors *darkTheme() const; 95 96 const CornerRegions &cornersMask(const int &radius); 97 98 void load(); 99 100 signals: 101 void backgroundsChanged(); 102 void compositingChanged(); 103 void hasShadowChanged(); 104 void outlineWidthChanged(); 105 void marginsAreaChanged(); 106 void themeChanged(); 107 108 private slots: 109 void loadConfig(); 110 void saveConfig(); 111 void loadThemeLightness(); 112 113 private: 114 void loadThemePaths(); 115 void loadCompositingRoundness(); 116 void updateBackgrounds(); 117 118 void setOriginalSchemeFile(const QString &file); 119 void updateHasShadow(); 120 void updateDefaultScheme(); 121 void updateDefaultSchemeValues(); 122 void updateMarginsAreaValues(); 123 void updateReversedScheme(); 124 void updateReversedSchemeValues(); 125 126 void qmlRegisterTypes(); 127 128 private: 129 bool m_hasShadow{false}; 130 bool m_isLightTheme{false}; 131 bool m_compositing{true}; 132 133 int m_outlineWidth{1}; 134 135 int m_marginsAreaTop{0}; 136 int m_marginsAreaLeft{0}; 137 int m_marginsAreaBottom{0}; 138 int m_marginsAreaRight{0}; 139 140 QString m_themePath; 141 QString m_themeWidgetsPath; 142 QString m_defaultSchemePath; 143 QString m_originalSchemePath; 144 QString m_reversedSchemePath; 145 146 QHash<int, CornerRegions> m_cornerRegions; 147 148 std::array<QMetaObject::Connection, 2> m_kdeConnections; 149 150 QTemporaryDir m_extendedThemeDir; 151 KConfigGroup m_themeGroup; 152 Plasma::Theme m_theme; 153 154 PanelBackground *m_backgroundTopEdge{nullptr}; 155 PanelBackground *m_backgroundLeftEdge{nullptr}; 156 PanelBackground *m_backgroundBottomEdge{nullptr}; 157 PanelBackground *m_backgroundRightEdge{nullptr}; 158 159 Latte::Corona *m_corona{nullptr}; 160 WindowSystem::SchemeColors *m_defaultScheme{nullptr}; 161 WindowSystem::SchemeColors *m_reversedScheme{nullptr}; 162 }; 163 164 } 165 } 166 167 #endif 168