forked from qt-creator/qt-creator
QmlDesigner: Drag textures from content library to material browser
Fixes: QDS-8337 Change-Id: Iee42341a18e4acaa0d455aef276df36013ebf21e Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -234,6 +234,22 @@ Item {
|
|||||||
width: root.width
|
width: root.width
|
||||||
caption: qsTr("Textures")
|
caption: qsTr("Textures")
|
||||||
|
|
||||||
|
dropEnabled: true
|
||||||
|
|
||||||
|
onDropEnter: (drag) => {
|
||||||
|
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture"
|
||||||
|
highlight = drag.accepted
|
||||||
|
}
|
||||||
|
|
||||||
|
onDropExit: {
|
||||||
|
highlight = false
|
||||||
|
}
|
||||||
|
|
||||||
|
onDrop: {
|
||||||
|
highlight = false
|
||||||
|
rootView.acceptBundleTextureDrop()
|
||||||
|
}
|
||||||
|
|
||||||
Grid {
|
Grid {
|
||||||
width: scrollView.width
|
width: scrollView.width
|
||||||
leftPadding: 5
|
leftPadding: 5
|
||||||
@@ -290,6 +306,21 @@ Item {
|
|||||||
enabled: root.enableUiElements
|
enabled: root.enableUiElements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DropArea {
|
||||||
|
id: masterDropArea
|
||||||
|
|
||||||
|
property int emptyHeight: scrollView.height - materialsSection.height - texturesSection.height
|
||||||
|
|
||||||
|
width: root.width
|
||||||
|
height: emptyHeight > 0 ? emptyHeight : 0
|
||||||
|
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
onEntered: (drag) => texturesSection.dropEnter(drag)
|
||||||
|
onDropped: (drag) => texturesSection.drop(drag)
|
||||||
|
onExited: texturesSection.dropExit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "contentlibrarywidget.h"
|
#include "contentlibrarywidget.h"
|
||||||
#include "contentlibrarymaterial.h"
|
#include "contentlibrarymaterial.h"
|
||||||
#include "contentlibrarymaterialsmodel.h"
|
#include "contentlibrarymaterialsmodel.h"
|
||||||
|
#include "contentlibrarytexture.h"
|
||||||
#include "contentlibrarytexturesmodel.h"
|
#include "contentlibrarytexturesmodel.h"
|
||||||
#include "modelnodeoperations.h"
|
#include "modelnodeoperations.h"
|
||||||
#include "nodelistproperty.h"
|
#include "nodelistproperty.h"
|
||||||
@@ -49,6 +50,10 @@ WidgetInfo ContentLibraryView::widgetInfo()
|
|||||||
[&] (QmlDesigner::ContentLibraryMaterial *mat) {
|
[&] (QmlDesigner::ContentLibraryMaterial *mat) {
|
||||||
m_draggedBundleMaterial = mat;
|
m_draggedBundleMaterial = mat;
|
||||||
});
|
});
|
||||||
|
connect(m_widget, &ContentLibraryWidget::bundleTextureDragStarted, this,
|
||||||
|
[&] (QmlDesigner::ContentLibraryTexture *tex) {
|
||||||
|
m_draggedBundleTexture = tex;
|
||||||
|
});
|
||||||
connect(m_widget, &ContentLibraryWidget::addTextureRequested, this,
|
connect(m_widget, &ContentLibraryWidget::addTextureRequested, this,
|
||||||
[&] (const QString texPath, ContentLibraryWidget::AddTextureMode mode) {
|
[&] (const QString texPath, ContentLibraryWidget::AddTextureMode mode) {
|
||||||
executeInTransaction("ContentLibraryView::widgetInfo", [&] {
|
executeInTransaction("ContentLibraryView::widgetInfo", [&] {
|
||||||
@@ -237,6 +242,14 @@ void ContentLibraryView::customNotification(const AbstractView *view, const QStr
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_draggedBundleMaterial = nullptr;
|
m_draggedBundleMaterial = nullptr;
|
||||||
|
} else if (identifier == "drop_bundle_texture") {
|
||||||
|
ModelNode matLib = materialLibraryNode();
|
||||||
|
if (!matLib.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_widget->addTexture(m_draggedBundleTexture);
|
||||||
|
|
||||||
|
m_draggedBundleTexture = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class ContentLibraryMaterial;
|
class ContentLibraryMaterial;
|
||||||
|
class ContentLibraryTexture;
|
||||||
class ContentLibraryWidget;
|
class ContentLibraryWidget;
|
||||||
class Model;
|
class Model;
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ private:
|
|||||||
QList<ModelNode> m_bundleMaterialTargets;
|
QList<ModelNode> m_bundleMaterialTargets;
|
||||||
QList<ModelNode> m_selectedModels; // selected 3D model nodes
|
QList<ModelNode> m_selectedModels; // selected 3D model nodes
|
||||||
ContentLibraryMaterial *m_draggedBundleMaterial = nullptr;
|
ContentLibraryMaterial *m_draggedBundleMaterial = nullptr;
|
||||||
|
ContentLibraryTexture *m_draggedBundleTexture = nullptr;
|
||||||
ModelNode m_activeSceneEnv;
|
ModelNode m_activeSceneEnv;
|
||||||
bool m_bundleMaterialAddToSelected = false;
|
bool m_bundleMaterialAddToSelected = false;
|
||||||
bool m_hasQuick3DImport = false;
|
bool m_hasQuick3DImport = false;
|
||||||
|
|||||||
@@ -58,11 +58,6 @@ bool ContentLibraryWidget::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_draggedMaterial) {
|
|
||||||
m_draggedMaterial = m_materialToDrag;
|
|
||||||
emit draggedMaterialChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit bundleMaterialDragStarted(m_materialToDrag);
|
emit bundleMaterialDragStarted(m_materialToDrag);
|
||||||
model->startDrag(mimeData, m_materialToDrag->icon().toLocalFile());
|
model->startDrag(mimeData, m_materialToDrag->icon().toLocalFile());
|
||||||
m_materialToDrag = nullptr;
|
m_materialToDrag = nullptr;
|
||||||
@@ -77,6 +72,7 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
mimeData->setData(Constants::MIME_TYPE_BUNDLE_TEXTURE, data);
|
mimeData->setData(Constants::MIME_TYPE_BUNDLE_TEXTURE, data);
|
||||||
mimeData->removeFormat("text/plain");
|
mimeData->removeFormat("text/plain");
|
||||||
|
|
||||||
|
emit bundleTextureDragStarted(m_textureToDrag);
|
||||||
model->startDrag(mimeData, m_textureToDrag->icon().toLocalFile());
|
model->startDrag(mimeData, m_textureToDrag->icon().toLocalFile());
|
||||||
m_textureToDrag = nullptr;
|
m_textureToDrag = nullptr;
|
||||||
}
|
}
|
||||||
@@ -84,11 +80,6 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
} else if (event->type() == QMouseEvent::MouseButtonRelease) {
|
} else if (event->type() == QMouseEvent::MouseButtonRelease) {
|
||||||
m_materialToDrag = nullptr;
|
m_materialToDrag = nullptr;
|
||||||
m_textureToDrag = nullptr;
|
m_textureToDrag = nullptr;
|
||||||
|
|
||||||
if (m_draggedMaterial) {
|
|
||||||
m_draggedMaterial = nullptr;
|
|
||||||
emit draggedMaterialChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QObject::eventFilter(obj, event);
|
return QObject::eventFilter(obj, event);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void bundleMaterialDragStarted(QmlDesigner::ContentLibraryMaterial *bundleMat);
|
void bundleMaterialDragStarted(QmlDesigner::ContentLibraryMaterial *bundleMat);
|
||||||
void draggedMaterialChanged();
|
void bundleTextureDragStarted(QmlDesigner::ContentLibraryTexture *bundleTex);
|
||||||
void addTextureRequested(const QString texPath, QmlDesigner::ContentLibraryWidget::AddTextureMode mode);
|
void addTextureRequested(const QString texPath, QmlDesigner::ContentLibraryWidget::AddTextureMode mode);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -70,7 +70,6 @@ private:
|
|||||||
QString m_filterText;
|
QString m_filterText;
|
||||||
|
|
||||||
ContentLibraryMaterial *m_materialToDrag = nullptr;
|
ContentLibraryMaterial *m_materialToDrag = nullptr;
|
||||||
ContentLibraryMaterial *m_draggedMaterial = nullptr;
|
|
||||||
ContentLibraryTexture *m_textureToDrag = nullptr;
|
ContentLibraryTexture *m_textureToDrag = nullptr;
|
||||||
QPoint m_dragStartPoint;
|
QPoint m_dragStartPoint;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -257,6 +257,11 @@ void MaterialBrowserWidget::acceptBundleMaterialDrop()
|
|||||||
m_materialBrowserView->emitCustomNotification("drop_bundle_material", {}, {}); // To ContentLibraryView
|
m_materialBrowserView->emitCustomNotification("drop_bundle_material", {}, {}); // To ContentLibraryView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaterialBrowserWidget::acceptBundleTextureDrop()
|
||||||
|
{
|
||||||
|
m_materialBrowserView->emitCustomNotification("drop_bundle_texture", {}, {}); // To ContentLibraryView
|
||||||
|
}
|
||||||
|
|
||||||
QString MaterialBrowserWidget::qmlSourcesPath()
|
QString MaterialBrowserWidget::qmlSourcesPath()
|
||||||
{
|
{
|
||||||
#ifdef SHARE_QML_PATH
|
#ifdef SHARE_QML_PATH
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public:
|
|||||||
Q_INVOKABLE void startDragMaterial(int index, const QPointF &mousePos);
|
Q_INVOKABLE void startDragMaterial(int index, const QPointF &mousePos);
|
||||||
Q_INVOKABLE void startDragTexture(int index, const QPointF &mousePos);
|
Q_INVOKABLE void startDragTexture(int index, const QPointF &mousePos);
|
||||||
Q_INVOKABLE void acceptBundleMaterialDrop();
|
Q_INVOKABLE void acceptBundleMaterialDrop();
|
||||||
|
Q_INVOKABLE void acceptBundleTextureDrop();
|
||||||
|
|
||||||
QQuickWidget *quickWidget() const;
|
QQuickWidget *quickWidget() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user