feat: keymap support script

This commit is contained in:
rankun 2019-08-26 09:18:33 +08:00
parent cb65678402
commit 950ae0ee35
11 changed files with 302 additions and 236 deletions

View file

@ -7,12 +7,12 @@
#include "receiver.h"
#include "inputconvertgame.h"
Controller::Controller(bool supportGame, QObject* parent) : QObject(parent)
Controller::Controller(QString gameScript, QObject* parent) : QObject(parent)
{
m_receiver = new Receiver(this);
Q_ASSERT(m_receiver);
if (supportGame) {
if (!gameScript.isEmpty()) {
m_inputConvert = new InputConvertGame(this);
} else {
m_inputConvert = new InputConvertNormal(this);

View file

@ -13,7 +13,7 @@ class Controller : public QObject
{
Q_OBJECT
public:
Controller(bool supportGame = false, QObject* parent = Q_NULLPTR);
Controller(QString gameScript = "", QObject* parent = Q_NULLPTR);
virtual ~Controller();
void setControlSocket(QTcpSocket* controlSocket);

View file

@ -9,10 +9,7 @@
InputConvertGame::InputConvertGame(Controller* controller)
: InputConvertNormal(controller)
{
m_keyMap.loadKeyMap("");
if (m_keyMap.enableMouseMoveMap()) {
m_mouseMoveLastConverPos = m_keyMap.getMouseMoveMap().startPos;
}
}
InputConvertGame::~InputConvertGame()
@ -102,6 +99,14 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c
}
}
void InputConvertGame::loadKeyMap(const QString &json)
{
m_keyMap.loadKeyMap(json);
if (m_keyMap.enableMouseMoveMap()) {
m_mouseMoveLastConverPos = m_keyMap.getMouseMoveMap().startPos;
}
}
void InputConvertGame::updateSize(const QSize &frameSize, const QSize &showSize)
{
m_frameSize = frameSize;

View file

@ -18,6 +18,8 @@ public:
virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize);
virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize);
void loadKeyMap(const QString& json);
protected:
void updateSize(const QSize& frameSize, const QSize& showSize);
void sendTouchDownEvent(int id, QPointF pos);

View file

@ -46,17 +46,6 @@ void KeyMap::loadKeyMap(const QString &json)
QMetaEnum metaEnumMouseButtons = QMetaEnum::fromType<Qt::MouseButtons>();
QMetaEnum metaEnumKeyMapType = QMetaEnum::fromType<KeyMap::KeyMapType>();
QFile loadFile(getKeyMapPath() + "/gameforpeace.json");
if(!loadFile.open(QIODevice::ReadOnly))
{
errorString = "json error: open file failed";
goto parseError;
}
allData = loadFile.readAll();
loadFile.close();
jsonDoc = QJsonDocument::fromJson(allData, &jsonError);
if(jsonError.error != QJsonParseError::NoError)

View file

@ -79,8 +79,7 @@ public:
MouseMoveMap getMouseMoveMap();
bool enableMouseMoveMap();
protected:
const QString& getKeyMapPath();
static const QString& getKeyMapPath();
private:
QVector<KeyMapNode> m_keyMapNodes;

View file

@ -26,7 +26,7 @@ Device::Device(DeviceParams params, QObject *parent)
m_vb->init();
m_decoder = new Decoder(m_vb, this);
m_fileHandler = new FileHandler(this);
m_controller = new Controller(params.supportGame, this);
m_controller = new Controller(params.gameScript, this);
m_videoForm = new VideoForm();
m_videoForm->setSerial(m_params.serial);
if (m_controller) {

View file

@ -25,7 +25,7 @@ public:
bool closeScreen = false; // 启动时自动息屏
bool useReverse = true; // true:先使用adb reverse失败后自动使用adb forwardfalse:直接使用adb forward
bool display = true; // 是否显示画面(或者仅仅后台录制)
bool supportGame = false; // 是否支持游戏映射
QString gameScript = ""; // 游戏映射脚本
};
explicit Device(DeviceParams params, QObject *parent = nullptr);
virtual ~Device();

View file

@ -8,6 +8,7 @@
#include "ui_dialog.h"
#include "device.h"
#include "videoform.h"
#include "keymap.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
@ -89,7 +90,7 @@ void Dialog::initUI()
#ifndef Q_OS_WIN32
// game only windows
ui->gameForPeaceCheck->setEnabled(false);
ui->gameCheck->setEnabled(false);
#endif
}
@ -103,6 +104,20 @@ void Dialog::execAdbCmd()
m_adb.execute("", cmd.split(" ", QString::SkipEmptyParts));
}
QString Dialog::getGameScript(const QString& fileName)
{
QFile loadFile(KeyMap::getKeyMapPath() + "/" + fileName);
if(!loadFile.open(QIODevice::ReadOnly))
{
outLog("open file failed:" + fileName, true);
return "";
}
QString ret = loadFile.readAll();
loadFile.close();
return ret;
}
void Dialog::on_updateDevice_clicked()
{
if (checkAdbRun()) {
@ -138,7 +153,13 @@ void Dialog::on_startServerBtn_clicked()
params.closeScreen = ui->closeScreenCheck->isChecked();
params.useReverse = ui->useReverseCheck->isChecked();
params.display = !ui->notDisplayCheck->isChecked();
params.supportGame = ui->gameForPeaceCheck->isChecked();
if (ui->gameCheck->isChecked()) {
if (ui->gameBox->currentText().isEmpty()) {
outLog("no keymap script selected", true);
} else {
params.gameScript = getGameScript(ui->gameBox->currentText());
}
}
m_deviceManage.connectDevice(params);
/*
@ -284,3 +305,28 @@ void Dialog::on_stopAllServerBtn_clicked()
{
m_deviceManage.disconnectAllDevice();
}
void Dialog::on_updateGameScriptBtn_clicked()
{
ui->gameBox->clear();
QDir dir(KeyMap::getKeyMapPath());
if (!dir.exists()) {
outLog("keymap directory not find", true);
return;
}
dir.setFilter(QDir::Files | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
QFileInfo fileInfo;
int size = list.size();
for (int i = 0; i < size; ++i) {
fileInfo = list.at(i);
ui->gameBox->addItem(fileInfo.fileName());
}
}
void Dialog::on_gameCheck_clicked(bool checked)
{
if (checked) {
on_updateGameScriptBtn_clicked();
}
}

View file

@ -49,10 +49,14 @@ private slots:
void on_stopAllServerBtn_clicked();
void on_updateGameScriptBtn_clicked();
void on_gameCheck_clicked(bool checked);
private:
bool checkAdbRun();
void initUI();
void execAdbCmd();
QString getGameScript(const QString& fileName);
private:
Ui::Dialog *ui;

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>533</width>
<height>608</height>
<width>600</width>
<height>637</height>
</rect>
</property>
<property name="maximumSize">
@ -21,214 +21,6 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QGroupBox" name="wirelessGroupBox">
<property name="title">
<string>Wireless</string>
</property>
<layout class="QGridLayout" name="gridLayout_4" columnstretch="2,0,0,1,2">
<item row="3" column="2">
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>5</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>5</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string notr="true">:</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLineEdit" name="devicePortEdt">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string notr="true">5555</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLineEdit" name="deviceIpEdt">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string notr="true">192.168.0.1</string>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QPushButton" name="wirelessConnectBtn">
<property name="text">
<string>wireless connect</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QPushButton" name="wirelessDisConnectBtn">
<property name="text">
<string>wireless disconnect</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QTextEdit" name="outEdit">
<property name="minimumSize">
<size>
<width>0</width>
<height>240</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="documentTitle">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="configGroupBox">
<property name="title">
<string>Start Config</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="9" colspan="2">
<widget class="QCheckBox" name="useReverseCheck">
<property name="text">
<string>use reverse</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QComboBox" name="videoSizeBox">
<property name="toolTip">
<string/>
</property>
</widget>
</item>
<item row="1" column="9" colspan="2">
<widget class="QPushButton" name="selectRecordPathBtn">
<property name="text">
<string>select path</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="QLabel" name="label_6">
<property name="text">
<string>record format</string>
</property>
</widget>
</item>
<item row="0" column="6" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>video size:</string>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="QComboBox" name="formatBox"/>
</item>
<item row="2" column="7" colspan="2">
<widget class="QCheckBox" name="closeScreenCheck">
<property name="text">
<string>close screen</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>bit rate:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>record save path:</string>
</property>
<property name="buddy">
<cstring>recordPathEdt</cstring>
</property>
</widget>
</item>
<item row="0" column="2" colspan="4">
<widget class="QComboBox" name="bitRateBox">
<property name="toolTip">
<string/>
</property>
<property name="currentText">
<string/>
</property>
</widget>
</item>
<item row="1" column="2" colspan="7">
<widget class="QLineEdit" name="recordPathEdt">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="gameForPeaceCheck">
<property name="text">
<string>Game for Peace</string>
</property>
</widget>
</item>
<item row="2" column="5" colspan="2">
<widget class="QCheckBox" name="alwaysTopCheck">
<property name="text">
<string>always top</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="2" colspan="2">
<widget class="QCheckBox" name="notDisplayCheck">
<property name="text">
<string>not display</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="usbGroupBox">
<property name="title">
<string>USB line</string>
@ -305,6 +97,93 @@
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="wirelessGroupBox">
<property name="title">
<string>Wireless</string>
</property>
<layout class="QGridLayout" name="gridLayout_4" columnstretch="2,0,0,1,2">
<item row="3" column="2">
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>5</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>5</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string notr="true">:</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLineEdit" name="devicePortEdt">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string notr="true">5555</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLineEdit" name="deviceIpEdt">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string notr="true">192.168.0.1</string>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QPushButton" name="wirelessConnectBtn">
<property name="text">
<string>wireless connect</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QPushButton" name="wirelessDisConnectBtn">
<property name="text">
<string>wireless disconnect</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="0">
<widget class="QTextEdit" name="outEdit">
<property name="minimumSize">
<size>
<width>0</width>
<height>240</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="documentTitle">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QGroupBox" name="adbGroupBox">
<property name="title">
<string notr="true">adb</string>
@ -351,6 +230,150 @@
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="configGroupBox">
<property name="title">
<string>Start Config</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>bit rate:</string>
</property>
</widget>
</item>
<item row="2" column="3" colspan="2">
<widget class="QCheckBox" name="notDisplayCheck">
<property name="text">
<string>not display</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="3" colspan="2">
<widget class="QComboBox" name="bitRateBox">
<property name="toolTip">
<string/>
</property>
<property name="currentText">
<string/>
</property>
</widget>
</item>
<item row="2" column="6" colspan="2">
<widget class="QCheckBox" name="alwaysTopCheck">
<property name="text">
<string>always top</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="11" colspan="2">
<widget class="QCheckBox" name="useReverseCheck">
<property name="text">
<string>use reverse</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="12">
<widget class="QComboBox" name="formatBox"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>record save path:</string>
</property>
<property name="buddy">
<cstring>recordPathEdt</cstring>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QLabel" name="label_4">
<property name="text">
<string>video size:</string>
</property>
</widget>
</item>
<item row="2" column="9" colspan="2">
<widget class="QCheckBox" name="closeScreenCheck">
<property name="text">
<string>close screen</string>
</property>
</widget>
</item>
<item row="1" column="3" colspan="8">
<widget class="QLineEdit" name="recordPathEdt">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QComboBox" name="videoSizeBox">
<property name="toolTip">
<string/>
</property>
</widget>
</item>
<item row="1" column="11" colspan="2">
<widget class="QPushButton" name="selectRecordPathBtn">
<property name="text">
<string>select path</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="QLabel" name="label_6">
<property name="text">
<string>record format</string>
</property>
</widget>
</item>
<item row="0" column="8" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="5">
<widget class="QComboBox" name="gameBox"/>
</item>
<item row="3" column="6" colspan="2">
<widget class="QPushButton" name="updateGameScriptBtn">
<property name="text">
<string>update script</string>
</property>
</widget>
</item>
<item row="3" column="10" colspan="2">
<widget class="QCheckBox" name="gameCheck">
<property name="text">
<string>Game for Peace</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
@ -364,8 +387,6 @@
<tabstop>wirelessDisConnectBtn</tabstop>
<tabstop>adbCommandEdt</tabstop>
<tabstop>adbCommandBtn</tabstop>
<tabstop>bitRateBox</tabstop>
<tabstop>videoSizeBox</tabstop>
<tabstop>formatBox</tabstop>
<tabstop>recordPathEdt</tabstop>
<tabstop>selectRecordPathBtn</tabstop>