tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 7 3f74d0d4af4c
--- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp	Fri Feb 19 23:40:16 2010 +0200
+++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp	Fri Mar 12 15:46:37 2010 +0200
@@ -71,6 +71,7 @@
     void colorize();
     void drawPixmapItem();
     void deviceCoordinateTranslateCaching();
+    void inheritOpacity();
 };
 
 void tst_QGraphicsEffect::initTestCase()
@@ -79,8 +80,8 @@
 class CustomItem : public QGraphicsRectItem
 {
 public:
-    CustomItem(qreal x, qreal y, qreal width, qreal height)
-        : QGraphicsRectItem(x, y, width, height), numRepaints(0),
+    CustomItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = 0)
+        : QGraphicsRectItem(x, y, width, height, parent), numRepaints(0),
           m_painter(0), m_styleOption(0)
     {}
 
@@ -560,6 +561,35 @@
     QVERIFY(item->numRepaints == numRepaints);
 }
 
+void tst_QGraphicsEffect::inheritOpacity()
+{
+    QGraphicsScene scene;
+    QGraphicsRectItem *rectItem = new QGraphicsRectItem(0, 0, 10, 10);
+    CustomItem *item = new CustomItem(0, 0, 10, 10, rectItem);
+
+    scene.addItem(rectItem);
+
+    item->setGraphicsEffect(new DeviceEffect);
+    item->setPen(Qt::NoPen);
+    item->setBrush(Qt::red);
+
+    rectItem->setOpacity(0.5);
+
+    QGraphicsView view(&scene);
+    view.show();
+    QTest::qWaitForWindowShown(&view);
+
+    QTRY_VERIFY(item->numRepaints >= 1);
+
+    int numRepaints = item->numRepaints;
+
+    rectItem->setOpacity(1);
+    QTest::qWait(50);
+
+    // item should have been rerendered due to opacity changing
+    QTRY_VERIFY(item->numRepaints > numRepaints);
+}
+
 QTEST_MAIN(tst_QGraphicsEffect)
 #include "tst_qgraphicseffect.moc"