Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/controllerglobalsettingswidget.cpp
4246 views
1
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#include "controllerglobalsettingswidget.h"
5
#include "controllerbindingwidgets.h"
6
#include "controllersettingswindow.h"
7
#include "controllersettingwidgetbinder.h"
8
#include "qtutils.h"
9
#include "settingwidgetbinder.h"
10
11
#include "fmt/format.h"
12
13
#include "util/ini_settings_interface.h"
14
#include "util/sdl_input_source.h"
15
16
#include "moc_controllerglobalsettingswidget.cpp"
17
18
ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent, ControllerSettingsWindow* dialog)
19
: QWidget(parent), m_dialog(dialog)
20
{
21
m_ui.setupUi(this);
22
23
SettingsInterface* sif = dialog->getEditingSettingsInterface();
24
25
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLSource, "InputSources", "SDL", true);
26
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLEnhancedMode, "InputSources",
27
"SDLControllerEnhancedMode", false);
28
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableTouchPadAsPointer, "InputSources",
29
"SDLTouchpadAsPointer", false);
30
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLPS5PlayerLED, "InputSources",
31
"SDLPS5PlayerLED", false);
32
connect(m_ui.enableSDLSource, &QCheckBox::checkStateChanged, this,
33
&ControllerGlobalSettingsWidget::updateSDLOptionsEnabled);
34
connect(m_ui.ledSettings, &QToolButton::clicked, this, &ControllerGlobalSettingsWidget::ledSettingsClicked);
35
connect(m_ui.SDLHelpText, &QLabel::linkActivated, this, &ControllerGlobalSettingsWidget::sdlHelpTextLinkClicked);
36
37
#ifdef _WIN32
38
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableDInputSource, "InputSources", "DInput",
39
false);
40
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableXInputSource, "InputSources", "XInput",
41
false);
42
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableRawInput, "InputSources", "RawInput",
43
false);
44
#else
45
m_ui.mainLayout->removeWidget(m_ui.xinputGroup);
46
delete m_ui.xinputGroup;
47
m_ui.xinputGroup = nullptr;
48
m_ui.mainLayout->removeWidget(m_ui.dinputGroup);
49
delete m_ui.dinputGroup;
50
m_ui.dinputGroup = nullptr;
51
#endif
52
53
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableMouseMapping, "UI", "EnableMouseMapping",
54
false);
55
ControllerSettingWidgetBinder::BindWidgetToInputProfileEnumSetting(
56
sif, m_ui.multitapMode, "ControllerPorts", "MultitapMode", &Settings::ParseMultitapModeName,
57
&Settings::GetMultitapModeName, &Settings::GetMultitapModeDisplayName, Settings::DEFAULT_MULTITAP_MODE,
58
MultitapMode::Count);
59
ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerXScale, "ControllerPorts",
60
"PointerXScale", 8.0f);
61
ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerYScale, "ControllerPorts",
62
"PointerYScale", 8.0f);
63
64
if (dialog->isEditingProfile())
65
{
66
m_ui.useProfileHotkeyBindings->setChecked(
67
m_dialog->getBoolValue("ControllerPorts", "UseProfileHotkeyBindings", false));
68
connect(m_ui.useProfileHotkeyBindings, &QCheckBox::checkStateChanged, this, [this](int new_state) {
69
m_dialog->setBoolValue("ControllerPorts", "UseProfileHotkeyBindings", (new_state == Qt::Checked));
70
emit bindingSetupChanged();
71
});
72
}
73
else
74
{
75
// remove profile options from the UI.
76
m_ui.mainLayout->removeWidget(m_ui.profileSettings);
77
delete m_ui.profileSettings;
78
m_ui.profileSettings = nullptr;
79
}
80
81
m_ui.deviceList->setModel(g_emu_thread->getInputDeviceListModel());
82
83
connect(m_ui.multitapMode, &QComboBox::currentIndexChanged, this, [this]() { emit bindingSetupChanged(); });
84
85
connect(m_ui.pointerXScale, &QSlider::valueChanged, this,
86
[this](int value) { m_ui.pointerXScaleLabel->setText(QStringLiteral("%1").arg(value)); });
87
connect(m_ui.pointerYScale, &QSlider::valueChanged, this,
88
[this](int value) { m_ui.pointerYScaleLabel->setText(QStringLiteral("%1").arg(value)); });
89
m_ui.pointerXScaleLabel->setText(QStringLiteral("%1").arg(m_ui.pointerXScale->value()));
90
m_ui.pointerYScaleLabel->setText(QStringLiteral("%1").arg(m_ui.pointerYScale->value()));
91
92
updateSDLOptionsEnabled();
93
}
94
95
ControllerGlobalSettingsWidget::~ControllerGlobalSettingsWidget() = default;
96
97
void ControllerGlobalSettingsWidget::ledSettingsClicked()
98
{
99
ControllerLEDSettingsDialog dialog(this, m_dialog);
100
dialog.exec();
101
}
102
103
void ControllerGlobalSettingsWidget::sdlHelpTextLinkClicked(const QString& link)
104
{
105
if (link == QStringLiteral("ADVANCED_SDL_OPTIONS"))
106
{
107
ControllerCustomSettingsDialog dialog(m_dialog, m_dialog->getEditingSettingsInterface(), "InputSources",
108
SDLInputSource::GetAdvancedSettingsInfo(), "SDLInputSource",
109
tr("Advanced SDL Options"));
110
dialog.exec();
111
}
112
}
113
114
void ControllerGlobalSettingsWidget::updateSDLOptionsEnabled()
115
{
116
const bool enabled = m_ui.enableSDLSource->isChecked();
117
if (m_ui.enableSDLEnhancedMode)
118
m_ui.enableSDLEnhancedMode->setEnabled(enabled);
119
if (m_ui.enableTouchPadAsPointer)
120
m_ui.enableTouchPadAsPointer->setEnabled(enabled);
121
if (m_ui.enableSDLPS5PlayerLED)
122
m_ui.enableSDLPS5PlayerLED->setEnabled(enabled);
123
if (m_ui.ledSettings)
124
m_ui.ledSettings->setEnabled(enabled);
125
}
126
127
ControllerLEDSettingsDialog::ControllerLEDSettingsDialog(QWidget* parent, ControllerSettingsWindow* dialog)
128
: QDialog(parent), m_dialog(dialog)
129
{
130
m_ui.setupUi(this);
131
m_ui.buttonBox->button(QDialogButtonBox::Close)->setDefault(true);
132
133
linkButton(m_ui.SDL0LED, 0);
134
linkButton(m_ui.SDL1LED, 1);
135
linkButton(m_ui.SDL2LED, 2);
136
linkButton(m_ui.SDL3LED, 3);
137
138
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::accept);
139
}
140
141
ControllerLEDSettingsDialog::~ControllerLEDSettingsDialog() = default;
142
143
void ControllerLEDSettingsDialog::linkButton(ColorPickerButton* button, u32 player_id)
144
{
145
std::string key = fmt::format("Player{}LED", player_id);
146
const u32 current_value =
147
SDLInputSource::ParseRGBForPlayerId(m_dialog->getStringValue("SDLExtra", key.c_str(), ""), player_id);
148
button->setColor(current_value);
149
150
connect(button, &ColorPickerButton::colorChanged, this, [this, key = std::move(key)](u32 new_rgb) {
151
m_dialog->setStringValue("SDLExtra", key.c_str(), fmt::format("{:06X}", new_rgb).c_str());
152
});
153
}
154
155