diff options
author | Jørgen Lind <jorgen.lind@theqtcompany.com> | 2015-01-14 09:41:23 +0100 |
---|---|---|
committer | Jørgen Lind <jorgen.lind@theqtcompany.com> | 2015-01-20 13:49:28 +0100 |
commit | 606ce564d82dd099fb1fca939692839cf571b1ac (patch) | |
tree | 45eb2b5ee6f7bb44617268156af2325d21a281ca /tests | |
parent | 8a23c8a613b5eb360a48ee6c64ea3507caf878e2 (diff) |
Send hover events also to QQuickItem::childMouseEventFilter
childMouseEventFilter already gets touch events, and it is logical to
send the hover events which are essentially mouse events. By also
sending hover events to the filter it allows an item to track the mouse.
Existing implementations of childMouseEventFilter should not be effected
by more events being sent to it as checking for the event type should be
practiced in all overloads.
Change-Id: Ie00aceef05e41e4e8f6d80007343c5a5b9f566cf
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index e019c57ccb..f4f948c429 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -365,6 +365,7 @@ private slots: void testRenderJob(); + void testHoverChildMouseEventFilter(); private: QTouchDevice *touchDevice; QTouchDevice *touchDeviceWithVelocity; @@ -2046,6 +2047,113 @@ void tst_qquickwindow::testRenderJob() QCOMPARE(RenderJob::deleted, 5); } +class EventCounter : public QQuickRectangle +{ + Q_OBJECT +public: + EventCounter(QQuickItem *parent = 0) + : QQuickRectangle(parent) + { } + + void addFilterEvent(QEvent::Type type) + { + m_returnTrueForType.append(type); + } + + int childMouseEventFilterEventCount(QEvent::Type type) + { + return m_childMouseEventFilterEventCount.value(type, 0); + } + + int eventCount(QEvent::Type type) + { + return m_eventCount.value(type, 0); + } + + void reset() + { + m_eventCount.clear(); + m_childMouseEventFilterEventCount.clear(); + } +protected: + bool childMouseEventFilter(QQuickItem *, QEvent *event) Q_DECL_OVERRIDE + { + m_childMouseEventFilterEventCount[event->type()]++; + return m_returnTrueForType.contains(event->type()); + } + + bool event(QEvent *event) Q_DECL_OVERRIDE + { + m_eventCount[event->type()]++; + return QQuickRectangle::event(event); + } + + +private: + QList<QEvent::Type> m_returnTrueForType; + QMap<QEvent::Type, int> m_childMouseEventFilterEventCount; + QMap<QEvent::Type, int> m_eventCount; +}; + +void tst_qquickwindow::testHoverChildMouseEventFilter() +{ + QQuickWindow window; + + window.resize(250, 250); + window.setPosition(100, 100); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + EventCounter *bottomItem = new EventCounter(window.contentItem()); + bottomItem->setObjectName("Bottom Item"); + bottomItem->setSize(QSizeF(150, 150)); + bottomItem->setAcceptHoverEvents(true); + + EventCounter *middleItem = new EventCounter(bottomItem); + middleItem->setObjectName("Middle Item"); + middleItem->setPosition(QPointF(50, 50)); + middleItem->setSize(QSizeF(150, 150)); + middleItem->setAcceptHoverEvents(true); + + EventCounter *topItem = new EventCounter(middleItem); + topItem->setObjectName("Top Item"); + topItem->setPosition(QPointF(50, 50)); + topItem->setSize(QSizeF(150, 150)); + topItem->setAcceptHoverEvents(true); + + QPoint pos(10, 10); + + QTest::mouseMove(&window, pos); + + QTRY_VERIFY(bottomItem->eventCount(QEvent::HoverEnter) > 0); + QVERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter) == 0); + QVERIFY(middleItem->eventCount(QEvent::HoverEnter) == 0); + QVERIFY(topItem->eventCount(QEvent::HoverEnter) == 0); + bottomItem->reset(); + + pos = QPoint(60, 60); + QTest::mouseMove(&window, pos); + QTRY_VERIFY(middleItem->eventCount(QEvent::HoverEnter) > 0); + QVERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter) == 0); + middleItem->reset(); + + pos = QPoint(70,70); + bottomItem->setFiltersChildMouseEvents(true); + QTest::mouseMove(&window, pos); + QTRY_VERIFY(middleItem->eventCount(QEvent::HoverMove) > 0); + QVERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverMove) > 0); + QVERIFY(topItem->eventCount(QEvent::HoverEnter) == 0); + bottomItem->reset(); + middleItem->reset(); + + pos = QPoint(110,110); + bottomItem->addFilterEvent(QEvent::HoverEnter); + QTest::mouseMove(&window, pos); + QTRY_VERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter) > 0); + QVERIFY(topItem->eventCount(QEvent::HoverEnter) == 0); + QVERIFY(middleItem->eventCount(QEvent::HoverEnter) == 0); +} + QTEST_MAIN(tst_qquickwindow) #include "tst_qquickwindow.moc" |