2 * Copyright (C) 2013,2015 Canonical, Ltd.
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.
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.
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/>.
17#include "GestureTest.h"
19#include <qpa/qwindowsysteminterface.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()
37 m_device = new QTouchDevice;
38 m_device->setType(QTouchDevice::TouchScreen);
39 QWindowSystemInterface::registerTouchDevice(m_device);
43void GestureTest::init()
45 m_view = new QQuickView;
46 m_view->setResizeMode(QQuickView::SizeRootObjectToView);
47 m_view->engine()->addImportPath(QStringLiteral(UBUNTU_GESTURES_PLUGIN_DIR));
48 m_view->engine()->addImportPath(QStringLiteral(TESTS_UTILS_MODULES_DIR));
49 m_view->setSource(QUrl::fromLocalFile(m_qmlFilename));
51 QVERIFY(QTest::qWaitForWindowExposed(m_view));
52 QVERIFY(m_view->rootObject() != 0);
54 m_fakeTimerFactory = new FakeTimerFactory;
56 m_touchRegistry = TouchRegistry::instance();
57 m_touchRegistry->setTimerFactory(m_fakeTimerFactory);
58 m_view->installEventFilter(m_touchRegistry);
60 qApp->processEvents();
63void GestureTest::cleanup()
65 m_view->removeEventFilter(m_touchRegistry);
66 delete m_touchRegistry;
67 m_touchRegistry = nullptr;
69 // TouchRegistry will take down the timer factory along with him
70 // delete m_fakeTimerFactory;
71 m_fakeTimerFactory = nullptr;
77////////////////////////// TouchMemento /////////////////////////////
79TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
80 : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
85bool TouchMemento::containsTouchWithId(int touchId) const
87 for (int i = 0; i < touchPoints.count(); ++i) {
88 if (touchPoints.at(i).id() == touchId) {
95////////////////////////// DummyItem /////////////////////////////
97DummyItem::DummyItem(QQuickItem *parent)
100 touchEventHandler = defaultTouchEventHandler;
101 mousePressEventHandler = defaultMouseEventHandler;
102 mouseMoveEventHandler = defaultMouseEventHandler;
103 mouseReleaseEventHandler = defaultMouseEventHandler;
104 mouseDoubleClickEventHandler = defaultMouseEventHandler;
107void DummyItem::touchEvent(QTouchEvent *event)
109 touchEvents.append(TouchMemento(event));
110 touchEventHandler(event);
113void DummyItem::mousePressEvent(QMouseEvent *event)
115 mousePressEventHandler(event);
118void DummyItem::mouseMoveEvent(QMouseEvent *event)
120 mouseMoveEventHandler(event);
123void DummyItem::mouseReleaseEvent(QMouseEvent *event)
125 mouseReleaseEventHandler(event);
128void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
130 mouseDoubleClickEventHandler(event);
133void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
138void DummyItem::defaultMouseEventHandler(QMouseEvent *event)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list