Qt: Add gamepad selector

This commit is contained in:
Vicki Pfau 2017-07-06 15:08:28 -07:00
parent f247d3b337
commit dfd111d389
3 changed files with 46 additions and 0 deletions

View File

@ -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<void (QComboBox::*)(int)>(&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) {

View File

@ -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;

View File

@ -72,6 +72,27 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Current Gamepad</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="gamepadName">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>