From ada9dd41c83aad3890b8f01a98fdbeae04528eba Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Thu, 8 Mar 2012 11:27:04 +1000 Subject: [PATCH] Implement mouseDrag Simulates the drag behavior by press-move-move-release mouse events, we need 2 move events here to trigger the drag threshold. Task-number: QTBUG-22753 Change-Id: Ic3470c061834b7410c524029d82375cba62afa36 Reviewed-by: Michael Brasser --- src/imports/testlib/TestCase.qml | 16 ++++++++ src/imports/testlib/main.cpp | 7 ++++ tests/auto/qmltest/events/tst_drag.qml | 74 ++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 tests/auto/qmltest/events/tst_drag.qml diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 0433483..1f9de5e 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -407,6 +407,22 @@ 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 draging + mouseMove(item, x + util.dragThreshold + 1, y + util.dragThreshold + 1, delay, button) + mouseMove(item, x + dx, y + dy, delay, button) + } + function mouseClick(item, x, y, button, modifiers, delay) { if (button === undefined) button = Qt.LeftButton diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp index 6473d21..18039e7 100644 --- a/src/imports/testlib/main.cpp +++ b/src/imports/testlib/main.cpp @@ -48,6 +48,8 @@ #include "private/qtestoptions_p.h" #include "QtQuick/qquickitem.h" #include +#include +#include QML_DECLARE_TYPE(QuickTestResult) QML_DECLARE_TYPE(QuickTestEvent) @@ -61,6 +63,7 @@ class QuickTestUtil : public QObject Q_OBJECT Q_PROPERTY(bool printAvailableFunctions READ printAvailableFunctions NOTIFY printAvailableFunctionsChanged) Q_PROPERTY(bool wrapper READ wrapper NOTIFY wrapperChanged) + Q_PROPERTY(int dragThreshold READ dragThreshold NOTIFY dragThresholdChanged) public: QuickTestUtil(QObject *parent = 0) :QObject(parent) @@ -76,9 +79,13 @@ public: { return true; } + int dragThreshold() const { return qApp->styleHints()->startDragDistance(); } + Q_SIGNALS: void printAvailableFunctionsChanged(); void wrapperChanged(); + void dragThresholdChanged(); + public Q_SLOTS: QQmlV8Handle typeName(const QVariant& v) const diff --git a/tests/auto/qmltest/events/tst_drag.qml b/tests/auto/qmltest/events/tst_drag.qml new file mode 100644 index 0000000..34b9685 --- /dev/null +++ b/tests/auto/qmltest/events/tst_drag.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle{ + id: root + width:200 + height:200 + + Rectangle { + id:container + width:20 + height:20 + color: "blue" + MouseArea { + id:mouseArea; anchors.fill : parent + drag.maximumX: 180 + drag.maximumY: 180 + drag.minimumX: 0 + drag.minimumY: 0 + drag.target: parent + } + } + + TestCase { + name:"mouserelease" + when:windowShown + function test_mouseDrag() { + mouseDrag(container, 10, 10, 20, 30); + compare(container.x, 20); + compare(container.y, 30); + } + } +} \ No newline at end of file -- 2.7.4