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/qquickanimatorcontroller_p.h>
21#include <private/qquickwindow_p.h>
26#include <UbuntuGestures/private/timer_p.h>
27#include <UbuntuGestures/private/touchregistry_p.h>
32GestureTest::GestureTest(const QString &qmlFilename)
33 : QObject(), m_device(nullptr), m_view(nullptr), m_qmlFilename(qmlFilename)
37void GestureTest::initTestCase()
40 m_device = new QTouchDevice;
41 m_device->setType(QTouchDevice::TouchScreen);
42 QWindowSystemInterface::registerTouchDevice(m_device);
46void GestureTest::init()
48 m_view = new QQuickView;
49 m_view->setResizeMode(QQuickView::SizeRootObjectToView);
50 m_view->setSource(QUrl::fromLocalFile(testDataDir() + "/plugins/Ubuntu/Gestures/" + m_qmlFilename));
52 QVERIFY(QTest::qWaitForWindowExposed(m_view));
53 QVERIFY(m_view->rootObject() != 0);
55 m_fakeTimerFactory = new FakeTimerFactory;
57 m_touchRegistry = TouchRegistry::instance();
58 m_touchRegistry->setTimerFactory(m_fakeTimerFactory);
59 m_view->installEventFilter(m_touchRegistry);
61 qApp->processEvents();
64void GestureTest::cleanup()
66 m_view->removeEventFilter(m_touchRegistry);
67 delete m_touchRegistry;
68 m_touchRegistry = nullptr;
70 // TouchRegistry will take down the timer factory along with him
71 // delete m_fakeTimerFactory;
72 m_fakeTimerFactory = nullptr;
78void GestureTest::sendTouchPress(qint64 timestamp, int id, QPointF pos)
80 sendTouch(timestamp, id, pos, Qt::TouchPointPressed, QEvent::TouchBegin);
83void GestureTest::sendTouchUpdate(qint64 timestamp, int id, QPointF pos)
85 sendTouch(timestamp, id, pos, Qt::TouchPointMoved, QEvent::TouchUpdate);
88void GestureTest::sendTouchRelease(qint64 timestamp, int id, QPointF pos)
90 sendTouch(timestamp, id, pos, Qt::TouchPointReleased, QEvent::TouchEnd);
93void GestureTest::sendTouch(qint64 timestamp, int id, QPointF pos,
94 Qt::TouchPointState pointState, QEvent::Type eventType)
96 m_fakeTimerFactory->updateTime(timestamp);
98 QTouchEvent::TouchPoint point;
100 point.setState(pointState);
102 point.setScenePos(pos);
105 QList<QTouchEvent::TouchPoint> points;
108 QTouchEvent touchEvent(eventType, m_device, Qt::NoModifier, Qt::TouchPointPressed, points);
109 QCoreApplication::sendEvent(m_view, &touchEvent);
111 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(m_view);
112 if (windowPrivate->delayedTouch) {
113 windowPrivate->deliverDelayedTouchEvent();
115 // Touch events which constantly start animations (such as a behavior tracking
116 // the mouse point) need animations to start.
117 QQmlAnimationTimer *ut = QQmlAnimationTimer::instance();
118 if (ut && ut->hasStartAnimationPending())
119 ut->startAnimations();
123void GestureTest::passTime(qint64 timeSpanMs)
125 qint64 finalTime = m_fakeTimerFactory->timeSource()->msecsSinceReference() + timeSpanMs;
126 m_fakeTimerFactory->updateTime(finalTime);
129////////////////////////// TouchMemento /////////////////////////////
131TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
132 : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
137bool TouchMemento::containsTouchWithId(int touchId) const
139 for (int i = 0; i < touchPoints.count(); ++i) {
140 if (touchPoints.at(i).id() == touchId) {
147////////////////////////// DummyItem /////////////////////////////
149DummyItem::DummyItem(QQuickItem *parent)
152 touchEventHandler = defaultTouchEventHandler;
153 mousePressEventHandler = defaultMouseEventHandler;
154 mouseMoveEventHandler = defaultMouseEventHandler;
155 mouseReleaseEventHandler = defaultMouseEventHandler;
156 mouseDoubleClickEventHandler = defaultMouseEventHandler;
159void DummyItem::touchEvent(QTouchEvent *event)
161 touchEvents.append(TouchMemento(event));
162 touchEventHandler(event);
165void DummyItem::mousePressEvent(QMouseEvent *event)
167 mousePressEventHandler(event);
170void DummyItem::mouseMoveEvent(QMouseEvent *event)
172 mouseMoveEventHandler(event);
175void DummyItem::mouseReleaseEvent(QMouseEvent *event)
177 mouseReleaseEventHandler(event);
180void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
182 mouseDoubleClickEventHandler(event);
185void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
190void 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