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);
98private:
99 std::unique_ptr<class KTwoFingerSwipePrivate> const d;
100};
101
102/**
103 * @class KTwoFingerSwipeRecognizer ktwofingerswiperecognizer.h KTwoFingerSwipeRecognizer
104 *
105 * @short The recognizer for a two finger swipe gesture.
106 *
107 * Provides the recognizer for a two finger swipe gesture. To adjust the maximum swipe time
108 * and the minimum swipe distance, for a valid swipe gesture:
109 * @see setMaxSwipeTime
110 * @see setSwipeDistance
111 *
112 * @since 5.83
113 * @author Steffen Hartleib <steffenhartleib@t-online.de>
114 */
115class KWIDGETSADDONS_EXPORT KTwoFingerSwipeRecognizer : public QGestureRecognizer
116{
117public:
118 /**
119 * The constructor.
120 */
122
123 /**
124 * Destructor
125 */
127
128 /**
129 * Qt called this member to create a new QGesture object.
130 *
131 * @param target The target for the gesture.
132 *
133 * @return The new QGesture object.
134 */
135 QGesture* create(QObject *target) override;
136
137 /**
138 * Handles the given event for the watched object and update the gesture object.
139 *
140 * @param gesture The gesture object.
141 * @param watched The watched object.
142 * @param event The event.
143 *
144 * @return The result reflects how much of the gesture has been recognized.
145 */
146 Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override;
147
148 /**
149 * @return The maximum duration for the swipe gesture, in milliseconds.
150 */
151 Q_REQUIRED_RESULT int maxSwipeTime() const;
152
153 /**
154 * Set the maximum duration of the swipe gesture. If @param i is negative, it will be set to null.
155 *
156 * @param i The maximum duration in milliseconds.
157 */
158 void setMaxSwipeTime(int i);
159
160 /**
161 * @return The minimum distance for the swipe gesture.
162 */
163 Q_REQUIRED_RESULT int minSswipeDistance() const;
164
165 /**
166 * Set the minimum distance of the swipe gesture. If @param i is negative, it will be set to null.
167 *
168 * @param i The minimum distance.
169 */
170 void setSwipeDistance(int i);
171
172private:
173 std::unique_ptr<class KTwoFingerSwipeRecognizerPrivate> const d;
174 Q_DISABLE_COPY(KTwoFingerSwipeRecognizer)
175};
176
177#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 Jan 24 2025 11:56:58 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.