diff --git a/src/platform/qt/ShortcutView.cpp b/src/platform/qt/ShortcutView.cpp index cc8445f3a..eab54a0b0 100644 --- a/src/platform/qt/ShortcutView.cpp +++ b/src/platform/qt/ShortcutView.cpp @@ -35,6 +35,11 @@ ShortcutView::ShortcutView(QWidget* parent) connect(m_ui.keyEdit, &KeyEditor::axisChanged, this, &ShortcutView::updateAxis); connect(m_ui.shortcutTable, &QAbstractItemView::doubleClicked, this, &ShortcutView::load); connect(m_ui.clearButton, &QAbstractButton::clicked, this, &ShortcutView::clear); +#ifdef BUILD_SDL + connect(m_ui.gamepadName, static_cast(&QComboBox::currentIndexChanged), [this](int index) { + m_input->setGamepad(SDL_BINDING_BUTTON, index); + }); +#endif } ShortcutView::~ShortcutView() { @@ -51,6 +56,25 @@ void ShortcutView::setInputController(InputController* controller) { } m_input = controller; m_input->stealFocus(this); + updateGamepads(); +} + +void ShortcutView::updateGamepads() { + if (!m_input) { + return; + } +#ifdef BUILD_SDL + m_ui.gamepadName->clear(); + + QStringList gamepads = m_input->connectedGamepads(SDL_BINDING_BUTTON); + int activeGamepad = m_input->gamepad(SDL_BINDING_BUTTON); + + for (const auto& gamepad : gamepads) { + m_ui.gamepadName->addItem(gamepad); + } + m_ui.gamepadName->setCurrentIndex(activeGamepad); +#endif + } void ShortcutView::load(const QModelIndex& index) { diff --git a/src/platform/qt/ShortcutView.h b/src/platform/qt/ShortcutView.h index af2774bbb..fc35822c0 100644 --- a/src/platform/qt/ShortcutView.h +++ b/src/platform/qt/ShortcutView.h @@ -39,6 +39,7 @@ private slots: void clear(); void updateButton(int button); void updateAxis(int axis, int direction); + void updateGamepads(); private: Ui::ShortcutView m_ui; diff --git a/src/platform/qt/ShortcutView.ui b/src/platform/qt/ShortcutView.ui index 8b28e4d52..b77d46e98 100644 --- a/src/platform/qt/ShortcutView.ui +++ b/src/platform/qt/ShortcutView.ui @@ -72,6 +72,27 @@ + + + + + + Current Gamepad + + + + + + + + 1 + 0 + + + + + +