tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 7 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
    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     void deviceCoordinateTranslateCaching();
       
    74     void inheritOpacity();
    74 };
    75 };
    75 
    76 
    76 void tst_QGraphicsEffect::initTestCase()
    77 void tst_QGraphicsEffect::initTestCase()
    77 {}
    78 {}
    78 
    79 
    79 class CustomItem : public QGraphicsRectItem
    80 class CustomItem : public QGraphicsRectItem
    80 {
    81 {
    81 public:
    82 public:
    82     CustomItem(qreal x, qreal y, qreal width, qreal height)
    83     CustomItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = 0)
    83         : QGraphicsRectItem(x, y, width, height), numRepaints(0),
    84         : QGraphicsRectItem(x, y, width, height, parent), numRepaints(0),
    84           m_painter(0), m_styleOption(0)
    85           m_painter(0), m_styleOption(0)
    85     {}
    86     {}
    86 
    87 
    87     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    88     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    88     {
    89     {
   558     QTest::qWait(50);
   559     QTest::qWait(50);
   559 
   560 
   560     QVERIFY(item->numRepaints == numRepaints);
   561     QVERIFY(item->numRepaints == numRepaints);
   561 }
   562 }
   562 
   563 
       
   564 void tst_QGraphicsEffect::inheritOpacity()
       
   565 {
       
   566     QGraphicsScene scene;
       
   567     QGraphicsRectItem *rectItem = new QGraphicsRectItem(0, 0, 10, 10);
       
   568     CustomItem *item = new CustomItem(0, 0, 10, 10, rectItem);
       
   569 
       
   570     scene.addItem(rectItem);
       
   571 
       
   572     item->setGraphicsEffect(new DeviceEffect);
       
   573     item->setPen(Qt::NoPen);
       
   574     item->setBrush(Qt::red);
       
   575 
       
   576     rectItem->setOpacity(0.5);
       
   577 
       
   578     QGraphicsView view(&scene);
       
   579     view.show();
       
   580     QTest::qWaitForWindowShown(&view);
       
   581 
       
   582     QTRY_VERIFY(item->numRepaints >= 1);
       
   583 
       
   584     int numRepaints = item->numRepaints;
       
   585 
       
   586     rectItem->setOpacity(1);
       
   587     QTest::qWait(50);
       
   588 
       
   589     // item should have been rerendered due to opacity changing
       
   590     QTRY_VERIFY(item->numRepaints > numRepaints);
       
   591 }
       
   592 
   563 QTEST_MAIN(tst_QGraphicsEffect)
   593 QTEST_MAIN(tst_QGraphicsEffect)
   564 #include "tst_qgraphicseffect.moc"
   594 #include "tst_qgraphicseffect.moc"
   565 
   595