From d9cc1499954829faf9486fb72056e29f1bad58e3 Mon Sep 17 00:00:00 2001 From: Jani Hautakangas Date: Thu, 12 Dec 2013 21:48:35 +0200 Subject: Fix floating point clip rectangle rounding in raster and opengl paint engine Fixes: QTBUG-83229 Pick-to: 5.15 Change-Id: If94028f27c9085e391acb9c423cde1b7c12bca36 Reviewed-by: Eskil Abrahamsen Blomfeldt --- tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/auto/gui/painting') diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 060c22c1b4..960dfdd04f 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -138,6 +138,7 @@ private slots: void disableEnableClipping(); void setClipRect(); + void clipRect(); void setEqualClipRegionAndPath_data(); void setEqualClipRegionAndPath(); @@ -1750,6 +1751,42 @@ void tst_QPainter::setClipRect() } } +/* + Verify that the clipping works correctly. + The red outline should be covered by the blue rect on top and left, + while it should be clipped on the right and bottom and thus the red outline be visible + + See: QTBUG-83229 +*/ +void tst_QPainter::clipRect() +{ + int width = 654; + int height = 480; + QRect rect(0, 0, width, height); + + QImage image(width, height, QImage::Format_ARGB32); + QPainter p(&image); + qreal halfWidth = width / 2.0; + qreal halfHeight = height / 2.0; + + QRectF clipRect = QRectF(halfWidth - halfWidth / 2.0, halfHeight - halfHeight / 2.0, + halfWidth / 2.0, halfHeight / 2.0); + + p.fillRect(rect, Qt::white); + p.setPen(Qt::red); + p.drawRect(clipRect); + + p.setClipRect(clipRect, Qt::ReplaceClip); + p.fillRect(rect, Qt::blue); + + p.end(); + + QCOMPARE(image.pixelColor(clipRect.left() + 1, clipRect.top()), QColor(Qt::blue)); + QCOMPARE(image.pixelColor(clipRect.left(), clipRect.top() + 1), QColor(Qt::blue)); + QCOMPARE(image.pixelColor(clipRect.left() + 1, clipRect.bottom()), QColor(Qt::red)); + QCOMPARE(image.pixelColor(clipRect.right(), clipRect.top() + 1), QColor(Qt::red)); +} + /* This tests the two different clipping approaches in QRasterPaintEngine, one when using a QRegion and one when using a QPainterPath. They should -- cgit v1.2.3