diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2022-03-15 15:29:27 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2022-03-18 08:24:04 +0000 |
commit | de8a67a412acee39a5f3d50855b92e9712536440 (patch) | |
tree | 18a231cb5753292802c15e2ffc2ef945c2cde094 | |
parent | a23c4ce0143acbb9b3682e29d0d076a9eb7b334d (diff) |
QmlDesigner: Add drag support to empty asset library placeholder item
Fixes: QDS-6430
Change-Id: I561f4ed51ccb1e47472adb9baa6e5594eb93eafb
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
3 files changed, 58 insertions, 41 deletions
diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml index 57c0fe2521..8173457f73 100644 --- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml +++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml @@ -469,49 +469,61 @@ Item { visible: assetsModel.isEmpty && searchBox.isEmpty() clip: true - Column { - id: colNoAssets + DropArea { // handles external drop (goes into default folder based on suffix) + anchors.fill: parent - spacing: 20 - x: 20 - width: root.width - 2 * x - anchors.verticalCenter: parent.verticalCenter + onEntered: (drag)=> { + root.updateDropExtFiles(drag) + } - Text { - text: qsTr("Looks like you don't have any assets yet.") - color: StudioTheme.Values.themeTextColor - font.pixelSize: 18 - width: colNoAssets.width - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.WordWrap + onDropped: { + rootView.handleExtFilesDrop(root.dropSimpleExtFiles, root.dropComplexExtFiles) } - Image { - source: "image://qmldesigner_assets/browse" - anchors.horizontalCenter: parent.horizontalCenter - scale: maBrowse.containsMouse ? 1.2 : 1 - Behavior on scale { - NumberAnimation { - duration: 300 - easing.type: Easing.OutQuad - } + Column { + id: colNoAssets + + spacing: 20 + x: 20 + width: root.width - 2 * x + anchors.verticalCenter: parent.verticalCenter + + Text { + text: qsTr("Looks like you don't have any assets yet.") + color: StudioTheme.Values.themeTextColor + font.pixelSize: 18 + width: colNoAssets.width + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap } - MouseArea { - id: maBrowse - anchors.fill: parent - hoverEnabled: true - onClicked: rootView.handleAddAsset(); + Image { + source: "image://qmldesigner_assets/browse" + anchors.horizontalCenter: parent.horizontalCenter + scale: maBrowse.containsMouse ? 1.2 : 1 + Behavior on scale { + NumberAnimation { + duration: 300 + easing.type: Easing.OutQuad + } + } + + MouseArea { + id: maBrowse + anchors.fill: parent + hoverEnabled: true + onClicked: rootView.handleAddAsset(); + } } - } - Text { - text: qsTr("Drag-and-drop your assets here or click the '+' button to browse assets from the file system.") - color: StudioTheme.Values.themeTextColor - font.pixelSize: 18 - width: colNoAssets.width - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.WordWrap + Text { + text: qsTr("Drag-and-drop your assets here or click the '+' button to browse assets from the file system.") + color: StudioTheme.Values.themeTextColor + font.pixelSize: 18 + width: colNoAssets.width + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + } } } } diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp index bed85b99e8..34be8ab46d 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp @@ -218,11 +218,16 @@ void AssetsLibraryWidget::handleExtFilesDrop(const QStringList &simpleFilesPaths const QString &targetDirPath) { if (!simpleFilesPaths.isEmpty()) { - AddFilesResult result = ModelNodeOperations::addFilesToProject(simpleFilesPaths, targetDirPath); - if (result == AddFilesResult::Failed) { - Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"), - tr("Could not add %1 to project.") - .arg(simpleFilesPaths.join(' '))); + if (targetDirPath.isEmpty()) { + addResources(simpleFilesPaths); + } else { + AddFilesResult result = ModelNodeOperations::addFilesToProject(simpleFilesPaths, + targetDirPath); + if (result == AddFilesResult::Failed) { + Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"), + tr("Could not add %1 to project.") + .arg(simpleFilesPaths.join(' '))); + } } } diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h index 47a9ce681d..abf91c3a8c 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h @@ -82,7 +82,7 @@ public: Q_INVOKABLE void handleSearchfilterChanged(const QString &filterText); Q_INVOKABLE void handleExtFilesDrop(const QStringList &simpleFilesPaths, const QStringList &complexFilesPaths, - const QString &targetDirPath); + const QString &targetDirPath = {}); Q_INVOKABLE QSet<QString> supportedAssetSuffixes(bool complex); signals: |