QIcon: Fix that HiDPI image was not found with QRC alias

When using images in QRC and giving the 1x and 2x image files
respective aliases but without any file extension
(for example 'myimage' and 'myimage@2x'),
then QIcon would fail to find the 2x variant.

Task-number: QTBUG-44049
Change-Id: I400bf6d22aeefe0aa351c68e473bf24ac2a36471
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
This commit is contained in:
Eike Ziller 2015-01-26 16:22:48 +01:00
parent 6246e142a4
commit 4805714b0f

View File

@ -1026,13 +1026,13 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State
// Check if a "@2x" file exists and add it. // Check if a "@2x" file exists and add it.
static bool disable2xImageLoading = !qgetenv("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING").isEmpty(); static bool disable2xImageLoading = !qgetenv("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING").isEmpty();
if (!disable2xImageLoading && qApp->devicePixelRatio() > 1.0) { if (!disable2xImageLoading && qApp->devicePixelRatio() > 1.0) {
QString at2xfileName = fileName;
int dotIndex = fileName.lastIndexOf(QLatin1Char('.')); int dotIndex = fileName.lastIndexOf(QLatin1Char('.'));
if (dotIndex != -1) { if (dotIndex == -1) /* no dot */
QString at2xfileName = fileName; dotIndex = fileName.size(); /* append */
at2xfileName.insert(dotIndex, QStringLiteral("@2x")); at2xfileName.insert(dotIndex, QStringLiteral("@2x"));
if (QFile::exists(at2xfileName)) if (QFile::exists(at2xfileName))
d->engine->addFile(at2xfileName, size, mode, state); d->engine->addFile(at2xfileName, size, mode, state);
}
} }
} }