From f6155937a023ddcaa632440d0c4666845d3db9bc Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Tue, 21 Feb 2023 14:04:33 +0200 Subject: [PATCH] QmlDesigner: Fix textures added as image or dragged using the icons Instead of using the paths to the real, downloaded textures, the paths of the icons (thumbnails) were being used. (cherry picked from commit e831c9e7133b280fefa52374010623c513de8e9f) Task-number: QDS-9228 Change-Id: I828b765c4f86502403b84fdf18532d1353d3a62c Reviewed-by: Thomas Hartmann Reviewed-by: Samuel Ghinet --- .../contentlibrary/contentlibrarytexture.cpp | 9 ++++++-- .../contentlibrary/contentlibrarytexture.h | 3 ++- .../contentlibrary/contentlibrarywidget.cpp | 22 ++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp index e0227203ba8..1f9cbe2ceda 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp @@ -39,7 +39,7 @@ QUrl ContentLibraryTexture::icon() const return m_icon; } -QString ContentLibraryTexture::path() const +QString ContentLibraryTexture::iconPath() const { return m_iconPath; } @@ -86,10 +86,15 @@ bool ContentLibraryTexture::isDownloaded() const if (m_fileExt.isEmpty()) return false; - QString fullPath = m_downloadPath + "/" + m_baseName + m_fileExt; + QString fullPath = realTexturePath(); return QFileInfo(fullPath).isFile(); } +QString ContentLibraryTexture::realTexturePath() const +{ + return m_downloadPath + "/" + m_baseName + m_fileExt; +} + void ContentLibraryTexture::setDownloaded() { m_fileExt = resolveFileExt(); diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h index 54b90ba6d88..383aed750bc 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h @@ -30,7 +30,8 @@ public: bool filter(const QString &searchText); QUrl icon() const; - QString path() const; + QString iconPath() const; + QString realTexturePath() const; QString parentDirPath() const; signals: diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp index c85194ffcf6..658ae784f7b 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp @@ -65,12 +65,13 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event) } } else if (m_textureToDrag) { QMouseEvent *me = static_cast(event); - if ((me->globalPos() - m_dragStartPoint).manhattanLength() > 20) { + if ((me->globalPos() - m_dragStartPoint).manhattanLength() > 20 + && m_textureToDrag->isDownloaded()) { QMimeData *mimeData = new QMimeData; - mimeData->setData(Constants::MIME_TYPE_BUNDLE_TEXTURE, {m_textureToDrag->path().toUtf8()}); + mimeData->setData(Constants::MIME_TYPE_BUNDLE_TEXTURE, {m_textureToDrag->iconPath().toUtf8()}); // Allows standard file drag-n-drop. As of now needed to drop on Assets view - mimeData->setUrls({QUrl::fromLocalFile(m_textureToDrag->path())}); + mimeData->setUrls({QUrl::fromLocalFile(m_textureToDrag->realTexturePath())}); emit bundleTextureDragStarted(m_textureToDrag); model->startDrag(mimeData, m_textureToDrag->icon().toLocalFile()); @@ -261,17 +262,26 @@ void ContentLibraryWidget::startDragTexture(QmlDesigner::ContentLibraryTexture * void ContentLibraryWidget::addImage(ContentLibraryTexture *tex) { - emit addTextureRequested(tex->path(), AddTextureMode::Image); + if (!tex->isDownloaded()) + return; + + emit addTextureRequested(tex->realTexturePath(), AddTextureMode::Image); } void ContentLibraryWidget::addTexture(ContentLibraryTexture *tex) { - emit addTextureRequested(tex->path(), AddTextureMode::Texture); + if (!tex->isDownloaded()) + return; + + emit addTextureRequested(tex->realTexturePath(), AddTextureMode::Texture); } void ContentLibraryWidget::addLightProbe(ContentLibraryTexture *tex) { - emit addTextureRequested(tex->path(), AddTextureMode::LightProbe); + if (!tex->isDownloaded()) + return; + + emit addTextureRequested(tex->realTexturePath(), AddTextureMode::LightProbe); } void ContentLibraryWidget::updateSceneEnvState()