43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#ifndef CURSORCONTROLLER_H
|
||
#define CURSORCONTROLLER_H
|
||
|
||
#include <QObject>
|
||
#include <QPoint>
|
||
#include <QKeyEvent>
|
||
#include <QTimer>
|
||
class CursorController : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
explicit CursorController(QObject *parent = nullptr);
|
||
|
||
// 可调参数
|
||
struct Config {
|
||
int step = 20; // 每步像素
|
||
bool wrap = false;// 边缘回绕
|
||
bool emulate = true; // 是否发送点击事件
|
||
int edgeGap = 5; // 离边缘空隙
|
||
};
|
||
|
||
Config cfg; // 直接改成员即可实时生效
|
||
|
||
public slots:
|
||
void handleKey(int key); // 接受 Qt::Key_xxx
|
||
void handleKey(int key, bool pressed);
|
||
signals:
|
||
void cursorMoved(const QPoint &globalPos);
|
||
void clicked(QWidget *target);
|
||
|
||
private:
|
||
QPoint m_pos;
|
||
bool m_useRealCursor; // true: 系统光标 false: 自绘光标
|
||
void move(const QPoint &delta);
|
||
void emulateClick();
|
||
|
||
QTimer m_holdTimer; // 用来检测是否达到长按时间
|
||
bool m_isLongPress; // 当前按键是否是长按
|
||
int m_curStep; // 当前应该用的步长(1 或 5)
|
||
};
|
||
|
||
#endif // CURSORCONTROLLER_H
|