summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2017-06-14 10:58:38 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-06-24 21:24:53 +0000
commit8dd8acf8bbfde548756ccde52cb14c848f2d8739 (patch)
treea9941d71d6439b14541f28cd0bc93bdc7f1cadb9
parentd9206926d88b779495cc32c3cfec6bcc53021546 (diff)
qt_findAtNxFile(): account for .9 (9-patch image) extensions
Currently a file with a .9.png extension will only have its @2x variant found if it follows this format: foo.9@2x.png Since ".9" should be considered part of the file suffix, it should ideally be able to look like this and still be picked up: foo@2x.9.png This patch makes qt_findAtNxFile() account for .9.* extensions. This is needed for the image-based style support in Qt Quick Controls 2, which uses 9-patch images. qmlbench benchmark results using benchmarks\auto\creation\quick.image\delegates_image.qml with QT_SCALE_FACTOR=2 show no difference in performance after this patch is applied. [ChangeLog][QtGui] High DPI variants of 9-patch images can now be loaded using the following syntax: "foo@2x.9.png" Change-Id: I6d1384113bef21b4fe85a104ee6b16869c93b077 Reviewed-by: J-P Nurmi <jpnurmi@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--src/gui/image/qicon.cpp7
-rw-r--r--tests/auto/gui/image/qiconhighdpi/icons/misc/button.9.pngbin0 -> 329 bytes
-rw-r--r--tests/auto/gui/image/qiconhighdpi/icons/misc/button@2x.9.pngbin0 -> 616 bytes
-rw-r--r--tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp19
-rw-r--r--tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.qrc2
5 files changed, 27 insertions, 1 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index fa4b4e01af..9b2e96d4b0 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -1469,8 +1469,13 @@ QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRati
return baseFileName;
int dotIndex = baseFileName.lastIndexOf(QLatin1Char('.'));
- if (dotIndex == -1) /* no dot */
+ if (dotIndex == -1) { /* no dot */
dotIndex = baseFileName.size(); /* append */
+ } else if (dotIndex >= 2 && baseFileName[dotIndex - 1] == QLatin1Char('9')
+ && baseFileName[dotIndex - 2] == QLatin1Char('.')) {
+ // If the file has a .9.* (9-patch image) extension, we must ensure that the @nx goes before it.
+ dotIndex -= 2;
+ }
QString atNxfileName = baseFileName;
atNxfileName.insert(dotIndex, QLatin1String("@2x"));
diff --git a/tests/auto/gui/image/qiconhighdpi/icons/misc/button.9.png b/tests/auto/gui/image/qiconhighdpi/icons/misc/button.9.png
new file mode 100644
index 0000000000..1a560a1d74
--- /dev/null
+++ b/tests/auto/gui/image/qiconhighdpi/icons/misc/button.9.png
Binary files differ
diff --git a/tests/auto/gui/image/qiconhighdpi/icons/misc/button@2x.9.png b/tests/auto/gui/image/qiconhighdpi/icons/misc/button@2x.9.png
new file mode 100644
index 0000000000..f010dc55c7
--- /dev/null
+++ b/tests/auto/gui/image/qiconhighdpi/icons/misc/button@2x.9.png
Binary files differ
diff --git a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp
index ce7f68a0a6..51892cca04 100644
--- a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp
+++ b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp
@@ -39,6 +39,7 @@ private slots:
void initTestCase();
void fromTheme_data();
void fromTheme();
+ void ninePatch();
};
tst_QIconHighDpi::tst_QIconHighDpi()
@@ -182,6 +183,24 @@ void tst_QIconHighDpi::fromTheme()
QCOMPARE(pixmap.devicePixelRatio(), expectedDpr);
}
+void tst_QIconHighDpi::ninePatch()
+{
+ const QIcon icon(":/icons/misc/button.9.png");
+ const int dpr = qCeil(qApp->devicePixelRatio());
+
+ switch (dpr) {
+ case 1:
+ QCOMPARE(icon.availableSizes().size(), 1);
+ QCOMPARE(icon.availableSizes().at(0), QSize(42, 42));
+ break;
+ case 2:
+ QCOMPARE(icon.availableSizes().size(), 2);
+ QCOMPARE(icon.availableSizes().at(0), QSize(42, 42));
+ QCOMPARE(icon.availableSizes().at(1), QSize(82, 82));
+ break;
+ }
+}
+
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
diff --git a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.qrc b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.qrc
index 80b5e38ee6..5cc1c6d9b1 100644
--- a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.qrc
+++ b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.qrc
@@ -4,5 +4,7 @@
<file>icons/testtheme/22x22/actions/appointment-new.png</file>
<file>icons/testtheme/index.theme</file>
<file>icons/testtheme/22x22@2/actions/appointment-new.png</file>
+ <file>icons/misc/button.9.png</file>
+ <file>icons/misc/button@2x.9.png</file>
</qresource>
</RCC>