From d7e274a44621a4c1bb1ede66c00ee1d1e3f7bd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 13 Mar 2014 09:10:47 +0100 Subject: StyleSheetStyle: Load @Nx images Perform a @Nx image file lookup when loading pixmaps. Make drawBackgroundImage() handle high-dpi pixmaps, here the layout calculations needs to be in device- independent pixels Fixes: QTBUG-36825 Change-Id: I61e6f53c59f61f3bd88c34a036349e51e8c8ad92 Reviewed-by: Ulf Hermann Reviewed-by: Alex Blasche --- .../styles/qstylesheetstyle/images/testimage.png | Bin 299 -> 300 bytes .../qstylesheetstyle/images/testimage@2x.png | Bin 0 -> 318 bytes .../widgets/styles/qstylesheetstyle/resources.qrc | 1 + .../qstylesheetstyle/tst_qstylesheetstyle.cpp | 33 +++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 tests/auto/widgets/styles/qstylesheetstyle/images/testimage@2x.png (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/styles/qstylesheetstyle/images/testimage.png b/tests/auto/widgets/styles/qstylesheetstyle/images/testimage.png index 06fb34f0d6..a4adc7a47f 100644 Binary files a/tests/auto/widgets/styles/qstylesheetstyle/images/testimage.png and b/tests/auto/widgets/styles/qstylesheetstyle/images/testimage.png differ diff --git a/tests/auto/widgets/styles/qstylesheetstyle/images/testimage@2x.png b/tests/auto/widgets/styles/qstylesheetstyle/images/testimage@2x.png new file mode 100644 index 0000000000..d55f0c507b Binary files /dev/null and b/tests/auto/widgets/styles/qstylesheetstyle/images/testimage@2x.png differ diff --git a/tests/auto/widgets/styles/qstylesheetstyle/resources.qrc b/tests/auto/widgets/styles/qstylesheetstyle/resources.qrc index 248bf80f50..f523070073 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/resources.qrc +++ b/tests/auto/widgets/styles/qstylesheetstyle/resources.qrc @@ -2,5 +2,6 @@ images/testimage.png + images/testimage@2x.png \ No newline at end of file diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 43aec651fe..f5d9433f70 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -33,6 +33,7 @@ #include #include +#include #include using namespace QTestPrivate; @@ -101,6 +102,9 @@ private slots: void styleSheetTargetAttribute(); void unpolish(); + void highdpiImages_data(); + void highdpiImages(); + private: QColor COLOR(const QWidget& w) { w.ensurePolished(); @@ -2066,6 +2070,35 @@ void tst_QStyleSheetStyle::unpolish() QCOMPARE(w.minimumWidth(), 0); } +void tst_QStyleSheetStyle::highdpiImages_data() +{ + QTest::addColumn("screenFactor"); + QTest::addColumn("color"); + + QTest::newRow("highdpi") << 2.0 << QColor(0x00, 0xFF, 0x00); + QTest::newRow("lowdpi") << 1.0 << QColor(0xFF, 0x00, 0x00); +} + +void tst_QStyleSheetStyle::highdpiImages() +{ + QFETCH(qreal, screenFactor); + QFETCH(QColor, color); + + QWidget w; + QScreen *screen = QGuiApplication::screenAt(w.pos()); + QHighDpiScaling::setScreenFactor(screen, screenFactor); + w.setStyleSheet("QWidget { background-image: url(\":/images/testimage.png\"); }"); + w.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&w)); + QImage image(w.size(), QImage::Format_ARGB32); + w.render(&image); + QVERIFY(testForColors(image, color)); + + QHighDpiScaling::setScreenFactor(screen, 1.0); + QHighDpiScaling::updateHighDpiScaling(); // reset to normal +} + QTEST_MAIN(tst_QStyleSheetStyle) #include "tst_qstylesheetstyle.moc" -- cgit v1.2.3