all repos — mgba @ ec5445d5ada31006cf154f5cba767b4239b7ffd3

mGBA Game Boy Advance Emulator

Qt: Allow tab and backtab to be mapped for key sequences
Jeffrey Pfau jeffrey@endrift.com
Mon, 05 Jan 2015 02:27:50 -0800
commit

ec5445d5ada31006cf154f5cba767b4239b7ffd3

parent

851d942cdd8ceebfe08f9a1be8940d4c3a62e689

M src/platform/qt/ShortcutController.hsrc/platform/qt/ShortcutController.h

@@ -95,12 +95,12 @@

void clearKey(const QModelIndex& index); void clearButton(const QModelIndex& index); + static QKeySequence keyEventToSequence(const QKeyEvent*); + protected: bool eventFilter(QObject*, QEvent*) override; private: - static QKeySequence keyEventToSequence(const QKeyEvent*); - ShortcutItem* itemAt(const QModelIndex& index); const ShortcutItem* itemAt(const QModelIndex& index) const; void loadShortcuts(ShortcutItem*);
M src/platform/qt/ShortcutView.cppsrc/platform/qt/ShortcutView.cpp

@@ -8,6 +8,8 @@

#include "GamepadButtonEvent.h" #include "ShortcutController.h" +#include <QKeyEvent> + using namespace QGBA; ShortcutView::ShortcutView(QWidget* parent)

@@ -17,8 +19,9 @@ , m_inputController(nullptr)

{ m_ui.setupUi(this); m_ui.keyEdit->setValueButton(-1); + m_ui.keySequenceEdit->installEventFilter(this); - connect(m_ui.keySequenceEdit, SIGNAL(editingFinished()), this, SLOT(updateKey())); + connect(m_ui.keySequenceEdit, SIGNAL(keySequenceChanged(const QKeySequence&)), this, SLOT(updateKey(const QKeySequence&))); connect(m_ui.keyEdit, SIGNAL(valueChanged(int)), this, SLOT(updateButton(int))); connect(m_ui.shortcutTable, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(load(const QModelIndex&))); connect(m_ui.clearButton, SIGNAL(clicked()), this, SLOT(clear()));

@@ -43,6 +46,21 @@ }

return QWidget::event(event); } +bool ShortcutView::eventFilter(QObject*, QEvent* event) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); + if (keyEvent->key() != Qt::Key_Tab && keyEvent->key() != Qt::Key_Backtab) { + return false; + } + if (!(keyEvent->modifiers() & ~Qt::ShiftModifier)) { + m_ui.keySequenceEdit->setKeySequence(ShortcutController::keyEventToSequence(keyEvent)); + keyEvent->accept(); + return true; + } + } + return false; +} + void ShortcutView::load(const QModelIndex& index) { if (!m_controller) { return;

@@ -82,19 +100,17 @@ m_ui.keySequenceEdit->setKeySequence(QKeySequence());

} } -void ShortcutView::updateKey() { +void ShortcutView::updateKey(const QKeySequence& shortcut) { if (!m_controller || m_controller->isMenuAt(m_ui.shortcutTable->selectionModel()->currentIndex())) { return; } - m_ui.keySequenceEdit->clearFocus(); - m_controller->updateKey(m_ui.shortcutTable->selectionModel()->currentIndex(), m_ui.keySequenceEdit->keySequence()); + m_controller->updateKey(m_ui.shortcutTable->selectionModel()->currentIndex(), shortcut); } void ShortcutView::updateButton(int button) { if (!m_controller || m_controller->isMenuAt(m_ui.shortcutTable->selectionModel()->currentIndex())) { return; } - m_ui.keyEdit->clearFocus(); m_controller->updateButton(m_ui.shortcutTable->selectionModel()->currentIndex(), button); }
M src/platform/qt/ShortcutView.hsrc/platform/qt/ShortcutView.h

@@ -26,17 +26,15 @@ void setInputController(InputController* controller);

protected: virtual bool event(QEvent* event) override; + virtual bool eventFilter(QObject* obj, QEvent* event) override; private slots: void load(const QModelIndex&); void clear(); - void updateKey(); + void updateKey(const QKeySequence&); void updateButton(int button); private: - void loadKey(const QAction*); - void loadButton(); - Ui::ShortcutView m_ui; ShortcutController* m_controller;