forked from qt-creator/qt-creator
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:
@@ -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()
|
||||
}
|
||||
)"
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -111,6 +111,7 @@ public:
|
||||
QSizeF instanceSize() const;
|
||||
int instancePenWidth() const;
|
||||
bool instanceIsRenderPixmapNull() const;
|
||||
bool instanceIsVisible() const;
|
||||
|
||||
QPixmap instanceRenderPixmap() const;
|
||||
QPixmap instanceBlurredRenderPixmap() const;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user