File indexing completed on 2024-11-24 04:54:31
0001 /* 0002 SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include <QTest> 0007 #include <QGuiApplication> 0008 #include <QObject> 0009 #include <QEvent> 0010 #include "keyfilter.h" 0011 0012 class FakeCursor : public QObject { 0013 Q_OBJECT 0014 Q_PROPERTY(QPoint pos READ pos WRITE setPos NOTIFY posChanged) 0015 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) 0016 enum Direction { Up = 0, Down, Left, Right }; 0017 QPoint _pos; 0018 qreal step; 0019 bool _visible; 0020 0021 Q_SIGNALS: 0022 void posChanged(); 0023 void visibleChanged(); 0024 0025 public: 0026 FakeCursor(); 0027 virtual ~FakeCursor(); 0028 void setPos(QPoint p) { 0029 if (p != _pos) { 0030 _pos = p; 0031 Q_EMIT posChanged(); 0032 } 0033 } 0034 bool visible() const { return _visible; } 0035 QPoint pos() const { return _pos; } 0036 0037 0038 public Q_SLOTS: 0039 void move(int d); 0040 void setStep(qreal s) { if (s) step = s; } 0041 void toggleVisible() { _visible = !_visible; Q_EMIT visibleChanged(); } 0042 void click() { 0043 QWindow * w = QGuiApplication::allWindows()[0]; 0044 QTest::touchEvent(w, device).press(0, _pos); 0045 QTest::touchEvent(w, device).release(0, _pos); 0046 } 0047 void closeEvent(); 0048 void moveEvent(QEvent *event); 0049 0050 private: 0051 QPointingDevice *device; 0052 };