File indexing completed on 2024-11-17 04:55:14
0001 /* 0002 SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include "virtualMouse.h" 0007 #include <QKeyEvent> 0008 #include <QDebug> 0009 0010 FakeCursor::FakeCursor() 0011 : step(1), _visible(true), device(QTest::createTouchDevice()) 0012 { 0013 } 0014 0015 FakeCursor::~FakeCursor() 0016 { 0017 } 0018 0019 void FakeCursor::move(int d){ 0020 QWindow * w = QGuiApplication::allWindows()[0]; 0021 switch (d) { 0022 case Up: if(_pos.ry() > 1) { _pos.ry() -= step; } break; 0023 case Down: if(_pos.ry() < w->height() - 5) { _pos.ry() += step; } break; 0024 case Left: if(_pos.rx() > 1) { _pos.rx() -= step; } break; 0025 case Right: if(_pos.rx() < w->width() - 20) { _pos.rx() += step; } break; 0026 } 0027 Q_EMIT posChanged(); 0028 } 0029 0030 void FakeCursor::closeEvent(){ 0031 QWindow * w = QGuiApplication::allWindows()[0]; 0032 QEvent event(QEvent::CloseSoftwareInputPanel); 0033 QCoreApplication::sendEvent(w, &event); 0034 } 0035 0036 void FakeCursor::moveEvent(QEvent *event){ 0037 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); 0038 switch (keyEvent->key()) { 0039 case Qt::Key_Up: move(0); break; 0040 case Qt::Key_Down: move(1); break; 0041 case Qt::Key_Left: move(2); break; 0042 case Qt::Key_Right: move(3); break; 0043 case Qt::Key_Return: click(); break; 0044 } 0045 }