File indexing completed on 2025-02-02 14:20:12
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef KTWOFINGERSWIPE_H 0009 #define KTWOFINGERSWIPE_H 0010 0011 #include <kwidgetsaddons_export.h> 0012 0013 #include <QGesture> 0014 #include <QGestureRecognizer> 0015 #include <memory> 0016 0017 /** 0018 * @class KTwoFingerSwipe ktwofingerswipe.h KTwoFingerSwipe 0019 * 0020 * @short A two finger swipe gesture. 0021 * 0022 * Provides a class for a two finger swipe gesture. 0023 * 0024 * Note: The QGestureManager need a QMainwindow, to delivery the gesture. 0025 * 0026 * @since 5.83 0027 * @author Steffen Hartleib <steffenhartleib@t-online.de> 0028 */ 0029 class KWIDGETSADDONS_EXPORT KTwoFingerSwipe : public QGesture 0030 { 0031 Q_OBJECT 0032 Q_PROPERTY(QPointF pos READ pos WRITE setPos) 0033 Q_PROPERTY(QPointF screenPos READ screenPos WRITE setScreenPos) 0034 Q_PROPERTY(QPointF scenePos READ scenePos WRITE setScenePos) 0035 Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle) 0036 public: 0037 /** 0038 * The constructor. 0039 */ 0040 explicit KTwoFingerSwipe(QObject *parent = nullptr); 0041 0042 /** 0043 * Destructor 0044 */ 0045 ~KTwoFingerSwipe() override; 0046 0047 /** 0048 * The start position of the gesture, relative to the widget that received the gesture. 0049 * 0050 * Note: This is not necessarily the same position as in the widget that grabGesture() uses. 0051 * 0052 * @return The start position of the gesture, relative to the widget. 0053 */ 0054 Q_REQUIRED_RESULT QPointF pos() const; 0055 0056 /** 0057 * Sets the position, relative to the widget. 0058 * 0059 * @param pos The position. 0060 */ 0061 void setPos(QPointF pos); 0062 0063 /** 0064 * @return The start screen position of the gesture. 0065 */ 0066 Q_REQUIRED_RESULT QPointF screenPos() const; 0067 0068 /** 0069 * Sets the screen position. 0070 * 0071 * @param screenPos The screen position. 0072 */ 0073 void setScreenPos(QPointF screenPos); 0074 0075 /** 0076 * @return The start scene position of the gesture. 0077 */ 0078 Q_REQUIRED_RESULT QPointF scenePos() const; 0079 0080 /** 0081 * Sets the scene position. 0082 * 0083 * @param scenePos The scene position, identical to the screen position for widgets. 0084 */ 0085 void setScenePos(QPointF scenePos); 0086 0087 /** 0088 * @return The angle of the swipe gesture. 0089 */ 0090 Q_REQUIRED_RESULT qreal swipeAngle() const; 0091 0092 /** 0093 * Sets the angle of the swipe gesture 0094 * 0095 * @param swipeAngle The angle. 0096 */ 0097 void setSwipeAngle(qreal swipeAngle); 0098 private: 0099 std::unique_ptr<class KTwoFingerSwipePrivate> const d; 0100 }; 0101 0102 /** 0103 * @class KTwoFingerSwipeRecognizer ktwofingerswiperecognizer.h KTwoFingerSwipeRecognizer 0104 * 0105 * @short The recognizer for a two finger swipe gesture. 0106 * 0107 * Provides the recognizer for a two finger swipe gesture. To adjust the maximum swipe time 0108 * and the minimum swipe distance, for a valid swipe gesture: 0109 * @see setMaxSwipeTime 0110 * @see setSwipeDistance 0111 * 0112 * @since 5.83 0113 * @author Steffen Hartleib <steffenhartleib@t-online.de> 0114 */ 0115 class KWIDGETSADDONS_EXPORT KTwoFingerSwipeRecognizer : public QGestureRecognizer 0116 { 0117 public: 0118 /** 0119 * The constructor. 0120 */ 0121 KTwoFingerSwipeRecognizer(); 0122 0123 /** 0124 * Destructor 0125 */ 0126 ~KTwoFingerSwipeRecognizer() override; 0127 0128 /** 0129 * Qt called this member to create a new QGesture object. 0130 * 0131 * @param target The target for the gesture. 0132 * 0133 * @return The new QGesture object. 0134 */ 0135 QGesture* create(QObject *target) override; 0136 0137 /** 0138 * Handles the given event for the watched object and update the gesture object. 0139 * 0140 * @param gesture The gesture object. 0141 * @param watched The watched object. 0142 * @param event The event. 0143 * 0144 * @return The result reflects how much of the gesture has been recognized. 0145 */ 0146 Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override; 0147 0148 /** 0149 * @return The maximum duration for the swipe gesture, in milliseconds. 0150 */ 0151 Q_REQUIRED_RESULT int maxSwipeTime() const; 0152 0153 /** 0154 * Set the maximum duration of the swipe gesture. If @param i is negative, it will be set to null. 0155 * 0156 * @param i The maximum duration in milliseconds. 0157 */ 0158 void setMaxSwipeTime(int i); 0159 0160 /** 0161 * @return The minimum distance for the swipe gesture. 0162 */ 0163 Q_REQUIRED_RESULT int minSswipeDistance() const; 0164 0165 /** 0166 * Set the minimum distance of the swipe gesture. If @param i is negative, it will be set to null. 0167 * 0168 * @param i The minimum distance. 0169 */ 0170 void setSwipeDistance(int i); 0171 0172 private: 0173 std::unique_ptr<class KTwoFingerSwipeRecognizerPrivate> const d; 0174 Q_DISABLE_COPY(KTwoFingerSwipeRecognizer) 0175 }; 0176 0177 #endif