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.

Task-number: QDS-9228
Change-Id: I828b765c4f86502403b84fdf18532d1353d3a62c
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Samuel Ghinet
2023-02-21 14:04:33 +02:00
parent 0e8dcb8862
commit e831c9e713
3 changed files with 25 additions and 9 deletions

View File

@@ -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();

View File

@@ -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:

View File

@@ -65,12 +65,13 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event)
}
} else if (m_textureToDrag) {
QMouseEvent *me = static_cast<QMouseEvent *>(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()