QmlDesigner: Allow dropping image assets to User Assets

Also fixes a corner case where a "Content Library is disabled inside a non-visual component." message is displayed under Textures if the materials model is empty.

Fixes: QDS-14443
Fixes: QDS-12825
Change-Id: I9fa37b843534a1a54f08652f7a66915ac30d024d
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Shrief Gabr
2025-01-01 22:38:16 +02:00
parent 98988e5463
commit 9bd23da2c3
3 changed files with 34 additions and 1 deletions

View File

@@ -104,6 +104,7 @@ Item {
bottomPadding: StudioTheme.Values.sectionPadding
caption: categoryTitle
dropEnabled: true
category: "ContentLib_User"
function expandSection() {
@@ -114,6 +115,24 @@ Item {
onCountChanged: root.assignMaxCount()
onDropEnter: (drag) => {
drag.accepted = categoryTitle === "Textures"
&& drag.formats[0] === "application/vnd.qtdesignstudio.assets"
section.highlight = drag.accepted
}
onDropExit: {
section.highlight = false
}
onDrop: (drag) => {
section.highlight = false
ContentLibraryBackend.rootView.acceptTexturesDrop(drag.urls)
drag.accept()
section.expandSection()
}
Grid {
width: section.width - section.leftPadding - section.rightPadding
spacing: StudioTheme.Values.sectionGridSpacing
@@ -182,7 +201,7 @@ Item {
qsTr("<b>Content Library</b> is not supported in Qt5 projects.")
else if (!ContentLibraryBackend.rootView.hasQuick3DImport && categoryTitle !== "Textures")
qsTr("To use " + categoryName + ", first add the QtQuick3D module in the <b>Components</b> view.")
else if (!ContentLibraryBackend.rootView.hasMaterialLibrary)
else if (!ContentLibraryBackend.rootView.hasMaterialLibrary && categoryTitle !== "Textures")
qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
else if (categoryEmpty)
qsTr("There are no "+ categoryName + " in the <b>User Assets</b>.")

View File

@@ -87,6 +87,19 @@ WidgetInfo ContentLibraryView::widgetInfo()
m_draggedBundleItem = item;
});
connect(m_widget, &ContentLibraryWidget::acceptTexturesDrop, this,
[this](const QList<QUrl> &urls) {
QStringList paths;
for (const QUrl &url : urls) {
QString path = url.toLocalFile();
if (Asset(path).isImage())
paths.append(path);
}
addLibAssets(paths);
});
connect(m_widget,
&ContentLibraryWidget::addTextureRequested,
this,

View File

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