Path: blob/master/src/duckstation-qt/controllerglobalsettingswidget.cpp
4246 views
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>1// SPDX-License-Identifier: CC-BY-NC-ND-4.023#include "controllerglobalsettingswidget.h"4#include "controllerbindingwidgets.h"5#include "controllersettingswindow.h"6#include "controllersettingwidgetbinder.h"7#include "qtutils.h"8#include "settingwidgetbinder.h"910#include "fmt/format.h"1112#include "util/ini_settings_interface.h"13#include "util/sdl_input_source.h"1415#include "moc_controllerglobalsettingswidget.cpp"1617ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent, ControllerSettingsWindow* dialog)18: QWidget(parent), m_dialog(dialog)19{20m_ui.setupUi(this);2122SettingsInterface* sif = dialog->getEditingSettingsInterface();2324ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLSource, "InputSources", "SDL", true);25ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLEnhancedMode, "InputSources",26"SDLControllerEnhancedMode", false);27ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableTouchPadAsPointer, "InputSources",28"SDLTouchpadAsPointer", false);29ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLPS5PlayerLED, "InputSources",30"SDLPS5PlayerLED", false);31connect(m_ui.enableSDLSource, &QCheckBox::checkStateChanged, this,32&ControllerGlobalSettingsWidget::updateSDLOptionsEnabled);33connect(m_ui.ledSettings, &QToolButton::clicked, this, &ControllerGlobalSettingsWidget::ledSettingsClicked);34connect(m_ui.SDLHelpText, &QLabel::linkActivated, this, &ControllerGlobalSettingsWidget::sdlHelpTextLinkClicked);3536#ifdef _WIN3237ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableDInputSource, "InputSources", "DInput",38false);39ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableXInputSource, "InputSources", "XInput",40false);41ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableRawInput, "InputSources", "RawInput",42false);43#else44m_ui.mainLayout->removeWidget(m_ui.xinputGroup);45delete m_ui.xinputGroup;46m_ui.xinputGroup = nullptr;47m_ui.mainLayout->removeWidget(m_ui.dinputGroup);48delete m_ui.dinputGroup;49m_ui.dinputGroup = nullptr;50#endif5152ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableMouseMapping, "UI", "EnableMouseMapping",53false);54ControllerSettingWidgetBinder::BindWidgetToInputProfileEnumSetting(55sif, m_ui.multitapMode, "ControllerPorts", "MultitapMode", &Settings::ParseMultitapModeName,56&Settings::GetMultitapModeName, &Settings::GetMultitapModeDisplayName, Settings::DEFAULT_MULTITAP_MODE,57MultitapMode::Count);58ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerXScale, "ControllerPorts",59"PointerXScale", 8.0f);60ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerYScale, "ControllerPorts",61"PointerYScale", 8.0f);6263if (dialog->isEditingProfile())64{65m_ui.useProfileHotkeyBindings->setChecked(66m_dialog->getBoolValue("ControllerPorts", "UseProfileHotkeyBindings", false));67connect(m_ui.useProfileHotkeyBindings, &QCheckBox::checkStateChanged, this, [this](int new_state) {68m_dialog->setBoolValue("ControllerPorts", "UseProfileHotkeyBindings", (new_state == Qt::Checked));69emit bindingSetupChanged();70});71}72else73{74// remove profile options from the UI.75m_ui.mainLayout->removeWidget(m_ui.profileSettings);76delete m_ui.profileSettings;77m_ui.profileSettings = nullptr;78}7980m_ui.deviceList->setModel(g_emu_thread->getInputDeviceListModel());8182connect(m_ui.multitapMode, &QComboBox::currentIndexChanged, this, [this]() { emit bindingSetupChanged(); });8384connect(m_ui.pointerXScale, &QSlider::valueChanged, this,85[this](int value) { m_ui.pointerXScaleLabel->setText(QStringLiteral("%1").arg(value)); });86connect(m_ui.pointerYScale, &QSlider::valueChanged, this,87[this](int value) { m_ui.pointerYScaleLabel->setText(QStringLiteral("%1").arg(value)); });88m_ui.pointerXScaleLabel->setText(QStringLiteral("%1").arg(m_ui.pointerXScale->value()));89m_ui.pointerYScaleLabel->setText(QStringLiteral("%1").arg(m_ui.pointerYScale->value()));9091updateSDLOptionsEnabled();92}9394ControllerGlobalSettingsWidget::~ControllerGlobalSettingsWidget() = default;9596void ControllerGlobalSettingsWidget::ledSettingsClicked()97{98ControllerLEDSettingsDialog dialog(this, m_dialog);99dialog.exec();100}101102void ControllerGlobalSettingsWidget::sdlHelpTextLinkClicked(const QString& link)103{104if (link == QStringLiteral("ADVANCED_SDL_OPTIONS"))105{106ControllerCustomSettingsDialog dialog(m_dialog, m_dialog->getEditingSettingsInterface(), "InputSources",107SDLInputSource::GetAdvancedSettingsInfo(), "SDLInputSource",108tr("Advanced SDL Options"));109dialog.exec();110}111}112113void ControllerGlobalSettingsWidget::updateSDLOptionsEnabled()114{115const bool enabled = m_ui.enableSDLSource->isChecked();116if (m_ui.enableSDLEnhancedMode)117m_ui.enableSDLEnhancedMode->setEnabled(enabled);118if (m_ui.enableTouchPadAsPointer)119m_ui.enableTouchPadAsPointer->setEnabled(enabled);120if (m_ui.enableSDLPS5PlayerLED)121m_ui.enableSDLPS5PlayerLED->setEnabled(enabled);122if (m_ui.ledSettings)123m_ui.ledSettings->setEnabled(enabled);124}125126ControllerLEDSettingsDialog::ControllerLEDSettingsDialog(QWidget* parent, ControllerSettingsWindow* dialog)127: QDialog(parent), m_dialog(dialog)128{129m_ui.setupUi(this);130m_ui.buttonBox->button(QDialogButtonBox::Close)->setDefault(true);131132linkButton(m_ui.SDL0LED, 0);133linkButton(m_ui.SDL1LED, 1);134linkButton(m_ui.SDL2LED, 2);135linkButton(m_ui.SDL3LED, 3);136137connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::accept);138}139140ControllerLEDSettingsDialog::~ControllerLEDSettingsDialog() = default;141142void ControllerLEDSettingsDialog::linkButton(ColorPickerButton* button, u32 player_id)143{144std::string key = fmt::format("Player{}LED", player_id);145const u32 current_value =146SDLInputSource::ParseRGBForPlayerId(m_dialog->getStringValue("SDLExtra", key.c_str(), ""), player_id);147button->setColor(current_value);148149connect(button, &ColorPickerButton::colorChanged, this, [this, key = std::move(key)](u32 new_rgb) {150m_dialog->setStringValue("SDLExtra", key.c_str(), fmt::format("{:06X}", new_rgb).c_str());151});152}153154155