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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include "tomlc99/toml.h"
#include "Bootstrap.hxx"
Bootstrap::Bootstrap(QObject *parent):
QObject(parent),
bsTheme(None),
bsDarkMode(false),
bsLightBodyColor("#212529"),
bsDarkBodyColor("#adb5bd"),
bsLightBodyBg("#fff"),
bsDarkBodyBg("#212529"),
bsLightBorderColor("#dee2e6"),
bsDarkBorderColor("#495057")
{
QFile conf{QStringLiteral(":/qtquickcontrols2.conf")};
if (!conf.open(QIODevice::ReadOnly | QIODevice::Text)) return;
auto toml = toml_parse(conf.readAll().data(), nullptr, 0);
conf.close();
auto bootstrap = toml_table_in(toml, "Bootstrap");
if (!bootstrap) {
toml_free(toml);
return;
}
auto darkMode = toml_bool_in(bootstrap, "DarkMode");
if (darkMode.ok) bsDarkMode = darkMode.u.b;
auto bodyColor = toml_array_in(bootstrap, "BodyColor");
if (bodyColor) {
auto lightBodyColor = toml_string_at(bodyColor, 0).u.s;
bsLightBodyColor = QColor{lightBodyColor};
free(lightBodyColor);
auto darkBodyColor = toml_string_at(bodyColor, 1).u.s;
bsDarkBodyColor = QColor{darkBodyColor};
free(darkBodyColor);
}
auto bodyBg = toml_array_in(bootstrap, "BodyBg");
if (bodyBg) {
auto lightBodyBg = toml_string_at(bodyBg, 0).u.s;
bsLightBodyBg = QColor{lightBodyBg};
free(lightBodyBg);
auto darkBodyBg = toml_string_at(bodyBg, 1).u.s;
bsDarkBodyBg = QColor{darkBodyBg};
free(darkBodyBg);
}
auto borderColor = toml_array_in(bootstrap, "BorderColor");
if (borderColor) {
auto lightBorderColor = toml_string_at(borderColor, 0).u.s;
bsLightBorderColor = QColor{lightBorderColor};
free(lightBorderColor);
auto darkBorderColor = toml_string_at(borderColor, 1).u.s;
bsDarkBorderColor = QColor{darkBorderColor};
free(darkBorderColor);
}
toml_free(toml);
}
Bootstrap *Bootstrap::qmlAttachedProperties(QObject *object)
{
return new Bootstrap(object);
}
bool Bootstrap::darkMode() const
{
return bsDarkMode;
}
void Bootstrap::setDarkMode(bool darkMode)
{
if (darkMode == bsDarkMode) return;
bsDarkMode = darkMode;
emit darkModeChanged();
emit bodyColorChanged();
emit bodyBgChanged();
emit borderColorChanged();
}
Bootstrap::Theme Bootstrap::theme() const
{
return bsTheme;
}
void Bootstrap::setTheme(Theme theme)
{
if (theme == bsTheme) return;
bsTheme = theme;
emit themeChanged();
}
QColor Bootstrap::bodyColor() const
{
return bsDarkMode ? bsDarkBodyColor : bsLightBodyColor;
}
QColor Bootstrap::bodyBg() const
{
return bsDarkMode ? bsDarkBodyBg : bsLightBodyBg;
}
QColor Bootstrap::borderColor() const
{
return bsDarkMode ? bsDarkBorderColor : bsLightBorderColor;
}
|