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
qstylekitstyle_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 QSTYLEKITSTYLE_P_H
6#define QSTYLEKITSTYLE_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 <QtWidgets/private/qtwidgetsglobal_p.h>
20#include <QtWidgets/qcommonstyle.h>
21#include <QtWidgets/private/qcommonstyle_p.h>
22#include <QtQml/qqmlengine.h>
23#include "qstylekitstyle.h"
24#include <QtLabsStyleKit/private/qqstylekitreader_p.h>
25
27
28class QQStyleKitDelegateProperties;
30class QQStyleKitImageProperties;
33class QQStyleKitReader;
34class QQStyleKitStyle;
36{
37 Q_DECLARE_PUBLIC(QStyleKitStyle)
38
39 // Stores all the metrics needed to draw and size a control.
40 // Cached per-control type and state so that we don't have to do multiple
41 // lookups on the reader for each property when drawing
42 struct ControlMetrics
43 {
54 int spacing;
55 };
56 // Key for the metrics cache
57 struct MetricsCacheKey
58 {
59 QQStyleKitReader::ControlType type;
60 QQSK::State state;
61
62 friend bool operator==(MetricsCacheKey lhs, MetricsCacheKey rhs) noexcept
63 { return lhs.type == rhs.type && lhs.state == rhs.state; }
64 friend size_t qHash(MetricsCacheKey key, size_t seed = 0) noexcept
65 { return qHashMulti(seed, key.type, key.state); }
66 };
67
68 // Stores the resolved properties for a control in a specific state.
69 // Used by painters to read properties when drawing.
70 // The reader stays internal and we expose only the property accessors
71 // to avoid mutating the reader and reconfigure resolution mid-paint.
72 struct QQStyleKitResolved
73 {
74 const QQStyleKitReader *reader = nullptr;
75 const ControlMetrics *metrics = nullptr;
76 const QWidget *widget = nullptr;
77
78 bool isValid() const { return reader && metrics; }
79 const QQStyleKitTextProperties *text() const;
80 const QQStyleKitDelegateProperties *background() const;
81 const QQStyleKitHandleProperties *handle() const;
82 const QQStyleKitIndicatorWithSubTypes *indicator() const;
83 QFont font() const;
84 };
85 // Stores the resolved properties for layout purposes.
86 // Accessors read static values via the shared reader (transitions disabled),
87 // so layout never depends on animation state.
88 struct QQStyleKitLayoutResolved
89 {
90 const ControlMetrics *metrics = nullptr;
91 const QQStyleKitControlProperties *staticProps = nullptr;
92 QFont staticFont;
93
94 bool isValid() const { return metrics; }
95 const QQStyleKitTextProperties *text() const;
96 const QQStyleKitDelegateProperties *background() const;
97 const QQStyleKitHandleProperties *handle() const;
98 const QQStyleKitIndicatorWithSubTypes *indicator() const;
99 QFont font() const { return staticFont; }
100 };
101
102 // Copied from qstylesheetstyle_p.h
103 template <typename T>
104 struct Tampered {
105 T oldWidgetValue;
106 decltype(std::declval<T>().resolveMask()) resolveMask;
107
108 // only call this function on an rvalue *this (it mangles oldWidgetValue)
109 T reverted(T current) && {
110 oldWidgetValue.setResolveMask(oldWidgetValue.resolveMask() & resolveMask);
111 current.setResolveMask(current.resolveMask() & ~resolveMask);
112 current.resolve(oldWidgetValue);
113 current.setResolveMask(current.resolveMask() | oldWidgetValue.resolveMask());
114 return current;
115 }
116 };
117
118private:
119 QStyleKitStylePrivate();
120
121 bool loadStyle();
122 void updateStyle();
123
124 void unsetStyleFont(QWidget *widget);
125 void setStyleFont(QWidget *widget);
126
127 void unsetStylePalette(QWidget *widget);
128 void setStylePalette(QWidget *widget, const QPalette &stylePalette) const;
129 void refreshStylePalette(QWidget *widget);
130
131 QQStyleKitReader *readerForWidget(const QWidget *widget) const;
132 void cleanupWidgetReader(const QWidget *widget) const;
133
134 QQStyleKitReader *readerForItemViewItem(const QWidget *widget, quint64 itemKey) const;
135 void cleanupItemViewItemReaders(const QWidget *widget) const;
136 static quint64 itemViewItemKeyForOption(const QStyleOption *opt);
137
138 QQStyleKitReader *ensureSharedReader() const;
139
140 QQSK::State resolvedStateFor(QQStyleKitReader::ControlType type, QStyle::State state) const;
141
142 QQStyleKitResolved resolve(const QWidget *w, QQStyleKitReader::ControlType type, QStyle::State state) const;
143 QQStyleKitResolved resolveItemViewItem(const QWidget *w, const QStyleOption *opt,
144 QQStyleKitReader::ControlType type, QStyle::State state) const;
145
146 QQStyleKitLayoutResolved resolveLayout(QQStyleKitReader::ControlType type,
147 QStyle::State state) const;
148
149 const ControlMetrics &metricsFor(QQStyleKitReader::ControlType type, QQSK::State state) const;
150 void clearMetricsCache();
151
152 ControlMetrics metricsForReader(QQStyleKitReader *reader) const;
153
154 void drawControlIndicator(const QQStyleKitDelegateProperties *indicator, const QRectF &rect, QPainter *p) const;
155 void drawControlText(const QQStyleKitTextProperties *textProps, const QFont &font,
156 const QRect &rect, const QString &text, uint textFlags, QPainter *p) const;
157 void drawStyledItemRect(const QQStyleKitDelegateProperties *, const QRectF &rect, QPainter *p) const;
158 void drawStyledItemImage(const QQStyleKitImageProperties *image, const QRectF &rect,
159 qreal opacity, QPainter *p) const;
160
161 QRect getAlignedRectInContainer(const QRect &container, const QSize &indicatorSize,
162 uint alignment, const QMargins &padding,
163 const QMargins &indicatorMargins) const;
164
165 QQmlEngine *qmlEngine = nullptr;
166 QQStyleKitStyle *style = nullptr;
167 // Reader for static metric reads
168 mutable QQStyleKitReader *sharedReader = nullptr;
169 // Per-widget readers
170 // Separate per-widget readers are used in order to support transitions,
171 // as each reader provides interpolated property values during these transitions.
172 mutable QHash<const QWidget *, QQStyleKitReader *> widgetReaders;
173 // Per-item readers for item-view items
175 // Cache of resolved metrics per control type and state
176 mutable QHash<MetricsCacheKey, ControlMetrics> metricsCache;
179 QString stylePath;
180};
181
182QT_END_NAMESPACE
183
184#endif // QSTYLEKITSTYLE_P_H
\inmodule QtLabsStyleKit
Combined button and popup list for selecting options.
static uint resolvedAlignment(uint raw, Qt::Alignment hDefault, Qt::Alignment vDefault)
static QQStyleKitReader::ControlType controlTypeForWidget(const QWidget *widget)
static const QWidget * containerWidget(const QWidget *w)