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>
This commit is contained in:
Miikka Heikkinen
2024-02-06 13:30:30 +02:00
parent 8b97598011
commit c5f86ea0b5
6 changed files with 73 additions and 5 deletions

View File

@@ -583,9 +583,13 @@ import QtQuick
Item { Item {
id: rootItem 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 property var _isEffectItem
// This is an internal property used to manage the effect. Do not modify.
property Item _oldParent: null property Item _oldParent: null
)" )"
}; };
@@ -593,7 +597,7 @@ Item {
s += header.arg(qApp->applicationVersion(), QDateTime::currentDateTime().toString()); s += header.arg(qApp->applicationVersion(), QDateTime::currentDateTime().toString());
if (m_shaderFeatures.enabled(ShaderFeatures::Source)) { 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"; s += " property Item source: null\n";
} }
if (m_shaderFeatures.enabled(ShaderFeatures::Time) if (m_shaderFeatures.enabled(ShaderFeatures::Time)
@@ -622,11 +626,26 @@ R"(
} }
if (parent) { if (parent) {
_oldParent = parent _oldParent = parent
if (visible) {
parent.layer.enabled = true parent.layer.enabled = true
parent.layer.effect = effectComponent parent.layer.effect = effectComponent
}
%1 %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()
}
)" )"
}; };

View File

@@ -863,6 +863,7 @@ QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode)
void FormEditorView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyName> > &propertyList) void FormEditorView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyName> > &propertyList)
{ {
QList<FormEditorItem*> changedItems; QList<FormEditorItem*> changedItems;
bool needEffectUpdate = false;
for (auto &nodePropertyPair : propertyList) { for (auto &nodePropertyPair : propertyList) {
const QmlItemNode qmlItemNode(nodePropertyPair.first); const QmlItemNode qmlItemNode(nodePropertyPair.first);
const PropertyName propertyName = nodePropertyPair.second; const PropertyName propertyName = nodePropertyPair.second;
@@ -873,10 +874,14 @@ void FormEditorView::instancePropertyChanged(const QList<QPair<ModelNode, Proper
m_scene->synchronizeOtherProperty(item, propertyName); m_scene->synchronizeOtherProperty(item, propertyName);
changedItems.append(item); changedItems.append(item);
} }
} else if (propertyName == "visible" && qmlItemNode.isEffectItem()) {
needEffectUpdate = true;
} }
} }
} }
m_currentTool->formEditorItemsChanged(changedItems); m_currentTool->formEditorItemsChanged(changedItems);
if (needEffectUpdate)
updateHasEffects();
} }
bool FormEditorView::isMoveToolAvailable() const bool FormEditorView::isMoveToolAvailable() const
@@ -1011,7 +1016,7 @@ void FormEditorView::updateHasEffects()
FormEditorItem *item = m_scene->itemForQmlItemNode(qmlNode); FormEditorItem *item = m_scene->itemForQmlItemNode(qmlNode);
if (item) if (item)
item->setHasEffect(false); item->setHasEffect(false);
if (qmlNode.isEffectItem()) { if (qmlNode.isEffectItem() && qmlNode.instanceIsVisible()) {
FormEditorItem *parentItem = m_scene->itemForQmlItemNode(qmlNode.modelParentItem()); FormEditorItem *parentItem = m_scene->itemForQmlItemNode(qmlNode.modelParentItem());
if (parentItem) if (parentItem)
parentItem->setHasEffect(true); parentItem->setHasEffect(true);

View File

@@ -111,6 +111,7 @@ public:
QSizeF instanceSize() const; QSizeF instanceSize() const;
int instancePenWidth() const; int instancePenWidth() const;
bool instanceIsRenderPixmapNull() const; bool instanceIsRenderPixmapNull() const;
bool instanceIsVisible() const;
QPixmap instanceRenderPixmap() const; QPixmap instanceRenderPixmap() const;
QPixmap instanceBlurredRenderPixmap() const; QPixmap instanceBlurredRenderPixmap() const;

View File

@@ -480,6 +480,11 @@ bool QmlItemNode::instanceIsRenderPixmapNull() const
return nodeInstance().renderPixmap().isNull(); return nodeInstance().renderPixmap().isNull();
} }
bool QmlItemNode::instanceIsVisible() const
{
return nodeInstance().property("visible").toBool();
}
QPixmap QmlItemNode::instanceRenderPixmap() const QPixmap QmlItemNode::instanceRenderPixmap() const
{ {
return nodeInstance().renderPixmap(); return nodeInstance().renderPixmap();

View File

@@ -36,6 +36,8 @@
#include "dummycontextobject.h" #include "dummycontextobject.h"
#include <qmlprivategate.h>
#include <private/qquickdesignersupport_p.h> #include <private/qquickdesignersupport_p.h>
namespace QmlDesigner { namespace QmlDesigner {
@@ -217,4 +219,37 @@ void QmlDesigner::Qt5RenderNodeInstanceServer::removeSharedMemory(const QmlDesig
ImageContainer::removeSharedMemorys(command.keyNumbers()); 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 } // namespace QmlDesigner

View File

@@ -17,6 +17,7 @@ public:
void clearScene(const ClearSceneCommand &command) override; void clearScene(const ClearSceneCommand &command) override;
void completeComponent(const CompleteComponentCommand &command) override; void completeComponent(const CompleteComponentCommand &command) override;
void removeSharedMemory(const RemoveSharedMemoryCommand &command) override; void removeSharedMemory(const RemoveSharedMemoryCommand &command) override;
void changePropertyValues(const ChangeValuesCommand &command) override;
protected: protected:
void collectItemChangesAndSendChangeCommands() override; void collectItemChangesAndSendChangeCommands() override;
@@ -24,6 +25,8 @@ protected:
void resizeCanvasToRootItem() override; void resizeCanvasToRootItem() override;
private: private:
void makeDirtyRecursive(const ServerNodeInstance &instance);
QSet<ServerNodeInstance> m_dirtyInstanceSet; QSet<ServerNodeInstance> m_dirtyInstanceSet;
}; };