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