4#include <QtQuick/private/qquickitem_p.h>
7#include "../qqstylekitcontrolproperties_p.h"
11QQmlComponent* QQStyleKitDelegateContainer::s_defaultDelegateComponent =
nullptr;
24 if (m_delegateInstance)
25 disconnect(m_delegateInstance,
nullptr,
this,
nullptr);
30 return m_delegateProperties;
35 if (m_delegateProperties == delegateProperties)
38 if (m_delegateProperties) {
40
41
42
43 qmlWarning(
this) <<
"Changing delegateStyle on StyleKitContainer is not supported.";
47 m_delegateProperties = delegateProperties;
48 emit delegateStyleChanged();
58 if (m_control == control)
61 emit quickControlChanged();
66 return m_delegateInstance;
71 return m_delegateComponent == s_defaultDelegateComponent;
76 if (m_inGeometryChange) {
78
79
80
81
82
83
84
88 qreal implicitWidth = 0;
89 qreal implicitHeight = 0;
91 if (m_delegateInstance) {
92 implicitWidth = m_delegateInstance->implicitWidth();
93 implicitHeight = m_delegateInstance->implicitHeight();
94 }
else if (m_delegateProperties) {
96
97
98 implicitWidth = qMax(m_delegateProperties->minimumWidth(), m_delegateProperties->implicitWidth());
99 implicitHeight = m_delegateProperties->implicitHeight();
102 setImplicitWidth(implicitWidth);
103 setImplicitHeight(implicitHeight);
108 if (m_delegateInstance)
110 if (!m_delegateProperties)
113 if (!m_delegateProperties->visible()) {
114 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
119 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
124 if (QQmlComponent *delegateComponent = m_delegateProperties->delegate()) {
125 m_delegateComponent = delegateComponent;
127 if (!s_defaultDelegateComponent || s_defaultDelegateComponent->engine() != qmlEngine(
this)) {
128 delete s_defaultDelegateComponent;
129 QQmlEngine *engine = qmlEngine(
this);
130 s_defaultDelegateComponent =
new QQmlComponent(engine);
131 const QString qmlCode = QString::fromUtf8(R"(
132 import QtQuick
133 import Qt.labs.StyleKit
134 StyledItem {
135 width: parent.width
136 height: parent.height
137 }
138 )");
139 s_defaultDelegateComponent->setData(qmlCode.toUtf8(), QUrl());
140 Q_ASSERT_X(!s_defaultDelegateComponent->isError(),
__FUNCTION__,
141 s_defaultDelegateComponent->errorString().toUtf8().constData());
143 m_delegateComponent = s_defaultDelegateComponent;
146 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
147 m_delegateInstance = qobject_cast<QQuickItem*>(m_delegateComponent->beginCreate(ctx));
148 Q_ASSERT(m_delegateInstance);
149 m_delegateInstance->setParent(
this);
150 m_delegateInstance->setParentItem(
this);
151 m_delegateInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
152 m_delegateInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
153 m_delegateComponent->completeCreate();
155 updateImplicitSize();
160 emit usingDefaultDelegateChanged();
165 if (m_shadowInstance)
167 if (!m_delegateProperties)
170 if (!m_delegateProperties->visible()) {
171 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
175 if (!m_delegateProperties->shadow()->visible()) {
176 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
180 if (m_delegateProperties->shadow()->color().alpha() == 0) {
181 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
185 if (m_delegateProperties->shadow()->opacity() == 0) {
186 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
191 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
193 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
195 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
197 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
200 if (QQmlComponent *shadowComponent = m_delegateProperties->shadow()->delegate()) {
201 m_shadowComponent = shadowComponent;
203 if (!s_defaultShadowComponent || s_defaultShadowComponent->engine() != qmlEngine(
this)) {
204 delete s_defaultShadowComponent;
205 QQmlEngine *engine = qmlEngine(
this);
206 s_defaultShadowComponent =
new QQmlComponent(engine);
207 const QString qmlCode = QString::fromUtf8(R"(
208 import Qt.labs.StyleKit.impl
209 Shadow {}
210 )");
211 s_defaultShadowComponent->setData(qmlCode.toUtf8(), QUrl());
212 Q_ASSERT_X(!s_defaultShadowComponent->isError(),
__FUNCTION__,
213 s_defaultShadowComponent->errorString().toUtf8().constData());
215 m_shadowComponent = s_defaultShadowComponent;
218 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
219 m_shadowInstance = qobject_cast<QQuickItem*>(m_shadowComponent->beginCreate(ctx));
220 Q_ASSERT(m_shadowInstance);
221 m_shadowInstance->setParent(
this);
222 m_shadowInstance->setParentItem(
this);
223 m_shadowInstance->setZ(-1);
224 m_shadowInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
225 m_shadowInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
226 m_shadowComponent->completeCreate();
231 QQuickItem::componentComplete();
232 Q_ASSERT(m_delegateProperties);
235 maybeCreateDelegate();
236 connect(m_delegateProperties, &QQStyleKitDelegateProperties::delegateChanged,
this, [
this]{
237 if (!m_delegateInstance) {
238 maybeCreateDelegate();
240 const QQmlComponent *newDelegateComp = m_delegateProperties->delegate();
241 if (m_delegateComponent == newDelegateComp)
243 if (!newDelegateComp && m_delegateComponent == s_defaultDelegateComponent) {
245
249 delete m_delegateInstance;
250 maybeCreateDelegate();
251 emit delegateInstanceChanged();
256 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::delegateChanged,
this, [
this]{
257 if (!m_shadowInstance) {
260 const QQmlComponent *newShadowComp = m_delegateProperties->shadow()->delegate();
261 if (m_shadowComponent == newShadowComp)
263 if (!newShadowComp && m_shadowComponent == s_defaultShadowComponent) {
265
269 delete m_shadowInstance;
274 updateImplicitSize();
279 QScopedValueRollback implicitSizeUpdateGuard(m_inGeometryChange,
true);
280 QQuickItem::geometryChange(newGeometry, oldGeometry);
285#include "moc_qqstylekitdelegatecontainer_p.cpp"
QQStyleKitDelegateProperties * delegateStyle() const
~QQStyleKitDelegateContainer() override
bool usingDefaultDelegate() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QObject * quickControl() const
void setQuickControl(QObject *control)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setDelegateStyle(QQStyleKitDelegateProperties *delegateProperties)
QQuickItem * delegateInstance() const
Combined button and popup list for selecting options.