parent
b7b72acf8c
commit
05a40d6699
@ -1,8 +1,10 @@
|
||||
HEADERS += \
|
||||
$$PWD/controlevent.h \
|
||||
$$PWD/controller.h
|
||||
$$PWD/controller.h \
|
||||
$$PWD/inputconvert.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/controlevent.cpp \
|
||||
$$PWD/controller.cpp
|
||||
$$PWD/controller.cpp \
|
||||
$$PWD/inputconvert.cpp
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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
|
||||
Loading…
Reference in new issue