diff options
author | Matt Vogt <matthew.vogt@jollamobile.com> | 2012-12-31 16:27:43 +1000 |
---|---|---|
committer | Robin Burchell <robin+qt@viroteck.net> | 2013-01-08 05:56:25 +0100 |
commit | 27697b3819d1b33bec6e32ba53a7e83fc25a66ec (patch) | |
tree | ec042ed34ed74ab57deedbb2e1e1060a1f19d5a3 /src | |
parent | d39a1865be268c58f7e47dfd9ccb47a53013fdd4 (diff) |
Generate real mouse events on mouseMove
Actual mouseMove events are necessary to properly simulate the
behavior of complex components such as Flickable. Instead of just
manipulating the cursor position, record the current button state so
that we can generate move events that are not suppressed.
In addition, add a mouseStartDrag() convenience function so that client
code does not need to be aware of QML's interpretation of the drag
threshold value.
Change-Id: I1ded27f976846660a0ec91906d0b2a6372efccd5
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/testlib/TestCase.qml | 26 | ||||
-rw-r--r-- | src/quicktestlib/quicktestevent.cpp | 26 | ||||
-rw-r--r-- | src/quicktestlib/quicktestevent_p.h | 5 |
3 files changed, 49 insertions, 8 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index d696f84..cb884aa 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -68,6 +68,9 @@ Item { // both qmlviewer and the QtQuickTest module test wrapper. property bool windowShown: Qt.qtest_wrapper ? qtest.windowShown : false + // The number of pixels movement needed to initiate a drag operation + property alias startDragDistance: qtest_events_normal.startDragDistance + // Internal private state. Identifiers prefixed with qtest are reserved. property bool qtest_prevWhen: true property int qtest_testId: -1 @@ -410,6 +413,23 @@ Item { qtest_fail("window not shown", 2) } + function mouseDrag(item, x, y, dx, dy, button, modifiers, delay) { + if (item.x === undefined || item.y === undefined) + return + if (button === undefined) + button = Qt.LeftButton + if (modifiers === undefined) + modifiers = Qt.NoModifier + if (delay == undefined) + delay = -1 + + mousePress(item, x, y, button, modifiers, delay) + //trigger dragging (QML requires drag to exceed the QApplication value, not just reach it) + var dragDistance = startDragDistance + 1 + mouseMove(item, x + dragDistance, y + dragDistance, delay, button) + mouseMove(item, x + dx, y + dy, delay, button) + } + function mouseClick(item, x, y, button, modifiers, delay) { if (button === undefined) button = Qt.LeftButton @@ -432,10 +452,12 @@ Item { qtest_fail("window not shown", 2) } - function mouseMove(item, x, y, delay) { + function mouseMove(item, x, y, delay, buttons) { if (delay == undefined) delay = -1 - if (!qtest_events.mouseMove(item, x, y, delay)) + if (buttons == undefined) + buttons = Qt.NoButton + if (!qtest_events.mouseMove(item, x, y, delay, buttons)) qtest_fail("window not shown", 2) } diff --git a/src/quicktestlib/quicktestevent.cpp b/src/quicktestlib/quicktestevent.cpp index 83aff91..69917b6 100644 --- a/src/quicktestlib/quicktestevent.cpp +++ b/src/quicktestlib/quicktestevent.cpp @@ -62,6 +62,11 @@ QuickTestEvent::~QuickTestEvent() { } +int QuickTestEvent::startDragDistance() +{ + return qApp->startDragDistance(); +} + bool QuickTestEvent::keyPress(int key, int modifiers, int delay) { QWidget *widget = eventWidget(); @@ -152,9 +157,15 @@ namespace QtQuickTest me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey); break; case MouseMove: - QCursor::setPos(widget->mapToGlobal(pos)); - qApp->processEvents(); - return; + if (button == Qt::NoButton) { + // If we send a mouse move event with no button pressed, it will be + // rejected (unless mouseTracking is set to true); simulate instead + QCursor::setPos(widget->mapToGlobal(pos)); + qApp->processEvents(); + } else { + me = QMouseEvent(QEvent::MouseMove, pos, widget->mapToGlobal(pos), button, button, stateKey); + } + break; default: QTEST_ASSERT(false); } @@ -225,13 +236,14 @@ bool QuickTestEvent::mouseDoubleClick } bool QuickTestEvent::mouseMove - (QObject *item, qreal x, qreal y, int delay) + (QObject *item, qreal x, qreal y, int delay, int buttons) { QWidget *view = eventWidget(); if (!view) return false; + QtQuickTest::mouseEvent(QtQuickTest::MouseMove, view, item, - Qt::NoButton, Qt::NoModifier, + Qt::MouseButton(buttons), Qt::NoModifier, QPointF(x, y), delay); return true; } @@ -247,6 +259,10 @@ QWidget *QuickTestEvent::eventWidget() if (!item) return 0; QGraphicsScene *s = item->scene(); + while (!s && item) { + item = qobject_cast<QDeclarativeItem *>(item->parent()); + s = item->scene(); + } if (!s) return 0; QList<QGraphicsView *> views = s->views(); diff --git a/src/quicktestlib/quicktestevent_p.h b/src/quicktestlib/quicktestevent_p.h index 1f5926f..e11f921 100644 --- a/src/quicktestlib/quicktestevent_p.h +++ b/src/quicktestlib/quicktestevent_p.h @@ -50,10 +50,13 @@ QT_BEGIN_NAMESPACE class Q_QUICK_TEST_EXPORT QuickTestEvent : public QObject { Q_OBJECT + Q_PROPERTY(int startDragDistance READ startDragDistance) public: QuickTestEvent(QObject *parent = 0); ~QuickTestEvent(); + static int startDragDistance(); + public Q_SLOTS: bool keyPress(int key, int modifiers, int delay); bool keyRelease(int key, int modifiers, int delay); @@ -67,7 +70,7 @@ public Q_SLOTS: int modifiers, int delay); bool mouseDoubleClick(QObject *item, qreal x, qreal y, int button, int modifiers, int delay); - bool mouseMove(QObject *item, qreal x, qreal y, int delay); + bool mouseMove(QObject *item, qreal x, qreal y, int delay, int buttons); private: QWidget *eventWidget(); |