From 85b4cc88fc0b18022aa55bee335a3b327e9f5d58 Mon Sep 17 00:00:00 2001 From: Shrief Gabr Date: Wed, 18 Sep 2024 16:40:25 +0300 Subject: [PATCH] QmlDesigner: Enable drag & drop in EffectComposer image fields Fixes: QDS-13574 Change-Id: I2c5727f48306140f5d26ea21de51322b833b5c4b Reviewed-by: Marco Bubke Reviewed-by: Miikka Heikkinen Reviewed-by: Mahmoud Badri --- .../effectcomposer/effectcomposerview.cpp | 24 +++++++++++++++++++ .../effectcomposer/effectcomposerview.h | 5 ++++ src/plugins/effectcomposer/uniform.cpp | 8 +++++++ .../propertyeditor/propertyeditorvalue.cpp | 7 +++++- .../propertyeditor/propertyeditorvalue.h | 1 + .../libs/designercore/model/model.cpp | 3 +++ 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/plugins/effectcomposer/effectcomposerview.cpp b/src/plugins/effectcomposer/effectcomposerview.cpp index a9726f55182..76ff57d49d5 100644 --- a/src/plugins/effectcomposer/effectcomposerview.cpp +++ b/src/plugins/effectcomposer/effectcomposerview.cpp @@ -6,6 +6,7 @@ #include "effectcomposermodel.h" #include "effectcomposernodesmodel.h" #include "effectcomposerwidget.h" +#include "studioquickwidget.h" #include #include @@ -234,4 +235,27 @@ void EffectComposerView::removeUnusedEffectImports() } } +void EffectComposerView::highlightSupportedProperties(bool highlight, const QString &suffix) +{ + QQmlContext *ctxObj = m_widget->quickWidget()->rootContext(); + ctxObj->setContextProperty("activeDragSuffix", suffix); + ctxObj->setContextProperty("hasActiveDrag", highlight); +} + +void EffectComposerView::dragStarted(QMimeData *mimeData) +{ + if (mimeData->hasFormat(QmlDesigner::Constants::MIME_TYPE_ASSETS)) { + QString format = mimeData->formats()[0]; + const QString assetPath = QString::fromUtf8(mimeData->data(format)).split(',')[0]; + const QString suffix = "*." + assetPath.split('.').last().toLower(); + + highlightSupportedProperties(true, suffix); + } +} + +void EffectComposerView::dragEnded() +{ + highlightSupportedProperties(false); +} + } // namespace EffectComposer diff --git a/src/plugins/effectcomposer/effectcomposerview.h b/src/plugins/effectcomposer/effectcomposerview.h index b8b130f3de3..338960f1f08 100644 --- a/src/plugins/effectcomposer/effectcomposerview.h +++ b/src/plugins/effectcomposer/effectcomposerview.h @@ -41,6 +41,11 @@ public: const QList &lastSelectedNodeList) override; void nodeAboutToBeRemoved(const QmlDesigner::ModelNode &removedNode) override; + void dragStarted(QMimeData *mimeData) override; + void dragEnded() override; + + void highlightSupportedProperties(bool highlight, const QString &suffix = {}); + private: void customNotification(const AbstractView *view, const QString &identifier, const QList &nodeList, const QList &data) override; diff --git a/src/plugins/effectcomposer/uniform.cpp b/src/plugins/effectcomposer/uniform.cpp index 590b38b423b..c42f11063d6 100644 --- a/src/plugins/effectcomposer/uniform.cpp +++ b/src/plugins/effectcomposer/uniform.cpp @@ -57,6 +57,14 @@ Uniform::Uniform(const QString &effectName, const QJsonObject &propObj, const QS m_backendValue = new QmlDesigner::PropertyEditorValue(this); m_backendValue->setValue(value); + + connect(m_backendValue, &QmlDesigner::PropertyEditorValue::dropCommitted, + this, [this](const QString &dropData) { + m_backendValue->setValue(dropData); + auto *model = QmlDesigner::QmlDesignerPlugin::instance() + ->currentDesignDocument()->currentModel(); + model->endDrag(); + }); } Uniform::Type Uniform::type() const diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index 74c1ba65a60..0d85d3f36bb 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -530,7 +530,12 @@ void PropertyEditorValue::commitDrop(const QString &dropData) }); } - m_modelNode.view()->model()->endDrag(); + emit dropCommitted(dropData); + + if (!m_modelNode.model()) + return; + + m_modelNode.model()->endDrag(); } void PropertyEditorValue::openMaterialEditor(int idx) diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h index 997640d377e..d8cee333cbb 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h @@ -200,6 +200,7 @@ signals: void isValidChanged(); void isExplicitChanged(); void hasActiveDragChanged(); + void dropCommitted(QString dropData); private: QStringList generateStringList(const QString &string) const; diff --git a/src/plugins/qmldesigner/libs/designercore/model/model.cpp b/src/plugins/qmldesigner/libs/designercore/model/model.cpp index cd29f942e18..b100cd678ab 100644 --- a/src/plugins/qmldesigner/libs/designercore/model/model.cpp +++ b/src/plugins/qmldesigner/libs/designercore/model/model.cpp @@ -1948,6 +1948,9 @@ void Model::startDrag(std::unique_ptr mimeData, const QPixmap &icon, void Model::endDrag() { + if (!d->drag) + return; + d->notifyDragEnded(); d->drag.reset(); }