diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2020-08-25 13:24:05 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2020-08-28 14:01:14 +0000 |
commit | ee281afa733ee0cf9a6a23d648485961da995678 (patch) | |
tree | ba57b74d1917abc559e137d86cb16526fc59a126 /src/plugins | |
parent | 2f6d0a1ad32feb625805e05b97009d86fd9ee574 (diff) |
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>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp index 4671f94bf6..f86b377933 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp @@ -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); - - // 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()); + newModelNode = QmlItemNode::createQmlObjectNode(m_view, itemLibraryEntry, {}, targetProp, false); + return newModelNode.isValid(); + } + return false; + }; + + 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 |