Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 <michael.brasser@nokia.com>
  • Loading branch information
yinyunqiao authored and Qt by Nokia committed Mar 13, 2012
1 parent b262e81 commit ada9dd4
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/imports/testlib/TestCase.qml
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/imports/testlib/main.cpp
Expand Up @@ -48,6 +48,8 @@
#include "private/qtestoptions_p.h"
#include "QtQuick/qquickitem.h"
#include <QtQml/private/qqmlengine_p.h>
#include <QtGui/QGuiApplication>
#include <QtGui/qstylehints.h>

QML_DECLARE_TYPE(QuickTestResult)
QML_DECLARE_TYPE(QuickTestEvent)
Expand All @@ -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)
Expand All @@ -76,9 +79,13 @@ class QuickTestUtil : public QObject
{
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
Expand Down
74 changes: 74 additions & 0 deletions 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);
}
}
}

0 comments on commit ada9dd4

Please sign in to comment.