forked from qt-creator/qt-creator
QmlDesigner: Allow dragging image Assets to the Material Browser
When dragging an image from the Assets Library to the Textures section of the Material Browser, now Textures will be created from those assets. Task-number: QDS-8783 Change-Id: Ibbfb8697705a7d1af7714f3a32caff24282ee7a9 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -34,6 +34,9 @@ Item {
|
|||||||
var complexSuffixes = rootView.supportedAssetSuffixes(true)
|
var complexSuffixes = rootView.supportedAssetSuffixes(true)
|
||||||
for (const u of drag.urls) {
|
for (const u of drag.urls) {
|
||||||
var url = u.toString()
|
var url = u.toString()
|
||||||
|
if (assetsModel.urlPathExistsInModel(url))
|
||||||
|
continue;
|
||||||
|
|
||||||
var ext = '*.' + url.slice(url.lastIndexOf('.') + 1).toLowerCase()
|
var ext = '*.' + url.slice(url.lastIndexOf('.') + 1).toLowerCase()
|
||||||
if (simpleSuffixes.includes(ext))
|
if (simpleSuffixes.includes(ext))
|
||||||
root.dropSimpleExtFiles.push(url)
|
root.dropSimpleExtFiles.push(url)
|
||||||
|
@@ -716,6 +716,8 @@ Item {
|
|||||||
|
|
||||||
onDropEnter: (drag) => {
|
onDropEnter: (drag) => {
|
||||||
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture"
|
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture"
|
||||||
|
|| drag.formats[0] === "application/vnd.qtdesignstudio.assets"
|
||||||
|
|
||||||
highlight = drag.accepted
|
highlight = drag.accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,7 +728,10 @@ Item {
|
|||||||
onDrop: (drag) => {
|
onDrop: (drag) => {
|
||||||
drag.accept()
|
drag.accept()
|
||||||
highlight = false
|
highlight = false
|
||||||
rootView.acceptBundleTextureDrop()
|
if (drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture")
|
||||||
|
rootView.acceptBundleTextureDrop()
|
||||||
|
else if (drag.formats[0] === "application/vnd.qtdesignstudio.assets")
|
||||||
|
rootView.acceptAssetsDrop(drag.urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
onExpandedChanged: {
|
onExpandedChanged: {
|
||||||
|
@@ -150,6 +150,12 @@ bool AssetsLibraryModel::addNewFolder(const QString &folderPath)
|
|||||||
return dir.mkpath(iterPath);
|
return dir.mkpath(iterPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AssetsLibraryModel::urlPathExistsInModel(const QUrl &url) const
|
||||||
|
{
|
||||||
|
QModelIndex index = indexForPath(url.toLocalFile());
|
||||||
|
return index.isValid();
|
||||||
|
}
|
||||||
|
|
||||||
bool AssetsLibraryModel::deleteFolderRecursively(const QModelIndex &folderIndex)
|
bool AssetsLibraryModel::deleteFolderRecursively(const QModelIndex &folderIndex)
|
||||||
{
|
{
|
||||||
auto idx = mapToSource(folderIndex);
|
auto idx = mapToSource(folderIndex);
|
||||||
|
@@ -39,6 +39,7 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE QList<QModelIndex> parentIndices(const QModelIndex &index) const;
|
Q_INVOKABLE QList<QModelIndex> parentIndices(const QModelIndex &index) const;
|
||||||
Q_INVOKABLE bool indexIsValid(const QModelIndex &index) const;
|
Q_INVOKABLE bool indexIsValid(const QModelIndex &index) const;
|
||||||
|
Q_INVOKABLE bool urlPathExistsInModel(const QUrl &url) const;
|
||||||
Q_INVOKABLE QString currentProjectDirPath() const;
|
Q_INVOKABLE QString currentProjectDirPath() const;
|
||||||
Q_INVOKABLE QString contentDirPath() const;
|
Q_INVOKABLE QString contentDirPath() const;
|
||||||
Q_INVOKABLE bool requestDeleteFiles(const QStringList &filePaths);
|
Q_INVOKABLE bool requestDeleteFiles(const QStringList &filePaths);
|
||||||
|
@@ -72,8 +72,16 @@ bool AssetsLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
if ((me->globalPos() - m_dragStartPoint).manhattanLength() > 10) {
|
if ((me->globalPos() - m_dragStartPoint).manhattanLength() > 10) {
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
mimeData->setData(Constants::MIME_TYPE_ASSETS, m_assetsToDrag.join(',').toUtf8());
|
mimeData->setData(Constants::MIME_TYPE_ASSETS, m_assetsToDrag.join(',').toUtf8());
|
||||||
m_model->startDrag(mimeData,
|
|
||||||
m_assetsIconProvider->requestPixmap(m_assetsToDrag[0], nullptr, {128, 128}));
|
QList<QUrl> urlsToDrag = Utils::transform(m_assetsToDrag, [](const QString &path) {
|
||||||
|
return QUrl::fromLocalFile(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
mimeData->setUrls(urlsToDrag);
|
||||||
|
|
||||||
|
m_model->startDrag(mimeData, m_assetsIconProvider->requestPixmap(m_assetsToDrag[0],
|
||||||
|
nullptr, {128, 128}));
|
||||||
|
|
||||||
m_assetsToDrag.clear();
|
m_assetsToDrag.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -235,7 +235,7 @@ ModelNodePreviewImageOperation DesignerActionManager::modelNodePreviewOperation(
|
|||||||
|
|
||||||
bool DesignerActionManager::externalDragHasSupportedAssets(const QMimeData *mimeData) const
|
bool DesignerActionManager::externalDragHasSupportedAssets(const QMimeData *mimeData) const
|
||||||
{
|
{
|
||||||
if (!mimeData->hasUrls())
|
if (!mimeData->hasUrls() || mimeData->hasFormat(Constants::MIME_TYPE_ASSETS))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QSet<QString> filtersSet;
|
QSet<QString> filtersSet;
|
||||||
|
@@ -216,6 +216,17 @@ WidgetInfo MaterialBrowserView::widgetInfo()
|
|||||||
tr("Material Browser view"));
|
tr("Material Browser view"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaterialBrowserView::createTextures(const QStringList &assetPaths)
|
||||||
|
{
|
||||||
|
auto *create = new CreateTextures(this, false);
|
||||||
|
|
||||||
|
executeInTransaction("MaterialBrowserView::createTextures", [&]() {
|
||||||
|
create->execute(assetPaths, AddTextureMode::Texture, m_sceneId);
|
||||||
|
});
|
||||||
|
|
||||||
|
create->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
void MaterialBrowserView::modelAttached(Model *model)
|
void MaterialBrowserView::modelAttached(Model *model)
|
||||||
{
|
{
|
||||||
AbstractView::modelAttached(model);
|
AbstractView::modelAttached(model);
|
||||||
|
@@ -55,6 +55,7 @@ public:
|
|||||||
void applyTextureToModel3D(const QmlObjectNode &model3D, const ModelNode &texture = {});
|
void applyTextureToModel3D(const QmlObjectNode &model3D, const ModelNode &texture = {});
|
||||||
void applyTextureToMaterial(const QList<ModelNode> &materials, const ModelNode &texture);
|
void applyTextureToMaterial(const QList<ModelNode> &materials, const ModelNode &texture);
|
||||||
|
|
||||||
|
void createTextures(const QStringList &assetPaths);
|
||||||
|
|
||||||
Q_INVOKABLE void updatePropsModel(const QString &matId);
|
Q_INVOKABLE void updatePropsModel(const QString &matId);
|
||||||
Q_INVOKABLE void applyTextureToProperty(const QString &matId, const QString &propName);
|
Q_INVOKABLE void applyTextureToProperty(const QString &matId, const QString &propName);
|
||||||
|
@@ -278,6 +278,12 @@ void MaterialBrowserWidget::acceptBundleTextureDrop()
|
|||||||
m_materialBrowserView->model()->endDrag();
|
m_materialBrowserView->model()->endDrag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaterialBrowserWidget::acceptAssetsDrop(const QList<QUrl> &urls)
|
||||||
|
{
|
||||||
|
QStringList assetPaths = Utils::transform(urls, [](const QUrl &url) { return url.toLocalFile(); });
|
||||||
|
m_materialBrowserView->createTextures(assetPaths);
|
||||||
|
}
|
||||||
|
|
||||||
void MaterialBrowserWidget::acceptTextureDropOnMaterial(int matIndex, const QString &texId)
|
void MaterialBrowserWidget::acceptTextureDropOnMaterial(int matIndex, const QString &texId)
|
||||||
{
|
{
|
||||||
ModelNode mat = m_materialBrowserModel->materialAt(matIndex);
|
ModelNode mat = m_materialBrowserModel->materialAt(matIndex);
|
||||||
|
@@ -59,6 +59,7 @@ public:
|
|||||||
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();
|
Q_INVOKABLE void acceptBundleTextureDrop();
|
||||||
|
Q_INVOKABLE void acceptAssetsDrop(const QList<QUrl> &urls);
|
||||||
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
|
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
|
||||||
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
|
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user