forked from qt-creator/qt-creator
QmlDesigner: Allow drag-n-drop a bundle material to materials section
Fixes: QDS-8041 Change-Id: I848f636f41c58e11c719517f4073243a76e293b6 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -187,6 +187,21 @@ Item {
|
|||||||
width: root.width
|
width: root.width
|
||||||
caption: qsTr("Materials")
|
caption: qsTr("Materials")
|
||||||
hideHeader: !materialBrowserBundleModel.matBundleExists
|
hideHeader: !materialBrowserBundleModel.matBundleExists
|
||||||
|
dropEnabled: true
|
||||||
|
|
||||||
|
onDropEnter: (drag) => {
|
||||||
|
drag.accepted = rootView.draggedBundleMaterial
|
||||||
|
userMaterialsSection.highlight = rootView.draggedBundleMaterial
|
||||||
|
}
|
||||||
|
|
||||||
|
onDropExit: {
|
||||||
|
userMaterialsSection.highlight = false
|
||||||
|
}
|
||||||
|
|
||||||
|
onDrop: {
|
||||||
|
userMaterialsSection.highlight = false
|
||||||
|
materialBrowserBundleModel.addToProject(rootView.draggedBundleMaterial)
|
||||||
|
}
|
||||||
|
|
||||||
Grid {
|
Grid {
|
||||||
id: grid
|
id: grid
|
||||||
|
@@ -139,14 +139,24 @@ bool MaterialBrowserWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
mimeData->setData(Constants::MIME_TYPE_BUNDLE_MATERIAL, data);
|
mimeData->setData(Constants::MIME_TYPE_BUNDLE_MATERIAL, data);
|
||||||
mimeData->removeFormat("text/plain");
|
mimeData->removeFormat("text/plain");
|
||||||
|
|
||||||
|
if (!m_draggedBundleMaterial) {
|
||||||
|
m_draggedBundleMaterial = m_bundleMaterialToDrag;
|
||||||
|
emit draggedBundleMaterialChanged();
|
||||||
|
}
|
||||||
|
|
||||||
emit bundleMaterialDragStarted(m_bundleMaterialToDrag);
|
emit bundleMaterialDragStarted(m_bundleMaterialToDrag);
|
||||||
model->startDrag(mimeData, m_bundleMaterialToDrag->icon().toLocalFile());
|
model->startDrag(mimeData, m_bundleMaterialToDrag->icon().toLocalFile());
|
||||||
m_bundleMaterialToDrag = {};
|
m_bundleMaterialToDrag = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event->type() == QMouseEvent::MouseButtonRelease) {
|
} else if (event->type() == QMouseEvent::MouseButtonRelease) {
|
||||||
m_materialToDrag = {};
|
m_materialToDrag = {};
|
||||||
m_bundleMaterialToDrag = {};
|
m_bundleMaterialToDrag = nullptr;
|
||||||
|
|
||||||
|
if (m_draggedBundleMaterial) {
|
||||||
|
m_draggedBundleMaterial = nullptr;
|
||||||
|
emit draggedBundleMaterialChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QObject::eventFilter(obj, event);
|
return QObject::eventFilter(obj, event);
|
||||||
|
@@ -58,6 +58,7 @@ class PreviewImageProvider;
|
|||||||
class MaterialBrowserWidget : public QFrame
|
class MaterialBrowserWidget : public QFrame
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(BundleMaterial *draggedBundleMaterial MEMBER m_draggedBundleMaterial NOTIFY draggedBundleMaterialChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MaterialBrowserWidget(MaterialBrowserView *view);
|
MaterialBrowserWidget(MaterialBrowserView *view);
|
||||||
@@ -81,6 +82,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void bundleMaterialDragStarted(QmlDesigner::BundleMaterial *bundleMat);
|
void bundleMaterialDragStarted(QmlDesigner::BundleMaterial *bundleMat);
|
||||||
|
void draggedBundleMaterialChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
@@ -102,6 +104,7 @@ private:
|
|||||||
|
|
||||||
ModelNode m_materialToDrag;
|
ModelNode m_materialToDrag;
|
||||||
BundleMaterial *m_bundleMaterialToDrag = nullptr;
|
BundleMaterial *m_bundleMaterialToDrag = nullptr;
|
||||||
|
BundleMaterial *m_draggedBundleMaterial = nullptr;
|
||||||
QPoint m_dragStartPoint;
|
QPoint m_dragStartPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user