Qt: Add gamepad selector
Vicki Pfau vi@endrift.com
Thu, 06 Jul 2017 15:08:28 -0700
3 files changed,
46 insertions(+),
0 deletions(-)
M
src/platform/qt/ShortcutView.cpp
→
src/platform/qt/ShortcutView.cpp
@@ -35,6 +35,11 @@ connect(m_ui.keyEdit, &KeyEditor::valueChanged, this, &ShortcutView::updateButton);
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 @@ m_input->releaseFocus(this);
} 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) {
M
src/platform/qt/ShortcutView.h
→
src/platform/qt/ShortcutView.h
@@ -39,6 +39,7 @@ void load(const QModelIndex&);
void clear(); void updateButton(int button); void updateAxis(int axis, int direction); + void updateGamepads(); private: Ui::ShortcutView m_ui;
M
src/platform/qt/ShortcutView.ui
→
src/platform/qt/ShortcutView.ui
@@ -72,6 +72,27 @@ </widget>
</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>