diff --git a/src/platform/qt/KeyEditor.cpp b/src/platform/qt/KeyEditor.cpp index 48fb427da..b769a024d 100644 --- a/src/platform/qt/KeyEditor.cpp +++ b/src/platform/qt/KeyEditor.cpp @@ -20,7 +20,11 @@ KeyEditor::KeyEditor(QWidget* parent) 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)); } diff --git a/src/platform/qt/ShortcutController.cpp b/src/platform/qt/ShortcutController.cpp index 7e31c9b29..b4974683b 100644 --- a/src/platform/qt/ShortcutController.cpp +++ b/src/platform/qt/ShortcutController.cpp @@ -171,6 +171,14 @@ const QAction* ShortcutController::actionAt(const QModelIndex& index) const { 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; diff --git a/src/platform/qt/ShortcutController.h b/src/platform/qt/ShortcutController.h index 6ec23e819..48c5eda7b 100644 --- a/src/platform/qt/ShortcutController.h +++ b/src/platform/qt/ShortcutController.h @@ -86,9 +86,8 @@ public: void addFunctions(QMenu* menu, std::function press, std::function 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 @@ protected: private: static QKeySequence keyEventToSequence(const QKeyEvent*); + ShortcutItem* itemAt(const QModelIndex& index); + const ShortcutItem* itemAt(const QModelIndex& index) const; void loadShortcuts(ShortcutItem*); ShortcutItem m_rootMenu; diff --git a/src/platform/qt/ShortcutView.cpp b/src/platform/qt/ShortcutView.cpp index eec867d28..141771810 100644 --- a/src/platform/qt/ShortcutView.cpp +++ b/src/platform/qt/ShortcutView.cpp @@ -47,7 +47,7 @@ void ShortcutView::load(const QModelIndex& index) { 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::load(const QModelIndex& index) { } 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 @@ void ShortcutView::updateKey() { } 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::loadKey(const QAction* action) { 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 }