~mterry/unity8/power-button-on-lock

« back to all changes in this revision

Viewing changes to plugins/Ubuntu/Gestures/TouchDispatcher.h

  • Committer: Michael Terry
  • Date: 2014-11-24 15:25:42 UTC
  • mfrom: (1368.1.82 unity8)
  • Revision ID: michael.terry@canonical.com-20141124152542-5cysva8ds3qfula6
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 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 UBUNTU_TOUCH_DISPATCHER_H
 
18
#define UBUNTU_TOUCH_DISPATCHER_H
 
19
 
 
20
#include "UbuntuGesturesQmlGlobal.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
 */
 
32
class UBUNTUGESTURESQML_EXPORT TouchDispatcher {
 
33
public:
 
34
    TouchDispatcher();
 
35
 
 
36
    void setTargetItem(QQuickItem *target);
 
37
    QQuickItem *targetItem() { return m_targetItem; }
 
38
 
 
39
    void dispatch(QEvent::Type eventType,
 
40
            QTouchDevice *device,
 
41
            Qt::KeyboardModifiers modifiers,
 
42
            const QList<QTouchEvent::TouchPoint> &touchPoints,
 
43
            QWindow *window,
 
44
            ulong timestamp);
 
45
private:
 
46
    void dispatchTouchBegin(
 
47
            QTouchDevice *device,
 
48
            Qt::KeyboardModifiers modifiers,
 
49
            const QList<QTouchEvent::TouchPoint> &touchPoints,
 
50
            QWindow *window,
 
51
            ulong timestamp);
 
52
    void dispatchAsTouch(QEvent::Type eventType,
 
53
            QTouchDevice *device,
 
54
            Qt::KeyboardModifiers modifiers,
 
55
            const QList<QTouchEvent::TouchPoint> &touchPoints,
 
56
            QWindow *window,
 
57
            ulong timestamp);
 
58
    void dispatchAsMouse(
 
59
            QTouchDevice *device,
 
60
            Qt::KeyboardModifiers modifiers,
 
61
            const QList<QTouchEvent::TouchPoint> &touchPoints,
 
62
            ulong timestamp);
 
63
 
 
64
    static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
 
65
    QTouchEvent *createQTouchEvent(QEvent::Type eventType,
 
66
            QTouchDevice *device,
 
67
            Qt::KeyboardModifiers modifiers,
 
68
            const QList<QTouchEvent::TouchPoint> &touchPoints,
 
69
            QWindow *window,
 
70
            ulong timestamp);
 
71
    QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::TouchPoint &p,
 
72
            ulong timestamp, Qt::KeyboardModifiers modifiers, bool transformNeeded = true);
 
73
 
 
74
    bool checkIfDoubleClicked(ulong newPressEventTimestamp);
 
75
 
 
76
    QPointer<QQuickItem> m_targetItem;
 
77
 
 
78
    enum {
 
79
        NoActiveTouch,
 
80
        DeliveringTouchEvents,
 
81
        DeliveringMouseEvents,
 
82
        TargetRejectedTouches
 
83
    } m_status;
 
84
 
 
85
    int m_touchMouseId;
 
86
    ulong m_touchMousePressTimestamp;
 
87
};
 
88
 
 
89
#endif // UBUNTU_TOUCH_DISPATCHER_H