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