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