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>bb10
parent
d9206926d8
commit
8dd8acf8bb
|
|
@ -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"));
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 329 B |
Binary file not shown.
|
After Width: | Height: | Size: 616 B |
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue