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 <mahmoud.badri@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Samuel Ghinet
2022-11-24 14:54:22 +02:00
parent 3321261cf3
commit 45c7a6b8e6
3 changed files with 30 additions and 1 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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<QObject *>();
PropertyEditorValue *propEditorVal = qobject_cast<PropertyEditorValue *>(propEditorValObj);
propEditorVal->setHasActiveDrag(highlight);
} else if (metaInfo.property(propName.toUtf8()).propertyType().isUrl()) {
QObject *propEditorValObj = propMap.value(propName).value<QObject *>();
PropertyEditorValue *propEditorVal = qobject_cast<PropertyEditorValue *>(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()