From 04ebd8e56f0a5b07fe419548b0ecc8b7845ce49c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 7 Mar 2013 13:10:49 +0100 Subject: Load "@2x" images on high-dpi "retina" systems. Check for the existence of a "@2x" file when adding an image to QIcon. For example, adding "foo.png" will also add "foo@2x.png" if that file exists. Change-Id: If32a3446cf56ca0828de17f6a361091e4c874f26 Reviewed-by: Gabriel de Dietrich --- src/gui/image/qicon.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/gui/image/qicon.cpp') diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 683fe51d2b..d73cd0aa57 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -958,6 +958,17 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State detach(); } d->engine->addFile(fileName, size, mode, state); + + // Check if a "@2x" file exists and add it. + if (qApp->devicePixelRatio() > 1.0) { + int dotIndex = fileName.lastIndexOf(QLatin1Char('.')); + if (dotIndex != -1) { + QString at2xfileName = fileName; + at2xfileName.insert(dotIndex, QStringLiteral("@2x")); + if (QFile::exists(at2xfileName)) + d->engine->addFile(at2xfileName, size, mode, state); + } + } } /*! -- cgit v1.2.3