Load "@2x" images on high-dpi "retina" systems.
authorMorten Johan Sørvig <morten.sorvig@digia.com>
Tue, 5 Mar 2013 07:55:34 +0000 (08:55 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 5 Mar 2013 08:31:09 +0000 (09:31 +0100)
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 <jens.bache-wiig@digia.com>

src/quick/util/qquickpixmapcache.cpp

index 0033be8..d5ef4b7 100644 (file)
@@ -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;