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>
20#include <private/qquickwindow_p.h>
25#include <UbuntuGestures/private/timer_p.h>
26#include <UbuntuGestures/private/touchregistry_p.h>
30GestureTest::GestureTest(const QString &qmlFilename)
31 : QObject(), m_device(nullptr), m_view(nullptr), m_qmlFilename(qmlFilename)
35void GestureTest::initTestCase()
38 m_device = new QTouchDevice;
39 m_device->setType(QTouchDevice::TouchScreen);
40 QWindowSystemInterface::registerTouchDevice(m_device);
44void GestureTest::init()
46 m_view = new QQuickView;
47 m_view->setResizeMode(QQuickView::SizeRootObjectToView);
48 m_view->setSource(QUrl::fromLocalFile(m_qmlFilename));
50 QVERIFY(QTest::qWaitForWindowExposed(m_view));
51 QVERIFY(m_view->rootObject() != 0);
53 m_fakeTimerFactory = new FakeTimerFactory;
55 m_touchRegistry = TouchRegistry::instance();
56 m_touchRegistry->setTimerFactory(m_fakeTimerFactory);
57 m_view->installEventFilter(m_touchRegistry);
59 qApp->processEvents();
62void GestureTest::cleanup()
64 m_view->removeEventFilter(m_touchRegistry);
65 delete m_touchRegistry;
66 m_touchRegistry = nullptr;
68 // TouchRegistry will take down the timer factory along with him
69 // delete m_fakeTimerFactory;
70 m_fakeTimerFactory = nullptr;
76void GestureTest::sendTouchPress(qint64 timestamp, int id, QPointF pos)
78 sendTouch(timestamp, id, pos, Qt::TouchPointPressed, QEvent::TouchBegin);
81void GestureTest::sendTouchUpdate(qint64 timestamp, int id, QPointF pos)
83 sendTouch(timestamp, id, pos, Qt::TouchPointMoved, QEvent::TouchUpdate);
86void GestureTest::sendTouchRelease(qint64 timestamp, int id, QPointF pos)
88 sendTouch(timestamp, id, pos, Qt::TouchPointReleased, QEvent::TouchEnd);
91void GestureTest::sendTouch(qint64 timestamp, int id, QPointF pos,
92 Qt::TouchPointState pointState, QEvent::Type eventType)
94 m_fakeTimerFactory->updateTime(timestamp);
96 QTouchEvent::TouchPoint point;
98 point.setState(pointState);
100 point.setScenePos(pos);
103 QList<QTouchEvent::TouchPoint> points;
106 QTouchEvent touchEvent(eventType, m_device, Qt::NoModifier, Qt::TouchPointPressed, points);
107 QCoreApplication::sendEvent(m_view, &touchEvent);
109 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(m_view);
110 windowPrivate->flushDelayedTouchEvent();
113void GestureTest::passTime(qint64 timeSpanMs)
115 qint64 finalTime = m_fakeTimerFactory->timeSource()->msecsSinceReference() + timeSpanMs;
116 m_fakeTimerFactory->updateTime(finalTime);
119////////////////////////// TouchMemento /////////////////////////////
121TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
122 : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
127bool TouchMemento::containsTouchWithId(int touchId) const
129 for (int i = 0; i < touchPoints.count(); ++i) {
130 if (touchPoints.at(i).id() == touchId) {
137////////////////////////// DummyItem /////////////////////////////
139DummyItem::DummyItem(QQuickItem *parent)
142 touchEventHandler = defaultTouchEventHandler;
143 mousePressEventHandler = defaultMouseEventHandler;
144 mouseMoveEventHandler = defaultMouseEventHandler;
145 mouseReleaseEventHandler = defaultMouseEventHandler;
146 mouseDoubleClickEventHandler = defaultMouseEventHandler;
149void DummyItem::touchEvent(QTouchEvent *event)
151 touchEvents.append(TouchMemento(event));
152 touchEventHandler(event);
155void DummyItem::mousePressEvent(QMouseEvent *event)
157 mousePressEventHandler(event);
160void DummyItem::mouseMoveEvent(QMouseEvent *event)
162 mouseMoveEventHandler(event);
165void DummyItem::mouseReleaseEvent(QMouseEvent *event)
167 mouseReleaseEventHandler(event);
170void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
172 mouseDoubleClickEventHandler(event);
175void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
180void 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