1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QQUICKMATERIALSTYLE_P_H
38#define QQUICKMATERIALSTYLE_P_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include <QtGui/qcolor.h>
52#include <QtQuickControls2/private/qquickattachedobject_p.h>
53
54QT_BEGIN_NAMESPACE
55
56class QQuickMaterialStyle : public QQuickAttachedObject
57{
58 Q_OBJECT
59 Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL)
60 Q_PROPERTY(QVariant primary READ primary WRITE setPrimary RESET resetPrimary NOTIFY primaryChanged FINAL)
61 Q_PROPERTY(QVariant accent READ accent WRITE setAccent RESET resetAccent NOTIFY accentChanged FINAL)
62 Q_PROPERTY(QVariant foreground READ foreground WRITE setForeground RESET resetForeground NOTIFY foregroundChanged FINAL)
63 Q_PROPERTY(QVariant background READ background WRITE setBackground RESET resetBackground NOTIFY backgroundChanged FINAL)
64 Q_PROPERTY(int elevation READ elevation WRITE setElevation RESET resetElevation NOTIFY elevationChanged FINAL)
65
66 Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY primaryChanged FINAL) // TODO: remove?
67 Q_PROPERTY(QColor accentColor READ accentColor NOTIFY accentChanged FINAL) // TODO: remove?
68 Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY backgroundChanged FINAL)
69 Q_PROPERTY(QColor primaryTextColor READ primaryTextColor NOTIFY paletteChanged FINAL)
70 Q_PROPERTY(QColor primaryHighlightedTextColor READ primaryHighlightedTextColor NOTIFY paletteChanged FINAL)
71 Q_PROPERTY(QColor secondaryTextColor READ secondaryTextColor NOTIFY paletteChanged FINAL)
72 Q_PROPERTY(QColor hintTextColor READ hintTextColor NOTIFY paletteChanged FINAL)
73 Q_PROPERTY(QColor textSelectionColor READ textSelectionColor NOTIFY paletteChanged FINAL)
74 Q_PROPERTY(QColor dropShadowColor READ dropShadowColor NOTIFY paletteChanged FINAL)
75 Q_PROPERTY(QColor dividerColor READ dividerColor NOTIFY paletteChanged FINAL)
76 Q_PROPERTY(QColor iconColor READ iconColor NOTIFY paletteChanged FINAL)
77 Q_PROPERTY(QColor iconDisabledColor READ iconDisabledColor NOTIFY paletteChanged FINAL)
78 Q_PROPERTY(QColor buttonColor READ buttonColor NOTIFY paletteChanged FINAL)
79 Q_PROPERTY(QColor buttonDisabledColor READ buttonDisabledColor NOTIFY paletteChanged FINAL)
80 Q_PROPERTY(QColor highlightedButtonColor READ highlightedButtonColor NOTIFY paletteChanged FINAL)
81 Q_PROPERTY(QColor frameColor READ frameColor NOTIFY paletteChanged FINAL)
82 Q_PROPERTY(QColor rippleColor READ rippleColor NOTIFY paletteChanged FINAL)
83 Q_PROPERTY(QColor highlightedRippleColor READ highlightedRippleColor NOTIFY paletteChanged FINAL)
84 Q_PROPERTY(QColor switchUncheckedTrackColor READ switchUncheckedTrackColor NOTIFY paletteChanged FINAL)
85 Q_PROPERTY(QColor switchCheckedTrackColor READ switchCheckedTrackColor NOTIFY paletteChanged FINAL)
86 Q_PROPERTY(QColor switchUncheckedHandleColor READ switchUncheckedHandleColor NOTIFY paletteChanged FINAL)
87 Q_PROPERTY(QColor switchCheckedHandleColor READ switchCheckedHandleColor NOTIFY paletteChanged FINAL)
88 Q_PROPERTY(QColor switchDisabledTrackColor READ switchDisabledTrackColor NOTIFY paletteChanged FINAL)
89 Q_PROPERTY(QColor switchDisabledHandleColor READ switchDisabledHandleColor NOTIFY paletteChanged FINAL)
90 Q_PROPERTY(QColor scrollBarColor READ scrollBarColor NOTIFY paletteChanged FINAL)
91 Q_PROPERTY(QColor scrollBarHoveredColor READ scrollBarHoveredColor NOTIFY paletteChanged FINAL)
92 Q_PROPERTY(QColor scrollBarPressedColor READ scrollBarPressedColor NOTIFY paletteChanged FINAL)
93 Q_PROPERTY(QColor dialogColor READ dialogColor NOTIFY paletteChanged FINAL)
94 Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY paletteChanged FINAL)
95 Q_PROPERTY(QColor listHighlightColor READ listHighlightColor NOTIFY paletteChanged FINAL)
96 Q_PROPERTY(QColor tooltipColor READ tooltipColor NOTIFY paletteChanged FINAL)
97 Q_PROPERTY(QColor toolBarColor READ toolBarColor NOTIFY paletteChanged FINAL)
98 Q_PROPERTY(QColor toolTextColor READ toolTextColor NOTIFY paletteChanged FINAL)
99 Q_PROPERTY(QColor spinBoxDisabledIconColor READ spinBoxDisabledIconColor NOTIFY paletteChanged FINAL)
100
101 Q_PROPERTY(int touchTarget READ touchTarget CONSTANT FINAL)
102 Q_PROPERTY(int buttonHeight READ buttonHeight CONSTANT FINAL)
103 Q_PROPERTY(int delegateHeight READ delegateHeight CONSTANT FINAL)
104 Q_PROPERTY(int dialogButtonBoxHeight READ dialogButtonBoxHeight CONSTANT FINAL)
105 Q_PROPERTY(int frameVerticalPadding READ frameVerticalPadding CONSTANT FINAL)
106 Q_PROPERTY(int menuItemHeight READ menuItemHeight CONSTANT FINAL)
107 Q_PROPERTY(int menuItemVerticalPadding READ menuItemVerticalPadding CONSTANT FINAL)
108 Q_PROPERTY(int switchDelegateVerticalPadding READ switchDelegateVerticalPadding CONSTANT FINAL)
109 Q_PROPERTY(int tooltipHeight READ tooltipHeight CONSTANT FINAL)
110
111public:
112 enum Theme {
113 Light,
114 Dark,
115 System
116 };
117
118 enum Variant {
119 Normal,
120 Dense
121 };
122
123 enum Color {
124 Red,
125 Pink,
126 Purple,
127 DeepPurple,
128 Indigo,
129 Blue,
130 LightBlue,
131 Cyan,
132 Teal,
133 Green,
134 LightGreen,
135 Lime,
136 Yellow,
137 Amber,
138 Orange,
139 DeepOrange,
140 Brown,
141 Grey,
142 BlueGrey
143 };
144
145 enum Shade {
146 Shade50,
147 Shade100,
148 Shade200,
149 Shade300,
150 Shade400,
151 Shade500,
152 Shade600,
153 Shade700,
154 Shade800,
155 Shade900,
156 ShadeA100,
157 ShadeA200,
158 ShadeA400,
159 ShadeA700,
160 };
161
162 Q_ENUM(Theme)
163 Q_ENUM(Variant)
164 Q_ENUM(Color)
165 Q_ENUM(Shade)
166
167 explicit QQuickMaterialStyle(QObject *parent = nullptr);
168
169 static QQuickMaterialStyle *qmlAttachedProperties(QObject *object);
170
171 Theme theme() const;
172 void setTheme(Theme theme);
173 void inheritTheme(Theme theme);
174 void propagateTheme();
175 void resetTheme();
176
177 QVariant primary() const;
178 void setPrimary(const QVariant &accent);
179 void inheritPrimary(uint primary, bool custom);
180 void propagatePrimary();
181 void resetPrimary();
182
183 QVariant accent() const;
184 void setAccent(const QVariant &accent);
185 void inheritAccent(uint accent, bool custom);
186 void propagateAccent();
187 void resetAccent();
188
189 QVariant foreground() const;
190 void setForeground(const QVariant &foreground);
191 void inheritForeground(uint foreground, bool custom, bool has);
192 void propagateForeground();
193 void resetForeground();
194
195 QVariant background() const;
196 void setBackground(const QVariant &background);
197 void inheritBackground(uint background, bool custom, bool has);
198 void propagateBackground();
199 void resetBackground();
200
201 int elevation() const;
202 void setElevation(int elevation);
203 void resetElevation();
204
205 QColor primaryColor() const;
206 QColor accentColor() const;
207 QColor backgroundColor() const;
208 QColor primaryTextColor() const;
209 QColor primaryHighlightedTextColor() const;
210 QColor secondaryTextColor() const;
211 QColor hintTextColor() const;
212 QColor textSelectionColor() const;
213 QColor dropShadowColor() const;
214 QColor dividerColor() const;
215 QColor iconColor() const;
216 QColor iconDisabledColor() const;
217 QColor buttonColor() const;
218 QColor buttonDisabledColor() const;
219 QColor highlightedButtonColor() const;
220 QColor highlightedButtonDisabledColor() const;
221 QColor frameColor() const;
222 QColor rippleColor() const;
223 QColor highlightedRippleColor() const;
224 QColor switchUncheckedTrackColor() const;
225 QColor switchCheckedTrackColor() const;
226 QColor switchUncheckedHandleColor() const;
227 QColor switchCheckedHandleColor() const;
228 QColor switchDisabledTrackColor() const;
229 QColor switchDisabledHandleColor() const;
230 QColor scrollBarColor() const;
231 QColor scrollBarHoveredColor() const;
232 QColor scrollBarPressedColor() const;
233 QColor dialogColor() const;
234 QColor backgroundDimColor() const;
235 QColor listHighlightColor() const;
236 QColor tooltipColor() const;
237 QColor toolBarColor() const;
238 QColor toolTextColor() const;
239 QColor spinBoxDisabledIconColor() const;
240
241 Q_INVOKABLE QColor color(Color color, Shade shade = Shade500) const;
242 Q_INVOKABLE QColor shade(const QColor &color, Shade shade) const;
243
244 int touchTarget() const;
245 int buttonHeight() const;
246 int delegateHeight() const;
247 int dialogButtonBoxHeight() const;
248 int frameVerticalPadding() const;
249 int menuItemHeight() const;
250 int menuItemVerticalPadding() const;
251 int switchDelegateVerticalPadding() const;
252 int tooltipHeight() const;
253
254 static void initGlobals();
255
256 static Variant variant();
257
258Q_SIGNALS:
259 void themeChanged();
260 void primaryChanged();
261 void accentChanged();
262 void foregroundChanged();
263 void backgroundChanged();
264 void elevationChanged();
265
266 void paletteChanged();
267
268protected:
269 void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) override;
270
271private:
272 void init();
273 bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const;
274
275 QColor backgroundColor(Shade shade) const;
276 QColor accentColor(Shade shade) const;
277 QColor buttonColor(bool highlighted) const;
278 Shade themeShade() const;
279
280 // These reflect whether a color value was explicitly set on the specific
281 // item that this attached style object represents.
282 bool m_explicitTheme = false;
283 bool m_explicitPrimary = false;
284 bool m_explicitAccent = false;
285 bool m_explicitForeground = false;
286 bool m_explicitBackground = false;
287 // These reflect whether the color value that was either inherited or
288 // explicitly set is in the form that QColor expects, rather than one of
289 // our pre-defined color enum values.
290 bool m_customPrimary = false;
291 bool m_customAccent = false;
292 bool m_customForeground = false;
293 bool m_customBackground = false;
294 // These will be true when this item has an explicit or inherited foreground/background
295 // color, or these colors were declared globally via settings (e.g. conf or env vars).
296 // Some color properties of the style will return different values depending on whether
297 // or not these are set.
298 bool m_hasForeground = false;
299 bool m_hasBackground = false;
300 // The actual values for this item, whether explicit, inherited or globally set.
301 Theme m_theme = Light;
302 uint m_primary = 0;
303 uint m_accent = 0;
304 uint m_foreground = 0;
305 uint m_background = 0;
306 int m_elevation = 0;
307};
308
309QT_END_NAMESPACE
310
311QML_DECLARE_TYPEINFO(QQuickMaterialStyle, QML_HAS_ATTACHED_PROPERTIES)
312
313#endif // QQUICKMATERIALSTYLE_P_H
314