forked from qt-creator/qt-creator
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:
@@ -634,9 +634,8 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
|
|||||||
|
|
||||||
ModelNode newModelNode;
|
ModelNode newModelNode;
|
||||||
|
|
||||||
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
|
auto createTextureNode = [&](const NodeAbstractProperty &targetProp) -> bool {
|
||||||
// if dropping an image on a default material, create a texture instead of image
|
if (targetProp.isValid()) {
|
||||||
m_view->executeInTransaction("QmlItemNode::createQmlItemNode", [&] {
|
|
||||||
// create a texture item lib
|
// create a texture item lib
|
||||||
ItemLibraryEntry itemLibraryEntry;
|
ItemLibraryEntry itemLibraryEntry;
|
||||||
itemLibraryEntry.setName("Texture");
|
itemLibraryEntry.setName("Texture");
|
||||||
@@ -649,14 +648,33 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
|
|||||||
itemLibraryEntry.addProperty(prop, type, val);
|
itemLibraryEntry.addProperty(prop, type, val);
|
||||||
|
|
||||||
// create a texture
|
// 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
|
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
|
||||||
// TODO: allow the user to choose which map property to set the texture for (QDS-2326)
|
// if dropping an image on a default material, create a texture instead of image
|
||||||
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial"))
|
m_view->executeInTransaction("NavigatorTreeModel::handleItemLibraryImageDrop", [&] {
|
||||||
targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId());
|
if (createTextureNode(targetProperty)) {
|
||||||
else if (targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial"))
|
// Automatically set the texture to default property
|
||||||
targetNode.bindingProperty("baseColorMap").setExpression(newModelNode.validId());
|
// 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")) {
|
} else if (targetNode.isSubclassOf("QtQuick3D.Texture")) {
|
||||||
// if dropping an image on a texture, set the texture source
|
// if dropping an image on a texture, set the texture source
|
||||||
|
Reference in New Issue
Block a user