tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 5 d3bac044e0f0
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     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 **
    68     void draw();
    68     void draw();
    69     void opacity();
    69     void opacity();
    70     void grayscale();
    70     void grayscale();
    71     void colorize();
    71     void colorize();
    72     void drawPixmapItem();
    72     void drawPixmapItem();
       
    73     void deviceCoordinateTranslateCaching();
    73 };
    74 };
    74 
    75 
    75 void tst_QGraphicsEffect::initTestCase()
    76 void tst_QGraphicsEffect::initTestCase()
    76 {}
    77 {}
    77 
    78 
   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