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
qqstylekitcontrolproperties_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 QQSTYLEKITCONTROLPROPERTIES_P_H
6#define QQSTYLEKITCONTROLPROPERTIES_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 <QtGui/QColor>
21#include <QtQuick/private/qquickrectangle_p.h>
22#include <QtQuick/private/qquickimage_p.h>
23#include <QtQuick/private/qquicktransition_p.h>
24#include <QtQuick/private/qquicktext_p.h>
25
28#include <QtQtQuickStyleKit/qtqtquickstylekitexports.h>
29
31
32using namespace Qt::StringLiterals;
33
34class QQStyleKitStyle;
39class QQStyleKitDelegateProperties;
40
42{
44
45public:
47
48 PropertyPathId propertyPathId(QQSK::Property property, PropertyPathId::Flag flag) const;
49 QString pathToString() const;
50
51 template<typename T>
52 inline T styleProperty(
53 QQSK::Property property,
54 QQSK::Property alternative = QQSK::Property::NoProperty) const
55 {
56 return qvariant_cast<T>(QQStyleKitPropertyResolver::readStyleProperty(this, property, alternative));
57 }
58
59 template<typename T>
60 inline T styleProperty(QQSK::Property property, const T &defaultValue) const
61 {
62 const QVariant value = QQStyleKitPropertyResolver::readStyleProperty(this, property);
63 return value.isValid() ? qvariant_cast<T>(value) : defaultValue;
64 }
65
66 template<typename T>
67 inline bool setStyleProperty(QQSK::Property property, T value)
68 {
69 // This function will return true if the new value differes from the old one
70 return QQStyleKitPropertyResolver::writeStyleProperty(this, property, QVariant::fromValue(value));
71 }
72
73 inline bool isDefined(QQSK::Property property) const
74 {
75 return QQStyleKitPropertyResolver::readStyleProperty(this, property).isValid();
76 }
77
78 template<typename SUBCLASS>
79 inline void handleStylePropertyChanged(void (SUBCLASS::*changedSignal)());
80
81 template <typename SUBCLASS, typename... CHANGED_SIGNALS>
82 inline void handleStylePropertiesChanged(CHANGED_SIGNALS... changedSignals);
83
84 template <typename T>
85 T *lazyCreateGroup(T *const &ptr, QQSK::PropertyGroup group) const;
86
87 inline bool isControlProperties() const
88 {
89 /* Only QQStyleKitControlProperties (as opposed to the nested delegates) have properties
90 * with an ID at the bottom of the available space. The exception is the global flag, which
91 * inherits the groupSpace from the control. */
92 return m_groupSpace.start == 0 && m_pathFlags != QQSK::PropertyPathFlag::Global;
93 }
94
96 inline QQSK::PropertyPathFlags pathFlags() const { return m_pathFlags; }
98
99protected:
102
103private:
104 bool shouldEmitLocally();
105 bool shouldEmitGlobally();
106
107 static QHash<PropertyPathId_t, QString> s_pathStrings;
108};
109
110// ************* QQStyleKitImageProperties ****************
111
113{
114 Q_OBJECT
115 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged FINAL)
118 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
120
121public:
123
124 template <typename... CHANGED_SIGNALS>
125 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
126
127 QUrl source() const;
128 void setSource(const QUrl &source);
129
130 QColor color() const;
131 void setColor(const QColor &color);
132
134 void setFillMode(QQuickImage::FillMode fillMode);
135
136signals:
140};
141
142// ************* QQStyleKitBorderProperties ****************
143
145{
146 Q_OBJECT
147 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL)
149 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
151
152public:
154
155 template <typename... CHANGED_SIGNALS>
156 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
157
158 qreal width() const;
159 void setWidth(qreal width);
160
161 QColor color() const;
162 void setColor(const QColor &color);
163
164signals:
167};
168
169// ************* QQStyleKitShadowProperties ****************
170
171class Q_QTQUICKSTYLEKIT_EXPORT QQStyleKitShadowProperties : public QQStyleKitPropertyGroup
172{
173 Q_OBJECT
174 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
175 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
176 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged FINAL)
177 Q_PROPERTY(qreal verticalOffset READ verticalOffset WRITE setVerticalOffset NOTIFY verticalOffsetChanged FINAL)
178 Q_PROPERTY(qreal horizontalOffset READ horizontalOffset WRITE setHorizontalOffset NOTIFY horizontalOffsetChanged FINAL)
179 Q_PROPERTY(qreal blur READ blur WRITE setBlur NOTIFY blurChanged FINAL)
180 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged FINAL)
181 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
182 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
183 QML_NAMED_ELEMENT(StyleKitShadowProperties)
184
185public:
186 QQStyleKitShadowProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent = nullptr);
187
188 template <typename... CHANGED_SIGNALS>
189 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
190
191 QColor color() const;
192 void setColor(QColor color);
193
194 qreal opacity() const;
195 void setOpacity(qreal opacity);
196
197 qreal scale() const;
198 void setScale(qreal scale);
199
200 qreal verticalOffset() const;
201 void setVerticalOffset(qreal verticalOffset);
202
203 qreal horizontalOffset() const;
204 void setHorizontalOffset(qreal horizontalOffset);
205
206 qreal blur() const;
207 void setBlur(qreal blur);
208
209 bool visible() const;
210 void setVisible(bool visible);
211
212 QQmlComponent *delegate() const;
213 void setDelegate(QQmlComponent *delegate);
214
215signals:
216 void colorChanged();
217 void opacityChanged();
218 void scaleChanged();
219 void verticalOffsetChanged();
220 void horizontalOffsetChanged();
221 void blurChanged();
222 void visibleChanged();
223 void delegateChanged();
224};
225
226// ************* QQStyleKitDelegateProperties ****************
227
228class Q_QTQUICKSTYLEKIT_EXPORT QQStyleKitDelegateProperties : public QQStyleKitPropertyGroup
229{
230 Q_OBJECT
231 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged FINAL)
232 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged FINAL)
233 Q_PROPERTY(qreal minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged FINAL)
234 Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged FINAL)
235 Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged FINAL)
236 Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged FINAL)
237 Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged FINAL)
238 Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged FINAL)
239 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL)
240 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
241 Q_PROPERTY(qreal topLeftRadius READ topLeftRadius WRITE setTopLeftRadius NOTIFY topLeftRadiusChanged FINAL)
242 Q_PROPERTY(qreal topRightRadius READ topRightRadius WRITE setTopRightRadius NOTIFY topRightRadiusChanged FINAL)
243 Q_PROPERTY(qreal bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius NOTIFY bottomLeftRadiusChanged FINAL)
244 Q_PROPERTY(qreal bottomRightRadius READ bottomRightRadius WRITE setBottomRightRadius NOTIFY bottomRightRadiusChanged FINAL)
245 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged FINAL)
246 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged FINAL)
247 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
248 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
249 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged FINAL)
250 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged FINAL)
251 Q_PROPERTY(QQuickGradient *gradient READ gradient WRITE setGradient NOTIFY gradientChanged FINAL)
252 Q_PROPERTY(QQStyleKitImageProperties *image READ image NOTIFY imageChanged FINAL)
253 Q_PROPERTY(QQStyleKitBorderProperties *border READ border NOTIFY borderChanged FINAL)
254 Q_PROPERTY(QQStyleKitShadowProperties *shadow READ shadow NOTIFY shadowChanged FINAL)
255 Q_PROPERTY(QObject *data READ data WRITE setData NOTIFY dataChanged FINAL)
256 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
257 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
258 QML_NAMED_ELEMENT(StyleKitDelegateProperties)
259
260public:
261 QQStyleKitDelegateProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent = nullptr);
262
263 template <typename... CHANGED_SIGNALS>
264 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
265
266 qreal radius() const;
267 void setRadius(qreal radius);
268
269 qreal topLeftRadius() const;
270 void setTopLeftRadius(qreal radius);
271
272 qreal topRightRadius() const;
273 void setTopRightRadius(qreal radius);
274
275 qreal bottomLeftRadius() const;
276 void setBottomLeftRadius(qreal radius);
277
278 qreal bottomRightRadius() const;
279 void setBottomRightRadius(qreal radius);
280
281 qreal scale() const;
282 void setScale(qreal scale);
283
284 qreal rotation() const;
285 void setRotation(qreal rotation);
286
287 qreal implicitWidth() const;
288 void setImplicitWidth(qreal width);
289
290 qreal implicitHeight() const;
291 void setImplicitHeight(qreal height);
292
293 qreal minimumWidth() const;
294 void setMinimumWidth(qreal width);
295
296 qreal margins() const;
297 void setMargins(qreal margins);
298
299 qreal leftMargin() const;
300 void setLeftMargin(qreal margin);
301
302 qreal rightMargin() const;
303 void setRightMargin(qreal margin);
304
305 qreal topMargin() const;
306 void setTopMargin(qreal margin);
307
308 qreal bottomMargin() const;
309 void setBottomMargin(qreal margin);
310
311 Qt::Alignment alignment() const;
312 void setAlignment(Qt::Alignment alignment);
313
314 qreal opacity() const;
315 void setOpacity(qreal opacity);
316
317 QColor color() const;
318 void setColor(const QColor &color);
319
320 bool visible() const;
321 void setVisible(bool visible);
322
323 bool clip() const;
324 void setClip(bool clip);
325
326 QQuickGradient *gradient() const;
327 void setGradient(QQuickGradient *gradient);
328
329 QObject *data() const;
330 void setData(QObject *data);
331
332 QQmlComponent *delegate() const;
333 void setDelegate(QQmlComponent *delegate);
334
335 QQStyleKitImageProperties *image() const;
336 QQStyleKitBorderProperties *border() const;
337 QQStyleKitShadowProperties *shadow() const;
338
339signals:
340 void colorChanged();
341 void radiusChanged();
342 void topLeftRadiusChanged();
343 void topRightRadiusChanged();
344 void bottomLeftRadiusChanged();
345 void bottomRightRadiusChanged();
346 void scaleChanged();
347 void rotationChanged();
348 void visibleChanged();
349 void clipChanged();
350 void borderChanged();
351 void shadowChanged();
352 void imageChanged();
353 void gradientChanged();
354 void colorImageChanged();
355 void implicitWidthChanged();
356 void implicitHeightChanged();
357 void minimumWidthChanged();
358 void marginsChanged();
359 void leftMarginChanged();
360 void rightMarginChanged();
361 void topMarginChanged();
362 void bottomMarginChanged();
363 void alignmentChanged();
364 void opacityChanged();
365 void dataChanged();
366 void delegateChanged();
367
368private:
369 QPointer<QQuickGradient> m_gradient;
370 QQStyleKitBorderProperties *m_border = nullptr;
371 QQStyleKitShadowProperties *m_shadow = nullptr;
372 QQStyleKitImageProperties *m_image = nullptr;
373};
374
375// ************* QQStyleKitHandleProperties ****************
376
378{
379 Q_OBJECT
380 Q_PROPERTY(QQStyleKitDelegateProperties *first READ first NOTIFY firstChanged FINAL)
382 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
384
385public:
387 QQStyleKitDelegateProperties *first() const;
388 QQStyleKitDelegateProperties *second() const;
389
390signals:
393
394private:
395 QQStyleKitDelegateProperties *m_first = nullptr;
396 QQStyleKitDelegateProperties *m_second = nullptr;
397
398 friend class QQStyleKitReader;
400};
401
402// ************* QQStyleKitIndicatorProperties ****************
403
405{
406 Q_OBJECT
407 Q_PROPERTY(QQStyleKitDelegateProperties *foreground READ foreground NOTIFY foregroundChanged FINAL)
408 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
410
411public:
413
414 template <typename... CHANGED_SIGNALS>
415 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
416
417 QQStyleKitDelegateProperties *foreground() const;
418
419signals:
421
422private:
423 QQStyleKitDelegateProperties *m_foreground = nullptr;
424
425 friend class QQStyleKitReader;
427};
428
429// ************* QQStyleKitIndicatorWithSubTypes ****************
430
432{
433 Q_OBJECT
434 Q_PROPERTY(QQStyleKitDelegateProperties *foreground READ foreground NOTIFY foregroundChanged FINAL)
437 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
439
440public:
442
443 template <typename... CHANGED_SIGNALS>
444 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
445
446 QQStyleKitDelegateProperties *foreground() const;
449
450signals:
452 void upChanged();
454
455private:
456 QQStyleKitDelegateProperties *m_foreground = nullptr;
457 QQStyleKitIndicatorProperties *m_up = nullptr;
458 QQStyleKitIndicatorProperties *m_down = nullptr;
459
460 friend class QQStyleKitReader;
462};
463
464// ************* QQStyleKitTextProperties ****************
465
467{
468 Q_OBJECT
469 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
479
480 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
482
483public:
485
486 template <typename... CHANGED_SIGNALS>
487 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
488
489 QColor color() const;
490 void setColor(const QColor &color);
491
492 Qt::Alignment alignment() const;
493 void setAlignment(Qt::Alignment alignment);
494
495 bool bold() const;
496 void setBold(bool bold);
497
498 bool italic() const;
499 void setItalic(bool italic);
500
501 qreal pointSize() const;
502 void setPointSize(qreal pointSize);
503
504 qreal padding() const;
505 void setPadding(qreal padding);
506
507 qreal leftPadding() const;
508 void setLeftPadding(qreal leftPadding);
509
510 qreal rightPadding() const;
511 void setRightPadding(qreal rightPadding);
512
513 qreal topPadding() const;
514 void setTopPadding(qreal topPadding);
515
516 qreal bottomPadding() const;
517 void setBottomPadding(qreal bottomPadding);
518
519signals:
530};
531
532/************* QQStyleKitControlProperties ****************
533 * QQStyleKitControlProperties (and all other subclasses of QQStyleKitPropertyGroup),
534 * is just an empty interface declaring the properties available for styling and reading.
535 * It contains as little data as possible since it will be instantiated a lot. E.g a style
536 * will instantiate them for every style.button, style.slider, etc defined, the same for a
537 * theme, and also each instance of a StyleKitReader. Those are all subclasses of this
538 * class. Each subclass will determine if the properties can be written to (as opposed to
539 * only be read), and if so, offer a storage for storing those values. That storage is typically
540 * a map that stores _only_ the properties that are written to, and nothing else.
541 */
543{
544 Q_OBJECT
545 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
556 QML_UNCREATABLE("This component acts as an interface, and cannot be instantiated")
558
559public:
561
563 template <typename... CHANGED_SIGNALS>
564 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
566 std::function<void (QQStyleKitDelegateProperties *, QQSK::Delegate, const QString &)> f);
567
568 QQStyleKitStyle *style() const;
569 QQSK::Subclass subclass() const;
572
573 qreal spacing() const;
574 void setSpacing(qreal spacing);
575
576 qreal padding() const;
577 void setPadding(qreal padding);
578
579 qreal leftPadding() const;
580 void setLeftPadding(qreal leftPadding);
581
582 qreal rightPadding() const;
583 void setRightPadding(qreal rightPadding);
584
585 qreal topPadding() const;
586 void setTopPadding(qreal topPadding);
587
588 qreal bottomPadding() const;
589 void setBottomPadding(qreal bottomPadding);
590
592 void setTransition(QQuickTransition *transition);
593
595
596 QQStyleKitDelegateProperties *background() const;
599
600signals:
612
613private:
615
617 QQStyleKitHandleProperties *m_handle = nullptr;
618 QQStyleKitIndicatorWithSubTypes *m_indicator = nullptr;
619 QQStyleKitTextProperties *m_text = nullptr;
620
622 friend class QQStyleKitReader;
623};
624
625QT_END_NAMESPACE
626
627#endif // QQSTYLEKITCONTROLPROPERTIES_P_H
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.