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::implicitWidthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
98 connect(m_delegateProperties, &QQStyleKitDelegateProperties::implicitHeightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
100 emit delegateStyleChanged();
105 if (!m_delegateProperties)
109
110
111
112
113
114 const qreal impWidthInStyle = qMax(m_delegateProperties->minimumWidth(), m_delegateProperties->implicitWidth());
115 const qreal impHeightInStyle = qMax(m_delegateProperties->minimumHeight(), m_delegateProperties->implicitHeight());
116 setImplicitWidth(impWidthInStyle > 0 || !m_imageOverlay ? impWidthInStyle : m_imageOverlay->implicitWidth());
117 setImplicitHeight(impHeightInStyle > 0 || !m_imageOverlay ? impHeightInStyle : m_imageOverlay->implicitHeight());
124 if (!m_delegateProperties)
126 if (m_delegateProperties->color().alpha() == 0
127 && (m_delegateProperties->border()->color().alpha() == 0
128 || m_delegateProperties->border()->width() == 0)) {
130 connect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
132 connect(m_delegateProperties->border(), &QQStyleKitBorderProperties::colorChanged,
134 connect(m_delegateProperties->border(), &QQStyleKitBorderProperties::widthChanged,
139 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
141 disconnect(m_delegateProperties->border(), &QQStyleKitBorderProperties::colorChanged,
143 disconnect(m_delegateProperties->border(), &QQStyleKitBorderProperties::widthChanged,
146 QQmlEngine *engine = qmlEngine(
this);
148 static QQmlComponent *component =
nullptr;
149 if (!component || component->engine() != engine) {
151 component =
new QQmlComponent(engine);
152 const auto qmlCode = R"(
153 import QtQuick
154 Rectangle {
155 z: -3
156 width: parent.width
157 height: parent.height
158 color: delegateStyle.color
159 opacity: delegateStyle.opacity
160 topLeftRadius: delegateStyle.topLeftRadius
161 topRightRadius: delegateStyle.topRightRadius
162 bottomLeftRadius: delegateStyle.bottomLeftRadius
163 bottomRightRadius: delegateStyle.bottomRightRadius
164 border.width: delegateStyle.border.width
165 border.color: delegateStyle.border.color
166 }
167 )"_ba;
168 component->setData(qmlCode, QUrl());
169 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
172 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
173 m_colorOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
174 Q_ASSERT(m_colorOverlay);
175 m_colorOverlay->setParent(
this);
176 m_colorOverlay->setParentItem(
this);
177 component->completeCreate();
183
184
185
186
187 if (m_gradientOverlay)
189 if (!m_delegateProperties)
191 if (!m_delegateProperties->gradient()) {
192 connect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
197 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
200 QQmlEngine *engine = qmlEngine(
this);
202 static QQmlComponent *component =
nullptr;
203 if (!component || component->engine() != engine) {
205 component =
new QQmlComponent(engine);
206 const auto qmlCode = R"(
207 import QtQuick
208 Rectangle {
209 z: -2
210 width: parent.width
211 height: parent.height
212 color: "transparent"
213 visible: delegateStyle.gradient != null
214 gradient: delegateStyle.gradient
215 topLeftRadius: delegateStyle.topLeftRadius
216 topRightRadius: delegateStyle.topRightRadius
217 bottomLeftRadius: delegateStyle.bottomLeftRadius
218 bottomRightRadius: delegateStyle.bottomRightRadius
219 border.width: delegateStyle.border.width
220 border.color: delegateStyle.border.color
221 }
222 )"_ba;
223 component->setData(qmlCode, QUrl());
224 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
227 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
228 m_gradientOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
229 Q_ASSERT(m_gradientOverlay);
230 m_gradientOverlay->setParent(
this);
231 m_gradientOverlay->setParentItem(
this);
232 component->completeCreate();
239 if (!m_delegateProperties)
241 if (m_delegateProperties->image()->source().isEmpty()
242 || m_delegateProperties->image()->color().alpha() == 0) {
243 connect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
245 connect(m_delegateProperties->image(), &QQStyleKitImageProperties::colorChanged,
250 disconnect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
252 disconnect(m_delegateProperties->image(), &QQStyleKitImageProperties::colorChanged,
255 QQmlEngine *engine = qmlEngine(
this);
257 static QQmlComponent *component =
nullptr;
258 if (!component || component->engine() != engine) {
260 component =
new QQmlComponent(engine);
261 const auto qmlCode = R"(
262 import QtQuick.Controls.impl
263 ColorImage {
264 z: -1
265 width: parent.width
266 height: parent.height
267 color: delegateStyle.image.color
268 source: delegateStyle.image.source
269 fillMode: delegateStyle.image.fillMode
270 }
271 )"_ba;
272 component->setData(qmlCode, QUrl());
273 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
276 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
277 m_imageOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
278 m_imageOverlay->setParent(
this);
279 m_imageOverlay->setParentItem(
this);
280 component->completeCreate();
282 updateImplicitSize();
283 connect(m_imageOverlay, &QQuickItem::implicitWidthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
284 connect(m_imageOverlay, &QQuickItem::implicitHeightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
289#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.