File indexing completed on 2024-05-12 05:32:09
0001 /* 0002 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "effect/globals.h" 0010 0011 #include <QQmlParserStatus> 0012 0013 class QAction; 0014 0015 namespace KWin 0016 { 0017 0018 /** 0019 * The SwipeGestureHandler type provides a way to handle global swipe gestures. 0020 * 0021 * Example usage: 0022 * @code 0023 * SwipeGestureHandler { 0024 * direction: SwipeGestureHandler.Direction.Up 0025 * fingerCount: 3 0026 * onActivated: console.log("activated") 0027 * } 0028 * @endcode 0029 */ 0030 class SwipeGestureHandler : public QObject, public QQmlParserStatus 0031 { 0032 Q_OBJECT 0033 Q_INTERFACES(QQmlParserStatus) 0034 0035 Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged) 0036 Q_PROPERTY(int fingerCount READ fingerCount WRITE setFingerCount NOTIFY fingerCountChanged) 0037 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) 0038 Q_PROPERTY(Device deviceType READ deviceType WRITE setDeviceType NOTIFY deviceTypeChanged) 0039 0040 public: 0041 explicit SwipeGestureHandler(QObject *parent = nullptr); 0042 0043 // Matches SwipeDirection. 0044 enum class Direction { 0045 Invalid, 0046 Down, 0047 Left, 0048 Up, 0049 Right, 0050 }; 0051 Q_ENUM(Direction) 0052 0053 enum class Device { 0054 Touchpad, 0055 Touchscreen, 0056 }; 0057 Q_ENUM(Device) 0058 0059 void classBegin() override; 0060 void componentComplete() override; 0061 0062 Direction direction() const; 0063 void setDirection(Direction direction); 0064 0065 int fingerCount() const; 0066 void setFingerCount(int fingerCount); 0067 0068 qreal progress() const; 0069 void setProgress(qreal progress); 0070 0071 Device deviceType() const; 0072 void setDeviceType(Device device); 0073 0074 Q_SIGNALS: 0075 void activated(); 0076 void progressChanged(); 0077 void directionChanged(); 0078 void fingerCountChanged(); 0079 void deviceTypeChanged(); 0080 0081 private: 0082 QAction *m_action = nullptr; 0083 Direction m_direction = Direction::Invalid; 0084 Device m_deviceType = Device::Touchpad; 0085 qreal m_progress = 0; 0086 int m_fingerCount = 3; 0087 }; 0088 0089 /** 0090 * The PinchGestureHandler type provides a way to handle global pinch gestures. 0091 * 0092 * Example usage: 0093 * @code 0094 * PinchGestureHandler { 0095 * direction: PinchGestureHandler.Direction.Contracting 0096 * fingerCount: 3 0097 * onActivated: console.log("activated") 0098 * } 0099 * @endcode 0100 */ 0101 class PinchGestureHandler : public QObject, public QQmlParserStatus 0102 { 0103 Q_OBJECT 0104 Q_INTERFACES(QQmlParserStatus) 0105 0106 Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged) 0107 Q_PROPERTY(int fingerCount READ fingerCount WRITE setFingerCount NOTIFY fingerCountChanged) 0108 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) 0109 0110 public: 0111 explicit PinchGestureHandler(QObject *parent = nullptr); 0112 0113 // Matches PinchDirection. 0114 enum class Direction { 0115 Expanding, 0116 Contracting, 0117 }; 0118 Q_ENUM(Direction) 0119 0120 enum class Device { 0121 Touchpad, 0122 }; 0123 Q_ENUM(Device) 0124 0125 void classBegin() override; 0126 void componentComplete() override; 0127 0128 Direction direction() const; 0129 void setDirection(Direction direction); 0130 0131 int fingerCount() const; 0132 void setFingerCount(int fingerCount); 0133 0134 qreal progress() const; 0135 void setProgress(qreal progress); 0136 0137 Device deviceType() const; 0138 void setDeviceType(Device device); 0139 0140 Q_SIGNALS: 0141 void activated(); 0142 void progressChanged(); 0143 void directionChanged(); 0144 void fingerCountChanged(); 0145 void deviceTypeChanged(); 0146 0147 private: 0148 QAction *m_action = nullptr; 0149 Direction m_direction = Direction::Contracting; 0150 Device m_deviceType = Device::Touchpad; 0151 qreal m_progress = 0; 0152 int m_fingerCount = 3; 0153 }; 0154 0155 } // namespace KWin