diff --git a/src/platform/qt/ShortcutController.cpp b/src/platform/qt/ShortcutController.cpp index b4974683b..0bb6d5e94 100644 --- a/src/platform/qt/ShortcutController.cpp +++ b/src/platform/qt/ShortcutController.cpp @@ -193,7 +193,9 @@ void ShortcutController::updateKey(const QModelIndex& index, const QKeySequence& if (!oldShortcut.isEmpty()) { m_heldKeys.take(oldShortcut); } - m_heldKeys[keySequence] = item; + if (!keySequence.isEmpty()) { + m_heldKeys[keySequence] = item; + } } item->setShortcut(keySequence); if (m_config) { @@ -216,13 +218,23 @@ void ShortcutController::updateButton(const QModelIndex& index, int button) { if (oldButton >= 0) { m_buttons.take(oldButton); } - m_buttons[button] = item; + if (button >= 0) { + m_buttons[button] = item; + } if (m_config) { m_config->setQtOption(item->name(), button, BUTTON_SECTION); } emit dataChanged(createIndex(index.row(), 0, index.internalPointer()), createIndex(index.row(), 2, index.internalPointer())); } +void ShortcutController::clearKey(const QModelIndex& index) { + updateKey(index, QKeySequence()); +} + +void ShortcutController::clearButton(const QModelIndex& index) { + updateButton(index, -1); +} + bool ShortcutController::eventFilter(QObject*, QEvent* event) { if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { QKeyEvent* keyEvent = static_cast(event); diff --git a/src/platform/qt/ShortcutController.h b/src/platform/qt/ShortcutController.h index 48c5eda7b..53d8e1e1b 100644 --- a/src/platform/qt/ShortcutController.h +++ b/src/platform/qt/ShortcutController.h @@ -92,6 +92,9 @@ public: void updateKey(const QModelIndex& index, const QKeySequence& keySequence); void updateButton(const QModelIndex& index, int button); + void clearKey(const QModelIndex& index); + void clearButton(const QModelIndex& index); + protected: bool eventFilter(QObject*, QEvent*) override; diff --git a/src/platform/qt/ShortcutView.cpp b/src/platform/qt/ShortcutView.cpp index 141771810..df04e9226 100644 --- a/src/platform/qt/ShortcutView.cpp +++ b/src/platform/qt/ShortcutView.cpp @@ -21,6 +21,7 @@ ShortcutView::ShortcutView(QWidget* parent) connect(m_ui.keySequenceEdit, SIGNAL(editingFinished()), this, SLOT(updateKey())); 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())); } void ShortcutView::setController(ShortcutController* controller) { @@ -51,9 +52,29 @@ void ShortcutView::load(const QModelIndex& index) { return; } if (m_ui.gamepadButton->isChecked()) { - loadButton(); + m_ui.keyEdit->setFocus(); + m_ui.keyEdit->setValueButton(-1); // There are no default bindings } else { - loadKey(action); + m_ui.keySequenceEdit->setFocus(); + m_ui.keySequenceEdit->setKeySequence(action->shortcut()); + } +} + +void ShortcutView::clear() { + if (!m_controller) { + return; + } + QModelIndex index = m_ui.shortcutTable->selectionModel()->currentIndex(); + const QAction* action = m_controller->actionAt(index); + if (!action || m_controller->isMenuAt(index)) { + return; + } + if (m_ui.gamepadButton->isChecked()) { + m_controller->clearButton(index); + m_ui.keyEdit->setValueButton(-1); + } else { + m_controller->clearKey(index); + m_ui.keySequenceEdit->setKeySequence(QKeySequence()); } } @@ -69,15 +90,7 @@ 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); } -void ShortcutView::loadKey(const QAction* action) { - m_ui.keySequenceEdit->setFocus(); - m_ui.keySequenceEdit->setKeySequence(action->shortcut()); -} - -void ShortcutView::loadButton() { - m_ui.keyEdit->setFocus(); - m_ui.keyEdit->setValueButton(-1); // There are no default bindings -} diff --git a/src/platform/qt/ShortcutView.h b/src/platform/qt/ShortcutView.h index 7526a5dda..58cfe36d1 100644 --- a/src/platform/qt/ShortcutView.h +++ b/src/platform/qt/ShortcutView.h @@ -29,6 +29,7 @@ protected: private slots: void load(const QModelIndex&); + void clear(); void updateKey(); void updateButton(int button); diff --git a/src/platform/qt/ShortcutView.ui b/src/platform/qt/ShortcutView.ui index 0a0cc64c3..05d114c02 100644 --- a/src/platform/qt/ShortcutView.ui +++ b/src/platform/qt/ShortcutView.ui @@ -40,6 +40,13 @@ + + + + Clear + + + @@ -61,18 +68,6 @@ 0 - - - 40 - 0 - - - - - 100 - 16777215 - - @@ -83,27 +78,9 @@ 0 - - - 40 - 0 - - - - - 100 - 16777215 - - false - - Qt::AlignCenter - - - Press button -