From b40a2a881291b3eaea4b4834a162091537e6a34e Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 9 Jan 2015 10:49:47 +0100 Subject: Test: make mouse press, release, click and double click default to the center of the item Most of the times you just want to act on the item not caring the position. This helps for cleaner test code Change-Id: I0e8a4919c503e3fd6dee60e1bd937ac57622279f Reviewed-by: Simon Hausmann Reviewed-by: Christopher Adams Reviewed-by: Michael Brasser --- src/imports/testlib/TestCase.qml | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/imports/testlib/TestCase.qml') diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 5366748082..8425b0641c 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -934,12 +934,13 @@ Item { } /*! - \qmlmethod TestCase::mousePress(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) + \qmlmethod TestCase::mousePress(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) Simulates pressing a mouse \a button with an optional \a modifier - on an \a item. The position is defined by \a x and \a y. If \a delay is - specified, the test will wait for the specified amount of milliseconds - before the press. + on an \a item. The position is defined by \a x and \a y. + If \a x or \a y are not defined the position will be the center of \a item. + If \a delay is specified, the test will wait for the specified amount of + milliseconds before the press. 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. @@ -955,15 +956,20 @@ Item { modifiers = Qt.NoModifier if (delay == undefined) delay = -1 + if (x === undefined) + x = item.width / 2 + if (y === undefined) + y = item.height / 2 if (!qtest_events.mousePress(item, x, y, button, modifiers, delay)) qtest_fail("window not shown", 2) } /*! - \qmlmethod TestCase::mouseRelease(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) + \qmlmethod TestCase::mouseRelease(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) Simulates releasing a mouse \a button with an optional \a modifier on an \a item. The position of the release is defined by \a x and \a y. + If \a x or \a y are not defined the position will be the center of \a item. If \a delay is specified, the test will wait for the specified amount of milliseconds before releasing the button. @@ -981,6 +987,10 @@ Item { modifiers = Qt.NoModifier if (delay == undefined) delay = -1 + if (x === undefined) + x = item.width / 2 + if (y === undefined) + y = item.height / 2 if (!qtest_events.mouseRelease(item, x, y, button, modifiers, delay)) qtest_fail("window not shown", 2) } @@ -1035,10 +1045,11 @@ Item { } /*! - \qmlmethod TestCase::mouseClick(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) + \qmlmethod TestCase::mouseClick(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) Simulates clicking a mouse \a button with an optional \a modifier on an \a item. The position of the click is defined by \a x and \a y. + If \a x and \a y are not defined the position will be the center of \a item. If \a delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button. @@ -1056,15 +1067,20 @@ Item { modifiers = Qt.NoModifier if (delay == undefined) delay = -1 + if (x === undefined) + x = item.width / 2 + if (y === undefined) + y = item.height / 2 if (!qtest_events.mouseClick(item, x, y, button, modifiers, delay)) qtest_fail("window not shown", 2) } /*! - \qmlmethod TestCase::mouseDoubleClick(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) + \qmlmethod TestCase::mouseDoubleClick(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1) Simulates double-clicking a mouse \a button with an optional \a modifier on an \a item. The position of the click is defined by \a x and \a y. + If \a x and \a y are not defined the position will be the center of \a item. If \a delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button. @@ -1082,6 +1098,10 @@ Item { modifiers = Qt.NoModifier if (delay == undefined) delay = -1 + if (x === undefined) + x = item.width / 2 + if (y === undefined) + y = item.height / 2 if (!qtest_events.mouseDoubleClick(item, x, y, button, modifiers, delay)) qtest_fail("window not shown", 2) } -- cgit v1.2.3