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 #pragma once
9 
10 #include <kwidgetsaddons_export.h>
11 
12 #include <QGesture>
13 #include <QGestureRecognizer>
14 #include <memory>
15 
16 /**
17  * @class KTwoFingerTap ktwofingertap.h KTwoFingerTap
18  *
19  * @short A two finger tap gesture.
20  *
21  * Provides a class for a two finger tap gesture.
22  *
23  * Note: The QGestureManager need a QMainwindow, to delivery the gesture.
24  *
25  * @since 5.83
26  * @author Steffen Hartleib <steffenhartleib@t-online.de>
27  */
28 class KWIDGETSADDONS_EXPORT KTwoFingerTap : public QGesture
29 {
30     Q_OBJECT
31     Q_PROPERTY(QPointF pos READ pos WRITE setPos)
32     Q_PROPERTY(QPointF screenPos READ screenPos WRITE setScreenPos)
33     Q_PROPERTY(QPointF scenePos READ scenePos WRITE setScenePos)
34 public:
35     /**
36      * The constructor.
37      */
38     explicit KTwoFingerTap(QObject *parent = nullptr);
39 
40     /**
41      * Destructor
42      */
43     ~KTwoFingerTap() override;
44 
45     /**
46      * The position of the gesture, relative to the widget that received the gesture.
47      *
48      * Note: This is not necessarily the same position as in the widget that grabGesture() uses.
49      *
50      * @return The position of the gesture.
51      */
52     Q_REQUIRED_RESULT QPointF pos() const;
53 
54     /**
55      * Sets the position, relative to the widget.
56      *
57      * @param pos The position.
58      */
59     void setPos(QPointF pos);
60 
61     /**
62      * Sets the screen position.
63      *
64      * @param screenPos The screen position.
65      */
66     Q_REQUIRED_RESULT QPointF screenPos() const;
67 
68     /**
69      * @return The start scene position of the gesture.
70      */
71     void setScreenPos(QPointF screenPos);
72 
73     /**
74      * @return The start scene position of the gesture.
75      */
76     Q_REQUIRED_RESULT QPointF scenePos() const;
77 
78     /**
79      * Sets the scene position.
80      *
81      * @param scenePos The scene position, identical to the screen position for widgets.
82      */
83     void setScenePos(QPointF scenePos);
84 private:
85     std::unique_ptr<class KTwoFingerTapPrivate> const d;
86 };
87 
88 /**
89  * @class KTwoFingerTapRecognizer ktwofingertaprecognizer.h KTwoFingerTapRecognizer
90  *
91  * @short The recognizer for a two finger tap gesture.
92  *
93  * Provides the recognizer for a two finger tap gesture.
94  *
95  * @since 5.83
96  * @author Steffen Hartleib <steffenhartleib@t-online.de>
97  */
98 class KWIDGETSADDONS_EXPORT KTwoFingerTapRecognizer : public QGestureRecognizer
99 {
100 public:
101     /**
102      * The constructor.
103      */
104     KTwoFingerTapRecognizer();
105 
106     /**
107      * Destructor
108      */
109     ~KTwoFingerTapRecognizer() override;
110 
111     /**
112      * Qt called this member to create a new QGesture object.
113      *
114      * @param target The target for the gesture.
115      *
116      * @return The new QGesture object.
117      */
118     QGesture* create(QObject *target) override;
119 
120     /**
121      * Handles the given event for the watched object and update the gesture object.
122      *
123      * @param gesture The gesture object.
124      * @param watched The watched object.
125      * @param event The event.
126      *
127      * @return The result reflects how much of the gesture has been recognized.
128      */
129     Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override;
130 
131     /**
132      * @return The maximum wiggle room for a touch point.
133      */
134     Q_REQUIRED_RESULT int tapRadius() const;
135 
136     /**
137      * Set the maximum wiggle room for a touch point. If @param i is negative, it will be set to null.
138      *
139      * @param i The maximum wiggle room.
140      */
141     void setTapRadius(int i);
142 
143 private:
144     std::unique_ptr<class KTwoFingerTapRecognizerPrivate> const d;
145     Q_DISABLE_COPY(KTwoFingerTapRecognizer)
146 };
147