QmlDesigner: Add support for dragging textures to materials

Dragging textures to materials within material browser now works.

Fixes: QDS-8552
Change-Id: I1ec0287020fe2cd347bc0db7cda9d235678e9f04
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-12-13 16:29:25 +02:00
parent db7d7eb801
commit 857ee29c1a
3 changed files with 24 additions and 0 deletions

View File

@@ -43,6 +43,18 @@ Rectangle {
color: "transparent"
visible: materialVisible
DropArea {
anchors.fill: parent
onEntered: (drag) => {
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.texture"
}
onDropped: (drag) => {
rootView.acceptTextureDropOnMaterial(index, drag.getDataAsString(drag.keys[0]))
}
}
MouseArea {
id: mouseArea

View File

@@ -265,6 +265,17 @@ void MaterialBrowserWidget::acceptBundleTextureDrop()
m_materialBrowserView->emitCustomNotification("drop_bundle_texture", {}, {}); // To ContentLibraryView
}
void MaterialBrowserWidget::acceptTextureDropOnMaterial(int matIndex, const QString &texId)
{
ModelNode mat = m_materialBrowserModel->materialAt(matIndex);
ModelNode tex = m_materialBrowserView->modelNodeForInternalId(texId.toInt());
if (mat.isValid() && tex.isValid()) {
m_materialBrowserModel->selectMaterial(matIndex);
m_materialBrowserView->applyTextureToMaterial({mat}, tex);
}
}
void MaterialBrowserWidget::focusMaterialSection(bool focusMatSec)
{
if (focusMatSec != m_materialSectionFocused) {

View File

@@ -56,6 +56,7 @@ public:
Q_INVOKABLE void startDragTexture(int index, const QPointF &mousePos);
Q_INVOKABLE void acceptBundleMaterialDrop();
Q_INVOKABLE void acceptBundleTextureDrop();
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
QQuickWidget *quickWidget() const;