Repository navigation
Expand file tree
/
Copy pathQelTheme.cpp
More file actions
207 lines (180 loc) · 5.07 KB
/
Copy pathQelTheme.cpp
File metadata and controls
207 lines (180 loc) · 5.07 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "QelTheme.h"
#include <QColor>
namespace qel {
const QelTheme::ColorTokens &QelTheme::colors()
{
static const ColorTokens tokens = {
"#409EFF",
"#66B1FF",
"#ECF5FF",
"#A0CFFF",
"#67C23A",
"#85CE61",
"#E6A23C",
"#EBB563",
"#F56C6C",
"#F78989",
"#909399",
"#A6A9AD",
"#303133",
"#606266",
"#909399",
"#C0C4CC",
"#DCDFE6",
"#E4E7ED",
"#EBEEF5",
"#FFFFFF",
"#F5F7FA",
"#FAFAFA",
"#E6E9EF"
};
return tokens;
}
QString QelTheme::semanticColor(QelSemanticType type)
{
const ColorTokens &c = colors();
switch (type) {
case QelSemanticType::Success:
return c.success;
case QelSemanticType::Warning:
return c.warning;
case QelSemanticType::Danger:
return c.danger;
case QelSemanticType::Info:
return c.info;
case QelSemanticType::Primary:
return c.primary;
case QelSemanticType::Default:
default:
return c.textRegular;
}
}
QString QelTheme::semanticLightColor(QelSemanticType type, int level)
{
const QColor base(semanticColor(type));
const int safeLevel = qBound(0, level, 9);
const qreal whiteRatio = safeLevel / 10.0;
const int red = qRound(base.red() * (1.0 - whiteRatio) + 255.0 * whiteRatio);
const int green = qRound(base.green() * (1.0 - whiteRatio) + 255.0 * whiteRatio);
const int blue = qRound(base.blue() * (1.0 - whiteRatio) + 255.0 * whiteRatio);
return QColor(red, green, blue).name();
}
QelTheme::ButtonColors QelTheme::buttonColors(ButtonKind kind, bool isPlain)
{
switch (kind) {
case ButtonKind::Primary:
return primaryButtonColors(isPlain);
case ButtonKind::Success:
return successButtonColors(isPlain);
case ButtonKind::Warning:
return warningButtonColors(isPlain);
case ButtonKind::Danger:
return dangerButtonColors(isPlain);
case ButtonKind::Info:
return infoButtonColors(isPlain);
case ButtonKind::Text:
return textButtonColors(isPlain);
case ButtonKind::Default:
default:
return defaultButtonColors(isPlain);
}
}
QelTheme::ButtonColors QelTheme::defaultButtonColors(bool)
{
const ColorTokens &c = colors();
return {
{c.fillBlank, c.textRegular, c.borderBase},
{c.primaryLight, c.textRegular, c.borderBase},
{c.borderLighter, c.textPlaceholder, c.borderLight}
};
}
QelTheme::ButtonColors QelTheme::primaryButtonColors(bool isPlain)
{
const ColorTokens &c = colors();
if (isPlain) {
return {
{c.primaryLight, c.primary, c.primary},
{"#D9ECFF", c.primary, c.primaryHover},
{"#F3F8FF", c.primaryDisabled, "#D6E4FF"}
};
}
return {
{c.primary, c.fillBlank, c.primary},
{c.primaryHover, c.fillBlank, c.primaryHover},
{"#B3D8FF", c.fillBlank, "#B3D8FF"}
};
}
QelTheme::ButtonColors QelTheme::successButtonColors(bool isPlain)
{
const ColorTokens &c = colors();
if (isPlain) {
return {
{"#F0F9EB", c.success, c.success},
{"#E1F3D8", c.success, c.successHover},
{"#F4F7EF", "#B2E7A9", "#E1EFE3"}
};
}
return {
{c.success, c.fillBlank, c.success},
{c.successHover, c.fillBlank, c.successHover},
{"#B3E19D", c.fillBlank, "#B3E19D"}
};
}
QelTheme::ButtonColors QelTheme::warningButtonColors(bool isPlain)
{
const ColorTokens &c = colors();
if (isPlain) {
return {
{"#FDF6EC", c.warning, c.warning},
{"#FAECD8", c.warning, c.warningHover},
{"#FEF2E5", "#F1D09C", "#FCE7CE"}
};
}
return {
{c.warning, c.fillBlank, c.warning},
{c.warningHover, c.fillBlank, c.warningHover},
{"#F3D19E", c.fillBlank, "#F3D19E"}
};
}
QelTheme::ButtonColors QelTheme::dangerButtonColors(bool isPlain)
{
const ColorTokens &c = colors();
if (isPlain) {
return {
{"#FEF0F0", c.danger, c.danger},
{"#FDE2E2", c.danger, c.dangerHover},
{"#FEF2F2", "#F9B0B0", "#FDE2E2"}
};
}
return {
{c.danger, c.fillBlank, c.danger},
{c.dangerHover, c.fillBlank, c.dangerHover},
{"#FAB6B6", c.fillBlank, "#FAB6B6"}
};
}
QelTheme::ButtonColors QelTheme::infoButtonColors(bool isPlain)
{
const ColorTokens &c = colors();
if (isPlain) {
return {
{"#F4F4F5", c.info, c.info},
{"#EBEBEC", c.info, c.infoHover},
{"#F6F6F7", "#C8C9CC", "#ECECEE"}
};
}
return {
{c.info, c.fillBlank, c.info},
{c.infoHover, c.fillBlank, c.infoHover},
{"#C8C9CC", c.fillBlank, "#C8C9CC"}
};
}
QelTheme::ButtonColors QelTheme::textButtonColors(bool)
{
const ColorTokens &c = colors();
return {
{"transparent", c.primary, "transparent"},
{"transparent", c.primaryHover, "transparent"},
{"transparent", c.primaryDisabled, "transparent"}
};
}
} // namespace qel