1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#ifndef THEMEMANAGER_H
18#define THEMEMANAGER_H
19#include <QObject>
20#include <QPalette>
21#include <QHash>
22#include <QColor>
23#include <memory>
24
25class AppTheme:public QObject {
26 Q_OBJECT
27public:
28 explicit AppTheme(QObject* parent = nullptr);
29
30 enum ColorRole {
31 /* Color for QPalette */
32
33 PaletteWindow,
34 PaletteWindowText,
35 PaletteBase,
36 PaletteAlternateBase,
37 PaletteToolTipBase,
38 PaletteToolTipText,
39 PaletteText,
40 PaletteButton,
41 PaletteButtonText,
42 PaletteBrightText,
43 PaletteHighlight,
44 PaletteHighlightedText,
45 PaletteLink,
46 PaletteLinkVisited,
47
48 PaletteLight,
49 PaletteMidlight,
50 PaletteDark,
51 PaletteMid,
52 PaletteShadow,
53
54 PaletteWindowDisabled,
55 PaletteWindowTextDisabled,
56 PaletteBaseDisabled,
57 PaletteAlternateBaseDisabled,
58 PaletteToolTipBaseDisabled,
59 PaletteToolTipTextDisabled,
60 PaletteTextDisabled,
61 PaletteButtonDisabled,
62 PaletteButtonTextDisabled,
63 PaletteBrightTextDisabled,
64 PaletteHighlightDisabled,
65 PaletteHighlightedTextDisabled,
66 PaletteLinkDisabled,
67 PaletteLinkVisitedDisabled,
68
69 PaletteLightDisabled,
70 PaletteMidlightDisabled,
71 PaletteDarkDisabled,
72 PaletteMidDisabled,
73 PaletteShadowDisabled
74 };
75
76 Q_ENUM(ColorRole)
77
78 QColor color(ColorRole role) const;
79 QPalette palette() const;
80
81 void load(const QString& filename);
82
83 bool isDark() const;
84
85 const QString &defaultColorScheme() const;
86 void setDefaultColorScheme(const QString &newDefaultColorScheme);
87
88 const QString &displayName() const;
89
90 const QString &name() const;
91
92 const QString &defaultIconSet() const;
93 void setDefaultIconSet(const QString &newDefaultIconSet);
94
95private:
96 static QPalette initialPalette();
97private:
98 QHash<int,QColor> mColors;
99 QString mName;
100 QString mDisplayName;
101 bool mIsDark;
102 QString mDefaultColorScheme;
103 QString mDefaultIconSet;
104};
105
106using PAppTheme = std::shared_ptr<AppTheme>;
107
108class ThemeManager : public QObject
109{
110 Q_OBJECT
111public:
112 explicit ThemeManager(QObject *parent = nullptr);
113 PAppTheme theme(const QString& themeName);
114 bool useCustomTheme() const;
115 void setUseCustomTheme(bool newUseCustomTheme);
116 void prepareCustomeTheme();
117 QList<PAppTheme> getThemes();
118
119private:
120 bool mUseCustomTheme;
121};
122
123#endif // THEMEMANAGER_H
124