forked from qt-creator/qt-creator
QmlDesigner: Implement dragging an image to a material
Fixes: QDS-9269 Change-Id: Ia71d87773e6acce6659a30985d77d848feea0a89 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -48,11 +48,17 @@ Rectangle {
|
||||
|
||||
onEntered: (drag) => {
|
||||
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.texture"
|
||||
|| (drag.formats[0] === "application/vnd.qtdesignstudio.assets"
|
||||
&& rootView.hasAcceptableAssets(drag.urls))
|
||||
}
|
||||
|
||||
onDropped: (drag) => {
|
||||
drag.accept()
|
||||
|
||||
if (drag.formats[0] === "application/vnd.qtdesignstudio.texture")
|
||||
rootView.acceptTextureDropOnMaterial(index, drag.getDataAsString(drag.keys[0]))
|
||||
else if (drag.formats[0] === "application/vnd.qtdesignstudio.assets")
|
||||
rootView.acceptAssetsDropOnMaterial(index, drag.urls)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ class CreateTexture : public QObject
|
||||
|
||||
public:
|
||||
CreateTexture(AbstractView *view, bool importFiles = false);
|
||||
ModelNode execute(const QString &filePath, AddTextureMode mode, int sceneId = -1);
|
||||
ModelNode execute(const QString &filePath, AddTextureMode mode = AddTextureMode::Texture, int sceneId = -1);
|
||||
ModelNode resolveSceneEnv(int sceneId);
|
||||
void assignTextureAsLightProbe(const ModelNode &texture, int sceneId);
|
||||
|
||||
|
@@ -221,7 +221,7 @@ WidgetInfo MaterialBrowserView::widgetInfo()
|
||||
|
||||
void MaterialBrowserView::createTextures(const QStringList &assetPaths)
|
||||
{
|
||||
auto *create = new CreateTextures(this, false);
|
||||
auto *create = new CreateTextures(this);
|
||||
|
||||
executeInTransaction("MaterialBrowserView::createTextures", [&]() {
|
||||
create->execute(assetPaths, AddTextureMode::Texture, m_sceneId);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "materialbrowserwidget.h"
|
||||
|
||||
#include "createtexture.h"
|
||||
#include "materialbrowsermodel.h"
|
||||
#include "materialbrowsertexturesmodel.h"
|
||||
#include "materialbrowserview.h"
|
||||
@@ -295,6 +296,28 @@ void MaterialBrowserWidget::acceptAssetsDrop(const QList<QUrl> &urls)
|
||||
m_materialBrowserView->model()->endDrag();
|
||||
}
|
||||
|
||||
void MaterialBrowserWidget::acceptAssetsDropOnMaterial(int matIndex, const QList<QUrl> &urls)
|
||||
{
|
||||
ModelNode mat = m_materialBrowserModel->materialAt(matIndex);
|
||||
QTC_ASSERT(mat.isValid(), return);
|
||||
|
||||
auto *creator = new CreateTexture(m_materialBrowserView);
|
||||
|
||||
QString imageSrc = Utils::findOrDefault(urls, [] (const QUrl &url) {
|
||||
return Asset(url.toLocalFile()).isValidTextureSource();
|
||||
}).toLocalFile();
|
||||
|
||||
m_materialBrowserView->executeInTransaction(__FUNCTION__, [&] {
|
||||
ModelNode tex = creator->execute(imageSrc);
|
||||
QTC_ASSERT(tex.isValid(), return);
|
||||
|
||||
m_materialBrowserModel->selectMaterial(matIndex);
|
||||
m_materialBrowserView->applyTextureToMaterial({mat}, tex);
|
||||
});
|
||||
|
||||
creator->deleteLater();
|
||||
}
|
||||
|
||||
void MaterialBrowserWidget::acceptTextureDropOnMaterial(int matIndex, const QString &texId)
|
||||
{
|
||||
ModelNode mat = m_materialBrowserModel->materialAt(matIndex);
|
||||
|
@@ -61,6 +61,7 @@ public:
|
||||
Q_INVOKABLE bool hasAcceptableAssets(const QList<QUrl> &urls);
|
||||
Q_INVOKABLE void acceptBundleTextureDrop();
|
||||
Q_INVOKABLE void acceptAssetsDrop(const QList<QUrl> &urls);
|
||||
Q_INVOKABLE void acceptAssetsDropOnMaterial(int matIndex, const QList<QUrl> &urls);
|
||||
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
|
||||
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
|
||||
|
||||
|
Reference in New Issue
Block a user