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