3813 QCOMPARE(view.lastUpdateRegions.size(), 1); |
3814 QCOMPARE(view.lastUpdateRegions.size(), 1); |
3814 QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); |
3815 QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); |
3815 #endif |
3816 #endif |
3816 } |
3817 } |
3817 |
3818 |
|
3819 void tst_QGraphicsView::update_ancestorClipsChildrenToShape2() |
|
3820 { |
|
3821 QGraphicsScene scene(-150, -150, 300, 300); |
|
3822 |
|
3823 /* |
|
3824 Add two rects: |
|
3825 |
|
3826 +------------------+ |
|
3827 | child | |
|
3828 | +--------------+ | |
|
3829 | | parent | | |
|
3830 | | | | |
|
3831 | | | | |
|
3832 | | | | |
|
3833 | +--------------+ | |
|
3834 +------------------+ |
|
3835 |
|
3836 ... where the parent has no contents and clips the child to shape. |
|
3837 */ |
|
3838 QApplication::processEvents(); // Get rid of pending update. |
|
3839 |
|
3840 QGraphicsRectItem *parent = static_cast<QGraphicsRectItem *>(scene.addRect(-50, -50, 100, 100)); |
|
3841 parent->setBrush(QColor(0, 0, 255, 125)); |
|
3842 parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
3843 parent->setFlag(QGraphicsItem::ItemHasNoContents); |
|
3844 |
|
3845 QGraphicsRectItem *child = static_cast<QGraphicsRectItem *>(scene.addRect(-100, -100, 200, 200)); |
|
3846 child->setBrush(QColor(255, 0, 0, 125)); |
|
3847 child->setParentItem(parent); |
|
3848 |
|
3849 CustomView view(&scene); |
|
3850 view.show(); |
|
3851 QTest::qWaitForWindowShown(&view); |
|
3852 QTRY_VERIFY(view.painted); |
|
3853 |
|
3854 view.lastUpdateRegions.clear(); |
|
3855 view.painted = false; |
|
3856 |
|
3857 // Call child->update() and make sure the updated area is within its parent's clip. |
|
3858 QRectF expected = child->deviceTransform(view.viewportTransform()).mapRect(child->boundingRect()); |
|
3859 expected &= parent->deviceTransform(view.viewportTransform()).mapRect(parent->boundingRect()); |
|
3860 |
|
3861 child->update(); |
|
3862 QTRY_VERIFY(view.painted); |
|
3863 |
|
3864 #ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions |
|
3865 QTRY_VERIFY(view.painted); |
|
3866 QCOMPARE(view.lastUpdateRegions.size(), 1); |
|
3867 QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); |
|
3868 #endif |
|
3869 |
|
3870 QTest::qWait(50); |
|
3871 |
|
3872 view.lastUpdateRegions.clear(); |
|
3873 view.painted = false; |
|
3874 |
|
3875 // Invalidate the parent's geometry and trigger an update. |
|
3876 // The update area should be clipped to the parent's bounding rect for 'normal' items, |
|
3877 // but in this case the item has no contents (ItemHasNoContents) and its geometry |
|
3878 // is invalidated, which means we cannot clip the child update. So, the expected |
|
3879 // area is exactly the same as the child's bounding rect (adjusted for antialiasing). |
|
3880 parent->setRect(parent->rect().adjusted(-10, -10, -10, -10)); |
|
3881 expected = child->deviceTransform(view.viewportTransform()).mapRect(child->boundingRect()); |
|
3882 expected.adjust(-2, -2, 2, 2); // Antialiasing |
|
3883 |
|
3884 #ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions |
|
3885 QTRY_VERIFY(view.painted); |
|
3886 QCOMPARE(view.lastUpdateRegions.size(), 1); |
|
3887 QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); |
|
3888 #endif |
|
3889 } |
|
3890 |
3818 class FocusItem : public QGraphicsRectItem |
3891 class FocusItem : public QGraphicsRectItem |
3819 { |
3892 { |
3820 public: |
3893 public: |
3821 FocusItem() : QGraphicsRectItem(0, 0, 20, 20) { |
3894 FocusItem() : QGraphicsRectItem(0, 0, 20, 20) { |
3822 m_viewHasIMEnabledInFocusInEvent = false; |
3895 m_viewHasIMEnabledInFocusInEvent = false; |