QmlDesigner: Allow dropping materials on User Assets

Fixes: QDS-14444
Change-Id: Ic3dd93709497cbb9c14eba2ff784ef00d9b975d7
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Shrief Gabr
2025-01-02 12:55:05 +02:00
parent 9bd23da2c3
commit dd2a2f2fe2
4 changed files with 15 additions and 4 deletions

View File

@@ -116,8 +116,8 @@ Item {
onCountChanged: root.assignMaxCount() onCountChanged: root.assignMaxCount()
onDropEnter: (drag) => { onDropEnter: (drag) => {
drag.accepted = categoryTitle === "Textures" drag.accepted = (categoryTitle === "Textures" && drag.formats[0] === "application/vnd.qtdesignstudio.assets")
&& drag.formats[0] === "application/vnd.qtdesignstudio.assets" || (categoryTitle === "Materials" && drag.formats[0] === "application/vnd.qtdesignstudio.material")
section.highlight = drag.accepted section.highlight = drag.accepted
} }
@@ -128,9 +128,13 @@ Item {
onDrop: (drag) => { onDrop: (drag) => {
section.highlight = false section.highlight = false
ContentLibraryBackend.rootView.acceptTexturesDrop(drag.urls)
drag.accept() drag.accept()
section.expandSection() section.expandSection()
if (categoryTitle === "Textures")
ContentLibraryBackend.rootView.acceptTexturesDrop(drag.urls)
else if (categoryTitle === "Materials")
ContentLibraryBackend.rootView.acceptMaterialDrop(drag.getDataAsString(drag.formats[0]))
} }
Grid { Grid {

View File

@@ -130,7 +130,6 @@ StudioControls.Menu {
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("Add to Content Library") text: qsTr("Add to Content Library")
enabled: !materialBrowserModel.selectedMaterialIsComponent
onTriggered: MaterialBrowserBackend.rootView.addMaterialToContentLibrary() onTriggered: MaterialBrowserBackend.rootView.addMaterialToContentLibrary()
} }

View File

@@ -100,6 +100,13 @@ WidgetInfo ContentLibraryView::widgetInfo()
addLibAssets(paths); addLibAssets(paths);
}); });
connect(m_widget, &ContentLibraryWidget::acceptMaterialDrop, this,
[this](const QString &internalId) {
ModelNode matNode = QmlDesignerPlugin::instance()->viewManager()
.view()->modelNodeForInternalId(internalId.toInt());
addLibItem(matNode);
});
connect(m_widget, connect(m_widget,
&ContentLibraryWidget::addTextureRequested, &ContentLibraryWidget::addTextureRequested,
this, this,

View File

@@ -125,6 +125,7 @@ signals:
void importBundle(); void importBundle();
void requestTab(int tabIndex); void requestTab(int tabIndex);
void acceptTexturesDrop(const QList<QUrl> &urls); void acceptTexturesDrop(const QList<QUrl> &urls);
void acceptMaterialDrop(const QString &internalId);
protected: protected:
bool eventFilter(QObject *obj, QEvent *event) override; bool eventFilter(QObject *obj, QEvent *event) override;