on 436b607 help sign in
130 lines 3.4 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "GestureTest.h"
19#include <qpa/qwindowsysteminterface.h>
20#include <QQmlEngine>
21#include <QQuickView>
22#include <QtTest>
24#include <TouchRegistry.h>
26GestureTest::GestureTest(const QString &qmlFilename)
27 : QObject(), m_device(nullptr), m_view(nullptr), m_qmlFilename(qmlFilename)
31void GestureTest::initTestCase()
33 if (!m_device) {
34 m_device = new QTouchDevice;
35 m_device->setType(QTouchDevice::TouchScreen);
36 QWindowSystemInterface::registerTouchDevice(m_device);
37 }
40void GestureTest::init()
42 m_view = new QQuickView;
43 m_view->setResizeMode(QQuickView::SizeViewToRootObject);
44 m_view->engine()->addImportPath(QStringLiteral(UBUNTU_GESTURES_PLUGIN_DIR));
45 m_view->setSource(QUrl::fromLocalFile(m_qmlFilename));
46 m_view->show();
47 QVERIFY(QTest::qWaitForWindowExposed(m_view));
48 QVERIFY(m_view->rootObject() != 0);
50 m_touchRegistry = new TouchRegistry;
51 m_view->installEventFilter(m_touchRegistry);
53 qApp->processEvents();
56void GestureTest::cleanup()
58 m_view->removeEventFilter(m_touchRegistry);
59 delete m_touchRegistry;
60 m_touchRegistry = nullptr;
62 delete m_view;
63 m_view = nullptr;
66////////////////////////// TouchMemento /////////////////////////////
68TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
69 : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
74bool TouchMemento::containsTouchWithId(int touchId) const
76 for (int i = 0; i < touchPoints.count(); ++i) {
77 if (touchPoints.at(i).id() == touchId) {
78 return true;
79 }
80 }
81 return false;
84////////////////////////// DummyItem /////////////////////////////
86DummyItem::DummyItem(QQuickItem *parent)
87 : QQuickItem(parent)
89 touchEventHandler = defaultTouchEventHandler;
90 mousePressEventHandler = defaultMouseEventHandler;
91 mouseMoveEventHandler = defaultMouseEventHandler;
92 mouseReleaseEventHandler = defaultMouseEventHandler;
93 mouseDoubleClickEventHandler = defaultMouseEventHandler;
96void DummyItem::touchEvent(QTouchEvent *event)
98 touchEvents.append(TouchMemento(event));
99 touchEventHandler(event);
102void DummyItem::mousePressEvent(QMouseEvent *event)
104 mousePressEventHandler(event);
107void DummyItem::mouseMoveEvent(QMouseEvent *event)
109 mouseMoveEventHandler(event);
112void DummyItem::mouseReleaseEvent(QMouseEvent *event)
114 mouseReleaseEventHandler(event);
117void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
119 mouseDoubleClickEventHandler(event);
122void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
124 event->accept();
127void DummyItem::defaultMouseEventHandler(QMouseEvent *event)
129 event->accept();