Beispiel #1
0
void tst_QGraphicsEffect::itemHasNoContents()
{
    QGraphicsRectItem *parent = new QGraphicsRectItem;
    parent->setFlag(QGraphicsItem::ItemHasNoContents);

    MyGraphicsItem *child = new MyGraphicsItem;
    child->setParentItem(parent);
    child->resize(200, 200);

    QGraphicsScene scene;
    scene.addItem(parent);

    QGraphicsView view(&scene);
    view.show();
    QTest::qWaitForWindowShown(&view);
    QTRY_COMPARE(child->nbPaint, 1);

    CustomEffect *effect = new CustomEffect;
    parent->setGraphicsEffect(effect);
    QTRY_COMPARE(effect->numRepaints, 1);

    for (int i = 0; i < 3; ++i) {
        effect->reset();
        effect->update();
        QTRY_COMPARE(effect->numRepaints, 1);
    }
}
Beispiel #2
0
void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache()
{
    QGraphicsScene scene;
    MyGraphicsItem parent;
    parent.resize(200, 200);
    QGraphicsWidget child(&parent);
    child.resize(200, 200);
    child.setVisible(false);
    scene.addItem(&parent);
    QGraphicsView view(&scene);
    view.show();
    QApplication::setActiveWindow(&view);
    QTest::qWaitForWindowShown(&view);
    QTRY_COMPARE(parent.nbPaint, 1);
    //we set an effect on the parent
    parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent));
    //flush the events
    QApplication::processEvents();
    //new effect applied->repaint
    QCOMPARE(parent.nbPaint, 2);
    child.setVisible(true);
    //flush the events
    QApplication::processEvents();
    //a new child appears we need to redraw the effect.
    QCOMPARE(parent.nbPaint, 3);
}
Beispiel #3
0
void tst_QGraphicsEffect::graphicsEffectUpdateShouldNotInvalidateGraphicsItemCache()
{
    QGraphicsScene scene;
    MyGraphicsItem parent;
    parent.resize(200, 200);
    parent.setCacheMode(QGraphicsItem::ItemCoordinateCache);
    scene.addItem(&parent);

    QGraphicsView view(&scene);
    view.show();
    QApplication::setActiveWindow(&view);
    QTest::qWaitForWindowShown(&view);
    QTRY_COMPARE(parent.nbPaint, 1);

    //we set an effect on the parent
    MyGraphicsEffect* opacityEffect = new MyGraphicsEffect(&parent);
    opacityEffect->update();
    parent.setGraphicsEffect(opacityEffect);
    //flush the events
    QApplication::processEvents();
    //new effect applied->repaint
    QCOMPARE(parent.nbPaint, 1);

    opacityEffect->update();
    //flush the events
    QApplication::processEvents();
    //A change to the effect shouldn't invalidate the graphicsitem's cache
    // => it shouldn't trigger a paint
    QCOMPARE(parent.nbPaint, 1);
}
void tst_QGraphicsEffect::itemHasNoContents()
{
    QGraphicsRectItem *parent = new QGraphicsRectItem;
    parent->setFlag(QGraphicsItem::ItemHasNoContents);

    MyGraphicsItem *child = new MyGraphicsItem;
    child->setParentItem(parent);
    child->resize(200, 200);

    QGraphicsScene scene;
    scene.addItem(parent);

    QGraphicsView view(&scene);
    view.show();
    QTest::qWaitForWindowShown(&view);
#ifdef Q_OS_MAC
    if (QSysInfo::MacintoshVersion == QSysInfo::MV_LION) {
        QEXPECT_FAIL("", "QTBUG-26858", Abort);
    }
#endif
    QTRY_COMPARE(child->nbPaint, 1);

    CustomEffect *effect = new CustomEffect;
    parent->setGraphicsEffect(effect);
    QTRY_COMPARE(effect->numRepaints, 1);

    for (int i = 0; i < 3; ++i) {
        effect->reset();
        effect->update();
        QTRY_COMPARE(effect->numRepaints, 1);
    }
}
void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache()
{
    QGraphicsScene scene;
    MyGraphicsItem parent;
    parent.resize(200, 200);
    QGraphicsWidget child(&parent);
    child.resize(200, 200);
    child.setVisible(false);
    scene.addItem(&parent);
    QGraphicsView view(&scene);
    view.show();
    QApplication::setActiveWindow(&view);
    QTest::qWaitForWindowShown(&view);
#ifdef Q_OS_MAC
    if (QSysInfo::MacintoshVersion == QSysInfo::MV_LION) {
        QEXPECT_FAIL("", "QTBUG-26858", Abort);
    }
#endif
    QTRY_COMPARE(parent.nbPaint, 1);
    //we set an effect on the parent
    parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent));
    //flush the events
    QApplication::processEvents();
    //new effect applied->repaint
    QCOMPARE(parent.nbPaint, 2);
    child.setVisible(true);
    //flush the events
    QApplication::processEvents();
    //a new child appears we need to redraw the effect.
    QCOMPARE(parent.nbPaint, 3);
}
void tst_QGraphicsEffect::graphicsEffectUpdateShouldInvalidateParentGraphicsEffect()
{
    QGraphicsScene scene;
    // Add the parent
    MyGraphicsItem parent;
    parent.resize(200, 200);
    scene.addItem(&parent);
    // Add a child to the parent
    MyGraphicsItem child(&parent);
    child.resize(100, 100);

    QGraphicsView view(&scene);
    view.show();
    QApplication::setActiveWindow(&view);
    QTest::qWaitForWindowShown(&view);
    //flush the events
    QApplication::processEvents();
#ifdef Q_OS_MAC
    if (QSysInfo::MacintoshVersion == QSysInfo::MV_LION) {
        QEXPECT_FAIL("", "QTBUG-26858", Abort);
    }
#endif
    QTRY_COMPARE(parent.nbPaint, 1);
    QTRY_COMPARE(child.nbPaint, 1);

    //we set an effect on the parent and the child
    MyGraphicsEffect* effectForParent = new MyGraphicsEffect(&parent);
    parent.setGraphicsEffect(effectForParent);

    MyGraphicsEffect* effectForChild = new MyGraphicsEffect(&child);
    child.setGraphicsEffect(effectForChild);
    //flush the events
    QApplication::processEvents();
    // Both effects should start with no source invalidations
    QCOMPARE(effectForParent->nbSourceInvalidations, 0);
    QCOMPARE(effectForChild->nbSourceInvalidations, 0);

    // Trigger an update of the child graphics effect
    effectForChild->update();
    //flush the events
    QApplication::processEvents();
    // An update of the effect on the child shouldn't tell that effect that its source has been invalidated
    QCOMPARE(effectForChild->nbSourceInvalidations, 0);
    // The effect on the parent should however be notified of an invalidated source
    QCOMPARE(effectForParent->nbSourceInvalidations, 1);
}
Beispiel #7
0
void tst_QGraphicsEffect::prepareGeometryChangeInvalidateCache()
{
    MyGraphicsItem *item = new MyGraphicsItem;
    item->resize(200, 200);

    QGraphicsScene scene;
    scene.addItem(item);

    QGraphicsView view(&scene);
    if(PlatformQuirks::isAutoMaximizing())
        view.showFullScreen();
    else
        view.show();
    QTest::qWaitForWindowShown(&view);
    QTRY_COMPARE(item->nbPaint, 1);

    item->nbPaint = 0;
    item->setGraphicsEffect(new QGraphicsDropShadowEffect);
    QTRY_COMPARE(item->nbPaint, 1);

    item->nbPaint = 0;
    item->resize(300, 300);
    QTRY_COMPARE(item->nbPaint, 1);

    item->nbPaint = 0;
    item->setPos(item->pos() + QPointF(10, 10));
    QTest::qWait(50);
    QCOMPARE(item->nbPaint, 0);
}
void tst_QGraphicsEffect::prepareGeometryChangeInvalidateCache()
{
    MyGraphicsItem *item = new MyGraphicsItem;
    item->resize(200, 200);

    QGraphicsScene scene;
    scene.addItem(item);

    QGraphicsView view(&scene);
    if(PlatformQuirks::isAutoMaximizing())
        view.showFullScreen();
    else
        view.show();
    QTest::qWaitForWindowShown(&view);
#ifdef Q_OS_MAC
    if (QSysInfo::MacintoshVersion == QSysInfo::MV_LION) {
        QEXPECT_FAIL("", "QTBUG-26858", Abort);
    }
#endif
    QTRY_COMPARE(item->nbPaint, 1);

    item->nbPaint = 0;
    item->setGraphicsEffect(new QGraphicsDropShadowEffect);
    QTRY_COMPARE(item->nbPaint, 1);

    item->nbPaint = 0;
    item->resize(300, 300);
    QTRY_COMPARE(item->nbPaint, 1);

    item->nbPaint = 0;
    item->setPos(item->pos() + QPointF(10, 10));
    QTest::qWait(50);
    QCOMPARE(item->nbPaint, 0);
}