7#include <QtQuick/private/qquickrectangle_p.h>
8#include <QtQuick/private/qquickimplicitsizeitem_p_p.h>
9#include <QtQuickControls2Impl/private/qquickcolorimage_p.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
74 return m_delegateProperties;
79 if (m_delegateProperties == delegateStyle)
82 if (m_delegateProperties)
83 disconnect(m_delegateProperties,
nullptr,
this,
nullptr);
85 m_delegateProperties = delegateStyle;
87 if (!qmlEngine(
this)) {
88 qmlWarning(
this) <<
"Unable to draw delegate: no QQmlEngine found";
93 maybeCreateGradient();
97 connect(m_delegateProperties, &QQStyleKitDelegateProperties::widthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
98 connect(m_delegateProperties, &QQStyleKitDelegateProperties::heightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
100 emit delegateStyleChanged();
105 if (!m_delegateProperties)
109
110
111
112 const qreal widthInStyle = qMax(m_delegateProperties->minimumWidth(), m_delegateProperties->width());
113 const qreal heightInStyle = qMax(m_delegateProperties->minimumHeight(), m_delegateProperties->height());
114 setImplicitWidth(widthInStyle > 0 || !m_imageOverlay ? widthInStyle : m_imageOverlay->implicitWidth());
115 setImplicitHeight(heightInStyle > 0 || !m_imageOverlay ? heightInStyle : m_imageOverlay->implicitHeight());
122 if (!m_delegateProperties)
124 if (m_delegateProperties->color().alpha() == 0
125 && (m_delegateProperties->border()->color().alpha() == 0
126 || m_delegateProperties->border()->width() == 0)) {
128 connect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
130 connect(m_delegateProperties->border(), &QQStyleKitBorderProperties::colorChanged,
132 connect(m_delegateProperties->border(), &QQStyleKitBorderProperties::widthChanged,
137 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
139 disconnect(m_delegateProperties->border(), &QQStyleKitBorderProperties::colorChanged,
141 disconnect(m_delegateProperties->border(), &QQStyleKitBorderProperties::widthChanged,
144 QQmlEngine *engine = qmlEngine(
this);
146 static QQmlComponent *component =
nullptr;
147 if (!component || component->engine() != engine) {
149 component =
new QQmlComponent(engine);
150 const auto qmlCode = R"(
151 import QtQuick
152 Rectangle {
153 z: -3
154 width: parent.width
155 height: parent.height
156 color: delegateStyle.color
157 opacity: delegateStyle.opacity
158 topLeftRadius: delegateStyle.topLeftRadius
159 topRightRadius: delegateStyle.topRightRadius
160 bottomLeftRadius: delegateStyle.bottomLeftRadius
161 bottomRightRadius: delegateStyle.bottomRightRadius
162 border.width: delegateStyle.border.width
163 border.color: delegateStyle.border.color
164 }
165 )"_ba;
166 component->setData(qmlCode, QUrl());
167 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
170 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
171 m_colorOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
172 Q_ASSERT(m_colorOverlay);
173 m_colorOverlay->setParent(
this);
174 m_colorOverlay->setParentItem(
this);
175 component->completeCreate();
181
182
183
184
185 if (m_gradientOverlay)
187 if (!m_delegateProperties)
189 if (!m_delegateProperties->gradient()) {
190 connect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
195 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
198 QQmlEngine *engine = qmlEngine(
this);
200 static QQmlComponent *component =
nullptr;
201 if (!component || component->engine() != engine) {
203 component =
new QQmlComponent(engine);
204 const auto qmlCode = R"(
205 import QtQuick
206 Rectangle {
207 z: -2
208 width: parent.width
209 height: parent.height
210 color: "transparent"
211 visible: delegateStyle.gradient != null
212 gradient: delegateStyle.gradient
213 topLeftRadius: delegateStyle.topLeftRadius
214 topRightRadius: delegateStyle.topRightRadius
215 bottomLeftRadius: delegateStyle.bottomLeftRadius
216 bottomRightRadius: delegateStyle.bottomRightRadius
217 border.width: delegateStyle.border.width
218 border.color: delegateStyle.border.color
219 }
220 )"_ba;
221 component->setData(qmlCode, QUrl());
222 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
225 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
226 m_gradientOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
227 Q_ASSERT(m_gradientOverlay);
228 m_gradientOverlay->setParent(
this);
229 m_gradientOverlay->setParentItem(
this);
230 component->completeCreate();
237 if (!m_delegateProperties)
239 if (m_delegateProperties->image()->source().isEmpty()
240 || m_delegateProperties->image()->color().alpha() == 0) {
241 connect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
243 connect(m_delegateProperties->image(), &QQStyleKitImageProperties::colorChanged,
248 disconnect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
250 disconnect(m_delegateProperties->image(), &QQStyleKitImageProperties::colorChanged,
253 QQmlEngine *engine = qmlEngine(
this);
255 static QQmlComponent *component =
nullptr;
256 if (!component || component->engine() != engine) {
258 component =
new QQmlComponent(engine);
259 const auto qmlCode = R"(
260 import QtQuick.Controls.impl
261 ColorImage {
262 z: -1
263 width: parent.width
264 height: parent.height
265 color: delegateStyle.image.color
266 source: delegateStyle.image.source
267 fillMode: delegateStyle.image.fillMode
268 }
269 )"_ba;
270 component->setData(qmlCode, QUrl());
271 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
274 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
275 m_imageOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
276 m_imageOverlay->setParent(
this);
277 m_imageOverlay->setParentItem(
this);
278 component->completeCreate();
280 updateImplicitSize();
281 connect(m_imageOverlay, &QQuickItem::implicitWidthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
282 connect(m_imageOverlay, &QQuickItem::implicitHeightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
287#include "moc_qqstylekitdelegate_p.cpp"
void setDelegateStyle(QQStyleKitDelegateProperties *delegateStyle)
QQStyleKitDelegateProperties * delegateStyle() const
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Combined button and popup list for selecting options.