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