按键模式切换初步

This commit is contained in:
rankun 2018-11-13 13:49:22 +08:00
commit 2f6db53336
3 changed files with 48 additions and 29 deletions

View file

@ -15,6 +15,7 @@ InputConvertGame::~InputConvertGame()
void InputConvertGame::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) void InputConvertGame::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize)
{ {
if (m_gameMap) {
updateSize(frameSize, showSize); updateSize(frameSize, showSize);
// mouse move // mouse move
@ -26,17 +27,31 @@ void InputConvertGame::mouseEvent(const QMouseEvent *from, const QSize &frameSiz
if (processMouseClick(from)) { if (processMouseClick(from)) {
return; return;
} }
return; } else {
InputConvertNormal::mouseEvent(from, frameSize, showSize);
}
} }
void InputConvertGame::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize) void InputConvertGame::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize)
{ {
Q_UNUSED(from); if (m_gameMap) {
updateSize(frameSize, showSize); updateSize(frameSize, showSize);
} else {
InputConvertNormal::wheelEvent(from, frameSize, showSize);
}
} }
void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, const QSize& showSize) void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, const QSize& showSize)
{ {
switch (from->key()) {
case Qt::Key_QuoteLeft:
if (QEvent::KeyPress == from->type()) {
m_gameMap = !m_gameMap;
}
return;
}
if (m_gameMap) {
updateSize(frameSize, showSize); updateSize(frameSize, showSize);
if (!from || from->isAutoRepeat()) { if (!from || from->isAutoRepeat()) {
return; return;
@ -52,6 +67,9 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c
if (processKeyClick(from)) { if (processKeyClick(from)) {
return; return;
} }
} else {
InputConvertNormal::keyEvent(from, frameSize, showSize);
}
} }
void InputConvertGame::updateSize(const QSize &frameSize, const QSize &showSize) void InputConvertGame::updateSize(const QSize &frameSize, const QSize &showSize)

View file

@ -2,19 +2,19 @@
#define INPUTCONVERTGAME_H #define INPUTCONVERTGAME_H
#include <QPointF> #include <QPointF>
#include "inputconvertbase.h" #include "inputconvertnormal.h"
#define MULTI_TOUCH_MAX_NUM 10 #define MULTI_TOUCH_MAX_NUM 10
class InputConvertGame : public QObject, public InputConvertBase class InputConvertGame : public QObject, public InputConvertNormal
{ {
Q_OBJECT Q_OBJECT
public: public:
InputConvertGame(QObject* parent = Q_NULLPTR); InputConvertGame(QObject* parent = Q_NULLPTR);
virtual ~InputConvertGame(); virtual ~InputConvertGame();
void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); virtual void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize);
void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize);
void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize);
protected: protected:
void updateSize(const QSize& frameSize, const QSize& showSize); void updateSize(const QSize& frameSize, const QSize& showSize);
@ -61,6 +61,7 @@ private:
private: private:
QSize m_frameSize; QSize m_frameSize;
QSize m_showSize; QSize m_showSize;
bool m_gameMap = false;
int multiTouchID[MULTI_TOUCH_MAX_NUM] = { 0 }; int multiTouchID[MULTI_TOUCH_MAX_NUM] = { 0 };

View file

@ -9,9 +9,9 @@ public:
InputConvertNormal(); InputConvertNormal();
virtual ~InputConvertNormal(); virtual ~InputConvertNormal();
void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); virtual void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize);
void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize);
void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize);
private: private:
AndroidMotioneventButtons convertMouseButtons(Qt::MouseButtons buttonState); AndroidMotioneventButtons convertMouseButtons(Qt::MouseButtons buttonState);