1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the test suite of the Qt Toolkit. |
7 ** This file is part of the test suite of the Qt Toolkit. |
8 ** |
8 ** |
512 QTest::qWait(50); |
513 QTest::qWait(50); |
513 |
514 |
514 QTRY_VERIFY(effect->repaints >= 2); |
515 QTRY_VERIFY(effect->repaints >= 2); |
515 } |
516 } |
516 |
517 |
|
518 class DeviceEffect : public QGraphicsEffect |
|
519 { |
|
520 public: |
|
521 QRectF boundingRectFor(const QRectF &rect) const |
|
522 { return rect; } |
|
523 |
|
524 void draw(QPainter *painter) |
|
525 { |
|
526 QPoint offset; |
|
527 QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, QGraphicsEffect::NoPad); |
|
528 |
|
529 if (pixmap.isNull()) |
|
530 return; |
|
531 |
|
532 painter->save(); |
|
533 painter->setWorldTransform(QTransform()); |
|
534 painter->drawPixmap(offset, pixmap); |
|
535 painter->restore(); |
|
536 } |
|
537 }; |
|
538 |
|
539 void tst_QGraphicsEffect::deviceCoordinateTranslateCaching() |
|
540 { |
|
541 QGraphicsScene scene; |
|
542 CustomItem *item = new CustomItem(0, 0, 10, 10); |
|
543 scene.addItem(item); |
|
544 scene.setSceneRect(0, 0, 50, 0); |
|
545 |
|
546 item->setGraphicsEffect(new DeviceEffect); |
|
547 item->setPen(Qt::NoPen); |
|
548 item->setBrush(Qt::red); |
|
549 |
|
550 QGraphicsView view(&scene); |
|
551 view.show(); |
|
552 QTest::qWaitForWindowShown(&view); |
|
553 |
|
554 QTRY_VERIFY(item->numRepaints >= 1); |
|
555 int numRepaints = item->numRepaints; |
|
556 |
|
557 item->translate(10, 0); |
|
558 QTest::qWait(50); |
|
559 |
|
560 QVERIFY(item->numRepaints == numRepaints); |
|
561 } |
|
562 |
517 QTEST_MAIN(tst_QGraphicsEffect) |
563 QTEST_MAIN(tst_QGraphicsEffect) |
518 #include "tst_qgraphicseffect.moc" |
564 #include "tst_qgraphicseffect.moc" |
519 |
565 |