void tst_QGraphicsEffect::boundingRect() { // No source; empty bounding rect. CustomEffect *effect = new CustomEffect; QCOMPARE(effect->boundingRect(), QRectF()); // Install effect on QGraphicsItem. QRectF itemRect(0, 0, 100, 100); QGraphicsRectItem *item = new QGraphicsRectItem; item->setRect(itemRect); item->setGraphicsEffect(effect); int margin = effect->margin(); QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); // Make sure disabling/enabling the effect doesn't change the bounding rect. effect->setEnabled(false); QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); effect->setEnabled(true); QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); // Change effect margins. effect->setMargin(margin = 20); QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); // Uninstall effect on QGraphicsItem. QPointer<CustomEffect> ptr = effect; item->setGraphicsEffect(0); QVERIFY(!ptr); delete item; }
void tst_QGraphicsEffect::boundingRect2() { CustomEffect *effect = new CustomEffect; QGraphicsRectItem *root = new QGraphicsRectItem; root->setGraphicsEffect(effect); QGraphicsRectItem *child = new QGraphicsRectItem; QRectF childRect(0, 0, 100, 100); child->setFlag(QGraphicsItem::ItemClipsChildrenToShape); child->setRect(childRect); child->setParentItem(root); QGraphicsRectItem *grandChild = new QGraphicsRectItem; QRectF grandChildRect(0, 0, 200, 200); grandChild->setRect(grandChildRect); grandChild->setParentItem(child); // Make sure the effect's bounding rect is clipped to the child's bounding rect. QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect)); // Disable ItemClipsChildrenToShape; effect's bounding rect is no longer clipped. child->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect)); // Add root item to a scene, do the same tests as above. Results should be the same. QGraphicsScene scene; scene.addItem(root); child->setFlag(QGraphicsItem::ItemClipsChildrenToShape); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect)); child->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect)); // Now add the scene to a view, results should be the same. QGraphicsView view(&scene); child->setFlag(QGraphicsItem::ItemClipsChildrenToShape); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect)); child->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect)); CustomEffect *childEffect = new CustomEffect; child->setGraphicsEffect(childEffect); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childEffect->boundingRectFor(childRect | grandChildRect))); child->setGraphicsEffect(0); QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect)); }