diff options
author | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-10-26 12:00:43 (GMT) |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-10-26 12:00:43 (GMT) |
commit | 85f3f3ac74a2e7fe6a0874a46f9358a15f0dab34 (patch) | |
tree | 191b227596f18333f1609ff824d2746dd7f1090f /tests/auto/qgraphicsview/tst_qgraphicsview.cpp | |
parent | 26139fcacc05b4a74fce1ef4e0db819118765310 (diff) | |
parent | 2d071521228a6bc9ef423cbdbbd8560d28208790 (diff) | |
download | Qt-85f3f3ac74a2e7fe6a0874a46f9358a15f0dab34.zip Qt-85f3f3ac74a2e7fe6a0874a46f9358a15f0dab34.tar.gz Qt-85f3f3ac74a2e7fe6a0874a46f9358a15f0dab34.tar.bz2 |
Merge remote branch 'qt/master' into lighthouse-master
Conflicts:
src/opengl/qwindowsurface_gl.cpp
Diffstat (limited to 'tests/auto/qgraphicsview/tst_qgraphicsview.cpp')
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index af02c55..a53f04d 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -244,6 +244,7 @@ private slots: void QTBUG_4151_clipAndIgnore(); void QTBUG_5859_exposedRect(); void QTBUG_7438_cursor(); + void hoverLeave(); public slots: void dummySlot() {} @@ -4394,5 +4395,59 @@ void tst_QGraphicsView::QTBUG_7438_cursor() #endif } +class GraphicsItemWithHover : public QGraphicsRectItem +{ +public: + GraphicsItemWithHover() + : receivedEnterEvent(false), receivedLeaveEvent(false), + enterWidget(0), leaveWidget(0) + { + setRect(0, 0, 100, 100); + setAcceptHoverEvents(true); + } + + bool sceneEvent(QEvent *event) + { + if (event->type() == QEvent::GraphicsSceneHoverEnter) { + receivedEnterEvent = true; + enterWidget = static_cast<QGraphicsSceneHoverEvent *>(event)->widget(); + } else if (event->type() == QEvent::GraphicsSceneHoverLeave) { + receivedLeaveEvent = true; + leaveWidget = static_cast<QGraphicsSceneHoverEvent *>(event)->widget(); + } + return QGraphicsRectItem::sceneEvent(event); + } + + bool receivedEnterEvent; + bool receivedLeaveEvent; + QWidget *enterWidget; + QWidget *leaveWidget; +}; + +void tst_QGraphicsView::hoverLeave() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + GraphicsItemWithHover *item = new GraphicsItemWithHover; + scene.addItem(item); + + // move the cursor out of the way + QCursor::setPos(1,1); + + view.show(); + QTest::qWaitForWindowShown(&view); + + QPoint pos = view.viewport()->mapToGlobal(view.mapFromScene(item->mapToScene(10, 10))); + QCursor::setPos(pos); + QTest::qWait(200); + QVERIFY(item->receivedEnterEvent); + QCOMPARE(item->enterWidget, view.viewport()); + + QCursor::setPos(0,0); + QTest::qWait(200); + QVERIFY(item->receivedLeaveEvent); + QCOMPARE(item->leaveWidget, view.viewport()); +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" |