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