on db7effd help sign in
139 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::SizeRootObjectToView);
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 = TouchRegistry::instance();
55 m_touchRegistry->setTimerFactory(m_fakeTimerFactory);
56 m_view->installEventFilter(m_touchRegistry);
58 qApp->processEvents();
61void GestureTest::cleanup()
63 m_view->removeEventFilter(m_touchRegistry);
64 delete m_touchRegistry;
65 m_touchRegistry = nullptr;
67 // TouchRegistry will take down the timer factory along with him
68 // delete m_fakeTimerFactory;
69 m_fakeTimerFactory = nullptr;
71 delete m_view;
72 m_view = nullptr;
75////////////////////////// TouchMemento /////////////////////////////
77TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
78 : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
83bool TouchMemento::containsTouchWithId(int touchId) const
85 for (int i = 0; i < touchPoints.count(); ++i) {
86 if (touchPoints.at(i).id() == touchId) {
87 return true;
88 }
89 }
90 return false;
93////////////////////////// DummyItem /////////////////////////////
95DummyItem::DummyItem(QQuickItem *parent)
96 : QQuickItem(parent)
98 touchEventHandler = defaultTouchEventHandler;
99 mousePressEventHandler = defaultMouseEventHandler;
100 mouseMoveEventHandler = defaultMouseEventHandler;
101 mouseReleaseEventHandler = defaultMouseEventHandler;
102 mouseDoubleClickEventHandler = defaultMouseEventHandler;
105void DummyItem::touchEvent(QTouchEvent *event)
107 touchEvents.append(TouchMemento(event));
108 touchEventHandler(event);
111void DummyItem::mousePressEvent(QMouseEvent *event)
113 mousePressEventHandler(event);
116void DummyItem::mouseMoveEvent(QMouseEvent *event)
118 mouseMoveEventHandler(event);
121void DummyItem::mouseReleaseEvent(QMouseEvent *event)
123 mouseReleaseEventHandler(event);
126void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
128 mouseDoubleClickEventHandler(event);
131void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
133 event->accept();
136void DummyItem::defaultMouseEventHandler(QMouseEvent *event)
138 event->accept();