|
|
|
@ -1,27 +1,20 @@
|
|
|
|
|
|
|
|
#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()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (s_keyMapPath.isEmpty()) {
|
|
|
|
if (s_keyMapPath.isEmpty()) {
|
|
|
|
s_keyMapPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_KEYMAP_PATH"));
|
|
|
|
s_keyMapPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_KEYMAP_PATH"));
|
|
|
|
@ -43,7 +36,7 @@ void KeyMap::loadKeyMap(const QString &json)
|
|
|
|
|
|
|
|
|
|
|
|
jsonDoc = QJsonDocument::fromJson(json.toUtf8(), &jsonError);
|
|
|
|
jsonDoc = QJsonDocument::fromJson(json.toUtf8(), &jsonError);
|
|
|
|
|
|
|
|
|
|
|
|
if(jsonError.error != QJsonParseError::NoError) {
|
|
|
|
if (jsonError.error != QJsonParseError::NoError) {
|
|
|
|
errorString = QString("json error: %1").arg(jsonError.errorString());
|
|
|
|
errorString = QString("json error: %1").arg(jsonError.errorString());
|
|
|
|
goto parseError;
|
|
|
|
goto parseError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -57,13 +50,13 @@ void KeyMap::loadKeyMap(const QString &json)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switchKey = getItemKey(rootObj, "switchKey");
|
|
|
|
switchKey = getItemKey(rootObj, "switchKey");
|
|
|
|
if(switchKey.first == AT_INVALID) {
|
|
|
|
if (switchKey.first == AT_INVALID) {
|
|
|
|
errorString = QString("json error: switchKey invalid");
|
|
|
|
errorString = QString("json error: switchKey invalid");
|
|
|
|
goto parseError;
|
|
|
|
goto parseError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_switchKey.type = switchKey.first;
|
|
|
|
m_switchKey.type = switchKey.first;
|
|
|
|
m_switchKey.key= switchKey.second;
|
|
|
|
m_switchKey.key = switchKey.second;
|
|
|
|
|
|
|
|
|
|
|
|
// mouseMoveMap
|
|
|
|
// mouseMoveMap
|
|
|
|
if (checkItemObject(rootObj, "mouseMoveMap")) {
|
|
|
|
if (checkItemObject(rootObj, "mouseMoveMap")) {
|
|
|
|
@ -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";
|
|
|
|
@ -241,7 +218,7 @@ parseError:
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const KeyMap::KeyMapNode& KeyMap::getKeyMapNode(int key)
|
|
|
|
const KeyMap::KeyMapNode &KeyMap::getKeyMapNode(int key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto p = m_rmapKey.value(key, &m_invalidNode);
|
|
|
|
auto p = m_rmapKey.value(key, &m_invalidNode);
|
|
|
|
if (p == &m_invalidNode) {
|
|
|
|
if (p == &m_invalidNode) {
|
|
|
|
@ -250,12 +227,12 @@ const KeyMap::KeyMapNode& KeyMap::getKeyMapNode(int key)
|
|
|
|
return *p;
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const KeyMap::KeyMapNode& KeyMap::getKeyMapNodeKey(int key)
|
|
|
|
const KeyMap::KeyMapNode &KeyMap::getKeyMapNodeKey(int key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return *m_rmapKey.value(key, &m_invalidNode);
|
|
|
|
return *m_rmapKey.value(key, &m_invalidNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const KeyMap::KeyMapNode& KeyMap::getKeyMapNodeMouse(int key)
|
|
|
|
const KeyMap::KeyMapNode &KeyMap::getKeyMapNodeMouse(int key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return *m_rmapMouse.value(key, &m_invalidNode);
|
|
|
|
return *m_rmapMouse.value(key, &m_invalidNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -270,7 +247,7 @@ int KeyMap::getSwitchKey()
|
|
|
|
return m_switchKey.key;
|
|
|
|
return m_switchKey.key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const KeyMap::KeyMapNode& KeyMap::getMouseMoveMap()
|
|
|
|
const KeyMap::KeyMapNode &KeyMap::getMouseMoveMap()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_keyMapNodes[m_idxMouseMove];
|
|
|
|
return m_keyMapNodes[m_idxMouseMove];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -289,39 +266,31 @@ void KeyMap::makeReverseMap()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_rmapKey.clear();
|
|
|
|
m_rmapKey.clear();
|
|
|
|
m_rmapMouse.clear();
|
|
|
|
m_rmapMouse.clear();
|
|
|
|
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;
|
|
|
|
mr.insert(node.data.steerWheel.right.key, &node);
|
|
|
|
mr.insert(node.data.steerWheel.right.key, &node);
|
|
|
|
QMultiHash<int, KeyMapNode*>& mu = node.data.steerWheel.up.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
QMultiHash<int, KeyMapNode *> &mu = node.data.steerWheel.up.type == AT_KEY ? m_rmapKey : m_rmapMouse;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -333,12 +302,12 @@ QString KeyMap::getItemString(const QJsonObject &node, const QString &name)
|
|
|
|
return node.value(name).toString();
|
|
|
|
return node.value(name).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double KeyMap::getItemDouble(const QJsonObject& node, const QString& name)
|
|
|
|
double KeyMap::getItemDouble(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return node.value(name).toDouble();
|
|
|
|
return node.value(name).toDouble();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::getItemBool(const QJsonObject& node, const QString& name)
|
|
|
|
bool KeyMap::getItemBool(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return node.value(name).toBool(false);
|
|
|
|
return node.value(name).toBool(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -348,43 +317,43 @@ QJsonObject KeyMap::getItemObject(const QJsonObject &node, const QString &name)
|
|
|
|
return node.value(name).toObject();
|
|
|
|
return node.value(name).toObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPointF KeyMap::getItemPos(const QJsonObject& node, const QString& name)
|
|
|
|
QPointF KeyMap::getItemPos(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QJsonObject pos = node.value(name).toObject();
|
|
|
|
QJsonObject pos = node.value(name).toObject();
|
|
|
|
return QPointF(pos.value("x").toDouble(), pos.value("y").toDouble());
|
|
|
|
return QPointF(pos.value("x").toDouble(), pos.value("y").toDouble());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPair<KeyMap::ActionType, int> KeyMap::getItemKey(const QJsonObject& node, const QString& name)
|
|
|
|
QPair<KeyMap::ActionType, int> KeyMap::getItemKey(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QString value = getItemString(node, name);
|
|
|
|
QString value = getItemString(node, name);
|
|
|
|
int key = m_metaEnumKey.keyToValue(value.toStdString().c_str());
|
|
|
|
int key = m_metaEnumKey.keyToValue(value.toStdString().c_str());
|
|
|
|
int btn = m_metaEnumMouseButtons.keyToValue(value.toStdString().c_str());
|
|
|
|
int btn = m_metaEnumMouseButtons.keyToValue(value.toStdString().c_str());
|
|
|
|
if (key == -1 && btn == -1) {
|
|
|
|
if (key == -1 && btn == -1) {
|
|
|
|
return {AT_INVALID, -1};
|
|
|
|
return { AT_INVALID, -1 };
|
|
|
|
} else if (key != -1) {
|
|
|
|
} else if (key != -1) {
|
|
|
|
return {AT_KEY, key};
|
|
|
|
return { AT_KEY, key };
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return {AT_MOUSE, btn};
|
|
|
|
return { AT_MOUSE, btn };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KeyMap::KeyMapType KeyMap::getItemKeyMapType(const QJsonObject& node, const QString& name)
|
|
|
|
KeyMap::KeyMapType KeyMap::getItemKeyMapType(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QString value = getItemString(node, name);
|
|
|
|
QString value = getItemString(node, name);
|
|
|
|
return static_cast<KeyMap::KeyMapType>(m_metaEnumKeyMapType.keyToValue(value.toStdString().c_str()));
|
|
|
|
return static_cast<KeyMap::KeyMapType>(m_metaEnumKeyMapType.keyToValue(value.toStdString().c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkItemString(const QJsonObject& node, const QString& name)
|
|
|
|
bool KeyMap::checkItemString(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return node.contains(name) && node.value(name).isString();
|
|
|
|
return node.contains(name) && node.value(name).isString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkItemDouble(const QJsonObject& node, const QString& name)
|
|
|
|
bool KeyMap::checkItemDouble(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return node.contains(name) && node.value(name).isDouble();
|
|
|
|
return node.contains(name) && node.value(name).isDouble();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkItemBool(const QJsonObject& node, const QString& name)
|
|
|
|
bool KeyMap::checkItemBool(const QJsonObject &node, const QString &name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return node.contains(name) && node.value(name).isBool();
|
|
|
|
return node.contains(name) && node.value(name).isBool();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -394,38 +363,33 @@ bool KeyMap::checkItemObject(const QJsonObject &node, const QString &name)
|
|
|
|
return node.contains(name) && node.value(name).isObject();
|
|
|
|
return node.contains(name) && node.value(name).isObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkItemPos(const QJsonObject& node, const QString& name)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkForClick(const QJsonObject& node)
|
|
|
|
bool KeyMap::checkForClick(const QJsonObject &node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return checkForClickTwice(node) && checkItemBool(node, "switchMap");
|
|
|
|
return checkForClickTwice(node) && checkItemBool(node, "switchMap");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMap::checkForClickTwice(const QJsonObject& node)
|
|
|
|
bool KeyMap::checkForClickTwice(const QJsonObject &node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return checkItemString(node, "key") && checkItemPos(node, "pos");
|
|
|
|
return checkItemString(node, "key") && checkItemPos(node, "pos");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|