aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2012-03-13 11:47:59 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-04 10:12:10 +0200
commitb9c039b3ac76d20ffe2d05259d5406b7c1bac25d (patch)
tree56cd88fe36d29a19b22f31212924bd5eb023b161
parent8a80f76fd6591b0553c5e9574a5f04cd3bebb659 (diff)
Improve mouseWheel() function
Use new angleDela() API and update the documentation. Change-Id: Ie01c979d8c411e81165caedc7e020e39f9d64371 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r--src/imports/testlib/TestCase.qml12
-rw-r--r--src/imports/testlib/testcase.qdoc46
-rw-r--r--src/qmltest/quicktestevent.cpp8
-rw-r--r--src/qmltest/quicktestevent_p.h2
-rw-r--r--tests/auto/qmltest/events/tst_wheel.qml6
5 files changed, 55 insertions, 19 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 883a864e59..9060ecc3b3 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -455,18 +455,18 @@ Item {
qtest_fail("window not shown", 2)
}
- function mouseWheel(item, x, y, delta, buttons, modifiers, delay, orientation) {
+ function mouseWheel(item, x, y, xDelta, yDelta, buttons, modifiers, delay) {
if (delay == undefined)
delay = -1
if (buttons == undefined)
buttons = Qt.NoButton
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delta == undefined)
- delta = 0
- if (orientation == undefined)
- orientation = Qt.Vertical
- if (!qtest_events.mouseWheel(item, x, y, buttons, modifiers, delta, delay, orientation))
+ if (xDelta == undefined)
+ xDelta = 0
+ if (yDelta == undefined)
+ yDelta = 0
+ if (!qtest_events.mouseWheel(item, x, y, buttons, modifiers, xDelta, yDelta, delay))
qtest_fail("window not shown", 2)
}
diff --git a/src/imports/testlib/testcase.qdoc b/src/imports/testlib/testcase.qdoc
index 469614da6d..90fc538539 100644
--- a/src/imports/testlib/testcase.qdoc
+++ b/src/imports/testlib/testcase.qdoc
@@ -515,7 +515,7 @@
If \a item is obscured by another item, or a child of \a item occupies
that position, then the event will be delivered to the other item instead.
- \sa mouseRelease(), mouseClick(), mouseDoubleClick(), mouseMove()
+ \sa mouseRelease(), mouseClick(), mouseDoubleClick(), mouseMove(), mouseDrag(), mouseWheel()
*/
/*!
@@ -531,7 +531,7 @@
If \a item is obscured by another item, or a child of \a item occupies
that position, then the event will be delivered to the other item instead.
- \sa mousePress(), mouseClick(), mouseDoubleClick(), mouseMove()
+ \sa mousePress(), mouseClick(), mouseDoubleClick(), mouseMove(), mouseDrag(), mouseWheel()
*/
/*!
@@ -547,7 +547,7 @@
If \a item is obscured by another item, or a child of \a item occupies
that position, then the event will be delivered to the other item instead.
- \sa mousePress(), mouseRelease(), mouseDoubleClick(), mouseMove()
+ \sa mousePress(), mouseRelease(), mouseDoubleClick(), mouseMove(), mouseDrag(), mouseWheel()
*/
/*!
@@ -563,7 +563,7 @@
If \a item is obscured by another item, or a child of \a item occupies
that position, then the event will be delivered to the other item instead.
- \sa mousePress(), mouseRelease(), mouseClick(), mouseMove()
+ \sa mousePress(), mouseRelease(), mouseClick(), mouseMove(), mouseDrag(), mouseWheel()
*/
/*!
@@ -578,7 +578,43 @@
If \a item is obscured by another item, or a child of \a item occupies
that position, then the event will be delivered to the other item instead.
- \sa mousePress(), mouseRelease(), mouseClick(), mouseDoubleClick()
+ \sa mousePress(), mouseRelease(), mouseClick(), mouseDoubleClick(), mouseDrag(), mouseWheel()
+*/
+
+/*!
+ \qmlmethod TestCase::mouseDrag(item, x, y, dx, dy, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
+
+ Simulates dragging the mouse on an \a item with \a button pressed and an optional \a modifier.
+ The initial drag position is defined by \a x and \a y,
+ and drag distance is defined by \a dx and \a dy. If \a delay is specified,
+ the test will wait for the specified amount of milliseconds before releasing the button.
+
+ The position given by \a x and \a y is transformed from the co-ordinate
+ system of \a item into window co-ordinates and then delivered.
+ If \a item is obscured by another item, or a child of \a item occupies
+ that position, then the event will be delivered to the other item instead.
+
+ Note: this method does not imply a drop action, to make a drop, an additional
+ mouseRelease(item, x + dx, y + dy) is needed.
+
+ \sa mousePress(), mouseClick(), mouseDoubleClick(), mouseMove(), mouseRelease(), mouseWheel()
+*/
+
+/*!
+ \qmlmethod TestCase::mouseWheel(item, x, y, xDelta, yDelta, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
+
+ Simulates rotating the mouse wheel on an \a item with \a button pressed and an optional \a modifier.
+ The position of the wheel event is defined by \a x and \a y.
+ If \a delay is specified, the test will wait for the specified amount of milliseconds before releasing the button.
+
+ The position given by \a x and \a y is transformed from the co-ordinate
+ system of \a item into window co-ordinates and then delivered.
+ If \a item is obscured by another item, or a child of \a item occupies
+ that position, then the event will be delivered to the other item instead.
+
+ The \a xDelta and \a yDelta contain the wheel rotation distance in eighths of a degree. see \l QWheelEvent::angleDelta() for more details.
+
+ \sa mousePress(), mouseClick(), mouseDoubleClick(), mouseMove(), mouseRelease(), mouseDrag(), QWheelEvent::angleDelta()
*/
/*!
diff --git a/src/qmltest/quicktestevent.cpp b/src/qmltest/quicktestevent.cpp
index 9e401c9392..0bbf097ef4 100644
--- a/src/qmltest/quicktestevent.cpp
+++ b/src/qmltest/quicktestevent.cpp
@@ -148,7 +148,7 @@ namespace QtQuickTest
static void mouseWheel(QWindow* window, QObject* item, Qt::MouseButtons buttons,
Qt::KeyboardModifiers stateKey,
- QPointF _pos, int delta, int delay = -1, Qt::Orientation orientation = Qt::Vertical)
+ QPointF _pos, int xDelta, int yDelta, int delay = -1)
{
QTEST_ASSERT(window);
QTEST_ASSERT(item);
@@ -166,7 +166,7 @@ namespace QtQuickTest
QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
- QWheelEvent we(pos, window->mapToGlobal(pos), delta, buttons, stateKey, orientation);
+ QWheelEvent we(pos, window->mapToGlobal(pos), QPoint(0, 0), QPoint(xDelta, yDelta), 0, Qt::Vertical, buttons, stateKey);
QSpontaneKeyEvent::setSpontaneous(&we); // hmmmm
if (!qApp->notify(window, &we))
@@ -190,14 +190,14 @@ bool QuickTestEvent::mousePress
bool QuickTestEvent::mouseWheel(
QObject *item, qreal x, qreal y, int buttons,
- int modifiers, int delta, int delay, int orientation)
+ int modifiers, int xDelta, int yDelta, int delay)
{
QWindow *view = eventWindow();
if (!view)
return false;
QtQuickTest::mouseWheel(view, item, Qt::MouseButtons(buttons),
Qt::KeyboardModifiers(modifiers),
- QPointF(x, y), delta, delay, Qt::Orientation(orientation));
+ QPointF(x, y), xDelta, yDelta, delay);
return true;
}
diff --git a/src/qmltest/quicktestevent_p.h b/src/qmltest/quicktestevent_p.h
index 96a3737d8c..e48dbf4210 100644
--- a/src/qmltest/quicktestevent_p.h
+++ b/src/qmltest/quicktestevent_p.h
@@ -70,7 +70,7 @@ public Q_SLOTS:
bool mouseMove(QObject *item, qreal x, qreal y, int delay, int buttons);
bool mouseWheel(QObject *item, qreal x, qreal y, int buttons,
- int modifiers, int delta, int delay, int orientation);
+ int modifiers, int xDelta, int yDelta, int delay);
private:
QWindow *eventWindow();
diff --git a/tests/auto/qmltest/events/tst_wheel.qml b/tests/auto/qmltest/events/tst_wheel.qml
index 5d2bcc5e03..10c7c62163 100644
--- a/tests/auto/qmltest/events/tst_wheel.qml
+++ b/tests/auto/qmltest/events/tst_wheel.qml
@@ -70,14 +70,14 @@ Rectangle {
when: windowShown // Must have this line for events to work.
function test_wheel() {
- //mouseWheel(item, x, y, delta, buttons = Qt.NoButton, modifiers = Qt.NoModifier, delay = -1, orientation = Qt.Vertical)
- mouseWheel(flick, 200, 200, -120, Qt.NoButton, Qt.NoModifier, -1, Qt.Vertical);
+ //mouseWheel(item, x, y, xDelta, yDelta, buttons = Qt.NoButton, modifiers = Qt.NoModifier, delay = -1)
+ mouseWheel(flick, 200, 200, 0, -120, Qt.NoButton, Qt.NoModifier, -1);
wait(1000);
verify(flick.contentY > 0);
verify(flick.contentX == 0);
flick.contentY = 0;
verify(flick.contentY == 0);
- mouseWheel(flick, 200, 200, -120, Qt.NoButton, Qt.NoModifier, -1, Qt.Horizontal);
+ mouseWheel(flick, 200, 200, -120, 0, Qt.NoButton, Qt.NoModifier, -1);
wait(1000);
verify(flick.contentX > 0);
verify(flick.contentY == 0);