Warning, file /plasma/latte-dock/app/plasma/extended/theme.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Copyright 2018  Michail Vourlakos <mvourlakos@gmail.com>
0003  *
0004  * This file is part of Latte-Dock
0005  *
0006  * Latte-Dock is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * Latte-Dock is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  *
0019  */
0020 
0021 #ifndef PLASMATHEMEEXTENDED_H
0022 #define PLASMATHEMEEXTENDED_H
0023 
0024 // C++
0025 #include <array>
0026 
0027 // Qt
0028 #include <QObject>
0029 #include <QTemporaryDir>
0030 
0031 // KDE
0032 #include <KConfigGroup>
0033 #include <KSharedConfig>
0034 
0035 // Plasma
0036 #include <Plasma/FrameSvg>
0037 #include <Plasma/Theme>
0038 
0039 namespace Latte {
0040 class Corona;
0041 namespace WindowSystem {
0042 class SchemeColors;
0043 }
0044 }
0045 
0046 namespace Latte {
0047 namespace PlasmaExtended {
0048 
0049 class Theme: public QObject
0050 {
0051     Q_OBJECT
0052     Q_PROPERTY(bool hasShadow READ hasShadow NOTIFY hasShadowChanged)
0053     Q_PROPERTY(bool isLightTheme READ isLightTheme NOTIFY themeChanged)
0054     Q_PROPERTY(bool isDarkTheme READ isDarkTheme NOTIFY themeChanged)
0055 
0056     Q_PROPERTY(int bottomEdgeRoundness READ bottomEdgeRoundness NOTIFY roundnessChanged)
0057     Q_PROPERTY(int leftEdgeRoundness READ leftEdgeRoundness NOTIFY roundnessChanged)
0058     Q_PROPERTY(int topEdgeRoundness READ topEdgeRoundness NOTIFY roundnessChanged)
0059     Q_PROPERTY(int rightEdgeRoundness READ rightEdgeRoundness NOTIFY roundnessChanged)
0060 
0061     Q_PROPERTY(int outlineWidth READ outlineWidth NOTIFY outlineWidthChanged)
0062 
0063     Q_PROPERTY(float bottomEdgeMaxOpacity READ bottomEdgeMaxOpacity NOTIFY maxOpacityChanged)
0064     Q_PROPERTY(float leftEdgeMaxOpacity READ leftEdgeMaxOpacity NOTIFY maxOpacityChanged)
0065     Q_PROPERTY(float topEdgeMaxOpacity READ topEdgeMaxOpacity NOTIFY maxOpacityChanged)
0066     Q_PROPERTY(float rightEdgeMaxOpacity READ rightEdgeMaxOpacity NOTIFY maxOpacityChanged)
0067 
0068     Q_PROPERTY(Latte::WindowSystem::SchemeColors *defaultTheme READ defaultTheme NOTIFY themeChanged)
0069     Q_PROPERTY(Latte::WindowSystem::SchemeColors *lightTheme READ lightTheme NOTIFY themeChanged)
0070     Q_PROPERTY(Latte::WindowSystem::SchemeColors *darkTheme READ darkTheme NOTIFY themeChanged)
0071 
0072 public:
0073     Theme(KSharedConfig::Ptr config, QObject *parent);
0074     ~Theme() override;;
0075 
0076     bool hasShadow() const;
0077     bool isLightTheme() const;
0078     bool isDarkTheme() const;
0079 
0080     int bottomEdgeRoundness() const;
0081     int leftEdgeRoundness() const;
0082     int topEdgeRoundness() const;
0083     int rightEdgeRoundness() const;
0084 
0085     int outlineWidth() const;
0086     void setOutlineWidth(int width);
0087 
0088     float bottomEdgeMaxOpacity() const;
0089     float leftEdgeMaxOpacity() const;
0090     float topEdgeMaxOpacity() const;
0091     float rightEdgeMaxOpacity() const;
0092 
0093     WindowSystem::SchemeColors *defaultTheme() const;
0094     WindowSystem::SchemeColors *lightTheme() const;
0095     WindowSystem::SchemeColors *darkTheme() const;
0096 
0097     void load();
0098 
0099 signals:
0100     void compositingChanged();
0101     void hasShadowChanged();
0102     void maxOpacityChanged();
0103     void outlineWidthChanged();
0104     void roundnessChanged();
0105     void themeChanged();
0106 
0107 private slots:
0108     void loadConfig();
0109     void saveConfig();
0110     void loadThemeLightness();
0111 
0112 private:
0113     void loadThemePaths();
0114     void loadRoundness();
0115     void loadCompositingRoundness();
0116 
0117     void setOriginalSchemeFile(const QString &file);
0118     void parseThemeSvgFiles();
0119     void updateDefaultScheme();
0120     void updateDefaultSchemeValues();
0121     void updateReversedScheme();
0122     void updateReversedSchemeValues();
0123 
0124     int roundness(const QImage &svgImage, Plasma::Types::Location edge);
0125 
0126 private:
0127     bool m_isLightTheme{false};
0128     bool m_compositing{true};
0129 
0130     int m_bottomEdgeRoundness{0};
0131     int m_leftEdgeRoundness{0};
0132     int m_topEdgeRoundness{0};
0133     int m_rightEdgeRoundness{0};
0134 
0135     int m_outlineWidth{1};
0136 
0137     float m_bottomEdgeMaxOpacity{1};
0138     float m_leftEdgeMaxOpacity{1};
0139     float m_topEdgeMaxOpacity{1};
0140     float m_rightEdgeMaxOpacity{1};
0141 
0142     QString m_themePath;
0143     QString m_themeWidgetsPath;
0144     QString m_defaultSchemePath;
0145     QString m_originalSchemePath;
0146     QString m_reversedSchemePath;
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     Latte::Corona *m_corona{nullptr};
0155     WindowSystem::SchemeColors *m_defaultScheme{nullptr};
0156     WindowSystem::SchemeColors *m_reversedScheme{nullptr};
0157 };
0158 
0159 }
0160 }
0161 
0162 #endif