diff options
author | Alessandro Portale <alessandro.portale@digia.com> | 2014-07-09 13:20:53 +0200 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@digia.com> | 2014-07-10 00:03:39 +0200 |
commit | c5687da7523fe81e2fc5d4bfb57638a95e41b883 (patch) | |
tree | dad9543747c7b2473fdf6d58e00b7f03bbbb64e0 /src/libs/utils/stylehelper.cpp | |
parent | ece0c7c93747587131d6252b1a705b92470c09e5 (diff) |
Utils: Helper function for dpi aware pixmap loading
QIcon can load a @2x variant of an image in case it exists and
in case the devicePixelRatio is 2. In Qt Creator, we need the same
functionality for loading QPixmaps. This patch adds the helper
function.
Change-Id: I8e50d1dabb7c8dce1347c8e0a0ce611ec102f9d3
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/libs/utils/stylehelper.cpp')
-rw-r--r-- | src/libs/utils/stylehelper.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libs/utils/stylehelper.cpp b/src/libs/utils/stylehelper.cpp index 9bb00b1b4e8..4513f9117cc 100644 --- a/src/libs/utils/stylehelper.cpp +++ b/src/libs/utils/stylehelper.cpp @@ -34,6 +34,7 @@ #include <QPixmapCache> #include <QPainter> #include <QApplication> +#include <QFileInfo> #include <QStyleOption> #include <qmath.h> @@ -537,4 +538,25 @@ QLinearGradient StyleHelper::statusBarGradient(const QRect &statusBarRect) return grad; } +QPixmap StyleHelper::dpiSpecificPixmap(const QString &fileName) +{ + QString pixmapFileName = fileName; + qreal pixmapDevicePixelRatio = 1.0; + + // See QIcon::addFile() + if (qApp->devicePixelRatio() > 1.0) { + const QFileInfo fi(fileName); + const QString at2xfileName = fi.path() + QLatin1Char('/') + + fi.completeBaseName() + QStringLiteral("@2x.") + fi.suffix(); + if (QFileInfo::exists(at2xfileName)) { + pixmapFileName = at2xfileName; + pixmapDevicePixelRatio = 2.0; + } + } + + QPixmap result(pixmapFileName); + result.setDevicePixelRatio(pixmapDevicePixelRatio); + return result; +} + } // namespace Utils |