forked from qt-creator/qt-creator
QmlDesigner: Implement dragging a bundle texture to a material
Fixes: QDS-9375 Change-Id: Id73e54341e12ec023bb0b55ddffdb7f6b89e2267 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -48,6 +48,7 @@ Rectangle {
|
||||
|
||||
onEntered: (drag) => {
|
||||
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.texture"
|
||||
|| drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture"
|
||||
|| (drag.formats[0] === "application/vnd.qtdesignstudio.assets"
|
||||
&& rootView.hasAcceptableAssets(drag.urls))
|
||||
}
|
||||
@@ -57,6 +58,8 @@ Rectangle {
|
||||
|
||||
if (drag.formats[0] === "application/vnd.qtdesignstudio.texture")
|
||||
rootView.acceptTextureDropOnMaterial(index, drag.getDataAsString(drag.keys[0]))
|
||||
else if (drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture")
|
||||
rootView.acceptBundleTextureDropOnMaterial(index, drag.urls[0])
|
||||
else if (drag.formats[0] === "application/vnd.qtdesignstudio.assets")
|
||||
rootView.acceptAssetsDropOnMaterial(index, drag.urls)
|
||||
}
|
||||
|
@@ -288,6 +288,24 @@ void MaterialBrowserWidget::acceptBundleTextureDrop()
|
||||
m_materialBrowserView->model()->endDrag();
|
||||
}
|
||||
|
||||
void MaterialBrowserWidget::acceptBundleTextureDropOnMaterial(int matIndex, const QUrl &bundleTexPath)
|
||||
{
|
||||
ModelNode mat = m_materialBrowserModel->materialAt(matIndex);
|
||||
QTC_ASSERT(mat.isValid(), return);
|
||||
|
||||
auto *creator = new CreateTexture(m_materialBrowserView, true);
|
||||
|
||||
m_materialBrowserView->executeInTransaction(__FUNCTION__, [&] {
|
||||
ModelNode tex = creator->execute(bundleTexPath.toLocalFile());
|
||||
QTC_ASSERT(tex.isValid(), return);
|
||||
|
||||
m_materialBrowserModel->selectMaterial(matIndex);
|
||||
m_materialBrowserView->applyTextureToMaterial({mat}, tex);
|
||||
});
|
||||
|
||||
creator->deleteLater();
|
||||
}
|
||||
|
||||
void MaterialBrowserWidget::acceptAssetsDrop(const QList<QUrl> &urls)
|
||||
{
|
||||
QStringList assetPaths = Utils::transform(urls, [](const QUrl &url) { return url.toLocalFile(); });
|
||||
|
@@ -60,6 +60,7 @@ public:
|
||||
Q_INVOKABLE void acceptBundleMaterialDrop();
|
||||
Q_INVOKABLE bool hasAcceptableAssets(const QList<QUrl> &urls);
|
||||
Q_INVOKABLE void acceptBundleTextureDrop();
|
||||
Q_INVOKABLE void acceptBundleTextureDropOnMaterial(int matIndex, const QUrl &bundleTexPath);
|
||||
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);
|
||||
|
Reference in New Issue
Block a user