Debian Codegraph @

tests/unit/swipearea13/GestureTest.h

raw
1 /*
2 * Copyright 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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #ifndef GESTURETEST_H
18 #define GESTURETEST_H
19
20 #include <functional>
21
22 #include <QtGui/QTouchEvent>
23 #include <QtQuick/QQuickItem>
24 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
25 #include <LomiriGestures-Qt6/lomirigesturesglobal.h>
26 #else
27 #include <LomiriGestures/lomirigesturesglobal.h>
28 #endif
29
30 class LomiriTestCase;
31 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
32 class QTouchDevice;
33 #else
34 class QPointingDevice;
35 #endif
36
37 UG_FORWARD_DECLARE_CLASS(FakeTimerFactory)
38 UG_FORWARD_DECLARE_CLASS(TouchRegistry)
39
40 /*
41 The common stuff among tests come here
42 */
43
44 class TouchMemento {
45 public:
46 TouchMemento(const QTouchEvent *touchEvent);
47 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
48 Qt::TouchPointStates touchPointStates;
49 QList<QTouchEvent::TouchPoint> touchPoints;
50 #else
51 QEventPoint::States touchPointStates;
52 QList<QEventPoint> touchPoints;
53 #endif
54
55 bool containsTouchWithId(int touchId) const;
56 };
57
58 class DummyItem : public QQuickItem
59 {
60 Q_OBJECT
61 public:
62 DummyItem(QQuickItem *parent = 0);
63
64 QList<TouchMemento> touchEvents;
65 std::function<void(QTouchEvent*)> touchEventHandler;
66 std::function<void(QMouseEvent*)> mousePressEventHandler;
67 std::function<void(QMouseEvent*)> mouseMoveEventHandler;
68 std::function<void(QMouseEvent*)> mouseReleaseEventHandler;
69 std::function<void(QMouseEvent*)> mouseDoubleClickEventHandler;
70 protected:
71 void touchEvent(QTouchEvent *event) override;
72
73 void mousePressEvent(QMouseEvent *event) override;
74 void mouseMoveEvent(QMouseEvent *event) override;
75 void mouseReleaseEvent(QMouseEvent *event) override;
76 void mouseDoubleClickEvent(QMouseEvent *event) override;
77 private:
78 static void defaultTouchEventHandler(QTouchEvent *event);
79 static void defaultMouseEventHandler(QMouseEvent *event);
80 };
81
82 class GestureTest : public QObject
83 {
84 Q_OBJECT
85 public:
86 // \param qmlFilename name of the qml file to be loaded by the QQuickView
87 GestureTest(const QString &qmlFilename);
88
89 protected Q_SLOTS:
90 void initTestCase(); // will be called before the first test function is executed
91 virtual void init(); // called right before each and every test function is executed
92 virtual void cleanup(); // called right after each and every test function is executed
93
94 protected:
95 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
96 QTouchDevice *m_device;
97 #else
98 QPointingDevice *m_device;
99 #endif
100 LomiriTestCase *m_view;
101 TouchRegistry *m_touchRegistry;
102 UG_PREPEND_NAMESPACE(FakeTimerFactory) *m_fakeTimerFactory;
103 QString m_qmlFilename;
104 };
105
106 #endif // GESTURETEST_H