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