1
/***************************************************************************
3
** Copyright (C) 2011 - 2013 Research In Motion
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the Qt3D module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#include <QtTest/QtTest>
43
#include <QtQuick/qquickview.h>
44
#include <QtQml/qqmlengine.h>
45
#include <QtQml/qqmlcontext.h>
47
#include <qpa/qwindowsysteminterface.h>
49
class tst_Picking : public QObject
58
void cleanupTestCase();
59
void testWithNavigation();
60
void testWithoutNavigation();
67
QQuickItem *rootObject;
71
void tst_Picking::initTestCase()
73
window = new QQuickView(0);
74
window->setSource(QUrl::fromLocalFile(QFINDTESTDATA("data/tst_picking.qml")));
75
window->setGeometry(0,0,480,480);
77
QTest::qWaitForWindowExposed(window);
78
rootObject = window->rootObject();
81
void tst_Picking::cleanupTestCase()
86
void tst_Picking::testWithNavigation()
88
rootObject->setProperty("navigation", true);
92
void tst_Picking::testWithoutNavigation()
94
rootObject->setProperty("navigation", false);
98
void tst_Picking::testMouse()
100
QTest::mousePress(window, Qt::LeftButton, 0, QPoint(240, 90));
101
QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(240, 90), 300);
103
QTRY_COMPARE(rootObject->property("pickedObjectPressed").toString(), QString("first"));
104
QTRY_COMPARE(rootObject->property("pickedObjectClicked").toString(), QString("first"));
105
QTRY_COMPARE(rootObject->property("pickedObjectReleased").toString(), QString("first"));
107
QTest::mousePress(window, Qt::LeftButton, 0, QPoint(240, 320));
108
QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(240, 240),300);
110
QTRY_COMPARE(rootObject->property("pickedObjectPressed").toString(), QString("second"));
111
QTRY_COMPARE(rootObject->property("pickedObjectClicked").toString(), QString("first"));
112
QTRY_COMPARE(rootObject->property("pickedObjectReleased").toString(), QString("second"));
114
QTest::mousePress(window, Qt::LeftButton, 0, QPoint(20, 100));
115
QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(20, 100), 300);
117
QTRY_COMPARE(rootObject->property("pickedObjectPressed").toString(), QString("second"));
118
QTRY_COMPARE(rootObject->property("pickedObjectClicked").toString(), QString("first"));
119
QTRY_COMPARE(rootObject->property("pickedObjectReleased").toString(), QString("second"));
122
void tst_Picking::testMove()
124
rootObject->setProperty("hoveredObject", "");
125
QTest::mouseMove(window, QPoint(240, 90));
126
QTRY_COMPARE(rootObject->property("hoveredObject").toString(), QString("first"));
128
QTest::mouseMove(window, QPoint(240, 200));
129
QTRY_COMPARE(rootObject->property("hoveredObject").toString(), QString(""));
132
QTEST_MAIN(tst_Picking)
134
#include "tst_picking.moc"