From 45c7a6b8e60955d53601b19b6aeda51c5310db4d Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Thu, 24 Nov 2022 14:54:22 +0200 Subject: [PATCH] Implement drag-and-drop from Assets View to Texture Editor The asset (i.e. image) can now be dragged to the "Source" property of the Texture Editor. Task-number: QDS-8341 Change-Id: I2d30bdf245a8328a864c116c727d3faaaad347cc Reviewed-by: Mahmoud Badri Reviewed-by: Thomas Hartmann --- .../textureeditor/textureeditorcontextobject.cpp | 13 +++++++++++++ .../textureeditor/textureeditorcontextobject.h | 8 ++++++++ .../components/textureeditor/textureeditorview.cpp | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp index 8ccd7b8fad7..d358425a1a3 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp @@ -103,6 +103,19 @@ void TextureEditorContextObject::setMajorVersion(int majorVersion) emit majorVersionChanged(); } +QString TextureEditorContextObject::activeDragSuffix() const +{ + return m_activeDragSuffix; +} + +void TextureEditorContextObject::setActiveDragSuffix(const QString &suffix) +{ + if (m_activeDragSuffix != suffix) { + m_activeDragSuffix = suffix; + emit activeDragSuffixChanged(); + } +} + bool TextureEditorContextObject::hasActiveTimeline() const { return m_hasActiveTimeline; diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h index 2ad65821281..cc479e5092e 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h @@ -42,6 +42,8 @@ class TextureEditorContextObject : public QObject Q_PROPERTY(QQmlPropertyMap *backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged) + Q_PROPERTY(QString activeDragSuffix READ activeDragSuffix NOTIFY activeDragSuffixChanged) + public: TextureEditorContextObject(QQmlContext *context, QObject *parent = nullptr); @@ -95,6 +97,9 @@ public: bool hasSingleModelSelection() const; void setHasSingleModelSelection(bool b); + QString activeDragSuffix() const; + void setActiveDragSuffix(const QString &suffix); + bool hasAliasExport() const { return m_aliasExport; } void setSelectedMaterial(const ModelNode &matNode); @@ -126,6 +131,7 @@ signals: void hasQuick3DImportChanged(); void hasMaterialLibraryChanged(); void hasSingleModelSelectionChanged(); + void activeDragSuffixChanged(); private: QUrl m_specificsUrl; @@ -152,6 +158,8 @@ private: bool m_hasSingleModelSelection = false; ModelNode m_selectedTexture; + + QString m_activeDragSuffix; }; } // QmlDesigner diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp index 37dd6c3ffa9..9384c9baf75 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp @@ -821,10 +821,15 @@ void QmlDesigner::TextureEditorView::highlightSupportedProperties(bool highlight QTC_ASSERT(metaInfo.isValid(), return); for (const QString &propName : propNames) { - if (metaInfo.property(propName.toUtf8()).propertyType().isQtQuick3DTexture()) { // TODO: support dropping to texture source + if (metaInfo.property(propName.toUtf8()).propertyType().isQtQuick3DTexture()) { QObject *propEditorValObj = propMap.value(propName).value(); PropertyEditorValue *propEditorVal = qobject_cast(propEditorValObj); propEditorVal->setHasActiveDrag(highlight); + } else if (metaInfo.property(propName.toUtf8()).propertyType().isUrl()) { + QObject *propEditorValObj = propMap.value(propName).value(); + PropertyEditorValue *propEditorVal = qobject_cast(propEditorValObj); + if (propEditorVal) + propEditorVal->setHasActiveDrag(highlight); } } } @@ -841,6 +846,9 @@ void TextureEditorView::dragStarted(QMimeData *mimeData) return; highlightSupportedProperties(); + + const QString suffix = "*." + assetPath.split('.').last().toLower(); + m_qmlBackEnd->contextObject()->setActiveDragSuffix(suffix); } void TextureEditorView::dragEnded()