第一次上传

This commit is contained in:
2025-08-20 23:06:28 +08:00
commit c0593df9e1
485 changed files with 533424 additions and 0 deletions

18
PublicFunctions/Basic.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "Basic.h"
/**
* @brief map 映射函数,把x的值,映射到out_min到out_max的范围内
* @param x 需要映射的值
* @param in_min x有可能的最小值
* @param in_max x有可能的最大值
* @param out_min 输出的最小值
* @param out_max 输出的最大值
* @return 映射结果
*/
M_d64 map(M_d64 x, M_d64 in_min, M_d64 in_max, M_d64 out_min, M_d64 out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void Sleep(M_u16 msec){
QTime _Timer = QTime::currentTime().addMSecs(msec);
while( QTime::currentTime() < _Timer )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}

11
PublicFunctions/Basic.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef BASIC_H
#define BASIC_H
#include <GlobalDefinitions/DataType.h>
#include <QCoreApplication>
#include <QTime>
double map(double x, double in_min, double in_max, double out_min, double out_max);
void Sleep(uint16_t msec);
#endif // BASIC_H

View File

@@ -0,0 +1,6 @@
#include "Components.h"
Components::Components(QObject *parent) : QObject(parent)
{
}

View File

@@ -0,0 +1,16 @@
#ifndef COMPONENTS_H
#define COMPONENTS_H
#include <QObject>
class Components : public QObject
{
Q_OBJECT
public:
explicit Components(QObject *parent = nullptr);
signals:
};
#endif // COMPONENTS_H

View File

@@ -0,0 +1,70 @@
#include "CursorController.h"
#include <QWidget>
#include <QCursor>
#include <QApplication>
#include <QScreen>
#include <QMouseEvent>
#include <QDebug>
CursorController::CursorController(QObject *parent)
: QObject(parent)
{
// 判断能否真正移动系统光标
m_useRealCursor = QGuiApplication::platformName() != "eglfs"
&& QGuiApplication::platformName() != "linuxfb"
&& QGuiApplication::platformName() != "minimal";
if (!m_useRealCursor)
m_pos = QGuiApplication::primaryScreen()->geometry().center();
else
m_pos = QCursor::pos();
}
void CursorController::handleKey(int key)
{
QPoint delta;
switch (key) {
case Qt::Key_Up: delta = QPoint(0, -cfg.step); break;
case Qt::Key_Down: delta = QPoint(0, cfg.step); break;
case Qt::Key_Left: delta = QPoint(-cfg.step, 0); break;
case Qt::Key_Right: delta = QPoint( cfg.step, 0); break;
case Qt::Key_Return:
case Qt::Key_Space:
if (cfg.emulate) emulateClick();
return;
default: return;
}
move(delta);
}
void CursorController::move(const QPoint &delta)
{
QRect desk = QGuiApplication::primaryScreen()->geometry();
m_pos += delta;
if (cfg.wrap) {
m_pos.setX(((m_pos.x() - desk.left()) % desk.width() + desk.width()) % desk.width() + desk.left());
m_pos.setY(((m_pos.y() - desk.top()) % desk.height() + desk.height()) % desk.height() + desk.top());
} else {
m_pos.setX(qBound(desk.left() + cfg.edgeGap, m_pos.x(), desk.right() - cfg.edgeGap));
m_pos.setY(qBound(desk.top() + cfg.edgeGap, m_pos.y(), desk.bottom() - cfg.edgeGap));
}
if (m_useRealCursor)
QCursor::setPos(m_pos);
emit cursorMoved(m_pos);
}
void CursorController::emulateClick()
{
QWidget *w = QApplication::widgetAt(m_pos);
if (w) {
QPoint local = w->mapFromGlobal(m_pos);
QMouseEvent press (QEvent::MouseButtonPress, local, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QMouseEvent release(QEvent::MouseButtonRelease, local, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QApplication::sendEvent(w, &press);
QApplication::sendEvent(w, &release);
}
emit clicked(w);
}

View File

@@ -0,0 +1,38 @@
#ifndef CURSORCONTROLLER_H
#define CURSORCONTROLLER_H
#include <QObject>
#include <QPoint>
#include <QKeyEvent>
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
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();
};
#endif // CURSORCONTROLLER_H