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 HorizontalHeaderViewDelegate,
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 VerticalHeaderViewDelegate
109 };
110 Q_ENUM(ControlType)
111
112 enum class AlternateState {
113 Alternate1,
114 Alternate2
115 };
116 Q_ENUM(AlternateState)
117
118 QQStyleKitReader(QObject *parent = nullptr);
119 ~QQStyleKitReader();
120
121 QQStyleKitExtendableControlType controlType() const;
122 void setControlType(QQStyleKitExtendableControlType type);
123#ifdef QT_DEBUG
124 ControlType typeAsControlType() const;
125#endif
126
127 bool hovered() const;
128 void setHovered(bool hovered);
129
130 bool enabled() const;
131 void setEnabled(bool enabled);
132
133 bool focused() const;
134 void setFocused(bool focused);
135
136 bool checked() const;
137 void setChecked(bool checked);
138
139 bool pressed() const;
140 void setPressed(bool pressed);
141
142 QQuickPalette *palette() const;
143 void setPalette(QQuickPalette *palette);
144 QPalette effectivePalette() const;
145
146 bool vertical() const;
147 void setVertical(bool vertical);
148
149 bool highlighted() const;
150 void setHighlighted(bool highlighted);
151
152 QQStyleKitStyle *explicitStyle() const;
153 void setExplicitStyle(QQStyleKitStyle *style);
154
155 QFont font() const;
156
157 QQStyleKitControlProperties *global() const;
158
159 QVariant readStyleProperty(PropertyStorageId key) const;
160 void writeStyleProperty(PropertyStorageId key, const QVariant &value);
161 void clearLocalStorage();
162
163 QQSK::State controlState() const;
164
165 void setControlTypeAndState(QQStyleKitExtendableControlType controlType, QQSK::State flags,
166 bool applyStateChange = true);
167
168 QObject *target() const;
169 void setTarget(QObject *target);
170
171 // Called by componentComplete()
172 // Factored out so the widget style can call it
173 void setCompleted(bool completed);
174
175 bool transitionsEnabled() const;
176 void setTransitionsEnabled(bool enabled);
177
178 static void resetReadersForStyle(const QQStyleKitStyle *style);
179
180 static QList<QQStyleKitReader *> s_allReaders;
181
182signals:
183 void controlTypeChanged();
184 void customTypeChanged();
185 void propertiesChanged();
186 void enabledChanged();
187 void focusedChanged();
188 void checkedChanged();
189 void hoveredChanged();
190 void pressedChanged();
191 void paletteChanged();
192 void verticalChanged();
193 void highlightedChanged();
194 void fontChanged();
195
196private slots:
197 void onPaletteChanged();
198
199protected:
200 void classBegin() override {}
201 void componentComplete() override;
202
203private:
204 void updateControl(bool applyStateChange = true);
205 void populateLocalStorage();
206 bool dontEmitChangedSignals() const;
207
208 QQuickStateGroup *stateGroup();
209 QQmlComponent *createControlChangesComponent() const;
210 QQmlComponent *createDelegateChangesComponent(const QString &delegateName) const;
211 void instantiatePropertyChanges(QQmlComponent *comp);
212 void maybeTrackDelegates();
213
214 bool rebuildEffectivePalette();
215 bool rebuildEffectiveFont();
216
217private:
218 Q_DISABLE_COPY(QQStyleKitReader)
219
220 /* The reason we have a QQStyleKitExtendableControlType in addition to
221 * QQStyleKitReader::ControlType, is that we allow the style to define controls types
222 * in the style beyond the types we offer in Qt Quick Controls. The predefined controls
223 * (QQStyleKitReader::ControlType) have types that starts at 100000 (ControlType::Unspecified),
224 * and any number before that is available for use for defining custom controls. */
225 QQStyleKitExtendableControlType m_type = ControlType::Unspecified;
226
227 bool m_dontEmitChangedSignals: 1;
228 bool m_effectiveVariationsDirty: 1;
229 bool m_transitionsEnabled: 1;
230 bool m_completed: 1;
231
232 QPointer<QQuickPalette> m_palette;
233 QPalette m_effectivePalette;
234 QFont m_font;
235 bool m_fontDirty = true;
236 quint64 m_lastTextFontOverridesSignature = 0;
237 mutable QQStyleKitPropertyStorage m_storage;
238 AlternateState m_alternateState = AlternateState::Alternate1;
239 QQSK::State m_state = QQSK::StateFlag::Unspecified;
240 QQuickStateGroup *m_stateGroup = nullptr;
241 QQSK::Delegates m_trackedDelegates = QQSK::Delegate::NoDelegate;
242
243 QPointer<QObject> m_target;
244 QPointer<QQStyleKitStyle> m_explicitStyle;
245 QPointer<QQStyleKitReader> m_parentReader;
246 QList<QPointer<QQStyleKitVariation>> m_effectiveVariations;
247
248 QQStyleKitControlProperties m_global;
249
250 using PropertyChangesComponents = QMap<std::pair<Qt::totally_ordered_wrapper<QQmlEngine*>, QString>, QPointer<QQmlComponent>>;
251 static PropertyChangesComponents s_propertyChangesComponents;
252
253 friend class QQStyleKitControlProperties;
254 friend class QQStyleKitPropertyResolver;
255 friend class QQStyleKitPropertyGroup;
256};
257
258QT_END_NAMESPACE
259
260#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.