diff options
Diffstat (limited to 'tests/auto/qpainterpath/tst_qpainterpath.cpp')
-rw-r--r-- | tests/auto/qpainterpath/tst_qpainterpath.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/tests/auto/qpainterpath/tst_qpainterpath.cpp b/tests/auto/qpainterpath/tst_qpainterpath.cpp index cff84e9..873fe59 100644 --- a/tests/auto/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/qpainterpath/tst_qpainterpath.cpp @@ -109,6 +109,8 @@ private slots: void operators(); void connectPathDuplicatePoint(); + + void translate(); }; // Testing get/set functions @@ -819,7 +821,6 @@ void tst_QPainterPath::closing() } } -#if QT_VERSION >= 0x040200 void tst_QPainterPath::testArcMoveTo_data() { QTest::addColumn<QRectF>("rect"); @@ -1170,7 +1171,43 @@ void tst_QPainterPath::connectPathDuplicatePoint() QCOMPARE(c, a); } -#endif +void tst_QPainterPath::translate() +{ + QPainterPath path; + + // Path with no elements. + QCOMPARE(path.currentPosition(), QPointF()); + path.translate(50.5, 50.5); + QCOMPARE(path.currentPosition(), QPointF()); + QCOMPARE(path.translated(50.5, 50.5).currentPosition(), QPointF()); + + // path.isEmpty(), but we have one MoveTo element that should be translated. + path.moveTo(50, 50); + QCOMPARE(path.currentPosition(), QPointF(50, 50)); + path.translate(99.9, 99.9); + QCOMPARE(path.currentPosition(), QPointF(149.9, 149.9)); + path.translate(-99.9, -99.9); + QCOMPARE(path.currentPosition(), QPointF(50, 50)); + QCOMPARE(path.translated(-50, -50).currentPosition(), QPointF(0, 0)); + + // Complex path. + QRegion shape(100, 100, 300, 200, QRegion::Ellipse); + shape -= QRect(225, 175, 50, 50); + QPainterPath complexPath; + complexPath.addRegion(shape); + QVector<QPointF> untranslatedElements; + for (int i = 0; i < complexPath.elementCount(); ++i) + untranslatedElements.append(QPointF(complexPath.elementAt(i))); + + const QPainterPath untranslatedComplexPath(complexPath); + const QPointF offset(100, 100); + complexPath.translate(offset); + + for (int i = 0; i < complexPath.elementCount(); ++i) + QCOMPARE(QPointF(complexPath.elementAt(i)) - offset, untranslatedElements.at(i)); + + QCOMPARE(complexPath.translated(-offset), untranslatedComplexPath); +} QTEST_APPLESS_MAIN(tst_QPainterPath) |