mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-04 06:38:39 +00:00
鼠标事件转换
This commit is contained in:
parent
28259c30fc
commit
c7a636817d
5 changed files with 156 additions and 12 deletions
|
@ -1,8 +1,10 @@
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/controlevent.h \
|
$$PWD/controlevent.h \
|
||||||
$$PWD/controller.h
|
$$PWD/controller.h \
|
||||||
|
$$PWD/inputconvert.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/controlevent.cpp \
|
$$PWD/controlevent.cpp \
|
||||||
$$PWD/controller.cpp
|
$$PWD/controller.cpp \
|
||||||
|
$$PWD/inputconvert.cpp
|
||||||
|
|
||||||
|
|
97
src/inputcontrol/inputconvert.cpp
Normal file
97
src/inputcontrol/inputconvert.cpp
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
#include "inputconvert.h"
|
||||||
|
|
||||||
|
InputConvert::InputConvert()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ControlEvent* InputConvert::mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize)
|
||||||
|
{
|
||||||
|
if (!from) {
|
||||||
|
return Q_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// action
|
||||||
|
AndroidMotioneventAction action;
|
||||||
|
switch (from->type()) {
|
||||||
|
case QEvent::MouseButtonPress:
|
||||||
|
action = AMOTION_EVENT_ACTION_DOWN;
|
||||||
|
break;
|
||||||
|
case QEvent::MouseButtonRelease:
|
||||||
|
action = AMOTION_EVENT_ACTION_UP;
|
||||||
|
break;
|
||||||
|
case QEvent::MouseMove:
|
||||||
|
action = AMOTION_EVENT_ACTION_MOVE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return Q_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pos
|
||||||
|
QPointF pos = from->localPos();
|
||||||
|
// convert pos
|
||||||
|
pos.setX(pos.x() * frameSize.width() / showSize.width());
|
||||||
|
pos.setY(pos.y() * frameSize.height() / showSize.height());
|
||||||
|
|
||||||
|
// set data
|
||||||
|
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_MOUSE);
|
||||||
|
if (!controlEvent) {
|
||||||
|
return Q_NULLPTR;
|
||||||
|
}
|
||||||
|
controlEvent->setMouseEventData(action, convertMouseButtons(from->buttons()), QRect(pos.toPoint(), frameSize));
|
||||||
|
return controlEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
ControlEvent *InputConvert::wheelEvent(const QWheelEvent *from, const QSize& frameSize, const QSize& showSize)
|
||||||
|
{
|
||||||
|
if (!from) {
|
||||||
|
return Q_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// delta
|
||||||
|
qint32 hScroll = 0;
|
||||||
|
qint32 vScroll = 0;
|
||||||
|
switch (from->orientation()) {
|
||||||
|
case Qt::Horizontal:
|
||||||
|
hScroll = from->delta();
|
||||||
|
break;
|
||||||
|
case Qt::Vertical:
|
||||||
|
vScroll = from->delta();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pos
|
||||||
|
QPointF pos = from->posF();
|
||||||
|
// convert pos
|
||||||
|
pos.setX(pos.x() * frameSize.width() / showSize.width());
|
||||||
|
pos.setY(pos.y() * frameSize.height() / showSize.height());
|
||||||
|
|
||||||
|
// set data
|
||||||
|
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_SCROLL);
|
||||||
|
if (!controlEvent) {
|
||||||
|
return Q_NULLPTR;
|
||||||
|
}
|
||||||
|
controlEvent->setScrollEventData(QRect(pos.toPoint(), frameSize), hScroll, vScroll);
|
||||||
|
return controlEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
AndroidMotioneventButtons InputConvert::convertMouseButtons(Qt::MouseButtons buttonState)
|
||||||
|
{
|
||||||
|
quint32 buttons = 0;
|
||||||
|
if (buttonState & Qt::LeftButton) {
|
||||||
|
buttons |= AMOTION_EVENT_BUTTON_PRIMARY;
|
||||||
|
}
|
||||||
|
if (buttonState & Qt::RightButton) {
|
||||||
|
buttons |= AMOTION_EVENT_BUTTON_SECONDARY;
|
||||||
|
}
|
||||||
|
if (buttonState & Qt::MidButton) {
|
||||||
|
buttons |= AMOTION_EVENT_BUTTON_TERTIARY;
|
||||||
|
}
|
||||||
|
if (buttonState & Qt::XButton1) {
|
||||||
|
buttons |= AMOTION_EVENT_BUTTON_BACK;
|
||||||
|
}
|
||||||
|
if (buttonState & Qt::XButton2) {
|
||||||
|
buttons |= AMOTION_EVENT_BUTTON_FORWARD;
|
||||||
|
}
|
||||||
|
return (AndroidMotioneventButtons)buttons;
|
||||||
|
}
|
23
src/inputcontrol/inputconvert.h
Normal file
23
src/inputcontrol/inputconvert.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef INPUTCONVERT_H
|
||||||
|
#define INPUTCONVERT_H
|
||||||
|
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QWheelEvent>
|
||||||
|
|
||||||
|
#include "controlevent.h"
|
||||||
|
|
||||||
|
class InputConvert
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InputConvert();
|
||||||
|
|
||||||
|
// the frame size may be different from the real device size, so we need the size
|
||||||
|
// to which the absolute position apply, to scale it accordingly
|
||||||
|
static ControlEvent* mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize);
|
||||||
|
static ControlEvent* wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static AndroidMotioneventButtons convertMouseButtons(Qt::MouseButtons buttonState);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INPUTCONVERT_H
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "videoform.h"
|
#include "videoform.h"
|
||||||
#include "ui_videoform.h"
|
#include "ui_videoform.h"
|
||||||
|
#include "inputconvert.h"
|
||||||
|
|
||||||
VideoForm::VideoForm(QWidget *parent) :
|
VideoForm::VideoForm(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
|
@ -91,14 +92,32 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
|
|
||||||
void VideoForm::mousePressEvent(QMouseEvent *event)
|
void VideoForm::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QSize frameSize = ui->videoWidget->frameSize();
|
ControlEvent* controlEvent = InputConvert::mouseEvent(event, ui->videoWidget->frameSize(), size());
|
||||||
QSize widgetWize = size();
|
if (controlEvent) {
|
||||||
|
m_controller.postControlEvent(controlEvent);
|
||||||
QPoint pos = event->pos();
|
}
|
||||||
// convert pos
|
}
|
||||||
pos.setX(pos.x() * 1.0f * frameSize.width() / widgetWize.width());
|
|
||||||
pos.setY(pos.y() * 1.0f * frameSize.height() / widgetWize.height());
|
void VideoForm::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
QRect rc(pos, frameSize);
|
ControlEvent* controlEvent = InputConvert::mouseEvent(event, ui->videoWidget->frameSize(), size());
|
||||||
m_controller.test(rc);
|
if (controlEvent) {
|
||||||
|
m_controller.postControlEvent(controlEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoForm::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
ControlEvent* controlEvent = InputConvert::mouseEvent(event, ui->videoWidget->frameSize(), size());
|
||||||
|
if (controlEvent) {
|
||||||
|
m_controller.postControlEvent(controlEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoForm::wheelEvent(QWheelEvent *event)
|
||||||
|
{
|
||||||
|
ControlEvent* controlEvent = InputConvert::wheelEvent(event, ui->videoWidget->frameSize(), size());
|
||||||
|
if (controlEvent) {
|
||||||
|
m_controller.postControlEvent(controlEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::videoForm *ui;
|
Ui::videoForm *ui;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue