forked from MatsuriDayo/nekoray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeManager.cpp
86 lines (75 loc) · 2.84 KB
/
ThemeManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <QStyle>
#include <QApplication>
#include <QStyleFactory>
#include "ThemeManager.hpp"
ThemeManager *themeManager = new ThemeManager;
extern QString ReadFileText(const QString &path);
void ThemeManager::ApplyTheme(const QString &theme) {
auto internal = [=] {
if (this->system_style_name.isEmpty()) {
this->system_style_name = qApp->style()->objectName();
}
if (this->current_theme == theme) {
return;
}
bool ok;
auto themeId = theme.toInt(&ok);
if (ok) {
// System & Built-in
QString qss;
if (themeId != 0) {
QString path;
std::map<QString, QString> replace;
switch (themeId) {
case 1:
path = ":/themes/feiyangqingyun/qss/flatgray.css";
replace[":/qss/"] = ":/themes/feiyangqingyun/qss/";
break;
case 2:
path = ":/themes/feiyangqingyun/qss/lightblue.css";
replace[":/qss/"] = ":/themes/feiyangqingyun/qss/";
break;
case 3:
path = ":/themes/feiyangqingyun/qss/blacksoft.css";
replace[":/qss/"] = ":/themes/feiyangqingyun/qss/";
break;
default:
return;
}
qss = ReadFileText(path);
for (auto const &[a, b]: replace) {
qss = qss.replace(a, b);
}
}
auto system_style = QStyleFactory::create(this->system_style_name);
if (themeId == 0) {
// system theme
qApp->setPalette(system_style->standardPalette());
qApp->setStyle(system_style);
qApp->setStyleSheet("");
} else {
if (themeId == 1 || themeId == 2 || themeId == 3) {
// feiyangqingyun theme
QString paletteColor = qss.mid(20, 7);
qApp->setPalette(QPalette(paletteColor));
} else {
// other theme
qApp->setPalette(system_style->standardPalette());
}
qApp->setStyleSheet(qss);
}
} else {
// QStyleFactory
const auto &_style = QStyleFactory::create(theme);
if (_style != nullptr) {
qApp->setPalette(_style->standardPalette());
qApp->setStyle(_style);
qApp->setStyleSheet("");
}
}
current_theme = theme;
};
internal();
auto nekoray_css = ReadFileText(":/neko/neko.css");
qApp->setStyleSheet(qApp->styleSheet().append("\n").append(nekoray_css));
}