|
|
|
@ -1,25 +1,18 @@
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QMetaEnum>
|
|
|
|
#include <QMetaEnum>
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "keymap.h"
|
|
|
|
#include "keymap.h"
|
|
|
|
|
|
|
|
|
|
|
|
QString KeyMap::s_keyMapPath = "";
|
|
|
|
QString KeyMap::s_keyMapPath = "";
|
|
|
|
|
|
|
|
|
|
|
|
KeyMap::KeyMap(QObject *parent)
|
|
|
|
KeyMap::KeyMap(QObject *parent) : QObject(parent) {}
|
|
|
|
: QObject(parent)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
KeyMap::~KeyMap() {}
|
|
|
|
|
|
|
|
|
|
|
|
KeyMap::~KeyMap()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const QString &KeyMap::getKeyMapPath()
|
|
|
|
const QString &KeyMap::getKeyMapPath()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -110,8 +103,7 @@ void KeyMap::loadKeyMap(const QString &json)
|
|
|
|
|
|
|
|
|
|
|
|
KeyMap::KeyMapType type = getItemKeyMapType(node, "type");
|
|
|
|
KeyMap::KeyMapType type = getItemKeyMapType(node, "type");
|
|
|
|
switch (type) {
|
|
|
|
switch (type) {
|
|
|
|
case KeyMap::KMT_CLICK:
|
|
|
|
case KeyMap::KMT_CLICK: {
|
|
|
|
{
|
|
|
|
|
|
|
|
// safe check
|
|
|
|
// safe check
|
|
|
|
if (!checkForClick(node)) {
|
|
|
|
if (!checkForClick(node)) {
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
@ -129,10 +121,8 @@ void KeyMap::loadKeyMap(const QString &json)
|
|
|
|
keyMapNode.data.click.keyNode.pos = getItemPos(node, "pos");
|
|
|
|
keyMapNode.data.click.keyNode.pos = getItemPos(node, "pos");
|
|
|
|
keyMapNode.data.click.switchMap = getItemBool(node, "switchMap");
|
|
|
|
keyMapNode.data.click.switchMap = getItemBool(node, "switchMap");
|
|
|
|
m_keyMapNodes.push_back(keyMapNode);
|
|
|
|
m_keyMapNodes.push_back(keyMapNode);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
break;
|
|
|
|
case KeyMap::KMT_CLICK_TWICE: {
|
|
|
|
case KeyMap::KMT_CLICK_TWICE:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// safe check
|
|
|
|
// safe check
|
|
|
|
if (!checkForClickTwice(node)) {
|
|
|
|
if (!checkForClickTwice(node)) {
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
@ -151,10 +141,8 @@ void KeyMap::loadKeyMap(const QString &json)
|
|
|
|
keyMapNode.data.click.keyNode.pos = getItemPos(node, "pos");
|
|
|
|
keyMapNode.data.click.keyNode.pos = getItemPos(node, "pos");
|
|
|
|
keyMapNode.data.click.switchMap = getItemBool(node, "switchMap");
|
|
|
|
keyMapNode.data.click.switchMap = getItemBool(node, "switchMap");
|
|
|
|
m_keyMapNodes.push_back(keyMapNode);
|
|
|
|
m_keyMapNodes.push_back(keyMapNode);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
break;
|
|
|
|
case KeyMap::KMT_STEER_WHEEL: {
|
|
|
|
case KeyMap::KMT_STEER_WHEEL:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// safe check
|
|
|
|
// safe check
|
|
|
|
if (!checkForSteerWhell(node)) {
|
|
|
|
if (!checkForSteerWhell(node)) {
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
@ -164,8 +152,7 @@ void KeyMap::loadKeyMap(const QString &json)
|
|
|
|
QPair<ActionType, int> rightKey = getItemKey(node, "rightKey");
|
|
|
|
QPair<ActionType, int> rightKey = getItemKey(node, "rightKey");
|
|
|
|
QPair<ActionType, int> upKey = getItemKey(node, "upKey");
|
|
|
|
QPair<ActionType, int> upKey = getItemKey(node, "upKey");
|
|
|
|
QPair<ActionType, int> downKey = getItemKey(node, "downKey");
|
|
|
|
QPair<ActionType, int> downKey = getItemKey(node, "downKey");
|
|
|
|
if (leftKey.first == AT_INVALID || rightKey.first == AT_INVALID
|
|
|
|
if (leftKey.first == AT_INVALID || rightKey.first == AT_INVALID || upKey.first == AT_INVALID || downKey.first == AT_INVALID) {
|
|
|
|
|| upKey.first == AT_INVALID || downKey.first == AT_INVALID) {
|
|
|
|
|
|
|
|
if (leftKey.first == AT_INVALID) {
|
|
|
|
if (leftKey.first == AT_INVALID) {
|
|
|
|
qWarning() << "json error: keyMapNodes node invalid key: " << node.value("leftKey").toString();
|
|
|
|
qWarning() << "json error: keyMapNodes node invalid key: " << node.value("leftKey").toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -184,26 +171,16 @@ void KeyMap::loadKeyMap(const QString &json)
|
|
|
|
KeyMapNode keyMapNode;
|
|
|
|
KeyMapNode keyMapNode;
|
|
|
|
keyMapNode.type = type;
|
|
|
|
keyMapNode.type = type;
|
|
|
|
|
|
|
|
|
|
|
|
keyMapNode.data.steerWheel.left = { leftKey.first, leftKey.second,
|
|
|
|
keyMapNode.data.steerWheel.left = { leftKey.first, leftKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "leftOffset") };
|
|
|
|
QPointF(0, 0), QPointF(0, 0),
|
|
|
|
keyMapNode.data.steerWheel.right = { rightKey.first, rightKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "rightOffset") };
|
|
|
|
getItemDouble(node, "leftOffset") };
|
|
|
|
keyMapNode.data.steerWheel.up = { upKey.first, upKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "upOffset") };
|
|
|
|
keyMapNode.data.steerWheel.right = { rightKey.first, rightKey.second,
|
|
|
|
keyMapNode.data.steerWheel.down = { downKey.first, downKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "downOffset") };
|
|
|
|
QPointF(0, 0), QPointF(0, 0),
|
|
|
|
|
|
|
|
getItemDouble(node, "rightOffset") };
|
|
|
|
|
|
|
|
keyMapNode.data.steerWheel.up = { upKey.first, upKey.second,
|
|
|
|
|
|
|
|
QPointF(0, 0), QPointF(0, 0),
|
|
|
|
|
|
|
|
getItemDouble(node, "upOffset") };
|
|
|
|
|
|
|
|
keyMapNode.data.steerWheel.down = { downKey.first, downKey.second,
|
|
|
|
|
|
|
|
QPointF(0, 0), QPointF(0, 0),
|
|
|
|
|
|
|
|
getItemDouble(node, "downOffset") };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keyMapNode.data.steerWheel.centerPos = getItemPos(node, "centerPos");
|
|
|
|
keyMapNode.data.steerWheel.centerPos = getItemPos(node, "centerPos");
|
|
|
|
m_idxSteerWheel = m_keyMapNodes.size();
|
|
|
|
m_idxSteerWheel = m_keyMapNodes.size();
|
|
|
|
m_keyMapNodes.push_back(keyMapNode);
|
|
|
|
m_keyMapNodes.push_back(keyMapNode);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
break;
|
|
|
|
case KeyMap::KMT_DRAG: {
|
|
|
|
case KeyMap::KMT_DRAG:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// safe check
|
|
|
|
// safe check
|
|
|
|
if (!checkForDrag(node)) {
|
|
|
|
if (!checkForDrag(node)) {
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
qWarning() << "json error: keyMapNodes node format error";
|
|
|
|
@ -292,20 +269,15 @@ void KeyMap::makeReverseMap()
|
|
|
|
for (int i = 0; i < m_keyMapNodes.size(); ++i) {
|
|
|
|
for (int i = 0; i < m_keyMapNodes.size(); ++i) {
|
|
|
|
auto &node = m_keyMapNodes[i];
|
|
|
|
auto &node = m_keyMapNodes[i];
|
|
|
|
switch (node.type) {
|
|
|
|
switch (node.type) {
|
|
|
|
case KMT_CLICK:
|
|
|
|
case KMT_CLICK: {
|
|
|
|
{
|
|
|
|
|
|
|
|
QMultiHash<int, KeyMapNode *> &m = node.data.click.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
QMultiHash<int, KeyMapNode *> &m = node.data.click.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
m.insert(node.data.click.keyNode.key, &node);
|
|
|
|
m.insert(node.data.click.keyNode.key, &node);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
break;
|
|
|
|
case KMT_CLICK_TWICE: {
|
|
|
|
case KMT_CLICK_TWICE:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QMultiHash<int, KeyMapNode *> &m = node.data.clickTwice.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
QMultiHash<int, KeyMapNode *> &m = node.data.clickTwice.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
m.insert(node.data.clickTwice.keyNode.key, &node);
|
|
|
|
m.insert(node.data.clickTwice.keyNode.key, &node);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
break;
|
|
|
|
case KMT_STEER_WHEEL: {
|
|
|
|
case KMT_STEER_WHEEL:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QMultiHash<int, KeyMapNode *> &ml = node.data.steerWheel.left.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
QMultiHash<int, KeyMapNode *> &ml = node.data.steerWheel.left.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
ml.insert(node.data.steerWheel.left.key, &node);
|
|
|
|
ml.insert(node.data.steerWheel.left.key, &node);
|
|
|
|
QMultiHash<int, KeyMapNode *> &mr = node.data.steerWheel.right.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
QMultiHash<int, KeyMapNode *> &mr = node.data.steerWheel.right.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
@ -314,14 +286,11 @@ void KeyMap::makeReverseMap()
|
|
|
|
mu.insert(node.data.steerWheel.up.key, &node);
|
|
|
|
mu.insert(node.data.steerWheel.up.key, &node);
|
|
|
|
QMultiHash<int, KeyMapNode *> &md = node.data.steerWheel.down.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
QMultiHash<int, KeyMapNode *> &md = node.data.steerWheel.down.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
md.insert(node.data.steerWheel.down.key, &node);
|
|
|
|
md.insert(node.data.steerWheel.down.key, &node);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
break;
|
|
|
|
case KMT_DRAG: {
|
|
|
|
case KMT_DRAG:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QMultiHash<int, KeyMapNode *> &m = node.data.drag.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
QMultiHash<int, KeyMapNode *> &m = node.data.drag.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
m.insert(node.data.drag.keyNode.key, &node);
|
|
|
|
m.insert(node.data.drag.keyNode.key, &node);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -398,8 +367,7 @@ bool KeyMap::checkItemPos(const QJsonObject& node, const QString& name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (node.contains(name) && node.value(name).isObject()) {
|
|
|
|
if (node.contains(name) && node.value(name).isObject()) {
|
|
|
|
QJsonObject pos = node.value(name).toObject();
|
|
|
|
QJsonObject pos = node.value(name).toObject();
|
|
|
|
return pos.contains("x") && pos.value("x").isDouble()
|
|
|
|
return pos.contains("x") && pos.value("x").isDouble() && pos.contains("y") && pos.value("y").isDouble();
|
|
|
|
&& pos.contains("y") && pos.value("y").isDouble();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -416,16 +384,12 @@ bool KeyMap::checkForClickTwice(const QJsonObject& node)
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkForSteerWhell(const QJsonObject &node)
|
|
|
|
bool KeyMap::checkForSteerWhell(const QJsonObject &node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return checkItemString(node, "leftKey") && checkItemString(node, "rightKey")
|
|
|
|
return checkItemString(node, "leftKey") && checkItemString(node, "rightKey") && checkItemString(node, "upKey") && checkItemString(node, "downKey")
|
|
|
|
&& checkItemString(node, "upKey") && checkItemString(node, "downKey")
|
|
|
|
&& checkItemDouble(node, "leftOffset") && checkItemDouble(node, "rightOffset") && checkItemDouble(node, "upOffset")
|
|
|
|
&& checkItemDouble(node, "leftOffset") && checkItemDouble(node, "rightOffset")
|
|
|
|
&& checkItemDouble(node, "downOffset") && checkItemPos(node, "centerPos");
|
|
|
|
&& checkItemDouble(node, "upOffset") && checkItemDouble(node, "downOffset")
|
|
|
|
|
|
|
|
&& checkItemPos(node, "centerPos");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkForDrag(const QJsonObject &node)
|
|
|
|
bool KeyMap::checkForDrag(const QJsonObject &node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return checkItemString(node, "key")
|
|
|
|
return checkItemString(node, "key") && checkItemPos(node, "startPos") && checkItemPos(node, "endPos");
|
|
|
|
&& checkItemPos(node, "startPos") && checkItemPos(node, "endPos");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|