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 if (m_inGeometryChange) {
73
74
75
76
77
78
79
83 qreal implicitWidth = 0;
84 qreal implicitHeight = 0;
86 if (m_delegateInstance) {
87 implicitWidth = m_delegateInstance->implicitWidth();
88 implicitHeight = m_delegateInstance->implicitHeight();
89 }
else if (m_delegateProperties) {
91
92
93 implicitWidth = qMax(m_delegateProperties->minimumWidth(), m_delegateProperties->width());
94 implicitHeight = qMax(m_delegateProperties->minimumHeight(), m_delegateProperties->height());
97 setImplicitWidth(implicitWidth);
98 setImplicitHeight(implicitHeight);
103 if (m_delegateInstance)
105 if (!m_delegateProperties)
108 if (!m_delegateProperties->visible()) {
109 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
114 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
117 if (QQmlComponent *delegateComponent = m_delegateProperties->delegate()) {
118 m_delegateComponent = delegateComponent;
120 if (!s_defaultDelegateComponent || s_defaultDelegateComponent->engine() != qmlEngine(
this)) {
121 delete s_defaultDelegateComponent;
122 QQmlEngine *engine = qmlEngine(
this);
123 s_defaultDelegateComponent =
new QQmlComponent(engine);
124 const QString qmlCode = QString::fromUtf8(R"(
125 import Qt.labs.StyleKit
126 StyledItem {
127 visible: delegateStyle.visible
128 width: parent.width
129 height: parent.height
130 }
131 )");
132 s_defaultDelegateComponent->setData(qmlCode.toUtf8(), QUrl());
133 Q_ASSERT_X(!s_defaultDelegateComponent->isError(),
__FUNCTION__,
134 s_defaultDelegateComponent->errorString().toUtf8().constData());
136 m_delegateComponent = s_defaultDelegateComponent;
139 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
140 m_delegateInstance = qobject_cast<QQuickItem*>(m_delegateComponent->beginCreate(ctx));
141 Q_ASSERT(m_delegateInstance);
142 m_delegateInstance->setParent(
this);
143 m_delegateInstance->setParentItem(
this);
144 m_delegateInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
145 m_delegateInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
146 m_delegateComponent->completeCreate();
148 updateImplicitSize();
156 if (m_shadowInstance)
158 if (!m_delegateProperties)
161 if (!m_delegateProperties->visible()) {
162 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
166 if (!m_delegateProperties->shadow()->visible()) {
167 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
171 if (m_delegateProperties->shadow()->color().alpha() == 0) {
172 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
176 if (m_delegateProperties->shadow()->opacity() == 0) {
177 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
182 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
184 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
186 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
188 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
191 if (QQmlComponent *shadowComponent = m_delegateProperties->shadow()->delegate()) {
192 m_shadowComponent = shadowComponent;
194 if (!s_defaultShadowComponent || s_defaultShadowComponent->engine() != qmlEngine(
this)) {
195 delete s_defaultShadowComponent;
196 QQmlEngine *engine = qmlEngine(
this);
197 s_defaultShadowComponent =
new QQmlComponent(engine);
198 const QString qmlCode = QString::fromUtf8(R"(
199 import Qt.labs.StyleKit.impl
200 Shadow {}
201 )");
202 s_defaultShadowComponent->setData(qmlCode.toUtf8(), QUrl());
203 Q_ASSERT_X(!s_defaultShadowComponent->isError(),
__FUNCTION__,
204 s_defaultShadowComponent->errorString().toUtf8().constData());
206 m_shadowComponent = s_defaultShadowComponent;
209 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
210 m_shadowInstance = qobject_cast<QQuickItem*>(m_shadowComponent->beginCreate(ctx));
211 Q_ASSERT(m_shadowInstance);
212 m_shadowInstance->setParent(
this);
213 m_shadowInstance->setParentItem(
this);
214 m_shadowInstance->setZ(-1);
215 m_shadowInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
216 m_shadowInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
217 m_shadowComponent->completeCreate();
222 QQuickItem::componentComplete();
223 Q_ASSERT(m_delegateProperties);
226 maybeCreateDelegate();
227 connect(m_delegateProperties, &QQStyleKitDelegateProperties::delegateChanged,
this, [
this]{
228 if (!m_delegateInstance) {
229 maybeCreateDelegate();
231 const QQmlComponent *newDelegateComp = m_delegateProperties->delegate();
232 if (m_delegateComponent == newDelegateComp)
234 if (!newDelegateComp && m_delegateComponent == s_defaultDelegateComponent) {
236
240 delete m_delegateInstance;
241 maybeCreateDelegate();
242 emit delegateInstanceChanged();
247 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::delegateChanged,
this, [
this]{
248 if (!m_shadowInstance) {
251 const QQmlComponent *newShadowComp = m_delegateProperties->shadow()->delegate();
252 if (m_shadowComponent == newShadowComp)
254 if (!newShadowComp && m_shadowComponent == s_defaultShadowComponent) {
256
260 delete m_shadowInstance;
266
267
268
269
270
271
272
273 setRotation(m_delegateProperties->rotation());
274 setScale(m_delegateProperties->scale());
276 connect(m_delegateProperties, &QQStyleKitDelegateProperties::rotationChanged,
this, [
this]() {
277 setRotation(m_delegateProperties->rotation());
279 connect(m_delegateProperties, &QQStyleKitDelegateProperties::scaleChanged,
this, [
this]() {
280 setScale(m_delegateProperties->scale());
283 updateImplicitSize();
288 QScopedValueRollback implicitSizeUpdateGuard(m_inGeometryChange,
true);
289 QQuickItem::geometryChange(newGeometry, oldGeometry);
294#include "moc_qqstylekitdelegatecontainer_p.cpp"
QQStyleKitDelegateProperties * delegateStyle() const
~QQStyleKitDelegateContainer() override
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.