diff options
author | Trond Kjernåsen <trond@trolltech.com> | 2010-02-23 09:11:03 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond@trolltech.com> | 2010-02-23 09:11:03 (GMT) |
commit | 58533cbc7322c4f821f24043028e47925b537419 (patch) | |
tree | 6821780e44a2a603e828b10e6c7307b06ec1e8e3 /tests/auto/qpainter/tst_qpainter.cpp | |
parent | a948f901b196bab121cb8b5736204b4ce0c09e94 (diff) | |
download | Qt-58533cbc7322c4f821f24043028e47925b537419.zip Qt-58533cbc7322c4f821f24043028e47925b537419.tar.gz Qt-58533cbc7322c4f821f24043028e47925b537419.tar.bz2 |
Made the qDrawPixmaps() API public (with modifications).
QPainter has now gotten a drawPixmapFragments() function together
with a Fragment class that describes how each pixmap fragment is
supposed to be drawn.
Reviewed-by: Gunnar
Reviewed-by: Samuel
Diffstat (limited to 'tests/auto/qpainter/tst_qpainter.cpp')
-rw-r--r-- | tests/auto/qpainter/tst_qpainter.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index beb83a1..a03b2c7 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -107,6 +107,7 @@ private slots: void saveAndRestore(); void drawBorderPixmap(); + void drawPixmapFragments(); void drawLine_data(); void drawLine(); @@ -994,6 +995,49 @@ void tst_QPainter::drawBorderPixmap() QTileRules(Qt::StretchTile,Qt::StretchTile), 0); } +void tst_QPainter::drawPixmapFragments() +{ + QPixmap origPixmap(20, 20); + QPixmap resPixmap(20, 20); + QPainter::Fragment fragments[4] = { {15, 15, 0, 0, 10, 10, 1, 1, 0, 1}, + { 5, 15, 10, 0, 10, 10, 1, 1, 0, 1}, + {15, 5, 0, 10, 10, 10, 1, 1, 0, 1}, + { 5, 5, 10, 10, 10, 10, 1, 1, 0, 1} }; + { + QPainter p(&origPixmap); + p.fillRect(0, 0, 10, 10, Qt::red); + p.fillRect(10, 0, 10, 10, Qt::green); + p.fillRect(0, 10, 10, 10, Qt::blue); + p.fillRect(10, 10, 10, 10, Qt::yellow); + } + { + QPainter p(&resPixmap); + p.drawPixmapFragments(fragments, 4, origPixmap); + } + + QImage origImage = origPixmap.toImage().convertToFormat(QImage::Format_ARGB32); + QImage resImage = resPixmap.toImage().convertToFormat(QImage::Format_ARGB32); + + QVERIFY(resImage.size() == resPixmap.size()); + QVERIFY(resImage.pixel(5, 5) == origImage.pixel(15, 15)); + QVERIFY(resImage.pixel(5, 15) == origImage.pixel(15, 5)); + QVERIFY(resImage.pixel(15, 5) == origImage.pixel(5, 15)); + QVERIFY(resImage.pixel(15, 15) == origImage.pixel(5, 5)); + + + QPainter::Fragment fragment = QPainter::Fragment::create(QPointF(20, 20), QRectF(30, 30, 2, 2)); + QVERIFY(fragment.x == 20); + QVERIFY(fragment.y == 20); + QVERIFY(fragment.sourceLeft == 30); + QVERIFY(fragment.sourceTop == 30); + QVERIFY(fragment.width == 2); + QVERIFY(fragment.height == 2); + QVERIFY(fragment.scaleX == 1); + QVERIFY(fragment.scaleY == 1); + QVERIFY(fragment.rotation == 0); + QVERIFY(fragment.opacity == 1); +} + void tst_QPainter::drawLine_data() { QTest::addColumn<QLine>("line"); @@ -3443,8 +3487,8 @@ bool verifyOutlineFillConsistency(const QImage &img, QRgb outside, QRgb inside, if ((dx == 0) == (dy == 0)) continue; QRgb neighbor = img.pixel(p.x() + dx, p.y() + dy); - if (pixel == inside && neighbor == outside || - pixel == outside && neighbor == inside) + if ((pixel == inside && neighbor == outside) || + (pixel == outside && neighbor == inside)) return false; } } |