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
qqstylekitglobal_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 QQSTYLEKITGLOBAL_P_H
6#define QQSTYLEKITGLOBAL_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
22
23class QQSK: public QObject
24{
25 Q_OBJECT
26
27public:
28 enum class Delegate {
29 NoDelegate = 0x0000,
30 Control = 0x0001,
31 Background = 0x0002,
32 Handle = 0x0004,
33 HandleFirst = 0x0008,
34 HandleSecond = 0x0010,
35 Indicator = 0x0020,
36 IndicatorForeground = 0x0040,
37 IndicatorUp = 0x0080,
38 IndicatorUpForeground = 0x0100,
39 IndicatorDown = 0x0200,
40 IndicatorDownForeground = 0x0400,
41 };
42 Q_DECLARE_FLAGS(Delegates, Delegate)
43 Q_FLAG(Delegate)
44
45 enum class PropertyGroup {
46 Control,
47 Background,
48 Foreground,
49 Border,
50 Handle,
51 Image,
52 Indicator,
53 Shadow,
54 Text,
55 PATH_ID_GROUP_COUNT,
56
57 /* Sub types, like states, are a part of a propertys storage ID, not its Path ID.
58 * They appear in the group path, but are handled differently. */
59 DelegateSubtype0,
60 DelegateSubtype1,
61 DelegateSubtype2,
62
63 /* Read options are not a part of either the Path ID nor the Storage ID. They
64 * just offer a convenient API for providing read options when reading a property.
65 * The Global flag is used to signal that a property should be read directly from
66 * the global style, circumventing the local StyleKitReader cache. */
67 GlobalFlag,
68
69 Unspecified
70 };
71 Q_ENUM(PropertyGroup)
72
73 enum class PropertyPathFlag : quint8 {
74 NoFlags = 0x0,
75 DelegateSubtype0 = 0x1,
76 DelegateSubtype1 = 0x2,
77 DelegateSubtype2 = 0x4,
78 Global = 0x8
79 };
80 Q_DECLARE_FLAGS(PropertyPathFlags, PropertyPathFlag)
81 Q_FLAG(PropertyPathFlag)
82
83 enum class Property {
84 NoProperty,
85 BottomLeftRadius,
86 BottomMargin,
87 BottomPadding,
88 BottomRightRadius,
89 Clip,
90 Color,
91 Data,
92 Delegate,
93 FillMode,
94 Gradient,
95 HOffset,
96 Image,
97 ImplicitWidth,
98 ImplicitHeight,
99 LeftMargin,
100 LeftPadding,
101 Margins,
102 MinimumWidth,
103 Opacity,
104 Padding,
105 Radius,
106 RightMargin,
107 RightPadding,
108 Rotation,
109 Scale,
110 Source,
111 Spacing,
112 TopLeftRadius,
113 TopMargin,
114 TopPadding,
115 TopRightRadius,
116 Transition,
117 Variations,
118 Visible,
119 VOffset,
120 Width,
121 Blur,
122 Alignment,
123 Bold,
124 Italic,
125 PointSize,
126 COUNT
127 };
128 Q_ENUM(Property)
129
130 enum class StateFlag {
131 Unspecified = 0x000,
132 Normal = 0x001,
133 Pressed = 0x002,
134 Hovered = 0x004,
135 Highlighted = 0x008,
136 Focused = 0x010,
137 Checked = 0x020,
138 Vertical = 0x040,
139 Disabled = 0x080,
140 MAX_STATE = 0x100,
141 };
142 Q_DECLARE_FLAGS(State, StateFlag)
143 Q_FLAG(State)
144
145 enum class Subclass {
146 QQStyleKitState,
147 QQStyleKitReader,
148 };
149 Q_ENUM(Subclass)
150
151public:
152 template <typename T, typename Owner, typename... Args>
153 static inline T *lazyCreate(T *const &ptr, const Owner *self, Args&&... args)
154 {
155 if (!ptr) {
156 auto *mutableSelf = const_cast<Owner *>(self);
157 auto *&mutablePtr = const_cast<T *&>(ptr);
158 mutablePtr = new T(std::forward<Args>(args)..., mutableSelf);
159 }
160 return ptr;
161 }
162};
163
164Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::State)
165Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::Delegates)
166Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::PropertyPathFlags)
167
168using PropertyPathId_t = quint32;
169using PropertyStorageId = quint32;
170using QQStyleKitExtendableControlType = quint32;
171using QQStyleKitPropertyStorage = QHash<PropertyStorageId, QVariant>;
172
173constexpr PropertyPathId_t maxPropertyStorageSpaceSize = std::numeric_limits<PropertyPathId_t>::max();
174constexpr PropertyPathId_t nestedGroupCount = PropertyPathId_t(QQSK::PropertyGroup::PATH_ID_GROUP_COUNT);
175constexpr PropertyPathId_t maxStateCombinationCount = PropertyPathId_t(QQSK::StateFlag::MAX_STATE);
176constexpr PropertyPathId_t stateStorageSpaceSize = maxPropertyStorageSpaceSize / maxStateCombinationCount;
177constexpr PropertyPathId_t subtypeCount = PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype2) - PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype0) + 1;
178constexpr PropertyPathId_t nestedGroupsStartSize = maxPropertyStorageSpaceSize / (maxStateCombinationCount * subtypeCount);
179constexpr PropertyPathId_t subtypeStorageSpaceSize = maxPropertyStorageSpaceSize / (subtypeCount * maxStateCombinationCount);
180
185
188
189public:
194 Q_ENUM(Flag)
195
200
201 inline QQSK::Property property() const { return m_property; }
203 {
204 /* The path ID is the property's identifier when its group path is taken
205 * into account. Each property inside QQStyleKitControlProperties has a unique
206 * path ID. For example, both 'background.color' and 'indicator.color' use the
207 * same QQSK::Property (Color), but they still have different path IDs. */
208 return m_groupStart + PropertyPathId_t(m_property);
209 }
210 inline PropertyStorageId storageId(QQSK::State state) const
211 {
212 /* To compute the fully qualified property ID used as a key in a storage map
213 * (QMap) that holds its value, we need to prefix the path ID with the state ID,
214 * since the same path can have different values in different states.
215 * Because StateFlag::Normal == 1, we subtract 1 so that the address space for
216 * properties in the Normal state starts at 0. */
217 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
218 const PropertyPathId_t stateIndex = PropertyPathId_t(state) - 1;
219 const PropertyPathId_t stateStart = stateIndex * stateStorageSpaceSize;
220 return stateStart + pathId();
221 }
222
223private:
224 QQSK::Property m_property;
225 PropertyPathId_t m_groupStart;
226};
227
228QT_END_NAMESPACE
229
230#endif // QQSTYLEKITGLOBAL_P_H
QQSK::Property property() const
PropertyStorageId storageId(QQSK::State state) const
PropertyPathId_t pathId() const
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitTextProperties * text() const
QQStyleKitIndicatorWithSubTypes * indicator() const
void setTransition(QQuickTransition *transition)
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitDelegateProperties * background() const
QQStyleKitReader * asQQStyleKitReader() const
QQStyleKitHandleProperties * handle() const
QQStyleKitControlState * asQQStyleKitState() const
void forEachUsedDelegate(std::function< void(QQStyleKitDelegateProperties *, QQSK::Delegate, const QString &)> f)
QQStyleKitDelegateProperties * delegateProperties() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setDelegateProperties(QQStyleKitDelegateProperties *delegateProperties)
QQStyleKitDelegateProperties * first() const
QQStyleKitDelegateProperties * second() const
QQuickImage::FillMode fillMode() const
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
void setFillMode(QQuickImage::FillMode fillMode)
QQStyleKitDelegateProperties * foreground() const
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitDelegateProperties * foreground() const
QQStyleKitIndicatorProperties * down() const
QQStyleKitIndicatorProperties * up() const
bool setStyleProperty(QQSK::Property property, T value)
QQStyleKitPropertyGroupSpace m_groupSpace
T styleProperty(QQSK::Property property, const T &defaultValue) const
T styleProperty(QQSK::Property property, QQSK::Property alternative=QQSK::Property::NoProperty) const
T * lazyCreateGroup(T *const &ptr, QQSK::PropertyGroup group) const
QQSK::PropertyPathFlags pathFlags() const
void handleStylePropertyChanged(void(SUBCLASS::*changedSignal)())
PropertyPathId propertyPathId(QQSK::Property property, PropertyPathId::Flag flag) const
void handleStylePropertiesChanged(CHANGED_SIGNALS... changedSignals)
bool isDefined(QQSK::Property property) const
QQStyleKitControlProperties * controlProperties() const
void setRightPadding(qreal rightPadding)
void setBottomPadding(qreal bottomPadding)
void setAlignment(Qt::Alignment alignment)
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
Combined button and popup list for selecting options.
constexpr PropertyPathId_t nestedGroupCount
constexpr PropertyPathId_t nestedGroupsStartSize
constexpr PropertyPathId_t maxStateCombinationCount
constexpr PropertyPathId_t subtypeStorageSpaceSize
constexpr PropertyPathId_t stateStorageSpaceSize
constexpr PropertyPathId_t subtypeCount
constexpr PropertyPathId_t maxPropertyStorageSpaceSize