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 | |
54 | QT_BEGIN_NAMESPACE |
55 | |
56 | class 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 themeChanged FINAL) |
70 | Q_PROPERTY(QColor primaryHighlightedTextColor READ primaryHighlightedTextColor NOTIFY primaryHighlightedTextColorChanged FINAL) |
71 | Q_PROPERTY(QColor secondaryTextColor READ secondaryTextColor NOTIFY themeChanged FINAL) |
72 | Q_PROPERTY(QColor hintTextColor READ hintTextColor NOTIFY themeChanged FINAL) |
73 | Q_PROPERTY(QColor textSelectionColor READ textSelectionColor NOTIFY themeOrAccentChanged FINAL) |
74 | Q_PROPERTY(QColor dropShadowColor READ dropShadowColor CONSTANT FINAL) |
75 | Q_PROPERTY(QColor dividerColor READ dividerColor NOTIFY themeChanged FINAL) |
76 | Q_PROPERTY(QColor iconColor READ iconColor NOTIFY themeChanged FINAL) |
77 | Q_PROPERTY(QColor iconDisabledColor READ iconDisabledColor NOTIFY themeChanged FINAL) |
78 | Q_PROPERTY(QColor buttonColor READ buttonColor NOTIFY buttonColorChanged FINAL) |
79 | Q_PROPERTY(QColor buttonDisabledColor READ buttonDisabledColor NOTIFY buttonDisabledColorChanged FINAL) |
80 | Q_PROPERTY(QColor highlightedButtonColor READ highlightedButtonColor NOTIFY buttonColorChanged FINAL) |
81 | Q_PROPERTY(QColor frameColor READ frameColor NOTIFY themeChanged FINAL) |
82 | Q_PROPERTY(QColor rippleColor READ rippleColor NOTIFY themeChanged FINAL) |
83 | Q_PROPERTY(QColor highlightedRippleColor READ highlightedRippleColor NOTIFY themeOrAccentChanged FINAL) |
84 | Q_PROPERTY(QColor switchUncheckedTrackColor READ switchUncheckedTrackColor NOTIFY themeChanged FINAL) |
85 | Q_PROPERTY(QColor switchCheckedTrackColor READ switchCheckedTrackColor NOTIFY themeOrAccentChanged FINAL) |
86 | Q_PROPERTY(QColor switchUncheckedHandleColor READ switchUncheckedHandleColor NOTIFY themeChanged FINAL) |
87 | Q_PROPERTY(QColor switchCheckedHandleColor READ switchCheckedHandleColor NOTIFY themeOrAccentChanged FINAL) |
88 | Q_PROPERTY(QColor switchDisabledTrackColor READ switchDisabledTrackColor NOTIFY themeChanged FINAL) |
89 | Q_PROPERTY(QColor switchDisabledHandleColor READ switchDisabledHandleColor NOTIFY themeChanged FINAL) |
90 | Q_PROPERTY(QColor scrollBarColor READ scrollBarColor NOTIFY themeChanged FINAL) |
91 | Q_PROPERTY(QColor scrollBarHoveredColor READ scrollBarHoveredColor NOTIFY themeChanged FINAL) |
92 | Q_PROPERTY(QColor scrollBarPressedColor READ scrollBarPressedColor NOTIFY themeChanged FINAL) |
93 | Q_PROPERTY(QColor dialogColor READ dialogColor NOTIFY dialogColorChanged FINAL) |
94 | Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY themeChanged FINAL) |
95 | Q_PROPERTY(QColor listHighlightColor READ listHighlightColor NOTIFY themeChanged FINAL) |
96 | Q_PROPERTY(QColor tooltipColor READ tooltipColor NOTIFY tooltipColorChanged FINAL) |
97 | Q_PROPERTY(QColor toolBarColor READ toolBarColor NOTIFY toolBarColorChanged FINAL) |
98 | Q_PROPERTY(QColor toolTextColor READ toolTextColor NOTIFY toolTextColorChanged FINAL) |
99 | Q_PROPERTY(QColor spinBoxDisabledIconColor READ spinBoxDisabledIconColor NOTIFY themeChanged FINAL) |
100 | Q_PROPERTY(QColor sliderDisabledColor READ sliderDisabledColor NOTIFY themeChanged FINAL REVISION 15) |
101 | |
102 | Q_PROPERTY(int touchTarget READ touchTarget CONSTANT FINAL) |
103 | Q_PROPERTY(int buttonHeight READ buttonHeight CONSTANT FINAL) |
104 | Q_PROPERTY(int delegateHeight READ delegateHeight CONSTANT FINAL) |
105 | Q_PROPERTY(int dialogButtonBoxHeight READ dialogButtonBoxHeight CONSTANT FINAL) |
106 | Q_PROPERTY(int frameVerticalPadding READ frameVerticalPadding CONSTANT FINAL) |
107 | Q_PROPERTY(int menuItemHeight READ menuItemHeight CONSTANT FINAL) |
108 | Q_PROPERTY(int menuItemVerticalPadding READ menuItemVerticalPadding CONSTANT FINAL) |
109 | Q_PROPERTY(int switchDelegateVerticalPadding READ switchDelegateVerticalPadding CONSTANT FINAL) |
110 | Q_PROPERTY(int tooltipHeight READ tooltipHeight CONSTANT FINAL) |
111 | |
112 | public: |
113 | enum Theme { |
114 | Light, |
115 | Dark, |
116 | System |
117 | }; |
118 | |
119 | enum Variant { |
120 | Normal, |
121 | Dense |
122 | }; |
123 | |
124 | enum Color { |
125 | Red, |
126 | Pink, |
127 | Purple, |
128 | DeepPurple, |
129 | Indigo, |
130 | Blue, |
131 | LightBlue, |
132 | Cyan, |
133 | Teal, |
134 | Green, |
135 | LightGreen, |
136 | Lime, |
137 | Yellow, |
138 | Amber, |
139 | Orange, |
140 | DeepOrange, |
141 | Brown, |
142 | Grey, |
143 | BlueGrey |
144 | }; |
145 | |
146 | enum Shade { |
147 | Shade50, |
148 | Shade100, |
149 | Shade200, |
150 | Shade300, |
151 | Shade400, |
152 | Shade500, |
153 | Shade600, |
154 | Shade700, |
155 | Shade800, |
156 | Shade900, |
157 | ShadeA100, |
158 | ShadeA200, |
159 | ShadeA400, |
160 | ShadeA700, |
161 | }; |
162 | |
163 | Q_ENUM(Theme) |
164 | Q_ENUM(Variant) |
165 | Q_ENUM(Color) |
166 | Q_ENUM(Shade) |
167 | |
168 | explicit QQuickMaterialStyle(QObject *parent = nullptr); |
169 | |
170 | static QQuickMaterialStyle *qmlAttachedProperties(QObject *object); |
171 | |
172 | Theme theme() const; |
173 | void setTheme(Theme theme); |
174 | void inheritTheme(Theme theme); |
175 | void propagateTheme(); |
176 | void resetTheme(); |
177 | void themeChange(); |
178 | |
179 | QVariant primary() const; |
180 | void setPrimary(const QVariant &accent); |
181 | void inheritPrimary(uint primary, bool custom); |
182 | void propagatePrimary(); |
183 | void resetPrimary(); |
184 | void primaryChange(); |
185 | |
186 | QVariant accent() const; |
187 | void setAccent(const QVariant &accent); |
188 | void inheritAccent(uint accent, bool custom); |
189 | void propagateAccent(); |
190 | void resetAccent(); |
191 | void accentChange(); |
192 | |
193 | QVariant foreground() const; |
194 | void setForeground(const QVariant &foreground); |
195 | void inheritForeground(uint foreground, bool custom, bool has); |
196 | void propagateForeground(); |
197 | void resetForeground(); |
198 | void foregroundChange(); |
199 | |
200 | QVariant background() const; |
201 | void setBackground(const QVariant &background); |
202 | void inheritBackground(uint background, bool custom, bool has); |
203 | void propagateBackground(); |
204 | void resetBackground(); |
205 | void backgroundChange(); |
206 | |
207 | int elevation() const; |
208 | void setElevation(int elevation); |
209 | void resetElevation(); |
210 | void elevationChange(); |
211 | |
212 | QColor primaryColor() const; |
213 | QColor accentColor() const; |
214 | QColor backgroundColor() const; |
215 | QColor primaryTextColor() const; |
216 | QColor primaryHighlightedTextColor() const; |
217 | QColor secondaryTextColor() const; |
218 | QColor hintTextColor() const; |
219 | QColor textSelectionColor() const; |
220 | QColor dropShadowColor() const; |
221 | QColor dividerColor() const; |
222 | QColor iconColor() const; |
223 | QColor iconDisabledColor() const; |
224 | QColor buttonColor() const; |
225 | QColor buttonDisabledColor() const; |
226 | QColor highlightedButtonColor() const; |
227 | QColor highlightedButtonDisabledColor() const; |
228 | QColor frameColor() const; |
229 | QColor rippleColor() const; |
230 | QColor highlightedRippleColor() const; |
231 | QColor switchUncheckedTrackColor() const; |
232 | QColor switchCheckedTrackColor() const; |
233 | QColor switchUncheckedHandleColor() const; |
234 | QColor switchCheckedHandleColor() const; |
235 | QColor switchDisabledTrackColor() const; |
236 | QColor switchDisabledHandleColor() const; |
237 | QColor scrollBarColor() const; |
238 | QColor scrollBarHoveredColor() const; |
239 | QColor scrollBarPressedColor() const; |
240 | QColor dialogColor() const; |
241 | QColor backgroundDimColor() const; |
242 | QColor listHighlightColor() const; |
243 | QColor tooltipColor() const; |
244 | QColor toolBarColor() const; |
245 | QColor toolTextColor() const; |
246 | QColor spinBoxDisabledIconColor() const; |
247 | QColor sliderDisabledColor() const; |
248 | |
249 | Q_INVOKABLE QColor color(Color color, Shade shade = Shade500) const; |
250 | Q_INVOKABLE QColor shade(const QColor &color, Shade shade) const; |
251 | |
252 | int touchTarget() const; |
253 | int buttonHeight() const; |
254 | int delegateHeight() const; |
255 | int dialogButtonBoxHeight() const; |
256 | int frameVerticalPadding() const; |
257 | int () const; |
258 | int () const; |
259 | int switchDelegateVerticalPadding() const; |
260 | int tooltipHeight() const; |
261 | |
262 | static void initGlobals(); |
263 | |
264 | static Variant variant(); |
265 | |
266 | Q_SIGNALS: |
267 | void themeChanged(); |
268 | void primaryChanged(); |
269 | void accentChanged(); |
270 | void foregroundChanged(); |
271 | void backgroundChanged(); |
272 | void elevationChanged(); |
273 | |
274 | void themeOrAccentChanged(); |
275 | |
276 | void primaryHighlightedTextColorChanged(); |
277 | void buttonColorChanged(); |
278 | void buttonDisabledColorChanged(); |
279 | void dialogColorChanged(); |
280 | void tooltipColorChanged(); |
281 | void toolBarColorChanged(); |
282 | void toolTextColorChanged(); |
283 | |
284 | protected: |
285 | void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) override; |
286 | |
287 | private: |
288 | void init(); |
289 | bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const; |
290 | |
291 | QColor backgroundColor(Shade shade) const; |
292 | QColor accentColor(Shade shade) const; |
293 | QColor buttonColor(bool highlighted) const; |
294 | Shade themeShade() const; |
295 | |
296 | // These reflect whether a color value was explicitly set on the specific |
297 | // item that this attached style object represents. |
298 | bool m_explicitTheme = false; |
299 | bool m_explicitPrimary = false; |
300 | bool m_explicitAccent = false; |
301 | bool m_explicitForeground = false; |
302 | bool m_explicitBackground = false; |
303 | // These reflect whether the color value that was either inherited or |
304 | // explicitly set is in the form that QColor expects, rather than one of |
305 | // our pre-defined color enum values. |
306 | bool m_customPrimary = false; |
307 | bool m_customAccent = false; |
308 | bool m_customForeground = false; |
309 | bool m_customBackground = false; |
310 | // These will be true when this item has an explicit or inherited foreground/background |
311 | // color, or these colors were declared globally via settings (e.g. conf or env vars). |
312 | // Some color properties of the style will return different values depending on whether |
313 | // or not these are set. |
314 | bool m_hasForeground = false; |
315 | bool m_hasBackground = false; |
316 | // The actual values for this item, whether explicit, inherited or globally set. |
317 | Theme m_theme = Light; |
318 | uint m_primary = 0; |
319 | uint m_accent = 0; |
320 | uint m_foreground = 0; |
321 | uint m_background = 0; |
322 | int m_elevation = 0; |
323 | }; |
324 | |
325 | QT_END_NAMESPACE |
326 | |
327 | QML_DECLARE_TYPEINFO(QQuickMaterialStyle, QML_HAS_ATTACHED_PROPERTIES) |
328 | |
329 | #endif // QQUICKMATERIALSTYLE_P_H |
330 | |