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 QQUICKUNIVERSALSTYLE_P_H
38#define QQUICKUNIVERSALSTYLE_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 QQuickUniversalStylePrivate;
57
58class QQuickUniversalStyle : public QQuickAttachedObject
59{
60 Q_OBJECT
61 Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL)
62 Q_PROPERTY(QVariant accent READ accent WRITE setAccent RESET resetAccent NOTIFY accentChanged FINAL)
63 Q_PROPERTY(QVariant foreground READ foreground WRITE setForeground RESET resetForeground NOTIFY foregroundChanged FINAL)
64 Q_PROPERTY(QVariant background READ background WRITE setBackground RESET resetBackground NOTIFY backgroundChanged FINAL)
65
66 Q_PROPERTY(QColor altHighColor READ altHighColor NOTIFY paletteChanged FINAL)
67 Q_PROPERTY(QColor altLowColor READ altLowColor NOTIFY paletteChanged FINAL)
68 Q_PROPERTY(QColor altMediumColor READ altMediumColor NOTIFY paletteChanged FINAL)
69 Q_PROPERTY(QColor altMediumHighColor READ altMediumHighColor NOTIFY paletteChanged FINAL)
70 Q_PROPERTY(QColor altMediumLowColor READ altMediumLowColor NOTIFY paletteChanged FINAL)
71 Q_PROPERTY(QColor baseHighColor READ baseHighColor NOTIFY paletteChanged FINAL)
72 Q_PROPERTY(QColor baseLowColor READ baseLowColor NOTIFY paletteChanged FINAL)
73 Q_PROPERTY(QColor baseMediumColor READ baseMediumColor NOTIFY paletteChanged FINAL)
74 Q_PROPERTY(QColor baseMediumHighColor READ baseMediumHighColor NOTIFY paletteChanged FINAL)
75 Q_PROPERTY(QColor baseMediumLowColor READ baseMediumLowColor NOTIFY paletteChanged FINAL)
76 Q_PROPERTY(QColor chromeAltLowColor READ chromeAltLowColor NOTIFY paletteChanged FINAL)
77 Q_PROPERTY(QColor chromeBlackHighColor READ chromeBlackHighColor NOTIFY paletteChanged FINAL)
78 Q_PROPERTY(QColor chromeBlackLowColor READ chromeBlackLowColor NOTIFY paletteChanged FINAL)
79 Q_PROPERTY(QColor chromeBlackMediumLowColor READ chromeBlackMediumLowColor NOTIFY paletteChanged FINAL)
80 Q_PROPERTY(QColor chromeBlackMediumColor READ chromeBlackMediumColor NOTIFY paletteChanged FINAL)
81 Q_PROPERTY(QColor chromeDisabledHighColor READ chromeDisabledHighColor NOTIFY paletteChanged FINAL)
82 Q_PROPERTY(QColor chromeDisabledLowColor READ chromeDisabledLowColor NOTIFY paletteChanged FINAL)
83 Q_PROPERTY(QColor chromeHighColor READ chromeHighColor NOTIFY paletteChanged FINAL)
84 Q_PROPERTY(QColor chromeLowColor READ chromeLowColor NOTIFY paletteChanged FINAL)
85 Q_PROPERTY(QColor chromeMediumColor READ chromeMediumColor NOTIFY paletteChanged FINAL)
86 Q_PROPERTY(QColor chromeMediumLowColor READ chromeMediumLowColor NOTIFY paletteChanged FINAL)
87 Q_PROPERTY(QColor chromeWhiteColor READ chromeWhiteColor NOTIFY paletteChanged FINAL)
88 Q_PROPERTY(QColor listLowColor READ listLowColor NOTIFY paletteChanged FINAL)
89 Q_PROPERTY(QColor listMediumColor READ listMediumColor NOTIFY paletteChanged FINAL)
90
91public:
92 explicit QQuickUniversalStyle(QObject *parent = nullptr);
93
94 static QQuickUniversalStyle *qmlAttachedProperties(QObject *object);
95
96 enum Theme { Light, Dark, System };
97 Q_ENUM(Theme)
98
99 Theme theme() const;
100 void setTheme(Theme theme);
101 void inheritTheme(Theme theme);
102 void propagateTheme();
103 void resetTheme();
104
105 enum Color {
106 Lime,
107 Green,
108 Emerald,
109 Teal,
110 Cyan,
111 Cobalt,
112 Indigo,
113 Violet,
114 Pink,
115 Magenta,
116 Crimson,
117 Red,
118 Orange,
119 Amber,
120 Yellow,
121 Brown,
122 Olive,
123 Steel,
124 Mauve,
125 Taupe
126 };
127 Q_ENUM(Color)
128
129 QVariant accent() const;
130 void setAccent(const QVariant &accent);
131 void inheritAccent(QRgb accent);
132 void propagateAccent();
133 void resetAccent();
134
135 QVariant foreground() const;
136 void setForeground(const QVariant &foreground);
137 void inheritForeground(QRgb foreground, bool has);
138 void propagateForeground();
139 void resetForeground();
140
141 QVariant background() const;
142 void setBackground(const QVariant &background);
143 void inheritBackground(QRgb background, bool has);
144 void propagateBackground();
145 void resetBackground();
146
147 Q_INVOKABLE QColor color(Color color) const;
148
149 QColor altHighColor() const;
150 QColor altLowColor() const;
151 QColor altMediumColor() const;
152 QColor altMediumHighColor() const;
153 QColor altMediumLowColor() const;
154 QColor baseHighColor() const;
155 QColor baseLowColor() const;
156 QColor baseMediumColor() const;
157 QColor baseMediumHighColor() const;
158 QColor baseMediumLowColor() const;
159 QColor chromeAltLowColor() const;
160 QColor chromeBlackHighColor() const;
161 QColor chromeBlackLowColor() const;
162 QColor chromeBlackMediumLowColor() const;
163 QColor chromeBlackMediumColor() const;
164 QColor chromeDisabledHighColor() const;
165 QColor chromeDisabledLowColor() const;
166 QColor chromeHighColor() const;
167 QColor chromeLowColor() const;
168 QColor chromeMediumColor() const;
169 QColor chromeMediumLowColor() const;
170 QColor chromeWhiteColor() const;
171 QColor listLowColor() const;
172 QColor listMediumColor() const;
173
174 enum SystemColor {
175 AltHigh,
176 AltLow,
177 AltMedium,
178 AltMediumHigh,
179 AltMediumLow,
180 BaseHigh,
181 BaseLow,
182 BaseMedium,
183 BaseMediumHigh,
184 BaseMediumLow,
185 ChromeAltLow,
186 ChromeBlackHigh,
187 ChromeBlackLow,
188 ChromeBlackMediumLow,
189 ChromeBlackMedium,
190 ChromeDisabledHigh,
191 ChromeDisabledLow,
192 ChromeHigh,
193 ChromeLow,
194 ChromeMedium,
195 ChromeMediumLow,
196 ChromeWhite,
197 ListLow,
198 ListMedium
199 };
200
201 QColor systemColor(SystemColor role) const;
202
203 static void initGlobals();
204
205Q_SIGNALS:
206 void themeChanged();
207 void accentChanged();
208 void foregroundChanged();
209 void backgroundChanged();
210 void paletteChanged();
211
212protected:
213 void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) override;
214
215private:
216 bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba) const;
217
218 // These reflect whether a color value was explicitly set on the specific
219 // item that this attached style object represents.
220 bool m_explicitTheme = false;
221 bool m_explicitAccent = false;
222 bool m_explicitForeground = false;
223 bool m_explicitBackground = false;
224 // These will be true when this item has an explicit or inherited foreground/background
225 // color, or these colors were declared globally via settings (e.g. conf or env vars).
226 // Some color properties of the style will return different values depending on whether
227 // or not these are set.
228 bool m_hasForeground = false;
229 bool m_hasBackground = false;
230 // The actual values for this item, whether explicit, inherited or globally set.
231 Theme m_theme = Light;
232 QRgb m_accent = Qt::blue;
233 QRgb m_foreground = Qt::black;
234 QRgb m_background = Qt::white;
235};
236
237QT_END_NAMESPACE
238
239QML_DECLARE_TYPEINFO(QQuickUniversalStyle, QML_HAS_ATTACHED_PROPERTIES)
240
241#endif // QQUICKUNIVERSALSTYLE_P_H
242

source code of qtquickcontrols2/src/imports/controls/universal/qquickuniversalstyle_p.h