QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGestureRecognizer.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_GESTURE_RECOGNIZER_H
7#define QSK_GESTURE_RECOGNIZER_H
8
9#include "QskGlobal.h"
10
11#include <qobject.h>
12#include <qnamespace.h>
13#include <memory>
14
15class QQuickItem;
16class QEvent;
17class QMouseEvent;
18
19class QSK_EXPORT QskGestureRecognizer : public QObject
20{
21 Q_OBJECT
22
23 Q_PROPERTY( State state READ state NOTIFY stateChanged )
24 Q_PROPERTY( QQuickItem* watchedItem READ watchedItem WRITE setWatchedItem )
25 Q_PROPERTY( QQuickItem* targetItem READ targetItem WRITE setTargetItem )
26
27 Q_PROPERTY( Qt::MouseButtons acceptedMouseButtons
28 READ acceptedMouseButtons WRITE setAcceptedMouseButtons )
29
30 Q_PROPERTY( int timeout READ timeout WRITE setTimeout )
31
32 using Inherited = QObject;
33
34 public:
35 enum State
36 {
37 Idle,
38 Pending,
39 Accepted
40 };
41
42 Q_ENUM( State )
43
44 QskGestureRecognizer( QObject* parent = nullptr );
45 ~QskGestureRecognizer() override;
46
47 bool eventFilter( QObject*, QEvent* ) override;
48
49 // the item where the gesture happens
50 void setWatchedItem( QQuickItem* );
51 QQuickItem* watchedItem() const;
52
53 // the item processing the gesture events
54 void setTargetItem( QQuickItem* );
55 QQuickItem* targetItem() const;
56
57 // Qt::NoButton means: all buttons accepted
58 void setAcceptedMouseButtons( Qt::MouseButtons );
59 Qt::MouseButtons acceptedMouseButtons() const;
60
61 void setRejectOnTimeout( bool );
62 bool rejectOnTimeout() const;
63
64 void setTimeout( int );
65 int timeout() const;
66
67 // timestamp, when the Idle state had been left
68 quint64 timestampStarted() const;
69
70 void reject();
71 void accept();
72 void abort();
73
74 State state() const;
75
76 virtual bool isAcceptedPos( const QPointF& ) const;
77
78 Q_SIGNALS:
79 void stateChanged( State from, State to );
80
81 protected:
82 void timerEvent( QTimerEvent* ) override;
83
84 /*
85 This API works for single-touch gestures and multi-touch gestures,
86 that can be translated to single positions ( f.e 2 finger swipes ).
87 Once we support more complex inputs ( f.e pinch gesture ) we need to
88 make substantial adjustments here.
89 */
90 virtual void processPress( const QPointF&, quint64 timestamp, bool isFinal );
91 virtual void processMove( const QPointF&, quint64 timestamp );
92 virtual void processRelease( const QPointF&, quint64 timestamp );
93
94 private:
95 bool maybeGesture( const QQuickItem*, const QEvent* );
96 bool processMouseEvent( const QQuickItem*, const QMouseEvent* );
97
98 void setState( State );
99 void reset();
100
101 class PrivateData;
102 std::unique_ptr< PrivateData > m_data;
103};
104
105#endif