]> rtime.felk.cvut.cz Git - coffee/qtwebbrowser.git/blob - src/app/touchtracker.h
Use qml extension plugin
[coffee/qtwebbrowser.git] / src / app / touchtracker.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtBrowser project.
7 **
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 2 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.GPLv2 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU General Public License version 2 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 3.0 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 3.0 requirements will be
31 ** met: http://www.gnu.org/copyleft/gpl.html.
32 **
33 **
34 ** $QT_END_LICENSE$
35 **
36 ****************************************************************************/
37
38 #ifndef TOUCHTRACKER_H
39 #define TOUCHTRACKER_H
40
41 #include <QObject>
42 #include <QQuickItem>
43
44 class TouchTracker : public QQuickItem
45 {
46     Q_OBJECT
47     Q_PROPERTY(qreal touchX READ touchX NOTIFY touchChanged)
48     Q_PROPERTY(qreal touchY READ touchY NOTIFY touchChanged)
49     Q_PROPERTY(int xVelocity READ xVelocity NOTIFY velocityChanged)
50     Q_PROPERTY(int yVelocity READ yVelocity NOTIFY velocityChanged)
51     Q_PROPERTY(bool blockEvents READ blockEvents WRITE setBlockEvents NOTIFY blockEventsChanged)
52     Q_PROPERTY(QQuickItem* target READ target WRITE setTarget NOTIFY targetChanged)
53
54     struct PositionInfo
55     {
56         QPointF pos;
57         qint64 ts;
58         qreal x() const { return pos.x(); }
59         qreal y() const { return pos.y(); }
60     };
61
62 public:
63     TouchTracker(QQuickItem *parent = 0);
64
65     qreal touchX() const;
66     qreal touchY() const;
67     int xVelocity() const;
68     int yVelocity() const;
69     QQuickItem* target() const;
70     bool blockEvents() const;
71     void setBlockEvents(bool shouldBlock);
72     void setTarget(QQuickItem * target);
73
74 signals:
75     void touchChanged();
76     void blockEventsChanged();
77     void targetChanged();
78     void touchBegin();
79     void touchEnd();
80     void velocityChanged();
81     void scrollDirectionChanged();
82
83 protected:
84     bool eventFilter(QObject *obj, QEvent *event);
85     void touchEvent(QTouchEvent *event) override;
86
87 private:
88     bool m_blockEvents;
89     int m_diff;
90     int m_previousY;
91     PositionInfo m_startPoint;
92     PositionInfo m_currentPoint;
93     QQuickItem *m_target;
94     QQuickItem *m_delegate;
95 };
96
97 #endif // TOUCHTRACKER_H