Repository navigation
Expand file tree
/
Copy pathQelStyleHelper.cpp
More file actions
145 lines (125 loc) · 4.41 KB
/
Copy pathQelStyleHelper.cpp
File metadata and controls
145 lines (125 loc) · 4.41 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
#include "QelStyleHelper.h"
namespace qel {
QelVisualState QelStyleHelper::resolveState(const QelStateContext &ctx)
{
if (!ctx.enabled) {
return QelVisualState::Disabled;
}
if (ctx.loading) {
return QelVisualState::Loading;
}
if (ctx.pressed) {
return QelVisualState::Active;
}
if (ctx.hovered) {
return QelVisualState::Hover;
}
if (ctx.focused) {
return QelVisualState::Focus;
}
return QelVisualState::Normal;
}
QelStyleHelper::ComponentStyle QelStyleHelper::styleForState(
const StateStyleSet &styles,
QelVisualState state)
{
switch (state) {
case QelVisualState::Hover:
return styles.hover;
case QelVisualState::Active:
return styles.active;
case QelVisualState::Focus:
return styles.focus;
case QelVisualState::Disabled:
return styles.disabled;
case QelVisualState::Loading:
return styles.loading;
case QelVisualState::Normal:
default:
return styles.normal;
}
}
QelStyleHelper::ComponentStyle QelStyleHelper::buttonStyle(
QelTheme::ButtonKind kind,
bool isPlain,
QelVisualState state)
{
const QelTheme::ButtonColors colors = QelTheme::buttonColors(kind, isPlain);
switch (state) {
case QelVisualState::Disabled:
case QelVisualState::Loading:
return {colors.disabled.background, colors.disabled.text, colors.disabled.border};
case QelVisualState::Active:
case QelVisualState::Hover:
case QelVisualState::Focus:
return {colors.hover.background, colors.hover.text, colors.hover.border};
case QelVisualState::Normal:
default:
return {colors.normal.background, colors.normal.text, colors.normal.border};
}
}
QelStyleHelper::StateStyleSet QelStyleHelper::buttonStateStyles(
QelTheme::ButtonKind kind,
bool isPlain)
{
return {
buttonStyle(kind, isPlain, QelVisualState::Normal),
buttonStyle(kind, isPlain, QelVisualState::Hover),
buttonStyle(kind, isPlain, QelVisualState::Active),
buttonStyle(kind, isPlain, QelVisualState::Focus),
buttonStyle(kind, isPlain, QelVisualState::Disabled),
buttonStyle(kind, isPlain, QelVisualState::Loading)
};
}
QString QelStyleHelper::composeStateStyleSheet(
const QString &baseSelector,
const QString &loadingSelector,
const StateStyleSet &styles,
bool disableFocusOutline)
{
QString style;
style += QString("%1 { background-color: %2; color: %3; border: 1px solid %4; }")
.arg(baseSelector)
.arg(styles.normal.background)
.arg(styles.normal.text)
.arg(styles.normal.border);
style += QString("%1:hover { background-color: %2; color: %3; border: 1px solid %4; }")
.arg(baseSelector)
.arg(styles.hover.background)
.arg(styles.hover.text)
.arg(styles.hover.border);
style += QString("%1:pressed { background-color: %2; color: %3; border: 1px solid %4; }")
.arg(baseSelector)
.arg(styles.active.background)
.arg(styles.active.text)
.arg(styles.active.border);
style += QString("%1:focus { background-color: %2; color: %3; border: 1px solid %4;%5 }")
.arg(baseSelector)
.arg(styles.focus.background)
.arg(styles.focus.text)
.arg(styles.focus.border)
.arg(disableFocusOutline ? " outline: none;" : "");
style += QString("%1:disabled { background-color: %2; color: %3; border: 1px solid %4; }")
.arg(baseSelector)
.arg(styles.disabled.background)
.arg(styles.disabled.text)
.arg(styles.disabled.border);
if (!loadingSelector.isEmpty()) {
style += QString("%1 { background-color: %2; color: %3; border: 1px solid %4; }")
.arg(loadingSelector)
.arg(styles.loading.background)
.arg(styles.loading.text)
.arg(styles.loading.border);
}
return style;
}
QString QelStyleHelper::buttonStateStyleSheet(QelTheme::ButtonKind kind, bool isPlain)
{
const StateStyleSet styles = buttonStateStyles(kind, isPlain);
return composeStateStyleSheet(
"QPushButton",
"QPushButton[qel-loading=\"true\"]",
styles,
true);
}
} // namespace qel