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