Add opt-out environment variable for @2x images

There are cases where @2x images are in use but
where you don't want the associated behavior:
- You are implementing an image editor
- You are inheriting a resource set which has @2x
  images, but don't want that behavior with Qt.

Add support for disabling @2x behavior with QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING.

Change-Id: I206e050b6241f8935b4404c7a28b024a9e00d46c
Task-id: QTBUG-38485
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Morten Johan Sørvig 2014-05-19 22:56:13 +02:00
parent 19d289ab1b
commit 5f3ec26d90
2 changed files with 5 additions and 3 deletions

View File

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

View File

@ -1247,7 +1247,8 @@ bool QImageReader::read(QImage *image)
}
// successful read; check for "@2x" file name suffix and set device pixel ratio.
if (QFileInfo(fileName()).baseName().endsWith(QLatin1String("@2x"))) {
static bool disable2xImageLoading = !qgetenv("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING").isEmpty();
if (!disable2xImageLoading && QFileInfo(fileName()).baseName().endsWith(QLatin1String("@2x"))) {
image->setDevicePixelRatio(2.0);
}