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 delegateProperties on StyleKitContainer is not supported.";
47 m_delegateProperties = delegateProperties;
48 emit delegatePropertiesChanged();
58 if (m_control == control)
61 emit parentControlChanged();
66 return m_delegateInstance;
71 setImplicitWidth(m_delegateInstance ? m_delegateInstance->implicitWidth() : 0);
72 setImplicitHeight(m_delegateInstance ? m_delegateInstance->implicitHeight() : 0);
77 if (m_delegateInstance)
79 if (!m_delegateProperties)
82 if (!m_delegateProperties->visible()) {
83 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
88 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
91 if (QQmlComponent *delegateComponent = m_delegateProperties->delegate()) {
92 m_delegateComponent = delegateComponent;
94 if (!s_defaultDelegateComponent || s_defaultDelegateComponent->engine() != qmlEngine(
this)) {
95 delete s_defaultDelegateComponent;
96 QQmlEngine *engine = qmlEngine(
this);
97 s_defaultDelegateComponent =
new QQmlComponent(engine);
98 const QString qmlCode = QString::fromUtf8(R"(
99 import QtQuick
100 import Qt.labs.StyleKit
101 StyleKitDelegate {
102 width: parent.width
103 height: parent.height
104 }
105 )");
106 s_defaultDelegateComponent->setData(qmlCode.toUtf8(), QUrl());
107 Q_ASSERT_X(!s_defaultDelegateComponent->isError(),
__FUNCTION__,
108 s_defaultDelegateComponent->errorString().toUtf8().constData());
110 m_delegateComponent = s_defaultDelegateComponent;
113 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
114 m_delegateInstance = qobject_cast<QQuickItem*>(m_delegateComponent->beginCreate(ctx));
115 Q_ASSERT(m_delegateInstance);
116 m_delegateInstance->setParent(
this);
117 m_delegateInstance->setParentItem(
this);
118 m_delegateInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
119 m_delegateInstance->setProperty(
"delegateProperties", QVariant::fromValue(m_delegateProperties.get()));
120 m_delegateComponent->completeCreate();
122 updateImplicitSize();
129 if (m_shadowInstance)
131 if (!m_delegateProperties)
134 if (!m_delegateProperties->visible()) {
135 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
139 if (!m_delegateProperties->shadow()->visible()) {
140 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
144 if (m_delegateProperties->shadow()->color().alpha() == 0) {
145 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
149 if (m_delegateProperties->shadow()->opacity() == 0) {
150 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
155 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
157 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
159 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
161 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
164 if (QQmlComponent *shadowComponent = m_delegateProperties->shadow()->delegate()) {
165 m_shadowComponent = shadowComponent;
167 if (!s_defaultShadowComponent || s_defaultShadowComponent->engine() != qmlEngine(
this)) {
168 delete s_defaultShadowComponent;
169 QQmlEngine *engine = qmlEngine(
this);
170 s_defaultShadowComponent =
new QQmlComponent(engine);
171 const QString qmlCode = QString::fromUtf8(R"(
172 import Qt.labs.StyleKit.impl
173 Shadow {}
174 )");
175 s_defaultShadowComponent->setData(qmlCode.toUtf8(), QUrl());
176 Q_ASSERT_X(!s_defaultShadowComponent->isError(),
__FUNCTION__,
177 s_defaultShadowComponent->errorString().toUtf8().constData());
179 m_shadowComponent = s_defaultShadowComponent;
182 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
183 m_shadowInstance = qobject_cast<QQuickItem*>(m_shadowComponent->beginCreate(ctx));
184 Q_ASSERT(m_shadowInstance);
185 m_shadowInstance->setParent(
this);
186 m_shadowInstance->setParentItem(
this);
187 m_shadowInstance->setZ(-1);
188 m_shadowInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
189 m_shadowInstance->setProperty(
"delegateProperties", QVariant::fromValue(m_delegateProperties.get()));
190 m_shadowComponent->completeCreate();
195 QQuickItem::componentComplete();
196 Q_ASSERT(m_delegateProperties);
199 maybeCreateDelegate();
200 connect(m_delegateProperties, &QQStyleKitDelegateProperties::delegateChanged,
this, [
this]{
201 if (!m_delegateInstance) {
202 maybeCreateDelegate();
204 const QQmlComponent *newDelegateComp = m_delegateProperties->delegate();
205 if (m_delegateComponent == newDelegateComp)
207 if (!newDelegateComp && m_delegateComponent == s_defaultDelegateComponent) {
209
213 delete m_delegateInstance;
214 maybeCreateDelegate();
215 emit delegateInstanceChanged();
220 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::delegateChanged,
this, [
this]{
221 if (!m_shadowInstance) {
224 const QQmlComponent *newShadowComp = m_delegateProperties->shadow()->delegate();
225 if (m_shadowComponent == newShadowComp)
227 if (!newShadowComp && m_shadowComponent == s_defaultShadowComponent) {
229
233 delete m_shadowInstance;
241#include "moc_qqstylekitdelegatecontainer_p.cpp"
void setParentControl(QObject *control)
~QQStyleKitDelegateContainer() override
QQStyleKitDelegateProperties * delegateProperties() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setDelegateProperties(QQStyleKitDelegateProperties *delegateProperties)
QQuickItem * delegateInstance() const
QObject * parentControl() const
Combined button and popup list for selecting options.