Qt: Allow merging input indices
Vicki Pfau vi@endrift.com
Sun, 02 Jul 2017 22:21:03 -0700
3 files changed,
24 insertions(+),
11 deletions(-)
M
src/platform/qt/input/InputIndex.cpp
→
src/platform/qt/input/InputIndex.cpp
@@ -64,9 +64,15 @@ }
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 @@ m_menus[menu] = 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 @@ }
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); } }
M
src/platform/qt/input/InputItem.cpp
→
src/platform/qt/input/InputItem.cpp
@@ -16,7 +16,7 @@
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) {
M
src/platform/qt/input/InputItem.h
→
src/platform/qt/input/InputItem.h
@@ -43,14 +43,17 @@
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 @@ QMenu* m_menu = nullptr;
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; };