diff --git a/src/plugins/effectcomposer/effectcomposermodel.cpp b/src/plugins/effectcomposer/effectcomposermodel.cpp index 9919fc7a308..00d51a954a6 100644 --- a/src/plugins/effectcomposer/effectcomposermodel.cpp +++ b/src/plugins/effectcomposer/effectcomposermodel.cpp @@ -583,9 +583,13 @@ import QtQuick Item { id: rootItem - // This is an internal property used by tooling to identify effect items + // Use visible property to show and hide the effect. + visible: true + + // This is an internal property used by tooling to identify effect items. Do not modify. property var _isEffectItem + // This is an internal property used to manage the effect. Do not modify. property Item _oldParent: null )" }; @@ -593,7 +597,7 @@ Item { s += header.arg(qApp->applicationVersion(), QDateTime::currentDateTime().toString()); if (m_shaderFeatures.enabled(ShaderFeatures::Source)) { - s += " // This is the main source for the effect\n"; + s += " // This is the main source for the effect. Set internally to the current parent item. Do not modify.\n"; s += " property Item source: null\n"; } if (m_shaderFeatures.enabled(ShaderFeatures::Time) @@ -622,11 +626,26 @@ R"( } if (parent) { _oldParent = parent - parent.layer.enabled = true - parent.layer.effect = effectComponent + if (visible) { + parent.layer.enabled = true + parent.layer.effect = effectComponent + } %1 } } + + onVisibleChanged: { + if (visible) { + parent.layer.enabled = true + parent.layer.effect = effectComponent + source = parent + } else { + parent.layer.enabled = false + parent.layer.effect = null + source = null + } + parent.update() + } )" }; diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index 99d243867f7..9adc275236b 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -863,6 +863,7 @@ QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode) void FormEditorView::instancePropertyChanged(const QList > &propertyList) { QList changedItems; + bool needEffectUpdate = false; for (auto &nodePropertyPair : propertyList) { const QmlItemNode qmlItemNode(nodePropertyPair.first); const PropertyName propertyName = nodePropertyPair.second; @@ -873,10 +874,14 @@ void FormEditorView::instancePropertyChanged(const QListsynchronizeOtherProperty(item, propertyName); changedItems.append(item); } + } else if (propertyName == "visible" && qmlItemNode.isEffectItem()) { + needEffectUpdate = true; } } } m_currentTool->formEditorItemsChanged(changedItems); + if (needEffectUpdate) + updateHasEffects(); } bool FormEditorView::isMoveToolAvailable() const @@ -1011,7 +1016,7 @@ void FormEditorView::updateHasEffects() FormEditorItem *item = m_scene->itemForQmlItemNode(qmlNode); if (item) item->setHasEffect(false); - if (qmlNode.isEffectItem()) { + if (qmlNode.isEffectItem() && qmlNode.instanceIsVisible()) { FormEditorItem *parentItem = m_scene->itemForQmlItemNode(qmlNode.modelParentItem()); if (parentItem) parentItem->setHasEffect(true); diff --git a/src/plugins/qmldesigner/designercore/include/qmlitemnode.h b/src/plugins/qmldesigner/designercore/include/qmlitemnode.h index 5948ec7ab17..dde5515a5a0 100644 --- a/src/plugins/qmldesigner/designercore/include/qmlitemnode.h +++ b/src/plugins/qmldesigner/designercore/include/qmlitemnode.h @@ -111,6 +111,7 @@ public: QSizeF instanceSize() const; int instancePenWidth() const; bool instanceIsRenderPixmapNull() const; + bool instanceIsVisible() const; QPixmap instanceRenderPixmap() const; QPixmap instanceBlurredRenderPixmap() const; diff --git a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp index e524e91c70f..59295e6ae76 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp @@ -480,6 +480,11 @@ bool QmlItemNode::instanceIsRenderPixmapNull() const return nodeInstance().renderPixmap().isNull(); } +bool QmlItemNode::instanceIsVisible() const +{ + return nodeInstance().property("visible").toBool(); +} + QPixmap QmlItemNode::instanceRenderPixmap() const { return nodeInstance().renderPixmap(); diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp b/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp index 3a7882871c5..f9191950fd5 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp @@ -36,6 +36,8 @@ #include "dummycontextobject.h" +#include + #include namespace QmlDesigner { @@ -217,4 +219,37 @@ void QmlDesigner::Qt5RenderNodeInstanceServer::removeSharedMemory(const QmlDesig ImageContainer::removeSharedMemorys(command.keyNumbers()); } +void Qt5RenderNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) +{ + Qt5NodeInstanceServer::changePropertyValues(command); + + const QVector values = command.valueChanges(); + for (const PropertyValueContainer &container : values) { + // In case an effect item visibility changed to false, make sure all children are rendered + // again as they might not have valid pixmaps yet + if (container.name() == "visible" && !container.value().toBool() + && hasInstanceForId(container.instanceId())) { + ServerNodeInstance instance = instanceForId(container.instanceId()); + if (instance.isSubclassOf("QtQuick/PropertyChanges")) { + QObject *targetObject = Internal::QmlPrivateGate::PropertyChanges::targetObject( + instance.internalInstance()->object()); + if (hasInstanceForObject(targetObject)) + instance = instanceForObject(targetObject); + } + + if (instance.hasParent() && instance.propertyNames().contains("_isEffectItem")) + makeDirtyRecursive(instance.parent()); + } + } +} + +void Qt5RenderNodeInstanceServer::makeDirtyRecursive(const ServerNodeInstance &instance) +{ + const QList children = instance.childItems(); + for (const auto &child : children) { + m_dirtyInstanceSet.insert(child); + makeDirtyRecursive(child); + } +} + } // namespace QmlDesigner diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.h b/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.h index 53cb6fffb1f..738aa47b185 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.h +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.h @@ -17,6 +17,7 @@ public: void clearScene(const ClearSceneCommand &command) override; void completeComponent(const CompleteComponentCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; + void changePropertyValues(const ChangeValuesCommand &command) override; protected: void collectItemChangesAndSendChangeCommands() override; @@ -24,6 +25,8 @@ protected: void resizeCanvasToRootItem() override; private: + void makeDirtyRecursive(const ServerNodeInstance &instance); + QSet m_dirtyInstanceSet; };