diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-12-07 09:06:12 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-12-14 14:18:35 (GMT) |
commit | be525c78c8ac44e7c188a45a4e04a1d80ad9ba51 (patch) | |
tree | 72d8d1976cd8a74aafa4d92fb237141183b8d73f /tests/auto/qgraphicseffect | |
parent | 693ad0f9ca5ee424dc1e3c7aca88adb4915f5cdc (diff) | |
download | Qt-be525c78c8ac44e7c188a45a4e04a1d80ad9ba51.zip Qt-be525c78c8ac44e7c188a45a4e04a1d80ad9ba51.tar.gz Qt-be525c78c8ac44e7c188a45a4e04a1d80ad9ba51.tar.bz2 |
Optimize QGraphicsItemEffectSourcePrivate::pixmap() for QGraphicsPixmapItems.
Even for DeviceCoordinate mode we can return the raw pixmap if the
graphics item size is untransformed.
Reviewed-by: Bjørn Erik Nilsen
Diffstat (limited to 'tests/auto/qgraphicseffect')
-rw-r--r-- | tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index 259df4d..69fc118 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -69,6 +69,7 @@ private slots: void opacity(); void grayscale(); void colorize(); + void drawPixmapItem(); }; void tst_QGraphicsEffect::initTestCase() @@ -465,6 +466,54 @@ void tst_QGraphicsEffect::colorize() QCOMPARE(image.pixel(10, 10), qRgb(122, 193, 66)); } +class PixmapItemEffect : public QGraphicsEffect +{ +public: + PixmapItemEffect(const QPixmap &source) + : QGraphicsEffect() + , pixmap(source) + , repaints(0) + {} + + QRectF boundingRectFor(const QRectF &rect) const + { return rect; } + + void draw(QPainter *painter) + { + QVERIFY(sourcePixmap(Qt::LogicalCoordinates).pixmapData() == pixmap.pixmapData()); + QVERIFY((painter->worldTransform().type() <= QTransform::TxTranslate) == (sourcePixmap(Qt::DeviceCoordinates).pixmapData() == pixmap.pixmapData())); + + ++repaints; + } + QPixmap pixmap; + int repaints; +}; + +void tst_QGraphicsEffect::drawPixmapItem() +{ + QImage image(32, 32, QImage::Format_RGB32); + QPainter p(&image); + p.fillRect(0, 0, 32, 16, Qt::blue); + p.fillRect(0, 16, 32, 16, Qt::red); + p.end(); + + QGraphicsScene scene; + QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap::fromImage(image)); + scene.addItem(item); + + PixmapItemEffect *effect = new PixmapItemEffect(item->pixmap()); + item->setGraphicsEffect(effect); + + QGraphicsView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + item->rotate(180); + QTest::qWait(50); + + QTRY_VERIFY(effect->repaints >= 2); +} + QTEST_MAIN(tst_QGraphicsEffect) #include "tst_qgraphicseffect.moc" |