From c7191d3e214b9cdb17ec383b61f7e21e784f80d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 14 Mar 2013 08:51:07 +0100 Subject: Fixed artifacts when drawing same line with different clips. Expanding on the change fixing QTBUG-24762 with the realization that any line needs to be drawn in a consistent way regardless of system or painter clip, not just dashed lines. Task-number: QTBUG-25036 Change-Id: Ief7ef19cc92c52e7d792500a581a072ba032767e Reviewed-by: Gunnar Sletta --- tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 58 ++++++++++++++++++----- 1 file changed, 47 insertions(+), 11 deletions(-) (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 774ade5fb0..57ffcaf30d 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -280,7 +280,9 @@ private slots: void drawTextWithComplexBrush(); void QTBUG26013_squareCapStroke(); void QTBUG25153_drawLine(); - void dashing_systemClip(); + + void cosmeticStrokerClipping_data(); + void cosmeticStrokerClipping(); private: void fillData(); @@ -4462,22 +4464,54 @@ void tst_QPainter::QTBUG25153_drawLine() } } -static void dashing_systemClip_paint(QPainter *p) +enum CosmeticStrokerPaint +{ + Antialiasing, + Dashing +}; + +static void paint_func(QPainter *p, CosmeticStrokerPaint type) +{ + p->save(); + switch (type) { + case Antialiasing: + p->setPen(Qt::black); + p->setRenderHint(QPainter::Antialiasing); + p->drawLine(4, 8, 42, 42); + break; + case Dashing: + p->setPen(QPen(Qt::black, 1, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin)); + p->drawLine(8, 8, 42, 8); + p->drawLine(42, 8, 42, 42); + p->drawLine(42, 42, 8, 42); + p->drawLine(8, 42, 8, 8); + break; + default: + Q_ASSERT(false); + break; + } + p->restore(); +} + +Q_DECLARE_METATYPE(CosmeticStrokerPaint) + +void tst_QPainter::cosmeticStrokerClipping_data() { - p->setPen(QPen(Qt::black, 1, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin)); - p->drawLine(8, 8, 42, 8); - p->drawLine(42, 8, 42, 42); - p->drawLine(42, 42, 8, 42); - p->drawLine(8, 42, 8, 8); + QTest::addColumn("paint"); + + QTest::newRow("antialiasing_paint") << Antialiasing; + QTest::newRow("dashing_paint") << Dashing; } -void tst_QPainter::dashing_systemClip() +void tst_QPainter::cosmeticStrokerClipping() { + QFETCH(CosmeticStrokerPaint, paint); + QImage image(50, 50, QImage::Format_RGB32); image.fill(Qt::white); QPainter p(&image); - dashing_systemClip_paint(&p); + paint_func(&p, paint); p.end(); QImage old = image.copy(); @@ -4485,7 +4519,8 @@ void tst_QPainter::dashing_systemClip() image.paintEngine()->setSystemClip(QRect(10, 0, image.width() - 10, image.height())); p.begin(&image); - dashing_systemClip_paint(&p); + p.fillRect(image.rect(), Qt::white); + paint_func(&p, paint); // doing same paint operation again with different system clip should not change the image QCOMPARE(old, image); @@ -4493,7 +4528,8 @@ void tst_QPainter::dashing_systemClip() old = image; p.setClipRect(QRect(20, 20, 30, 30)); - dashing_systemClip_paint(&p); + p.fillRect(image.rect(), Qt::white); + paint_func(&p, paint); // ditto for regular clips QCOMPARE(old, image); -- cgit v1.2.3