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
|
||||
caption: qsTr("Materials")
|
||||
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 {
|
||||
id: grid
|
||||
|
@@ -139,14 +139,24 @@ bool MaterialBrowserWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
mimeData->setData(Constants::MIME_TYPE_BUNDLE_MATERIAL, data);
|
||||
mimeData->removeFormat("text/plain");
|
||||
|
||||
if (!m_draggedBundleMaterial) {
|
||||
m_draggedBundleMaterial = m_bundleMaterialToDrag;
|
||||
emit draggedBundleMaterialChanged();
|
||||
}
|
||||
|
||||
emit bundleMaterialDragStarted(m_bundleMaterialToDrag);
|
||||
model->startDrag(mimeData, m_bundleMaterialToDrag->icon().toLocalFile());
|
||||
m_bundleMaterialToDrag = {};
|
||||
m_bundleMaterialToDrag = nullptr;
|
||||
}
|
||||
}
|
||||
} else if (event->type() == QMouseEvent::MouseButtonRelease) {
|
||||
m_materialToDrag = {};
|
||||
m_bundleMaterialToDrag = {};
|
||||
m_bundleMaterialToDrag = nullptr;
|
||||
|
||||
if (m_draggedBundleMaterial) {
|
||||
m_draggedBundleMaterial = nullptr;
|
||||
emit draggedBundleMaterialChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
|
@@ -58,6 +58,7 @@ class PreviewImageProvider;
|
||||
class MaterialBrowserWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(BundleMaterial *draggedBundleMaterial MEMBER m_draggedBundleMaterial NOTIFY draggedBundleMaterialChanged)
|
||||
|
||||
public:
|
||||
MaterialBrowserWidget(MaterialBrowserView *view);
|
||||
@@ -81,6 +82,7 @@ public:
|
||||
|
||||
signals:
|
||||
void bundleMaterialDragStarted(QmlDesigner::BundleMaterial *bundleMat);
|
||||
void draggedBundleMaterialChanged();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
@@ -102,6 +104,7 @@ private:
|
||||
|
||||
ModelNode m_materialToDrag;
|
||||
BundleMaterial *m_bundleMaterialToDrag = nullptr;
|
||||
BundleMaterial *m_draggedBundleMaterial = nullptr;
|
||||
QPoint m_dragStartPoint;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user