KWidgetsAddons

ktwofingerswipe.h
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 ktwofingerswipe.h KTwoFingerSwipe
19 *
20 * @short 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 * @author Steffen Hartleib <steffenhartleib@t-online.de>
28 */
29class KWIDGETSADDONS_EXPORT KTwoFingerSwipe : public QGesture
30{
32 Q_PROPERTY(QPointF pos READ pos WRITE setPos)
33 Q_PROPERTY(QPointF screenPos READ screenPos WRITE setScreenPos)
34 Q_PROPERTY(QPointF scenePos READ scenePos WRITE setScenePos)
35 Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle)
36public:
37 /**
38 * The constructor.
39 */
40 explicit KTwoFingerSwipe(QObject *parent = nullptr);
41
42 /**
43 * Destructor
44 */
45 ~KTwoFingerSwipe() override;
46
47 /**
48 * The start position of the gesture, relative to the widget that received the gesture.
49 *
50 * Note: This is not necessarily the same position as in the widget that grabGesture() uses.
51 *
52 * @return The start position of the gesture, relative to the widget.
53 */
54 Q_REQUIRED_RESULT QPointF pos() const;
55
56 /**
57 * Sets the position, relative to the widget.
58 *
59 * @param pos The position.
60 */
61 void setPos(QPointF pos);
62
63 /**
64 * @return The start screen position of the gesture.
65 */
66 Q_REQUIRED_RESULT QPointF screenPos() const;
67
68 /**
69 * Sets the screen position.
70 *
71 * @param screenPos The screen position.
72 */
73 void setScreenPos(QPointF screenPos);
74
75 /**
76 * @return The start scene position of the gesture.
77 */
78 Q_REQUIRED_RESULT QPointF scenePos() const;
79
80 /**
81 * Sets the scene position.
82 *
83 * @param scenePos The scene position, identical to the screen position for widgets.
84 */
85 void setScenePos(QPointF scenePos);
86
87 /**
88 * @return The angle of the swipe gesture.
89 */
90 Q_REQUIRED_RESULT qreal swipeAngle() const;
91
92 /**
93 * Sets the angle of the swipe gesture
94 *
95 * @param swipeAngle The angle.
96 */
97 void setSwipeAngle(qreal swipeAngle);
98
99private:
100 std::unique_ptr<class KTwoFingerSwipePrivate> const d;
101};
102
103/**
104 * @class KTwoFingerSwipeRecognizer ktwofingerswiperecognizer.h KTwoFingerSwipeRecognizer
105 *
106 * @short The recognizer for a two finger swipe gesture.
107 *
108 * Provides the recognizer for a two finger swipe gesture. To adjust the maximum swipe time
109 * and the minimum swipe distance, for a valid swipe gesture:
110 * @see setMaxSwipeTime
111 * @see setSwipeDistance
112 *
113 * @since 5.83
114 * @author Steffen Hartleib <steffenhartleib@t-online.de>
115 */
116class KWIDGETSADDONS_EXPORT KTwoFingerSwipeRecognizer : public QGestureRecognizer
117{
118public:
119 /**
120 * The constructor.
121 */
123
124 /**
125 * Destructor
126 */
128
129 /**
130 * Qt called this member to create a new QGesture object.
131 *
132 * @param target The target for the gesture.
133 *
134 * @return The new QGesture object.
135 */
136 QGesture *create(QObject *target) override;
137
138 /**
139 * Handles the given event for the watched object and update the gesture object.
140 *
141 * @param gesture The gesture object.
142 * @param watched The watched object.
143 * @param event The event.
144 *
145 * @return The result reflects how much of the gesture has been recognized.
146 */
147 Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override;
148
149 /**
150 * @return The maximum duration for the swipe gesture, in milliseconds.
151 */
152 Q_REQUIRED_RESULT int maxSwipeTime() const;
153
154 /**
155 * Set the maximum duration of the swipe gesture. If @param i is negative, it will be set to null.
156 *
157 * @param i The maximum duration in milliseconds.
158 */
159 void setMaxSwipeTime(int i);
160
161 /**
162 * @return The minimum distance for the swipe gesture.
163 */
164 Q_REQUIRED_RESULT int minSswipeDistance() const;
165
166 /**
167 * Set the minimum distance of the swipe gesture. If @param i is negative, it will be set to null.
168 *
169 * @param i The minimum distance.
170 */
171 void setSwipeDistance(int i);
172
173private:
174 std::unique_ptr<class KTwoFingerSwipeRecognizerPrivate> const d;
175 Q_DISABLE_COPY(KTwoFingerSwipeRecognizer)
176};
177
178#endif
QGesture * create(QObject *target) override
Qt called this member to create a new QGesture object.
KTwoFingerSwipeRecognizer()
The constructor.
void setMaxSwipeTime(int i)
Set the maximum duration of the swipe gesture.
Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override
Handles the given event for the watched object and update the gesture object.
void setSwipeDistance(int i)
Set the minimum distance of the swipe gesture.
KTwoFingerSwipe(QObject *parent=nullptr)
The constructor.
void setScenePos(QPointF scenePos)
Sets the scene position.
void setPos(QPointF pos)
Sets the position, relative to the widget.
void setSwipeAngle(qreal swipeAngle)
Sets the angle of the swipe gesture.
void setScreenPos(QPointF screenPos)
Sets the screen position.
QGesture(QObject *parent)
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:02:04 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.