From: Morten Johan Sørvig Date: Tue, 5 Mar 2013 07:55:34 +0000 (+0100) Subject: Load "@2x" images on high-dpi "retina" systems. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=707bbe5dea9d7398b205124a54422f2fafb6f151;p=konrad%2Fqtdeclarative.git Load "@2x" images on high-dpi "retina" systems. Check for the existence of a "@2x" file when loading an image from a local file url. For example, Image { source = "foo.png" } will load "foo@2x.png" if that file exists. Change-Id: I37688d035bc9eb412d54be0eb758dd52ebfa5d90 Reviewed-by: Jens Bache-Wiig --- diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 0033be8..d5ef4b7 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -1020,6 +1020,17 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q if (localFile.isEmpty()) return 0; + // check for "retina" high-dpi and use @2x file if it exixts + if (qApp->devicePixelRatio() > 1) { + int dotIndex = localFile.lastIndexOf(QStringLiteral(".")); + if (dotIndex != -1) { + QString retinaFile = localFile; + retinaFile.insert(dotIndex, "@2x"); + if (QFile(retinaFile).exists()) + localFile = retinaFile; + } + } + QFile f(localFile); QSize readSize; QString errorString;