diff --git a/src/platform/qt/input/InputIndex.cpp b/src/platform/qt/input/InputIndex.cpp index b3c9d557b..182653dd5 100644 --- a/src/platform/qt/input/InputIndex.cpp +++ b/src/platform/qt/input/InputIndex.cpp @@ -64,9 +64,15 @@ void InputIndex::rebuild(const InputIndex* root) { if (!newItem) { continue; } - newItem->setShortcut(item->shortcut()); - newItem->setButton(item->button()); - newItem->setAxis(item->axis(), item->direction()); + if (item->hasShortcut()) { + newItem->setShortcut(item->shortcut()); + } + if (item->hasButton()) { + newItem->setButton(item->button()); + } + if (item->hasAxis()) { + newItem->setAxis(item->axis(), item->direction()); + } itemAdded(newItem); } @@ -184,7 +190,7 @@ void InputIndex::itemAdded(InputItem* child) { } m_names[child->name()] = child; - if (child->shortcut()) { + if (child->shortcut() > 0) { m_shortcuts[child->shortcut()] = child; } if (child->button() >= 0) { @@ -231,9 +237,13 @@ int InputIndex::toModifierKey(int key) { void InputIndex::saveConfig() { for (auto& item : m_items) { - m_config->setQtOption(item->name(), QKeySequence(item->shortcut()).toString(), KEY_SECTION); - m_config->setQtOption(item->name(), item->button(), BUTTON_SECTION); - if (item->direction() != GamepadAxisEvent::NEUTRAL) { + if (item->hasShortcut()) { + m_config->setQtOption(item->name(), QKeySequence(item->shortcut()).toString(), KEY_SECTION); + } + if (item->hasButton()) { + m_config->setQtOption(item->name(), item->button(), BUTTON_SECTION); + } + if (item->hasAxis()) { m_config->setQtOption(item->name(), QString("%1%2").arg(GamepadAxisEvent::POSITIVE ? '+' : '-').arg(item->axis()), AXIS_SECTION); } } diff --git a/src/platform/qt/input/InputItem.cpp b/src/platform/qt/input/InputItem.cpp index 058ad5987..f5a050757 100644 --- a/src/platform/qt/input/InputItem.cpp +++ b/src/platform/qt/input/InputItem.cpp @@ -16,7 +16,7 @@ InputItem::InputItem() InputItem::InputItem(QAction* action, const QString& name, QMenu* parent) : QObject(parent) , m_action(action) - , m_shortcut(action->shortcut().isEmpty() ? 0 : action->shortcut()[0]) + , m_shortcut(action->shortcut().isEmpty() ? -2 : action->shortcut()[0]) , m_name(name) , m_menu(parent) { diff --git a/src/platform/qt/input/InputItem.h b/src/platform/qt/input/InputItem.h index c95bdcad5..ffd582868 100644 --- a/src/platform/qt/input/InputItem.h +++ b/src/platform/qt/input/InputItem.h @@ -43,14 +43,17 @@ public: int shortcut() const { return m_shortcut; } void setShortcut(int sequence); void clearShortcut(); + bool hasShortcut() { return m_shortcut > -2; } int button() const { return m_button; } void setButton(int button); void clearButton(); + bool hasButton() { return m_button > -2; } int axis() const { return m_axis; } GamepadAxisEvent::Direction direction() const { return m_direction; } void setAxis(int axis, GamepadAxisEvent::Direction direction); + bool hasAxis() { return m_axis > -2; } bool operator==(const InputItem& other) const { return m_name == other.m_name; @@ -73,9 +76,9 @@ private: QString m_name; QString m_visibleName; - int m_shortcut = 0; - int m_button = -1; - int m_axis = -1; + int m_shortcut = -2; + int m_button = -2; + int m_axis = -2; GamepadAxisEvent::Direction m_direction = GamepadAxisEvent::NEUTRAL; };