all repos — mgba @ f247d3b337835cf29dd6d678fb7b3afa2086cbeb

mGBA Game Boy Advance Emulator

Qt: Allow merging input indices
Vicki Pfau vi@endrift.com
Sun, 02 Jul 2017 22:21:03 -0700
commit

f247d3b337835cf29dd6d678fb7b3afa2086cbeb

parent

ac2e7b644792c2bbde411d6433cc16ca27f71591

M src/platform/qt/input/InputIndex.cppsrc/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.cppsrc/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.hsrc/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; };