File indexing completed on 2024-04-14 05:24:28

0001 /*
0002     SPDX-FileCopyrightText: 2018 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef PLASMATHEMEEXTENDED_H
0007 #define PLASMATHEMEEXTENDED_H
0008 
0009 // C++
0010 #include <array>
0011 
0012 // Qt
0013 #include <QObject>
0014 #include <QHash>
0015 #include <QTemporaryDir>
0016 
0017 // KDE
0018 #include <KConfigGroup>
0019 #include <KSharedConfig>
0020 
0021 // Plasma
0022 #include <Plasma/FrameSvg>
0023 #include <Plasma/Theme>
0024 
0025 namespace Latte {
0026 class Corona;
0027 namespace WindowSystem {
0028 class SchemeColors;
0029 }
0030 }
0031 
0032 namespace Latte {
0033 namespace PlasmaExtended {
0034 class PanelBackground;
0035 }
0036 }
0037 
0038 namespace Latte {
0039 namespace PlasmaExtended {
0040 
0041 struct CornerRegions {
0042     QRegion topLeft;
0043     QRegion topRight;
0044     QRegion bottomLeft;
0045     QRegion bottomRight;
0046 };
0047 
0048 class Theme: public QObject
0049 {
0050     Q_OBJECT
0051     Q_PROPERTY(bool hasShadow READ hasShadow NOTIFY hasShadowChanged)
0052     Q_PROPERTY(bool isLightTheme READ isLightTheme NOTIFY themeChanged)
0053     Q_PROPERTY(bool isDarkTheme READ isDarkTheme NOTIFY themeChanged)
0054 
0055     Q_PROPERTY(int outlineWidth READ outlineWidth NOTIFY outlineWidthChanged)
0056 
0057     Q_PROPERTY(int marginsAreaTop READ marginsAreaTop NOTIFY marginsAreaChanged)
0058     Q_PROPERTY(int marginsAreaLeft READ marginsAreaLeft NOTIFY marginsAreaChanged)
0059     Q_PROPERTY(int marginsAreaBottom READ marginsAreaBottom NOTIFY marginsAreaChanged)
0060     Q_PROPERTY(int marginsAreaRight READ marginsAreaRight NOTIFY marginsAreaChanged)
0061 
0062     Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundTopEdge READ backgroundTopEdge NOTIFY backgroundsChanged)
0063     Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundLeftEdge READ backgroundLeftEdge NOTIFY backgroundsChanged)
0064     Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundBottomEdge READ backgroundBottomEdge NOTIFY backgroundsChanged)
0065     Q_PROPERTY(Latte::PlasmaExtended::PanelBackground *backgroundRightEdge READ backgroundRightEdge NOTIFY backgroundsChanged)
0066 
0067     Q_PROPERTY(Latte::WindowSystem::SchemeColors *defaultTheme READ defaultTheme NOTIFY themeChanged)
0068     Q_PROPERTY(Latte::WindowSystem::SchemeColors *lightTheme READ lightTheme NOTIFY themeChanged)
0069     Q_PROPERTY(Latte::WindowSystem::SchemeColors *darkTheme READ darkTheme NOTIFY themeChanged)
0070 
0071 public:
0072     Theme(KSharedConfig::Ptr config, QObject *parent);
0073     ~Theme() override;;
0074 
0075     bool hasShadow() const;
0076     bool isLightTheme() const;
0077     bool isDarkTheme() const;
0078 
0079     int outlineWidth() const;
0080     void setOutlineWidth(int width);
0081 
0082     int marginsAreaTop() const;
0083     int marginsAreaLeft() const;
0084     int marginsAreaBottom() const;
0085     int marginsAreaRight() const;
0086 
0087     PanelBackground *backgroundTopEdge() const;
0088     PanelBackground *backgroundLeftEdge() const;
0089     PanelBackground *backgroundBottomEdge() const;
0090     PanelBackground *backgroundRightEdge() const;
0091 
0092     WindowSystem::SchemeColors *defaultTheme() const;
0093     WindowSystem::SchemeColors *lightTheme() const;
0094     WindowSystem::SchemeColors *darkTheme() const;
0095 
0096     const CornerRegions &cornersMask(const int &radius);
0097 
0098     void load();
0099 
0100 signals:
0101     void backgroundsChanged();
0102     void compositingChanged();
0103     void hasShadowChanged();
0104     void outlineWidthChanged();
0105     void marginsAreaChanged();
0106     void themeChanged();
0107 
0108 private slots:
0109     void loadConfig();
0110     void saveConfig();
0111     void loadThemeLightness();
0112 
0113 private:
0114     void loadThemePaths();
0115     void loadCompositingRoundness();
0116     void updateBackgrounds();
0117 
0118     void setOriginalSchemeFile(const QString &file);
0119     void updateHasShadow();
0120     void updateDefaultScheme();
0121     void updateDefaultSchemeValues();
0122     void updateMarginsAreaValues();
0123     void updateReversedScheme();
0124     void updateReversedSchemeValues();
0125 
0126     void qmlRegisterTypes();
0127 
0128 private:
0129     bool m_hasShadow{false};
0130     bool m_isLightTheme{false};
0131     bool m_compositing{true};
0132 
0133     int m_outlineWidth{1};
0134 
0135     int m_marginsAreaTop{0};
0136     int m_marginsAreaLeft{0};
0137     int m_marginsAreaBottom{0};
0138     int m_marginsAreaRight{0};
0139 
0140     QString m_themePath;
0141     QString m_themeWidgetsPath;
0142     QString m_defaultSchemePath;
0143     QString m_originalSchemePath;
0144     QString m_reversedSchemePath;
0145 
0146     QHash<int, CornerRegions> m_cornerRegions;
0147 
0148     std::array<QMetaObject::Connection, 2> m_kdeConnections;
0149 
0150     QTemporaryDir m_extendedThemeDir;
0151     KConfigGroup m_themeGroup;
0152     Plasma::Theme m_theme;
0153 
0154     PanelBackground *m_backgroundTopEdge{nullptr};
0155     PanelBackground *m_backgroundLeftEdge{nullptr};
0156     PanelBackground *m_backgroundBottomEdge{nullptr};
0157     PanelBackground *m_backgroundRightEdge{nullptr};
0158 
0159     Latte::Corona *m_corona{nullptr};
0160     WindowSystem::SchemeColors *m_defaultScheme{nullptr};
0161     WindowSystem::SchemeColors *m_reversedScheme{nullptr};
0162 };
0163 
0164 }
0165 }
0166 
0167 #endif