summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2010-11-10 10:05:04 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2010-11-10 10:45:30 (GMT)
commit8d88491d44fdbad7e9d6ea618f14b5230e03d6f1 (patch)
treee7d4400a1a7279f06686e66294f51fe9d1921bb9
parent6e5221a1a891175b4d8ba93193c6133268b7bd5f (diff)
downloadQt-8d88491d44fdbad7e9d6ea618f14b5230e03d6f1.zip
Qt-8d88491d44fdbad7e9d6ea618f14b5230e03d6f1.tar.gz
Qt-8d88491d44fdbad7e9d6ea618f14b5230e03d6f1.tar.bz2
Fixed tst_qpixmap::grabWidget autotest failure on QWS.
We need to use the same rendering to compute the expected pixmap as used in QPixmap::grabWidget(), or the results will look different on a 16-bit display, as QPixmap::fromImage(ARGB32_Premultiplied_image) will get a different internal image format compared to QPixmap pixmap(size); pixmap.fill(Qt::transparent); Reviewed-by: Kim
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp54
1 files changed, 32 insertions, 22 deletions
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index a733d56..51e6cf5 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -812,33 +812,43 @@ void tst_QPixmap::drawBitmap()
void tst_QPixmap::grabWidget()
{
- QWidget widget;
- QImage image(128, 128, QImage::Format_ARGB32_Premultiplied);
- for (int row = 0; row < image.height(); ++row) {
- QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row));
- for (int col = 0; col < image.width(); ++col)
- line[col] = qRgba(rand() & 255, row, col, 127);
- }
+ for (int opaque = 0; opaque < 2; ++opaque) {
+ QWidget widget;
+ QImage image(128, 128, opaque ? QImage::Format_RGB32 : QImage::Format_ARGB32_Premultiplied);
+ for (int row = 0; row < image.height(); ++row) {
+ QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row));
+ for (int col = 0; col < image.width(); ++col)
+ line[col] = qRgba(rand() & 255, row, col, opaque ? 255 : 127);
+ }
- QPalette pal = widget.palette();
- pal.setBrush(QPalette::Window, QBrush(image));
- widget.setPalette(pal);
- widget.resize(128, 128);
+ QPalette pal = widget.palette();
+ pal.setBrush(QPalette::Window, QBrush(image));
+ widget.setPalette(pal);
+ widget.resize(128, 128);
- QPixmap expected = QPixmap::fromImage(QImage(image.scanLine(64) + 64 * 4, 64, 64, image.bytesPerLine(), image.format()));
- QPixmap actual = QPixmap::grabWidget(&widget, QRect(64, 64, 64, 64));
- QVERIFY(lenientCompare(actual, expected));
+ QPixmap expected(64, 64);
+ if (!opaque)
+ expected.fill(Qt::transparent);
- actual = QPixmap::grabWidget(&widget, 64, 64);
- QVERIFY(lenientCompare(actual, expected));
+ QPainter p(&expected);
+ p.translate(-64, -64);
+ p.drawTiledPixmap(0, 0, 128, 128, pal.brush(QPalette::Window).texture(), 0, 0);
+ p.end();
- // Make sure a widget that is not yet shown is grabbed correctly.
- QTreeWidget widget2;
- actual = QPixmap::grabWidget(&widget2);
- widget2.show();
- expected = QPixmap::grabWidget(&widget2);
+ QPixmap actual = QPixmap::grabWidget(&widget, QRect(64, 64, 64, 64));
+ QVERIFY(lenientCompare(actual, expected));
- QVERIFY(lenientCompare(actual, expected));
+ actual = QPixmap::grabWidget(&widget, 64, 64);
+ QVERIFY(lenientCompare(actual, expected));
+
+ // Make sure a widget that is not yet shown is grabbed correctly.
+ QTreeWidget widget2;
+ actual = QPixmap::grabWidget(&widget2);
+ widget2.show();
+ expected = QPixmap::grabWidget(&widget2);
+
+ QVERIFY(lenientCompare(actual, expected));
+ }
}
void tst_QPixmap::grabWindow()