aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2024-02-06 13:30:30 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2024-02-06 15:22:27 +0000
commitc5f86ea0b5782797a0746bfc3e849613a0bd6ebd (patch)
treef33f83b77ee997a4ef2bb0a3698cd162b8aa5166
parent8b97598011b79152c5addc367f938556cefc7fb2 (diff)
QmlDesigner: Implement effect item visibility handling
Now effects made with effect composer can be hidden/shown using visible property. Fixes: QDS-11786 Change-Id: I44782246adfa3ba3cd0a8203fa67b3f5412535f7 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r--src/plugins/effectcomposer/effectcomposermodel.cpp25
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorview.cpp7
-rw-r--r--src/plugins/qmldesigner/designercore/include/qmlitemnode.h1
-rw-r--r--src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp5
-rw-r--r--src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp35
-rw-r--r--src/tools/qml2puppet/qml2puppet/instances/qt5rendernodeinstanceserver.h3
6 files changed, 72 insertions, 4 deletions
diff --git a/src/plugins/effectcomposer/effectcomposermodel.cpp b/src/plugins/effectcomposer/effectcomposermodel.cpp
index 9919fc7a30..00d51a954a 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,10 +626,25 @@ R"(
}
if (parent) {
_oldParent = parent
+ if (visible) {
+ parent.layer.enabled = true
+ parent.layer.effect = effectComponent
+ }
+ %1
+ }
+ }
+
+ onVisibleChanged: {
+ if (visible) {
parent.layer.enabled = true
parent.layer.effect = effectComponent
- %1
+ 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 99d243867f..9adc275236 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<QPair<ModelNode, PropertyName> > &propertyList)
{
QList<FormEditorItem*> 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 QList<QPair<ModelNode, Proper
m_scene->synchronizeOtherProperty(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 5948ec7ab1..dde5515a5a 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 e524e91c70..59295e6ae7 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 3a7882871c..f9191950fd 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 <qmlprivategate.h>
+
#include <private/qquickdesignersupport_p.h>
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<PropertyValueContainer> 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<ServerNodeInstance> 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 53cb6fffb1..738aa47b18 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<ServerNodeInstance> m_dirtyInstanceSet;
};