summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index 8fa4dc3..cb5f057 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -149,6 +149,7 @@ private slots:
void closePopupOnOutsideClick();
void defaultSize();
void shortcutsDeletion();
+ void ensureClipping();
// Task fixes
void task236127_bspTreeIndexFails();
@@ -1928,6 +1929,87 @@ void tst_QGraphicsWidget::task250119_shortcutContext()
scene.removeItem(&w_signal);
}
+class ClippingAndTransformsScene : public QGraphicsScene
+{
+public:
+ QList<QGraphicsItem *> drawnItems;
+protected:
+ void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[],
+ const QStyleOptionGraphicsItem options[], QWidget *widget = 0)
+ {
+ drawnItems.clear();
+ for (int i = 0; i < numItems; ++i)
+ drawnItems << items[i];
+ QGraphicsScene::drawItems(painter, numItems, items, options, widget);
+ }
+};
+
+class RectWidget : public QGraphicsWidget
+{
+public:
+
+ RectWidget(Qt::GlobalColor color, QGraphicsItem *parent=0) : QGraphicsWidget(parent), mColor(color) {}
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ painter->setBrush(QBrush(mColor));
+ painter->drawRect(boundingRect());
+ }
+
+ Qt::GlobalColor mColor;
+};
+
+class RectItem : public QGraphicsItem
+{
+public:
+
+ RectItem(Qt::GlobalColor color, QGraphicsItem *parent=0) : QGraphicsItem(parent), mColor(color) {}
+
+ QRectF boundingRect() const
+ {return QRectF(10,10,50,50);}
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ painter->setBrush(QBrush(mColor));
+ painter->drawRect(boundingRect());
+ }
+
+ Qt::GlobalColor mColor;
+};
+
+void tst_QGraphicsWidget::ensureClipping()
+{
+ ClippingAndTransformsScene scene;
+ scene.setSceneRect(-50, -50, 200, 200);
+
+ //A root that clip children
+ RectWidget *clipWidget = new RectWidget(Qt::black);
+ scene.addItem(clipWidget);
+
+ clipWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
+
+ //a child
+ RectWidget *childWidget = new RectWidget(Qt::red, clipWidget);
+ clipWidget->setGeometry(QRectF(10, 10, 100, 100));
+ childWidget->setGeometry(QRectF(25, 25, 50, 50));
+
+ //We put a QGraphicsItem to be sure this one is also paint
+ RectItem *childitem = new RectItem(Qt::blue, clipWidget);
+
+ QGraphicsView view(&scene);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(250);
+
+ QList<QGraphicsItem *> expected;
+ expected << clipWidget << childWidget << childitem;
+ QVERIFY(scene.drawnItems.contains(clipWidget));
+ QVERIFY(scene.drawnItems.contains(childWidget));
+ QVERIFY(scene.drawnItems.contains(childitem));
+}
+
QTEST_MAIN(tst_QGraphicsWidget)
#include "tst_qgraphicswidget.moc"