aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2015-11-11 17:00:17 +0100
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2015-12-07 16:56:41 +0000
commit945d1fd3c94febc37fe56af54f2c2facc623c44f (patch)
tree26becf62704238873a47d5c3b3c5e0d06cf1a675 /src
parent35d8d060b8621cfd17f92f9c632d99ceceb9acaa (diff)
QQuickImageBase: Add support for @3x images
Use the qt_findAtNxFile function from QtGui. Note: this changes the behavior slightly if the file name contains '@2x' not at the end of the file name. We now check that it contains '@2x.' including the dot. Change-Id: I7e6a97d2d9c5aa0706538badf22a13e4c41824c0 Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com> Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickimagebase.cpp40
1 files changed, 12 insertions, 28 deletions
diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp
index 073fe58e7b..47952d86bd 100644
--- a/src/quick/items/qquickimagebase.cpp
+++ b/src/quick/items/qquickimagebase.cpp
@@ -36,6 +36,7 @@
#include <QtGui/qguiapplication.h>
#include <QtGui/qscreen.h>
+#include <QtGui/qicon.h>
#include <QtQml/qqmlinfo.h>
#include <QtQml/qqmlfile.h>
@@ -338,20 +339,6 @@ void QQuickImageBase::pixmapChange()
setImplicitSize(d->pix.width() / d->devicePixelRatio, d->pix.height() / d->devicePixelRatio);
}
-// /path/to/foo.png -> path/too/foo@2x.png
-static QString image2xPath(const QString &path)
-{
- const int dotIndex = path.lastIndexOf(QLatin1Char('.'));
- if (dotIndex == -1)
- return path + QLatin1String("@2x");
- if (path.contains(QLatin1String("@2x.")))
- return path;
-
- QString retinaPath = path;
- retinaPath.insert(dotIndex, QStringLiteral("@2x"));
- return retinaPath;
-}
-
void QQuickImageBase::resolve2xLocalFile(const QUrl &url, qreal targetDevicePixelRatio, QUrl *sourceUrl, qreal *sourceDevicePixelRatio)
{
Q_ASSERT(sourceUrl);
@@ -369,23 +356,20 @@ void QQuickImageBase::resolve2xLocalFile(const QUrl &url, qreal targetDevicePixe
return;
// Special case: the url in the QML source refers directly to an "@2x" file.
- if (localFile.contains(QLatin1String("@2x"))) {
- *sourceDevicePixelRatio = qreal(2.0);
- return;
+ int atLocation = localFile.lastIndexOf(QLatin1Char('@'));
+ if (atLocation > 0 && atLocation + 3 < localFile.size()) {
+ if (localFile[atLocation + 1].isDigit()
+ && localFile[atLocation + 2] == QLatin1Char('x')
+ && localFile[atLocation + 3] == QLatin1Char('.')) {
+ *sourceDevicePixelRatio = localFile[atLocation + 1].digitValue();
+ return;
+ }
}
- // Don't load @2x files non normal-dpi displays.
- if (!(targetDevicePixelRatio > qreal(1.0)))
- return;
-
// Look for an @2x version
- QString localFile2x = image2xPath(localFile);
- if (!QFile::exists(localFile2x))
- return;
-
- // @2x file found found: Change url and devicePixelRatio
- *sourceUrl = QUrl::fromLocalFile(localFile2x);
- *sourceDevicePixelRatio = qreal(2.0);
+ QString localFileX = qt_findAtNxFile(localFile, targetDevicePixelRatio, sourceDevicePixelRatio);
+ if (localFileX != localFile)
+ *sourceUrl = QUrl::fromLocalFile(localFileX);
}
bool QQuickImageBase::autoTransform() const