all repos — mgba @ 3854c7e4010cd4b1795aab47dd2009980e4d2b00

mGBA Game Boy Advance Emulator

Qt: Fix a handful of UX issues with gamepad mapping
Jeffrey Pfau jeffrey@endrift.com
Mon, 05 Jan 2015 01:17:53 -0800
commit

3854c7e4010cd4b1795aab47dd2009980e4d2b00

parent

e263467f139a17c5313242711ee2a39c8248cd6d

M src/platform/qt/KeyEditor.cppsrc/platform/qt/KeyEditor.cpp

@@ -20,7 +20,11 @@ }

void KeyEditor::setValue(int key) { if (m_button) { - setText(QString::number(key)); + if (key < 0) { + clear(); + } else { + setText(QString::number(key)); + } } else { setText(QKeySequence(key).toString(QKeySequence::NativeText)); }
M src/platform/qt/ShortcutController.cppsrc/platform/qt/ShortcutController.cpp

@@ -171,6 +171,14 @@ }

return item->action(); } +bool ShortcutController::isMenuAt(const QModelIndex& index) const { + const ShortcutItem* item = itemAt(index); + if (!item) { + return false; + } + return item->menu(); +} + void ShortcutController::updateKey(const QModelIndex& index, const QKeySequence& keySequence) { if (!index.isValid()) { return;
M src/platform/qt/ShortcutController.hsrc/platform/qt/ShortcutController.h

@@ -86,9 +86,8 @@ void addAction(QMenu* menu, QAction* action, const QString& name);

void addFunctions(QMenu* menu, std::function<void ()> press, std::function<void()> release, const QKeySequence& shortcut, const QString& visibleName, const QString& name); void addMenu(QMenu* menu, QMenu* parent = nullptr); - ShortcutItem* itemAt(const QModelIndex& index); - const ShortcutItem* itemAt(const QModelIndex& index) const; const QAction* actionAt(const QModelIndex& index) const; + bool isMenuAt(const QModelIndex& index) const; void updateKey(const QModelIndex& index, const QKeySequence& keySequence); void updateButton(const QModelIndex& index, int button);

@@ -99,6 +98,8 @@

private: static QKeySequence keyEventToSequence(const QKeyEvent*); + ShortcutItem* itemAt(const QModelIndex& index); + const ShortcutItem* itemAt(const QModelIndex& index) const; void loadShortcuts(ShortcutItem*); ShortcutItem m_rootMenu;
M src/platform/qt/ShortcutView.cppsrc/platform/qt/ShortcutView.cpp

@@ -47,7 +47,7 @@ if (!m_controller) {

return; } const QAction* action = m_controller->actionAt(index); - if (!action) { + if (!action || m_controller->isMenuAt(index)) { return; } if (m_ui.gamepadButton->isChecked()) {

@@ -58,7 +58,7 @@ }

} void ShortcutView::updateKey() { - if (!m_controller) { + if (!m_controller || m_controller->isMenuAt(m_ui.shortcutTable->selectionModel()->currentIndex())) { return; } m_ui.keySequenceEdit->clearFocus();

@@ -66,7 +66,7 @@ m_controller->updateKey(m_ui.shortcutTable->selectionModel()->currentIndex(), m_ui.keySequenceEdit->keySequence());

} void ShortcutView::updateButton(int button) { - if (!m_controller) { + if (!m_controller || m_controller->isMenuAt(m_ui.shortcutTable->selectionModel()->currentIndex())) { return; } m_controller->updateButton(m_ui.shortcutTable->selectionModel()->currentIndex(), button);

@@ -79,5 +79,5 @@ }

void ShortcutView::loadButton() { m_ui.keyEdit->setFocus(); - m_ui.keyEdit->setValueButton(-1); // TODO: Real value + m_ui.keyEdit->setValueButton(-1); // There are no default bindings }