on c8b50e3 help sign in
138 lines 3.6 kB history raw
1/*
2 * Copyright (C) 2013,2015 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 <Timer.h>
25#include <TouchRegistry.h>
27using namespace UbuntuGestures;
29GestureTest::GestureTest(const QString &qmlFilename)
30 : QObject(), m_device(nullptr), m_view(nullptr), m_qmlFilename(qmlFilename)
34void GestureTest::initTestCase()
36 if (!m_device) {
37 m_device = new QTouchDevice;
38 m_device->setType(QTouchDevice::TouchScreen);
39 QWindowSystemInterface::registerTouchDevice(m_device);
40 }
43void GestureTest::init()
45 m_view = new QQuickView;
46 m_view->setResizeMode(QQuickView::SizeViewToRootObject);
47 m_view->setSource(QUrl::fromLocalFile(m_qmlFilename));
48 m_view->show();
49 QVERIFY(QTest::qWaitForWindowExposed(m_view));
50 QVERIFY(m_view->rootObject() != 0);
52 m_fakeTimerFactory = new FakeTimerFactory;
54 m_touchRegistry = new TouchRegistry(nullptr, m_fakeTimerFactory);
55 m_view->installEventFilter(m_touchRegistry);
57 qApp->processEvents();
60void GestureTest::cleanup()
62 m_view->removeEventFilter(m_touchRegistry);
63 delete m_touchRegistry;
64 m_touchRegistry = nullptr;
66 // TouchRegistry will take down the timer factory along with him
67 // delete m_fakeTimerFactory;
68 m_fakeTimerFactory = nullptr;
70 delete m_view;
71 m_view = nullptr;
74////////////////////////// TouchMemento /////////////////////////////
76TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
77 : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
82bool TouchMemento::containsTouchWithId(int touchId) const
84 for (int i = 0; i < touchPoints.count(); ++i) {
85 if (touchPoints.at(i).id() == touchId) {
86 return true;
87 }
88 }
89 return false;
92////////////////////////// DummyItem /////////////////////////////
94DummyItem::DummyItem(QQuickItem *parent)
95 : QQuickItem(parent)
97 touchEventHandler = defaultTouchEventHandler;
98 mousePressEventHandler = defaultMouseEventHandler;
99 mouseMoveEventHandler = defaultMouseEventHandler;
100 mouseReleaseEventHandler = defaultMouseEventHandler;
101 mouseDoubleClickEventHandler = defaultMouseEventHandler;
104void DummyItem::touchEvent(QTouchEvent *event)
106 touchEvents.append(TouchMemento(event));
107 touchEventHandler(event);
110void DummyItem::mousePressEvent(QMouseEvent *event)
112 mousePressEventHandler(event);
115void DummyItem::mouseMoveEvent(QMouseEvent *event)
117 mouseMoveEventHandler(event);
120void DummyItem::mouseReleaseEvent(QMouseEvent *event)
122 mouseReleaseEventHandler(event);
125void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
127 mouseDoubleClickEventHandler(event);
130void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
132 event->accept();
135void DummyItem::defaultMouseEventHandler(QMouseEvent *event)
137 event->accept();