summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-07-13 16:34:32 -0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-07-13 16:36:10 -0700
commitd38fe875c7850ca2c6ca28f91e94ae276735fac8 (patch)
treee5c92cef74e0853490d77cf0139b23f00d548a6e /tests/auto/gui/painting/qpainter/tst_qpainter.cpp
parentac4e848c9802377b7c4ff673180f28b9ca76b746 (diff)
parent627f0a7f7d775ecd263b95dd07fca44bfcb0c5cf (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/widgets/widgets/qmainwindowlayout.cpp Change-Id: I306b4f5ad11bceb336c9091241b468d455fe6bb6
Diffstat (limited to 'tests/auto/gui/painting/qpainter/tst_qpainter.cpp')
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index ed5b9fabb6..779783d5ec 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -303,6 +303,8 @@ private slots:
void blendNullRGB32();
void toRGB64();
+ void fillPolygon();
+
private:
void fillData();
void setPenColor(QPainter& p);
@@ -5144,6 +5146,112 @@ void tst_QPainter::toRGB64()
}
}
+void tst_QPainter::fillPolygon()
+{
+ QImage image(50, 50, QImage::Format_RGB32);
+ image.fill(Qt::white);
+
+ QPainter painter(&image);
+ QBrush brush(Qt::black, Qt::SolidPattern);
+ painter.setBrush(brush);
+
+ QPen pen(Qt::red, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+ painter.setPen(pen);
+
+ const QPoint diamondpoints[5] = {
+ QPoint(-15, 0),
+ QPoint(0, -15),
+ QPoint(15, 0),
+ QPoint(0, 15),
+ QPoint(-15, 0)
+ };
+ enum { Outside1, Border1, Inside, Border2, Outside2 } state;
+
+ for (int i = 0; i < 16 ; i++)
+ {
+ for (int j = 0; j < 16 ; j++)
+ {
+ image.fill(Qt::white);
+ painter.resetTransform();
+ painter.translate(25 + i/16., 25 + j/16.);
+ painter.drawPolygon(diamondpoints, 5);
+
+ for (int x = 0; x < 50; x++) {
+ state = Outside1;
+ for (int y = 0; y < 50; y++) {
+ QRgb c = image.pixel(x, y);
+ switch (state) {
+ case Outside1:
+ if (c == QColor(Qt::red).rgb())
+ state = Border1;
+ else
+ QCOMPARE(c, QColor(Qt::white).rgb());
+ break;
+ case Border1:
+ if (c == QColor(Qt::black).rgb())
+ state = Inside;
+ else if (c == QColor(Qt::white).rgb())
+ state = Outside2;
+ else
+ QCOMPARE(c, QColor(Qt::red).rgb());
+ break;
+ case Inside:
+ if (c == QColor(Qt::red).rgb())
+ state = Border2;
+ else
+ QCOMPARE(c, QColor(Qt::black).rgb());
+ break;
+ case Border2:
+ if (c == QColor(Qt::white).rgb())
+ state = Outside2;
+ else
+ QCOMPARE(c, QColor(Qt::red).rgb());
+ break;
+ case Outside2:
+ QCOMPARE(c, QColor(Qt::white).rgb());
+ }
+ }
+ }
+ for (int y = 0; y < 50; y++) {
+ state = Outside1;
+ for (int x = 0; x < 50; x++) {
+ QRgb c = image.pixel(x, y);
+ switch (state) {
+ case Outside1:
+ if (c == QColor(Qt::red).rgb())
+ state = Border1;
+ else
+ QCOMPARE(c, QColor(Qt::white).rgb());
+ break;
+ case Border1:
+ if (c == QColor(Qt::black).rgb())
+ state = Inside;
+ else if (c == QColor(Qt::white).rgb())
+ state = Outside2;
+ else
+ QCOMPARE(c, QColor(Qt::red).rgb());
+ break;
+ case Inside:
+ if (c == QColor(Qt::red).rgb())
+ state = Border2;
+ else
+ QCOMPARE(c, QColor(Qt::black).rgb());
+ break;
+ case Border2:
+ if (c == QColor(Qt::white).rgb())
+ state = Outside2;
+ else
+ QCOMPARE(c, QColor(Qt::red).rgb());
+ break;
+ case Outside2:
+ QCOMPARE(c, QColor(Qt::white).rgb());
+ }
+ }
+ }
+ }
+ }
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"