Lomiri
Loading...
Searching...
No Matches
TouchDispatcher.h
1/*
2 * Copyright (C) 2014-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 */
16
17#ifndef LOMIRI_TOUCH_DISPATCHER_H
18#define LOMIRI_TOUCH_DISPATCHER_H
19
20#include "LomiriGesturesQmlGlobal.h"
21
22#include <QPointer>
23#include <QQuickItem>
24
25/*
26 Dispatches touches to the given target, converting the touch point
27 coordinates accordingly.
28
29 Also takes care of synthesizing mouse events in case the target
30 doesn't work with touch events.
31 */
32class LOMIRIGESTURESQML_EXPORT TouchDispatcher {
33public:
34 TouchDispatcher();
35
36 void setTargetItem(QQuickItem *target);
37 QQuickItem *targetItem() { return m_targetItem; }
38
39 void dispatch(QTouchDevice *device,
40 Qt::KeyboardModifiers modifiers,
41 const QList<QTouchEvent::TouchPoint> &touchPoints,
42 QWindow *window,
43 ulong timestamp);
44
45 void reset();
46
47 enum Status {
48 NoActiveTouch,
49 DeliveringTouchEvents,
50 DeliveringMouseEvents,
51 TargetRejectedTouches
52 };
53private:
54 void dispatchTouchBegin(
55 QTouchDevice *device,
56 Qt::KeyboardModifiers modifiers,
57 const QList<QTouchEvent::TouchPoint> &touchPoints,
58 QWindow *window,
59 ulong timestamp);
60 void dispatchAsTouch(QEvent::Type eventType,
61 QTouchDevice *device,
62 Qt::KeyboardModifiers modifiers,
63 const QList<QTouchEvent::TouchPoint> &touchPoints,
64 QWindow *window,
65 ulong timestamp);
66 void dispatchAsMouse(
67 QTouchDevice *device,
68 Qt::KeyboardModifiers modifiers,
69 const QList<QTouchEvent::TouchPoint> &touchPoints,
70 ulong timestamp);
71
72 static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
73 QTouchEvent *createQTouchEvent(QEvent::Type eventType,
74 QTouchDevice *device,
75 Qt::KeyboardModifiers modifiers,
76 const QList<QTouchEvent::TouchPoint> &touchPoints,
77 QWindow *window,
78 ulong timestamp);
79 QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::TouchPoint &p,
80 ulong timestamp, Qt::KeyboardModifiers modifiers, bool transformNeeded = true);
81
82 bool checkIfDoubleClicked(ulong newPressEventTimestamp);
83
84 void setStatus(Status status);
85
86 static QEvent::Type resolveEventType(const QList<QTouchEvent::TouchPoint> &touchPoints);
87
88 QPointer<QQuickItem> m_targetItem;
89
90 Status m_status;
91
92 int m_touchMouseId;
93 ulong m_touchMousePressTimestamp;
94};
95
96#endif // LOMIRI_TOUCH_DISPATCHER_H