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
qqstylekitreader_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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 QQSTYLEKITREADER_P_H
6#define QQSTYLEKITREADER_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 <QtQml/QtQml>
20#include <QtQuick/private/qquickpalette_p.h>
21
25
26#include <QtCore/qcompare.h>
27
29
30class QQuickPalette;
33
34class Q_LABSSTYLEKIT_EXPORT QQStyleKitReader : public QQStyleKitControlProperties
35{
36 Q_OBJECT
37 Q_PROPERTY(QQStyleKitExtendableControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged FINAL)
38 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
39 Q_PROPERTY(bool focused READ focused WRITE setFocused NOTIFY focusedChanged FINAL)
40 Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY checkedChanged FINAL)
41 Q_PROPERTY(bool hovered READ hovered WRITE setHovered NOTIFY hoveredChanged FINAL)
42 Q_PROPERTY(bool pressed READ pressed WRITE setPressed NOTIFY pressedChanged FINAL)
43 Q_PROPERTY(bool vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL)
44 Q_PROPERTY(bool highlighted READ highlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL)
45 Q_PROPERTY(QFont font READ font NOTIFY fontChanged FINAL)
46 Q_PROPERTY(QQuickPalette *palette READ palette WRITE setPalette NOTIFY paletteChanged FINAL)
47 Q_PROPERTY(QQStyleKitControlProperties *global READ global CONSTANT FINAL)
48
49 QML_NAMED_ELEMENT(StyleReader)
50
51public:
52 enum ControlType {
53 Unspecified = 100000,
54 Control,
55 AbstractButton,
56 ApplicationWindow,
57 Button,
58 CheckBox,
59 ComboBox,
60 FlatButton,
61 ProgressBar,
62 ScrollBar,
63 ScrollIndicator,
64 ScrollView,
65 Slider,
66 SpinBox,
67 SwitchControl,
68 SearchField,
69 TabBar,
70 TabButton,
71 TextArea,
72 TextField,
73 TextInput,
74 ToolBar,
75 ToolButton,
76 ToolSeparator,
77 RadioButton,
78 ItemDelegate,
79 Popup,
80 Menu,
81 Dialog,
82 Pane,
83 Page,
84 Frame,
85 Label,
86 GroupBox
87 };
88 Q_ENUM(ControlType)
89
90 enum class AlternateState {
91 Alternate1,
92 Alternate2
93 };
94 Q_ENUM(AlternateState)
95
96 QQStyleKitReader(QObject *parent = nullptr);
97 ~QQStyleKitReader();
98
99 QQStyleKitExtendableControlType controlType() const;
100 void setControlType(QQStyleKitExtendableControlType type);
101#ifdef QT_DEBUG
102 ControlType typeAsControlType() const;
103#endif
104
105 bool hovered() const;
106 void setHovered(bool hovered);
107
108 bool enabled() const;
109 void setEnabled(bool enabled);
110
111 bool focused() const;
112 void setFocused(bool focused);
113
114 bool checked() const;
115 void setChecked(bool checked);
116
117 bool pressed() const;
118 void setPressed(bool pressed);
119
120 QQuickPalette *palette() const;
121 void setPalette(QQuickPalette *palette);
122 QPalette effectivePalette() const;
123
124 bool vertical() const;
125 void setVertical(bool vertical);
126
127 bool highlighted() const;
128 void setHighlighted(bool highlighted);
129
130 QQStyleKitStyle *explicitStyle() const;
131 void setExplicitStyle(QQStyleKitStyle *style);
132
133 QFont font() const;
134
135 QQStyleKitControlProperties *global() const;
136
137 QVariant readStyleProperty(PropertyStorageId key) const;
138 void writeStyleProperty(PropertyStorageId key, const QVariant &value);
139 void clearLocalStorage();
140
141 QQSK::State controlState() const;
142
143 static void setTransitionEnabled(bool enabled);
144 static bool transitionEnabled();
145 static void resetReadersForStyle(const QQStyleKitStyle *style);
146
147 static QList<QQStyleKitReader *> s_allReaders;
148
149signals:
150 void controlTypeChanged();
151 void customTypeChanged();
152 void propertiesChanged();
153 void enabledChanged();
154 void focusedChanged();
155 void checkedChanged();
156 void hoveredChanged();
157 void pressedChanged();
158 void paletteChanged();
159 void verticalChanged();
160 void highlightedChanged();
161 void fontChanged();
162
163private slots:
164 void onPaletteChanged();
165
166private:
167 void updateControl();
168 void populateLocalStorage();
169 bool dontEmitChangedSignals() const;
170
171 QQuickStateGroup *stateGroup();
172 QQmlComponent *createControlChangesComponent() const;
173 QQmlComponent *createDelegateChangesComponent(const QString &delegateName) const;
174 void instantiatePropertyChanges(QQmlComponent *comp);
175 void maybeTrackDelegates();
176
177 bool rebuildEffectivePalette();
178 bool rebuildEffectiveFont();
179
180private:
181 Q_DISABLE_COPY(QQStyleKitReader)
182
183 /* The reason we have a QQStyleKitExtendableControlType in addition to
184 * QQStyleKitReader::ControlType, is that we allow the style to define controls types
185 * in the style beyond the types we offer in Qt Quick Controls. The predefined controls
186 * (QQStyleKitReader::ControlType) have types that starts at 100000 (ControlType::Unspecified),
187 * and any number before that is available for use for defining custom controls. */
188 QQStyleKitExtendableControlType m_type = ControlType::Unspecified;
189
190 bool m_dontEmitChangedSignals: 1;
191 bool m_effectiveVariationsDirty: 1;
192
193 QPointer<QQuickPalette> m_palette;
194 QPalette m_effectivePalette;
195 QFont m_font;
196 bool m_fontDirty = true;
197 quint64 m_lastTextFontOverridesSignature = 0;
198 mutable QQStyleKitPropertyStorage m_storage;
199 AlternateState m_alternateState = AlternateState::Alternate1;
200 QQSK::State m_state = QQSK::StateFlag::Unspecified;
201 QQuickStateGroup *m_stateGroup = nullptr;
202 QQSK::Delegates m_trackedDelegates = QQSK::Delegate::NoDelegate;
203
204 QPointer<QQStyleKitStyle> m_explicitStyle;
205 QPointer<QQStyleKitReader> m_parentReader;
206 QList<QPointer<QQStyleKitVariation>> m_effectiveVariations;
207
208 QQStyleKitControlProperties m_global;
209
210 using PropertyChangesComponents = QMap<std::pair<Qt::totally_ordered_wrapper<QQmlEngine*>, QString>, QQmlComponent *>;
211 static PropertyChangesComponents s_propertyChangesComponents;
212
213 friend class QQStyleKitControlProperties;
214 friend class QQStyleKitPropertyResolver;
215 friend class QQStyleKitPropertyGroup;
216};
217
218QT_END_NAMESPACE
219
220#endif // QQSTYLEKITREADER_P_H
Q_INVOKABLE bool styleLoaded() const
void setStyleUrl(const QString &styleUrl)
QQStyleKitStyle * style() const
void transitionsEnabledChanged()
void setStyle(QQStyleKitStyle *style)
void setTransitionsEnabled(bool enabled)
QQStyleKitDebug * debug() const
bool transitionsEnabled() const
QString styleUrl() const
void filterChanged()
QString filter() const
void setFilter(const QString &filter)
void setControl(QQuickItem *item)
static Q_INVOKABLE bool insideControl(const QObject *child)
static QQStyleKitAttached * qmlAttachedProperties(QObject *obj=nullptr)
Combined button and popup list for selecting options.