1 | /* |
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-or-later |
6 | */ |
7 | |
8 | #ifndef KTWOFINGERSWIPE_H |
9 | #define KTWOFINGERSWIPE_H |
10 | |
11 | #include <kwidgetsaddons_export.h> |
12 | |
13 | #include <QGesture> |
14 | #include <QGestureRecognizer> |
15 | #include <memory> |
16 | |
17 | /*! |
18 | * \class KTwoFingerSwipe |
19 | * |
20 | * \brief A two finger swipe gesture. |
21 | * |
22 | * Provides a class for a two finger swipe gesture. |
23 | * |
24 | * Note: The QGestureManager need a QMainwindow, to delivery the gesture. |
25 | * |
26 | * \since 5.83 |
27 | */ |
28 | class KWIDGETSADDONS_EXPORT KTwoFingerSwipe : public QGesture |
29 | { |
30 | Q_OBJECT |
31 | |
32 | /*! |
33 | * \property KTwoFingerSwipe::pos |
34 | */ |
35 | Q_PROPERTY(QPointF pos READ pos WRITE setPos) |
36 | |
37 | /*! |
38 | * \property KTwoFingerSwipe::screenPos |
39 | */ |
40 | Q_PROPERTY(QPointF screenPos READ screenPos WRITE setScreenPos) |
41 | |
42 | /*! |
43 | * \property KTwoFingerSwipe::scenePos |
44 | */ |
45 | Q_PROPERTY(QPointF scenePos READ scenePos WRITE setScenePos) |
46 | |
47 | /*! |
48 | * \property KTwoFingerSwipe::swipeAngle |
49 | */ |
50 | Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle) |
51 | public: |
52 | /*! |
53 | * The constructor. |
54 | */ |
55 | explicit KTwoFingerSwipe(QObject *parent = nullptr); |
56 | |
57 | ~KTwoFingerSwipe() override; |
58 | |
59 | /*! |
60 | * Returns the start position of the gesture, relative to the widget that received the gesture. |
61 | * |
62 | * \note This is not necessarily the same position as in the widget that grabGesture() uses. |
63 | */ |
64 | Q_REQUIRED_RESULT QPointF pos() const; |
65 | |
66 | /*! |
67 | * Sets the position, relative to the widget. |
68 | * |
69 | * \a pos The position. |
70 | */ |
71 | void setPos(QPointF pos); |
72 | |
73 | /*! |
74 | * Returns the start screen position of the gesture. |
75 | */ |
76 | Q_REQUIRED_RESULT QPointF screenPos() const; |
77 | |
78 | /*! |
79 | * Sets the screen position. |
80 | * |
81 | * \a screenPos The screen position. |
82 | */ |
83 | void setScreenPos(QPointF screenPos); |
84 | |
85 | /*! |
86 | * Return the start scene position of the gesture. |
87 | */ |
88 | Q_REQUIRED_RESULT QPointF scenePos() const; |
89 | |
90 | /*! |
91 | * Sets the scene position. |
92 | * |
93 | * \a scenePos The scene position, identical to the screen position for widgets. |
94 | */ |
95 | void setScenePos(QPointF scenePos); |
96 | |
97 | /*! |
98 | * Returns the angle of the swipe gesture. |
99 | */ |
100 | Q_REQUIRED_RESULT qreal swipeAngle() const; |
101 | |
102 | /*! |
103 | * Sets the angle of the swipe gesture |
104 | * |
105 | * \a swipeAngle The angle. |
106 | */ |
107 | void setSwipeAngle(qreal swipeAngle); |
108 | |
109 | private: |
110 | std::unique_ptr<class KTwoFingerSwipePrivate> const d; |
111 | }; |
112 | |
113 | /*! |
114 | * \class KTwoFingerSwipeRecognizer |
115 | * \inmodule KWidgetsAddons |
116 | * \inheaderfile KTwoFingerSwipe |
117 | * |
118 | * \brief The recognizer for a two finger swipe gesture. |
119 | * |
120 | * Provides the recognizer for a two finger swipe gesture. To adjust the maximum swipe time |
121 | * and the minimum swipe distance, for a valid swipe gesture: |
122 | * \sa setMaxSwipeTime |
123 | * \sa setSwipeDistance |
124 | * |
125 | * \since 5.83 |
126 | */ |
127 | class KWIDGETSADDONS_EXPORT KTwoFingerSwipeRecognizer : public QGestureRecognizer |
128 | { |
129 | public: |
130 | /*! |
131 | * The constructor. |
132 | */ |
133 | KTwoFingerSwipeRecognizer(); |
134 | |
135 | ~KTwoFingerSwipeRecognizer() override; |
136 | |
137 | /*! |
138 | * Qt called this member to create a new QGesture object. |
139 | * |
140 | * \a target The target for the gesture. |
141 | * |
142 | * Returns the new QGesture object. |
143 | */ |
144 | QGesture *create(QObject *target) override; |
145 | |
146 | /*! |
147 | * Handles the given event for the watched object and update the gesture object. |
148 | * |
149 | * \a gesture The gesture object. |
150 | * |
151 | * \a watched The watched object. |
152 | * |
153 | * \a event The event. |
154 | * |
155 | * Returns the result reflects how much of the gesture has been recognized. |
156 | */ |
157 | Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override; |
158 | |
159 | /*! |
160 | * Returns the maximum duration for the swipe gesture, in milliseconds. |
161 | */ |
162 | Q_REQUIRED_RESULT int maxSwipeTime() const; |
163 | |
164 | /*! |
165 | * Set the maximum duration of the swipe gesture. If \a i is negative, it will be set to null. |
166 | * |
167 | * \a i The maximum duration in milliseconds. |
168 | */ |
169 | void setMaxSwipeTime(int i); |
170 | |
171 | /*! |
172 | * Returns the minimum distance for the swipe gesture. |
173 | */ |
174 | Q_REQUIRED_RESULT int minSswipeDistance() const; |
175 | |
176 | /*! |
177 | * Set the minimum distance of the swipe gesture. If \a i is negative, it will be set to null. |
178 | * |
179 | * \a i The minimum distance. |
180 | */ |
181 | void setSwipeDistance(int i); |
182 | |
183 | private: |
184 | std::unique_ptr<class KTwoFingerSwipeRecognizerPrivate> const d; |
185 | Q_DISABLE_COPY(KTwoFingerSwipeRecognizer) |
186 | }; |
187 | |
188 | #endif |
189 | |