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, public QQmlParserStatus
35{
36 Q_OBJECT
37 Q_INTERFACES(QQmlParserStatus)
38 Q_PROPERTY(QQStyleKitExtendableControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged FINAL)
39 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
40 Q_PROPERTY(bool focused READ focused WRITE setFocused NOTIFY focusedChanged FINAL)
41 Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY checkedChanged FINAL)
42 Q_PROPERTY(bool hovered READ hovered WRITE setHovered NOTIFY hoveredChanged FINAL)
43 Q_PROPERTY(bool pressed READ pressed WRITE setPressed NOTIFY pressedChanged FINAL)
44 Q_PROPERTY(bool vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL)
45 Q_PROPERTY(bool highlighted READ highlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL)
46 Q_PROPERTY(QFont font READ font NOTIFY fontChanged FINAL)
47 Q_PROPERTY(QQuickPalette *palette READ palette WRITE setPalette NOTIFY paletteChanged FINAL)
48 Q_PROPERTY(QQStyleKitControlProperties *global READ global CONSTANT FINAL)
49
50 QML_NAMED_ELEMENT(StyleReader)
51
52public:
53 enum ControlType {
54 Unspecified = 100000,
55 Control,
56 AbstractButton,
57 ApplicationWindow,
58 BusyIndicator,
59 Button,
60 CheckBox,
61 CheckDelegate,
62 ComboBox,
63 DelayButton,
64 Dial,
65 Dialog,
66 DialogButtonBox,
67 Drawer,
68 FlatButton,
69 HeaderViewDelegate,
70 ProgressBar,
71 ScrollBar,
72 ScrollIndicator,
73 ScrollView,
74 Slider,
75 SpinBox,
76 SwipeDelegate,
77 SwitchControl,
78 SwitchDelegate,
79 SearchField,
80 TabBar,
81 TabButton,
82 TableViewDelegate,
83 TextArea,
84 TextField,
85 TextInput,
86 ToolBar,
87 ToolButton,
88 ToolSeparator,
89 ToolTip,
90 TreeViewDelegate,
91 Tumbler,
92 RadioButton,
93 RadioDelegate,
94 RoundButton,
95 ItemDelegate,
96 Popup,
97 Menu,
98 MenuBar,
99 MenuBarItem,
100 MenuItem,
101 MenuSeparator,
102 Pane,
103 Page,
104 PageIndicator,
105 Frame,
106 Label,
107 GroupBox
108 };
109 Q_ENUM(ControlType)
110
111 enum class AlternateState {
112 Alternate1,
113 Alternate2
114 };
115 Q_ENUM(AlternateState)
116
117 QQStyleKitReader(QObject *parent = nullptr);
118 ~QQStyleKitReader();
119
120 QQStyleKitExtendableControlType controlType() const;
121 void setControlType(QQStyleKitExtendableControlType type);
122#ifdef QT_DEBUG
123 ControlType typeAsControlType() const;
124#endif
125
126 bool hovered() const;
127 void setHovered(bool hovered);
128
129 bool enabled() const;
130 void setEnabled(bool enabled);
131
132 bool focused() const;
133 void setFocused(bool focused);
134
135 bool checked() const;
136 void setChecked(bool checked);
137
138 bool pressed() const;
139 void setPressed(bool pressed);
140
141 QQuickPalette *palette() const;
142 void setPalette(QQuickPalette *palette);
143 QPalette effectivePalette() const;
144
145 bool vertical() const;
146 void setVertical(bool vertical);
147
148 bool highlighted() const;
149 void setHighlighted(bool highlighted);
150
151 QQStyleKitStyle *explicitStyle() const;
152 void setExplicitStyle(QQStyleKitStyle *style);
153
154 QFont font() const;
155
156 QQStyleKitControlProperties *global() const;
157
158 QVariant readStyleProperty(PropertyStorageId key) const;
159 void writeStyleProperty(PropertyStorageId key, const QVariant &value);
160 void clearLocalStorage();
161
162 QQSK::State controlState() const;
163
164 void setControlTypeAndState(QQStyleKitExtendableControlType controlType, QQSK::State flags,
165 bool applyStateChange = true);
166
167 QObject *target() const;
168 void setTarget(QObject *target);
169
170 // Called by componentComplete()
171 // Factored out so the widget style can call it
172 void setCompleted(bool completed);
173
174 bool transitionsEnabled() const;
175 void setTransitionsEnabled(bool enabled);
176
177 static void resetReadersForStyle(const QQStyleKitStyle *style);
178
179 static QList<QQStyleKitReader *> s_allReaders;
180
181signals:
182 void controlTypeChanged();
183 void customTypeChanged();
184 void propertiesChanged();
185 void enabledChanged();
186 void focusedChanged();
187 void checkedChanged();
188 void hoveredChanged();
189 void pressedChanged();
190 void paletteChanged();
191 void verticalChanged();
192 void highlightedChanged();
193 void fontChanged();
194
195private slots:
196 void onPaletteChanged();
197
198protected:
199 void classBegin() override {}
200 void componentComplete() override;
201
202private:
203 void updateControl(bool applyStateChange = true);
204 void populateLocalStorage();
205 bool dontEmitChangedSignals() const;
206
207 QQuickStateGroup *stateGroup();
208 QQmlComponent *createControlChangesComponent() const;
209 QQmlComponent *createDelegateChangesComponent(const QString &delegateName) const;
210 void instantiatePropertyChanges(QQmlComponent *comp);
211 void maybeTrackDelegates();
212
213 bool rebuildEffectivePalette();
214 bool rebuildEffectiveFont();
215
216private:
217 Q_DISABLE_COPY(QQStyleKitReader)
218
219 /* The reason we have a QQStyleKitExtendableControlType in addition to
220 * QQStyleKitReader::ControlType, is that we allow the style to define controls types
221 * in the style beyond the types we offer in Qt Quick Controls. The predefined controls
222 * (QQStyleKitReader::ControlType) have types that starts at 100000 (ControlType::Unspecified),
223 * and any number before that is available for use for defining custom controls. */
224 QQStyleKitExtendableControlType m_type = ControlType::Unspecified;
225
226 bool m_dontEmitChangedSignals: 1;
227 bool m_effectiveVariationsDirty: 1;
228 bool m_transitionsEnabled: 1;
229 bool m_completed: 1;
230
231 QPointer<QQuickPalette> m_palette;
232 QPalette m_effectivePalette;
233 QFont m_font;
234 bool m_fontDirty = true;
235 quint64 m_lastTextFontOverridesSignature = 0;
236 mutable QQStyleKitPropertyStorage m_storage;
237 AlternateState m_alternateState = AlternateState::Alternate1;
238 QQSK::State m_state = QQSK::StateFlag::Unspecified;
239 QQuickStateGroup *m_stateGroup = nullptr;
240 QQSK::Delegates m_trackedDelegates = QQSK::Delegate::NoDelegate;
241
242 QPointer<QObject> m_target;
243 QPointer<QQStyleKitStyle> m_explicitStyle;
244 QPointer<QQStyleKitReader> m_parentReader;
245 QList<QPointer<QQStyleKitVariation>> m_effectiveVariations;
246
247 QQStyleKitControlProperties m_global;
248
249 using PropertyChangesComponents = QMap<std::pair<Qt::totally_ordered_wrapper<QQmlEngine*>, QString>, QPointer<QQmlComponent>>;
250 static PropertyChangesComponents s_propertyChangesComponents;
251
252 friend class QQStyleKitControlProperties;
253 friend class QQStyleKitPropertyResolver;
254 friend class QQStyleKitPropertyGroup;
255};
256
257QT_END_NAMESPACE
258
259#endif // QQSTYLEKITREADER_P_H
Q_INVOKABLE bool styleLoaded() const
QQStyleKitStyle * style() const
QUrl styleUrl() const
void transitionsEnabledChanged()
void setStyle(QQStyleKitStyle *style)
void setTransitionsEnabled(bool enabled)
QQStyleKitDebug * debug() const
bool transitionsEnabled() const
void setStyleUrl(const QUrl &styleUrl)
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.