1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKMATERIALSTYLE_P_H
5#define QQUICKMATERIALSTYLE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/qcolor.h>
19#include <QtQml/qqml.h>
20#include <QtQuickControls2/qquickattachedpropertypropagator.h>
21
22QT_BEGIN_NAMESPACE
23
24class QQuickMaterialStyle : public QQuickAttachedPropertyPropagator
25{
26 Q_OBJECT
27 Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL)
28 Q_PROPERTY(QVariant primary READ primary WRITE setPrimary RESET resetPrimary NOTIFY primaryChanged FINAL)
29 Q_PROPERTY(QVariant accent READ accent WRITE setAccent RESET resetAccent NOTIFY accentChanged FINAL)
30 Q_PROPERTY(QVariant foreground READ foreground WRITE setForeground RESET resetForeground NOTIFY foregroundChanged FINAL)
31 Q_PROPERTY(QVariant background READ background WRITE setBackground RESET resetBackground NOTIFY backgroundChanged FINAL)
32 Q_PROPERTY(int elevation READ elevation WRITE setElevation RESET resetElevation NOTIFY elevationChanged FINAL)
33 Q_PROPERTY(RoundedScale roundedScale READ roundedScale WRITE setRoundedScale RESET resetRoundedScale
34 NOTIFY roundedScaleChanged FINAL)
35 Q_PROPERTY(ContainerStyle containerStyle READ containerStyle WRITE setContainerStyle RESET resetContainerStyle
36 NOTIFY containerStyleChanged FINAL)
37
38 Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY primaryChanged FINAL) // TODO: remove?
39 Q_PROPERTY(QColor accentColor READ accentColor NOTIFY accentChanged FINAL) // TODO: remove?
40 Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY backgroundChanged FINAL)
41 Q_PROPERTY(QColor primaryTextColor READ primaryTextColor NOTIFY themeChanged FINAL)
42 Q_PROPERTY(QColor primaryHighlightedTextColor READ primaryHighlightedTextColor NOTIFY primaryHighlightedTextColorChanged FINAL)
43 Q_PROPERTY(QColor secondaryTextColor READ secondaryTextColor NOTIFY themeChanged FINAL)
44 Q_PROPERTY(QColor hintTextColor READ hintTextColor NOTIFY themeChanged FINAL)
45 Q_PROPERTY(QColor textSelectionColor READ textSelectionColor NOTIFY themeOrAccentChanged FINAL)
46 Q_PROPERTY(QColor dropShadowColor READ dropShadowColor CONSTANT FINAL)
47 Q_PROPERTY(QColor dividerColor READ dividerColor NOTIFY themeChanged FINAL)
48 Q_PROPERTY(QColor iconColor READ iconColor NOTIFY themeChanged FINAL)
49 Q_PROPERTY(QColor iconDisabledColor READ iconDisabledColor NOTIFY themeChanged FINAL)
50 Q_PROPERTY(QColor frameColor READ frameColor NOTIFY themeChanged FINAL)
51 Q_PROPERTY(QColor rippleColor READ rippleColor NOTIFY themeChanged FINAL)
52 Q_PROPERTY(QColor highlightedRippleColor READ highlightedRippleColor NOTIFY themeOrAccentChanged FINAL)
53 Q_PROPERTY(QColor switchUncheckedTrackColor READ switchUncheckedTrackColor NOTIFY themeChanged FINAL)
54 Q_PROPERTY(QColor switchCheckedTrackColor READ switchCheckedTrackColor NOTIFY themeOrAccentChanged FINAL)
55 Q_PROPERTY(QColor switchUncheckedHandleColor READ switchUncheckedHandleColor NOTIFY themeChanged FINAL)
56 Q_PROPERTY(QColor switchUncheckedHoveredHandleColor READ switchUncheckedHoveredHandleColor NOTIFY themeChanged FINAL)
57 Q_PROPERTY(QColor switchDisabledUncheckedTrackColor READ switchDisabledUncheckedTrackColor NOTIFY themeChanged FINAL)
58 Q_PROPERTY(QColor switchDisabledCheckedTrackColor READ switchDisabledCheckedTrackColor NOTIFY themeChanged FINAL)
59 Q_PROPERTY(QColor switchDisabledUncheckedTrackBorderColor READ switchDisabledUncheckedTrackBorderColor NOTIFY themeChanged FINAL)
60 Q_PROPERTY(QColor switchCheckedHandleColor READ switchCheckedHandleColor NOTIFY themeOrAccentChanged FINAL)
61 Q_PROPERTY(QColor switchDisabledUncheckedHandleColor READ switchDisabledUncheckedHandleColor NOTIFY themeChanged FINAL)
62 Q_PROPERTY(QColor switchDisabledCheckedHandleColor READ switchDisabledCheckedHandleColor NOTIFY themeChanged FINAL)
63 Q_PROPERTY(QColor switchDisabledCheckedIconColor READ switchDisabledCheckedIconColor NOTIFY themeChanged FINAL)
64 Q_PROPERTY(QColor switchDisabledUncheckedIconColor READ switchDisabledUncheckedIconColor NOTIFY themeChanged FINAL)
65 Q_PROPERTY(QColor scrollBarColor READ scrollBarColor NOTIFY themeChanged FINAL)
66 Q_PROPERTY(QColor scrollBarHoveredColor READ scrollBarHoveredColor NOTIFY themeChanged FINAL)
67 Q_PROPERTY(QColor scrollBarPressedColor READ scrollBarPressedColor NOTIFY themeChanged FINAL)
68 Q_PROPERTY(QColor dialogColor READ dialogColor NOTIFY dialogColorChanged FINAL)
69 Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY themeChanged FINAL)
70 Q_PROPERTY(QColor listHighlightColor READ listHighlightColor NOTIFY themeChanged FINAL)
71 Q_PROPERTY(QColor tooltipColor READ tooltipColor NOTIFY tooltipColorChanged FINAL)
72 Q_PROPERTY(QColor toolBarColor READ toolBarColor NOTIFY toolBarColorChanged FINAL)
73 Q_PROPERTY(QColor toolTextColor READ toolTextColor NOTIFY toolTextColorChanged FINAL)
74 Q_PROPERTY(QColor spinBoxDisabledIconColor READ spinBoxDisabledIconColor NOTIFY themeChanged FINAL)
75 Q_PROPERTY(QColor sliderDisabledColor READ sliderDisabledColor NOTIFY themeChanged FINAL REVISION(2, 15))
76 Q_PROPERTY(QColor textFieldFilledContainerColor READ textFieldFilledContainerColor NOTIFY themeChanged FINAL)
77
78 Q_PROPERTY(int touchTarget READ touchTarget CONSTANT FINAL)
79 Q_PROPERTY(int buttonHeight READ buttonHeight CONSTANT FINAL)
80 Q_PROPERTY(int delegateHeight READ delegateHeight CONSTANT FINAL)
81 Q_PROPERTY(int dialogButtonBoxHeight READ dialogButtonBoxHeight CONSTANT FINAL)
82 Q_PROPERTY(int frameVerticalPadding READ frameVerticalPadding CONSTANT FINAL)
83 Q_PROPERTY(int menuItemHeight READ menuItemHeight CONSTANT FINAL)
84 Q_PROPERTY(int menuItemVerticalPadding READ menuItemVerticalPadding CONSTANT FINAL)
85 Q_PROPERTY(int switchIndicatorWidth READ switchIndicatorWidth CONSTANT FINAL)
86 Q_PROPERTY(int switchIndicatorHeight READ switchIndicatorHeight CONSTANT FINAL)
87 Q_PROPERTY(int switchNormalHandleHeight READ switchNormalHandleHeight CONSTANT FINAL)
88 Q_PROPERTY(int switchCheckedHandleHeight READ switchCheckedHandleHeight CONSTANT FINAL)
89 Q_PROPERTY(int switchLargestHandleHeight READ switchLargestHandleHeight CONSTANT FINAL)
90 Q_PROPERTY(int switchDelegateVerticalPadding READ switchDelegateVerticalPadding CONSTANT FINAL)
91 Q_PROPERTY(int textFieldHeight READ textFieldHeight CONSTANT FINAL)
92 Q_PROPERTY(int textFieldHorizontalPadding READ textFieldHorizontalPadding CONSTANT FINAL)
93 Q_PROPERTY(int textFieldVerticalPadding READ textFieldVerticalPadding CONSTANT FINAL)
94 Q_PROPERTY(int tooltipHeight READ tooltipHeight CONSTANT FINAL)
95
96 QML_NAMED_ELEMENT(Material)
97 QML_ATTACHED(QQuickMaterialStyle)
98 QML_UNCREATABLE("")
99 QML_ADDED_IN_VERSION(2, 0)
100
101public:
102 enum Theme {
103 Light,
104 Dark,
105 System
106 };
107
108 enum Variant {
109 Normal,
110 Dense
111 };
112
113 enum Color {
114 Red,
115 Pink,
116 Purple,
117 DeepPurple,
118 Indigo,
119 Blue,
120 LightBlue,
121 Cyan,
122 Teal,
123 Green,
124 LightGreen,
125 Lime,
126 Yellow,
127 Amber,
128 Orange,
129 DeepOrange,
130 Brown,
131 Grey,
132 BlueGrey
133 };
134
135 enum Shade {
136 Shade50,
137 Shade100,
138 Shade200,
139 Shade300,
140 Shade400,
141 Shade500,
142 Shade600,
143 Shade700,
144 Shade800,
145 Shade900,
146 ShadeA100,
147 ShadeA200,
148 ShadeA400,
149 ShadeA700,
150 };
151
152 enum class RoundedScale {
153 NotRounded,
154 ExtraSmallScale = 4,
155 SmallScale = 8,
156 MediumScale = 12,
157 LargeScale = 16,
158 ExtraLargeScale = 28,
159 FullScale = 0xFF // For full we use half the height of the item.
160 };
161
162 enum class ContainerStyle {
163 Filled,
164 Outlined
165 };
166
167 Q_ENUM(Theme)
168 Q_ENUM(Variant)
169 Q_ENUM(Color)
170 Q_ENUM(Shade)
171 Q_ENUM(RoundedScale)
172 Q_ENUM(ContainerStyle)
173
174 explicit QQuickMaterialStyle(QObject *parent = nullptr);
175
176 static QQuickMaterialStyle *qmlAttachedProperties(QObject *object);
177
178 Theme theme() const;
179 void setTheme(Theme theme);
180 void inheritTheme(Theme theme);
181 void propagateTheme();
182 void resetTheme();
183 void themeChange();
184
185 QVariant primary() const;
186 void setPrimary(const QVariant &accent);
187 void inheritPrimary(uint primary, bool custom);
188 void propagatePrimary();
189 void resetPrimary();
190 void primaryChange();
191
192 QVariant accent() const;
193 void setAccent(const QVariant &accent);
194 void inheritAccent(uint accent, bool custom);
195 void propagateAccent();
196 void resetAccent();
197 void accentChange();
198
199 QVariant foreground() const;
200 void setForeground(const QVariant &foreground);
201 void inheritForeground(uint foreground, bool custom, bool has);
202 void propagateForeground();
203 void resetForeground();
204 void foregroundChange();
205
206 QVariant background() const;
207 void setBackground(const QVariant &background);
208 void inheritBackground(uint background, bool custom, bool has);
209 void propagateBackground();
210 void resetBackground();
211 void backgroundChange();
212
213 int elevation() const;
214 void setElevation(int elevation);
215 void resetElevation();
216 void elevationChange();
217
218 RoundedScale roundedScale() const;
219 void setRoundedScale(RoundedScale roundedScale);
220 void resetRoundedScale();
221
222 ContainerStyle containerStyle() const;
223 void setContainerStyle(ContainerStyle containerStyle);
224 void resetContainerStyle();
225
226 QColor primaryColor() const;
227 QColor accentColor() const;
228 QColor backgroundColor() const;
229 QColor primaryTextColor() const;
230 QColor primaryHighlightedTextColor() const;
231 QColor secondaryTextColor() const;
232 QColor hintTextColor() const;
233 QColor textSelectionColor() const;
234 QColor dropShadowColor() const;
235 QColor dividerColor() const;
236 QColor iconColor() const;
237 QColor iconDisabledColor() const;
238 Q_INVOKABLE QColor buttonColor(Theme theme, const QVariant &background, const QVariant &accent,
239 bool enabled, bool flat, bool highlighted, bool checked) const;
240 QColor frameColor() const;
241 QColor rippleColor() const;
242 QColor highlightedRippleColor() const;
243 QColor switchUncheckedTrackColor() const;
244 QColor switchCheckedTrackColor() const;
245 QColor switchDisabledUncheckedTrackColor() const;
246 QColor switchDisabledCheckedTrackColor() const;
247 QColor switchDisabledUncheckedTrackBorderColor() const;
248 QColor switchUncheckedHandleColor() const;
249 QColor switchUncheckedHoveredHandleColor() const;
250 QColor switchCheckedHandleColor() const;
251 QColor switchDisabledUncheckedHandleColor() const;
252 QColor switchDisabledCheckedHandleColor() const;
253 QColor switchDisabledCheckedIconColor() const;
254 QColor switchDisabledUncheckedIconColor() const;
255 QColor scrollBarColor() const;
256 QColor scrollBarHoveredColor() const;
257 QColor scrollBarPressedColor() const;
258 QColor dialogColor() const;
259 QColor backgroundDimColor() const;
260 QColor listHighlightColor() const;
261 QColor tooltipColor() const;
262 QColor toolBarColor() const;
263 QColor toolTextColor() const;
264 QColor spinBoxDisabledIconColor() const;
265 QColor sliderDisabledColor() const;
266 QColor textFieldFilledContainerColor() const;
267
268 Q_INVOKABLE QColor color(Color color, Shade shade = Shade500) const;
269 Q_INVOKABLE QColor shade(const QColor &color, Shade shade) const;
270
271 int touchTarget() const;
272 int buttonHeight() const;
273 int delegateHeight() const;
274 int dialogButtonBoxHeight() const;
275 int frameVerticalPadding() const;
276 int menuItemHeight() const;
277 int menuItemVerticalPadding() const;
278 int switchIndicatorWidth() const;
279 int switchIndicatorHeight() const;
280 int switchNormalHandleHeight() const;
281 int switchCheckedHandleHeight() const;
282 int switchLargestHandleHeight() const;
283 int switchDelegateVerticalPadding() const;
284 int textFieldHeight() const;
285 int textFieldHorizontalPadding() const;
286 int textFieldVerticalPadding() const;
287 int tooltipHeight() const;
288
289 static void initGlobals();
290
291 static Variant variant();
292
293Q_SIGNALS:
294 void themeChanged();
295 void primaryChanged();
296 void accentChanged();
297 void foregroundChanged();
298 void backgroundChanged();
299 void elevationChanged();
300
301 void themeOrAccentChanged();
302
303 void primaryHighlightedTextColorChanged();
304 void dialogColorChanged();
305 void tooltipColorChanged();
306 void toolBarColorChanged();
307 void toolTextColorChanged();
308 void roundedScaleChanged();
309 void containerStyleChanged();
310
311protected:
312 void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent) override;
313
314private:
315 void init();
316 bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const;
317
318 QColor backgroundColor(Shade shade) const;
319 QColor accentColor(Shade shade) const;
320
321 Shade themeShade() const;
322
323 // These reflect whether a color value was explicitly set on the specific
324 // item that this attached style object represents.
325 bool m_explicitTheme = false;
326 bool m_explicitPrimary = false;
327 bool m_explicitAccent = false;
328 bool m_explicitForeground = false;
329 bool m_explicitBackground = false;
330 // These reflect whether the color value that was either inherited or
331 // explicitly set is in the form that QColor expects, rather than one of
332 // our pre-defined color enum values.
333 bool m_customPrimary = false;
334 bool m_customAccent = false;
335 bool m_customForeground = false;
336 bool m_customBackground = false;
337 // These will be true when this item has an explicit or inherited foreground/background
338 // color, or these colors were declared globally via settings (e.g. conf or env vars).
339 // Some color properties of the style will return different values depending on whether
340 // or not these are set.
341 bool m_hasForeground = false;
342 bool m_hasBackground = false;
343 // The actual values for this item, whether explicit, inherited or globally set.
344 Theme m_theme = Light;
345 uint m_primary = 0;
346 uint m_accent = 0;
347 uint m_foreground = 0;
348 uint m_background = 0;
349 int m_elevation = 0;
350 RoundedScale m_roundedScale = RoundedScale::NotRounded;
351 ContainerStyle m_containerStyle = ContainerStyle::Filled;
352};
353
354QT_END_NAMESPACE
355
356#endif // QQUICKMATERIALSTYLE_P_H
357

source code of qtdeclarative/src/quickcontrols/material/qquickmaterialstyle_p.h