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 IndicatorFirst = 0x0080,
38 IndicatorFirstForeground = 0x0100,
39 IndicatorSecond = 0x0200,
40 IndicatorSecondForeground = 0x0400,
41 // Note: for now, "control.text" is not treated as a separate delegate, but
42 // as an integrated part of "control". Hence, there is no "Text" value in this enum.
43 };
44 Q_DECLARE_FLAGS(Delegates, Delegate)
45 Q_FLAG(Delegate)
46
47 enum class PropertyGroup {
48 Control,
49 Background,
50 Foreground,
51 Border,
52 Handle,
53 Image,
54 Indicator,
55 Shadow,
56 Text,
57 PATH_ID_GROUP_COUNT,
58
59 /* Sub types, like states, are a part of a propertys storage ID, not its Path ID.
60 * They appear in the group path, but are handled differently. */
61 DelegateSubtype0,
62 DelegateSubtype1,
63 DelegateSubtype2,
64
65 /* Read options are not a part of either the Path ID nor the Storage ID. They
66 * just offer a convenient API for providing read options when reading a property.
67 * The Global flag is used to signal that a property should be read directly from
68 * the global style, circumventing the local StyleKitReader cache. */
69 GlobalFlag,
70
71 Unspecified
72 };
73 Q_ENUM(PropertyGroup)
74
75 enum class PropertyPathFlag : quint8 {
76 NoFlags = 0x0,
77 DelegateSubtype0 = 0x1,
78 DelegateSubtype1 = 0x2,
79 DelegateSubtype2 = 0x4,
80 Global = 0x8
81 };
82 Q_DECLARE_FLAGS(PropertyPathFlags, PropertyPathFlag)
83 Q_FLAG(PropertyPathFlag)
84
85 enum class Property {
86 NoProperty,
87 BottomLeftRadius,
88 BottomMargin,
89 BottomPadding,
90 BottomRightRadius,
91 Clip,
92 Color,
93 Data,
94 Delegate,
95 FillMode,
96 FillWidth,
97 FillHeight,
98 Gradient,
99 HOffset,
100 Image,
101 LeftMargin,
102 LeftPadding,
103 Margins,
104 MinimumWidth,
105 MinimumHeight,
106 Opacity,
107 Padding,
108 Radius,
109 RightMargin,
110 RightPadding,
111 Rotation,
112 Scale,
113 Source,
114 Spacing,
115 TopLeftRadius,
116 TopMargin,
117 TopPadding,
118 TopRightRadius,
119 Transition,
120 Variations,
121 Visible,
122 VOffset,
123 Width,
124 Height,
125 Blur,
126 Alignment,
127 Bold,
128 Italic,
129 PointSize,
130 COUNT
131 };
132 Q_ENUM(Property)
133
134 enum class StateFlag {
135 Unspecified = 0x000,
136 Normal = 0x001,
137 Pressed = 0x002,
138 Hovered = 0x004,
139 Highlighted = 0x008,
140 Focused = 0x010,
141 Checked = 0x020,
142 Vertical = 0x040,
143 Disabled = 0x080,
144 MAX_STATE = 0x100,
145 };
146 Q_DECLARE_FLAGS(State, StateFlag)
147 Q_FLAG(State)
148
149 enum class Subclass {
150 QQStyleKitState,
151 QQStyleKitReader,
152 };
153 Q_ENUM(Subclass)
154
155public:
156 template <typename T, typename Owner, typename... Args>
157 static inline T *lazyCreate(T *const &ptr, const Owner *self, Args&&... args)
158 {
159 if (!ptr) {
160 auto *mutableSelf = const_cast<Owner *>(self);
161 auto *&mutablePtr = const_cast<T *&>(ptr);
162 mutablePtr = new T(std::forward<Args>(args)..., mutableSelf);
163 }
164 return ptr;
165 }
166};
167
168Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::State)
169Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::Delegates)
170Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::PropertyPathFlags)
171
172using PropertyPathId_t = quint32;
173using PropertyStorageId = quint32;
174using QQStyleKitExtendableControlType = quint32;
175using QQStyleKitPropertyStorage = QHash<PropertyStorageId, QVariant>;
176
177constexpr PropertyPathId_t maxPropertyStorageSpaceSize = std::numeric_limits<PropertyPathId_t>::max();
178constexpr PropertyPathId_t nestedGroupCount = PropertyPathId_t(QQSK::PropertyGroup::PATH_ID_GROUP_COUNT);
179constexpr PropertyPathId_t maxStateCombinationCount = PropertyPathId_t(QQSK::StateFlag::MAX_STATE);
180constexpr PropertyPathId_t stateStorageSpaceSize = maxPropertyStorageSpaceSize / maxStateCombinationCount;
181constexpr PropertyPathId_t subtypeCount = PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype2) - PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype0) + 1;
182constexpr PropertyPathId_t nestedGroupsStartSize = maxPropertyStorageSpaceSize / (maxStateCombinationCount * subtypeCount);
183constexpr PropertyPathId_t subtypeStorageSpaceSize = maxPropertyStorageSpaceSize / (subtypeCount * maxStateCombinationCount);
184
189
192
193public:
198 Q_ENUM(Flag)
199
204
205 inline QQSK::Property property() const { return m_property; }
207 {
208 /* The path ID is the property's identifier when its group path is taken
209 * into account. Each property inside QQStyleKitControlProperties has a unique
210 * path ID. For example, both 'background.color' and 'indicator.color' use the
211 * same QQSK::Property (Color), but they still have different path IDs. */
212 return m_groupStart + PropertyPathId_t(m_property);
213 }
214 inline PropertyStorageId storageId(QQSK::State state) const
215 {
216 /* To compute the fully qualified property ID used as a key in a storage map
217 * (QMap) that holds its value, we need to prefix the path ID with the state ID,
218 * since the same path can have different values in different states.
219 * Because StateFlag::Normal == 1, we subtract 1 so that the address space for
220 * properties in the Normal state starts at 0. */
221 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
222 const PropertyPathId_t stateIndex = PropertyPathId_t(state) - 1;
223 const PropertyPathId_t stateStart = stateIndex * stateStorageSpaceSize;
224 return stateStart + pathId();
225 }
226
227private:
228 QQSK::Property m_property;
229 PropertyPathId_t m_groupStart;
230};
231
232QT_END_NAMESPACE
233
234#endif // QQSTYLEKITGLOBAL_P_H
QQSK::Property property() const
PropertyStorageId storageId(QQSK::State state) const
PropertyPathId_t pathId() const
QQStyleKitDelegateProperties * delegateStyle() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setDelegateStyle(QQStyleKitDelegateProperties *delegateProperties)
QQStyleKitDelegateProperties * first() const
QQStyleKitDelegateProperties * second() const
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
QQStyleKitIndicatorProperties * second() const
QQStyleKitIndicatorProperties * first() const
bool setStyleProperty(QQSK::Property property, T value)
QQStyleKitPropertyGroupSpace m_groupSpace
void emitChangedForAllStylePropertiesRecursive(EmitFlags emitFlags)
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 setBottomPadding(qreal bottomPadding)
void setAlignment(Qt::Alignment alignment)
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitTextProperties * first() const
QQStyleKitTextProperties * second() 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