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

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtdeclarative/src/quickcontrols/universal/qquickuniversalstyle_p.h