File indexing completed on 2025-02-02 14:20:13
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 KTWOFINGERTAP_H 0009 #define KTWOFINGERTAP_H 0010 0011 #include <kwidgetsaddons_export.h> 0012 0013 #include <QGesture> 0014 #include <QGestureRecognizer> 0015 #include <memory> 0016 0017 /** 0018 * @class KTwoFingerTap ktwofingertap.h KTwoFingerTap 0019 * 0020 * @short A two finger tap gesture. 0021 * 0022 * Provides a class for a two finger tap 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 KTwoFingerTap : 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 public: 0036 /** 0037 * The constructor. 0038 */ 0039 explicit KTwoFingerTap(QObject *parent = nullptr); 0040 0041 /** 0042 * Destructor 0043 */ 0044 ~KTwoFingerTap() override; 0045 0046 /** 0047 * The position of the gesture, relative to the widget that received the gesture. 0048 * 0049 * Note: This is not necessarily the same position as in the widget that grabGesture() uses. 0050 * 0051 * @return The position of the gesture. 0052 */ 0053 Q_REQUIRED_RESULT QPointF pos() const; 0054 0055 /** 0056 * Sets the position, relative to the widget. 0057 * 0058 * @param pos The position. 0059 */ 0060 void setPos(QPointF pos); 0061 0062 /** 0063 * Sets the screen position. 0064 * 0065 * @param screenPos The screen position. 0066 */ 0067 Q_REQUIRED_RESULT QPointF screenPos() const; 0068 0069 /** 0070 * @return The start scene position of the gesture. 0071 */ 0072 void setScreenPos(QPointF screenPos); 0073 0074 /** 0075 * @return The start scene position of the gesture. 0076 */ 0077 Q_REQUIRED_RESULT QPointF scenePos() const; 0078 0079 /** 0080 * Sets the scene position. 0081 * 0082 * @param scenePos The scene position, identical to the screen position for widgets. 0083 */ 0084 void setScenePos(QPointF scenePos); 0085 private: 0086 std::unique_ptr<class KTwoFingerTapPrivate> const d; 0087 }; 0088 0089 /** 0090 * @class KTwoFingerTapRecognizer ktwofingertaprecognizer.h KTwoFingerTapRecognizer 0091 * 0092 * @short The recognizer for a two finger tap gesture. 0093 * 0094 * Provides the recognizer for a two finger tap gesture. 0095 * 0096 * @since 5.83 0097 * @author Steffen Hartleib <steffenhartleib@t-online.de> 0098 */ 0099 class KWIDGETSADDONS_EXPORT KTwoFingerTapRecognizer : public QGestureRecognizer 0100 { 0101 public: 0102 /** 0103 * The constructor. 0104 */ 0105 KTwoFingerTapRecognizer(); 0106 0107 /** 0108 * Destructor 0109 */ 0110 ~KTwoFingerTapRecognizer() override; 0111 0112 /** 0113 * Qt called this member to create a new QGesture object. 0114 * 0115 * @param target The target for the gesture. 0116 * 0117 * @return The new QGesture object. 0118 */ 0119 QGesture* create(QObject *target) override; 0120 0121 /** 0122 * Handles the given event for the watched object and update the gesture object. 0123 * 0124 * @param gesture The gesture object. 0125 * @param watched The watched object. 0126 * @param event The event. 0127 * 0128 * @return The result reflects how much of the gesture has been recognized. 0129 */ 0130 Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override; 0131 0132 /** 0133 * @return The maximum wiggle room for a touch point. 0134 */ 0135 Q_REQUIRED_RESULT int tapRadius() const; 0136 0137 /** 0138 * Set the maximum wiggle room for a touch point. If @param i is negative, it will be set to null. 0139 * 0140 * @param i The maximum wiggle room. 0141 */ 0142 void setTapRadius(int i); 0143 0144 private: 0145 std::unique_ptr<class KTwoFingerTapRecognizerPrivate> const d; 0146 Q_DISABLE_COPY(KTwoFingerTapRecognizer) 0147 }; 0148 0149 #endif