From b7df5571e0707f53716fa51d426d5ec31d36af43 Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Fri, 11 Dec 2020 14:45:12 +0200 Subject: Add high dpi image support for Logo and ProductImages Task-number: QTIFW-2061 Task-number: QTIFW-2060 Change-Id: Idaabb6a08f5e52aa7808de4b3ad541ae47dc4dd8 Reviewed-by: Arttu Tarkiainen --- src/libs/ifwtools/binarycreator.cpp | 1 - src/libs/installer/constants.h | 1 + src/libs/installer/fileutils.cpp | 17 +++++++++++++++++ src/libs/installer/fileutils.h | 1 + src/libs/installer/packagemanagergui.cpp | 5 ++++- src/libs/installer/settings.cpp | 11 +++++++---- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/libs/ifwtools/binarycreator.cpp b/src/libs/ifwtools/binarycreator.cpp index e8d1c3cd4..8fcc14ca3 100644 --- a/src/libs/ifwtools/binarycreator.cpp +++ b/src/libs/ifwtools/binarycreator.cpp @@ -60,7 +60,6 @@ using namespace QInstaller; using namespace QInstallerTools; -static const QLatin1String scHighDpi("@2x."); #ifndef Q_OS_WIN static void chmod755(const QString &absolutFilePath) diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h index 35fcb9c89..711aaa66b 100644 --- a/src/libs/installer/constants.h +++ b/src/libs/installer/constants.h @@ -98,6 +98,7 @@ static const QLatin1String scSupportsModify("SupportsModify"); static const QLatin1String scAllowUnstableComponents("AllowUnstableComponents"); static const QLatin1String scSaveDefaultRepositories("SaveDefaultRepositories"); static const QLatin1String scRepositoryCategoryDisplayName("RepositoryCategoryDisplayName"); +static const QLatin1String scHighDpi("@2x."); const char scRelocatable[] = "@RELOCATABLE_PATH@"; } diff --git a/src/libs/installer/fileutils.cpp b/src/libs/installer/fileutils.cpp index 76e5e3cd8..273901267 100644 --- a/src/libs/installer/fileutils.cpp +++ b/src/libs/installer/fileutils.cpp @@ -28,6 +28,7 @@ #include "fileutils.h" #include "globals.h" +#include "constants.h" #include #include @@ -40,6 +41,8 @@ #include #include #include +#include +#include #include @@ -707,3 +710,17 @@ QString QInstaller::replacePath(const QString &path, const QString &before, cons return QDir::cleanPath(after) + pathToPatch.mid(pathToReplace.size()); return path; } + +/*! + Replaces \a imagePath with high dpi image. If high dpi image is not provided or + high dpi screen is not in use, the original value is returned. +*/ +void QInstaller::replaceHighDpiImage(QString &imagePath) +{ + if (QGuiApplication::primaryScreen()->devicePixelRatio() >= 2 ) { + QFileInfo fi(imagePath); + QString highdpiPixmap = fi.absolutePath() + QLatin1Char('/') + fi.baseName() + scHighDpi + fi.suffix(); + if (QFileInfo::exists(highdpiPixmap)) + imagePath = highdpiPixmap; + } +} diff --git a/src/libs/installer/fileutils.h b/src/libs/installer/fileutils.h index 78241d3ce..101a6a1cc 100644 --- a/src/libs/installer/fileutils.h +++ b/src/libs/installer/fileutils.h @@ -92,6 +92,7 @@ private: bool INSTALLER_EXPORT isInBundle(const QString &path, QString *bundlePath = 0); QString replacePath(const QString &path, const QString &pathBefore, const QString &pathAfter); + void replaceHighDpiImage(QString &imagePath); #ifdef Q_OS_WIN QString INSTALLER_EXPORT getLongPathName(const QString &name); diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp index 339079b10..4a454e781 100644 --- a/src/libs/installer/packagemanagergui.cpp +++ b/src/libs/installer/packagemanagergui.cpp @@ -1238,10 +1238,13 @@ QPixmap PackageManagerPage::bannerPixmap() const /*! Returns the logo pixmap specified in the \c element of the package information file. + If @2x image is provided, returns that instead for high DPI displays. */ QPixmap PackageManagerPage::logoPixmap() const { - return QPixmap(m_core->value(QLatin1String("LogoPixmap"))); + QString logoPixmap = m_core->value(QLatin1String("LogoPixmap")); + QInstaller::replaceHighDpiImage(logoPixmap); + return QPixmap(logoPixmap); } /*! diff --git a/src/libs/installer/settings.cpp b/src/libs/installer/settings.cpp index aeacf7a8e..8b921213b 100644 --- a/src/libs/installer/settings.cpp +++ b/src/libs/installer/settings.cpp @@ -32,6 +32,7 @@ #include "repository.h" #include "repositorycategory.h" #include "globals.h" +#include "fileutils.h" #include #include @@ -497,10 +498,12 @@ QStringList Settings::productImages() const const QVariant variant = d->m_data.value(scProductImages); QStringList imagePaths; if (variant.canConvert()) { - foreach (const QString &imagePath, variant.value()) { - QFileInfo(imagePath).isAbsolute() - ? imagePaths.append(imagePath) - : imagePaths.append(d->m_data.value(scPrefix).toString() + QLatin1Char('/') + imagePath); + foreach (auto image, variant.value()) { + QString imagePath = QFileInfo(image).isAbsolute() + ? image + : d->m_data.value(scPrefix).toString() + QLatin1Char('/') + image; + QInstaller::replaceHighDpiImage(imagePath); + imagePaths.append(imagePath); } } return imagePaths; -- cgit v1.2.3