QmlDesigner: Support dragging images to TextureInputs

Dragging an image to TextureInput item creates a new Texture item at
the same level as the TextureInput and binds TextureInput.texture
property to the newly created texture. Any existing texture binding
is overwritten.

Task-number: QDS-2657
Change-Id: I79cf1a11608914ded4b868336a7d1a9c83071d87
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2020-08-25 13:24:05 +03:00
parent 2f6d0a1ad3
commit ee281afa73

View File

@@ -634,9 +634,8 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
ModelNode newModelNode;
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
// if dropping an image on a default material, create a texture instead of image
m_view->executeInTransaction("QmlItemNode::createQmlItemNode", [&] {
auto createTextureNode = [&](const NodeAbstractProperty &targetProp) -> bool {
if (targetProp.isValid()) {
// create a texture item lib
ItemLibraryEntry itemLibraryEntry;
itemLibraryEntry.setName("Texture");
@@ -649,14 +648,33 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
itemLibraryEntry.addProperty(prop, type, val);
// create a texture
newModelNode = QmlItemNode::createQmlObjectNode(m_view, itemLibraryEntry, {}, targetProperty, false);
newModelNode = QmlItemNode::createQmlObjectNode(m_view, itemLibraryEntry, {}, targetProp, false);
return newModelNode.isValid();
}
return false;
};
// Automatically set the texture to default property
// TODO: allow the user to choose which map property to set the texture for (QDS-2326)
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial"))
targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId());
else if (targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial"))
targetNode.bindingProperty("baseColorMap").setExpression(newModelNode.validId());
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
// if dropping an image on a default material, create a texture instead of image
m_view->executeInTransaction("NavigatorTreeModel::handleItemLibraryImageDrop", [&] {
if (createTextureNode(targetProperty)) {
// Automatically set the texture to default property
// TODO: allow the user to choose which map property to set the texture for (QDS-2326)
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial"))
targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId());
else if (targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial"))
targetNode.bindingProperty("baseColorMap").setExpression(newModelNode.validId());
}
});
} else if (targetNode.isSubclassOf("QtQuick3D.TextureInput")) {
// If dropping an image on a TextureInput, create a texture on the same level as
// TextureInput, as the TextureInput doesn't support Texture children (QTBUG-86219)
m_view->executeInTransaction("NavigatorTreeModel::handleItemLibraryImageDrop", [&] {
NodeAbstractProperty parentProp = targetProperty.parentProperty();
if (createTextureNode(parentProp)) {
// Automatically set the texture to texture property
targetNode.bindingProperty("texture").setExpression(newModelNode.validId());
}
});
} else if (targetNode.isSubclassOf("QtQuick3D.Texture")) {
// if dropping an image on a texture, set the texture source