Files
EJM_Display/PublicFunctions/CursorController.h
2025-09-15 22:28:43 +08:00

43 lines
1.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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