Debian Codegraph @

Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp

raw symbols SCIP
1 // Copyright 2017 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "DolphinQt/Config/Mapping/MappingWindow.h"
5
6 #include <QAction>
7 #include <QCheckBox>
8 #include <QComboBox>
9 #include <QDesktopServices>
10 #include <QDialogButtonBox>
11 #include <QGroupBox>
12 #include <QHBoxLayout>
13 #include <QPushButton>
14 #include <QScreen>
15 #include <QTabWidget>
16 #include <QTimer>
17 #include <QToolButton>
18 #include <QUrl>
19 #include <QVBoxLayout>
20
21 #include "Core/HotkeyManager.h"
22
23 #include "Common/CommonPaths.h"
24 #include "Common/FileSearch.h"
25 #include "Common/FileUtil.h"
26 #include "Common/IniFile.h"
27 #include "Common/StringUtil.h"
28
29 #include "Core/HW/SI/SI.h"
30 #include "Core/HW/SI/SI_DeviceAMBaseboard.h"
31
32 #include "DolphinQt/Config/Mapping/FreeLookGeneral.h"
33 #include "DolphinQt/Config/Mapping/FreeLookRotation.h"
34 #include "DolphinQt/Config/Mapping/GBAPadEmu.h"
35 #include "DolphinQt/Config/Mapping/GCKeyboardEmu.h"
36 #include "DolphinQt/Config/Mapping/GCMicrophone.h"
37 #include "DolphinQt/Config/Mapping/GCPadEmu.h"
38 #include "DolphinQt/Config/Mapping/Hotkey3D.h"
39 #include "DolphinQt/Config/Mapping/HotkeyControllerProfile.h"
40 #include "DolphinQt/Config/Mapping/HotkeyDebugging.h"
41 #include "DolphinQt/Config/Mapping/HotkeyGBA.h"
42 #include "DolphinQt/Config/Mapping/HotkeyGeneral.h"
43 #include "DolphinQt/Config/Mapping/HotkeyGraphics.h"
44 #include "DolphinQt/Config/Mapping/HotkeyStates.h"
45 #include "DolphinQt/Config/Mapping/HotkeyStatesOther.h"
46 #include "DolphinQt/Config/Mapping/HotkeyTAS.h"
47 #include "DolphinQt/Config/Mapping/HotkeyUSBEmu.h"
48 #include "DolphinQt/Config/Mapping/HotkeyWii.h"
49 #include "DolphinQt/Config/Mapping/MappingCommon.h"
50 #include "DolphinQt/Config/Mapping/WiimoteEmuExtension.h"
51 #include "DolphinQt/Config/Mapping/WiimoteEmuExtensionMotionInput.h"
52 #include "DolphinQt/Config/Mapping/WiimoteEmuExtensionMotionSimulation.h"
53 #include "DolphinQt/Config/Mapping/WiimoteEmuGeneral.h"
54 #include "DolphinQt/Config/Mapping/WiimoteEmuMotionControl.h"
55 #include "DolphinQt/Config/Mapping/WiimoteEmuMotionControlIMU.h"
56 #include "DolphinQt/QtUtils/ModalMessageBox.h"
57 #include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
58 #include "DolphinQt/QtUtils/QtUtils.h"
59 #include "DolphinQt/QtUtils/WindowActivationEventFilter.h"
60 #include "DolphinQt/QtUtils/WrapInScrollArea.h"
61 #include "DolphinQt/Settings.h"
62
63 #include "InputCommon/ControllerEmu/ControllerEmu.h"
64 #include "InputCommon/ControllerInterface/ControllerInterface.h"
65 #include "InputCommon/ControllerInterface/CoreDevice.h"
66 #include "InputCommon/InputConfig.h"
67
68 MappingWindow::MappingWindow(QWidget* parent, Type type, int port_num)
69 : QDialog(parent), m_port(port_num)
70 {
71 setWindowTitle(tr("Port %1").arg(port_num + 1));
72
73 CreateDevicesLayout();
74 CreateProfilesLayout();
75 CreateResetLayout();
76 CreateMainLayout();
77 ConnectWidgets();
78 SetMappingType(type);
79
80 const auto timer = new QTimer(this);
81 connect(timer, &QTimer::timeout, this, [this, timer] {
82 const double refresh_rate = screen()->refreshRate();
83 timer->setInterval(1000 / refresh_rate);
84
85 const auto lock = GetController()->GetStateLock();
86 emit Update();
87 });
88
89 timer->start(100);
90
91 const auto lock = GetController()->GetStateLock();
92 emit ConfigChanged();
93
94 auto* filter = new WindowActivationEventFilter(this);
95 installEventFilter(filter);
96
97 filter->connect(filter, &WindowActivationEventFilter::windowDeactivated,
98 [] { HotkeyManagerEmu::Enable(true); });
99 filter->connect(filter, &WindowActivationEventFilter::windowActivated,
100 [] { HotkeyManagerEmu::Enable(false); });
101
102 MappingCommon::CreateMappingProcessor(this);
103
104 QtUtils::AdjustSizeWithinScreen(this);
105 }
106
107 void MappingWindow::CreateDevicesLayout()
108 {
109 m_devices_layout = new QHBoxLayout();
110 m_devices_box = new QGroupBox(tr("Device"));
111 m_devices_combo = new QComboBox();
112
113 auto* const options = new QToolButton();
114 // Make it more apparent that this is a menu with more options.
115 options->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup);
116
117 const auto refresh_action = new QAction(tr("Refresh"), options);
118 connect(refresh_action, &QAction::triggered, this, &MappingWindow::RefreshDevices);
119
120 m_other_device_mappings = new QAction(tr("Create Mappings for Other Devices"), options);
121 m_other_device_mappings->setCheckable(true);
122
123 m_wait_for_alternate_mappings = new QAction(tr("Wait for Alternate Input Mappings"), options);
124 m_wait_for_alternate_mappings->setCheckable(true);
125
126 m_iterative_mapping = new QAction(tr("Enable Iterative Input Mapping"), options);
127 m_iterative_mapping->setCheckable(true);
128
129 options->addAction(refresh_action);
130 options->addAction(m_other_device_mappings);
131 options->addAction(m_wait_for_alternate_mappings);
132 options->addAction(m_iterative_mapping);
133 options->setDefaultAction(refresh_action);
134
135 m_devices_combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
136 options->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
137
138 m_devices_layout->addWidget(m_devices_combo);
139 m_devices_layout->addWidget(options);
140
141 m_devices_box->setLayout(m_devices_layout);
142 }
143
144 void MappingWindow::CreateProfilesLayout()
145 {
146 m_profiles_layout = new QHBoxLayout();
147 m_profiles_box = new QGroupBox(tr("Profile"));
148 m_profiles_combo = new QComboBox();
149 m_profiles_load = new NonDefaultQPushButton(tr("Load"));
150 m_profiles_save = new NonDefaultQPushButton(tr("Save"));
151
152 // Other actions
153 m_profile_other_actions = new QToolButton();
154 m_profile_other_actions->setPopupMode(QToolButton::InstantPopup);
155 m_profile_other_actions->setArrowType(Qt::DownArrow);
156 m_profile_other_actions->setStyleSheet(
157 QStringLiteral("QToolButton::menu-indicator { image: none; }")); // remove other arrow
158 m_profiles_delete = new QAction(tr("Delete"), this);
159 m_profiles_open_folder = new QAction(tr("Open Folder"), this);
160 m_profile_other_actions->addAction(m_profiles_delete);
161 m_profile_other_actions->addAction(m_profiles_open_folder);
162
163 auto* button_layout = new QHBoxLayout();
164
165 m_profiles_combo->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
166 m_profiles_combo->setMinimumWidth(100);
167 m_profiles_combo->setEditable(true);
168
169 m_profiles_layout->addWidget(m_profiles_combo);
170 button_layout->addWidget(m_profiles_load);
171 button_layout->addWidget(m_profiles_save);
172 button_layout->addWidget(m_profile_other_actions);
173 m_profiles_layout->addLayout(button_layout);
174
175 m_profiles_box->setLayout(m_profiles_layout);
176 }
177
178 void MappingWindow::CreateResetLayout()
179 {
180 m_reset_layout = new QHBoxLayout();
181 m_reset_box = new QGroupBox(tr("Reset"));
182 m_reset_clear = new NonDefaultQPushButton(tr("Clear"));
183 m_reset_default = new NonDefaultQPushButton(tr("Default"));
184
185 m_reset_box->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
186
187 m_reset_layout->addWidget(m_reset_default);
188 m_reset_layout->addWidget(m_reset_clear);
189
190 m_reset_box->setLayout(m_reset_layout);
191 }
192
193 void MappingWindow::CreateMainLayout()
194 {
195 m_main_layout = new QVBoxLayout();
196 m_config_layout = new QHBoxLayout();
197 m_tab_widget = new QTabWidget();
198 m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
199
200 m_tab_widget->setTabBarAutoHide(true);
201
202 m_config_layout->addWidget(m_devices_box);
203 m_config_layout->addWidget(m_reset_box);
204 m_config_layout->addWidget(m_profiles_box);
205
206 m_main_layout->addLayout(m_config_layout);
207 m_main_layout->addWidget(m_tab_widget);
208 m_main_layout->addWidget(m_button_box);
209
210 setLayout(m_main_layout);
211 }
212
213 void MappingWindow::ConnectWidgets()
214 {
215 connect(&Settings::Instance(), &Settings::DevicesChanged, this, &MappingWindow::ConfigChanged);
216 connect(this, &MappingWindow::ConfigChanged, this, &MappingWindow::UpdateDeviceList);
217 connect(m_devices_combo, &QComboBox::currentIndexChanged, this, &MappingWindow::OnSelectDevice);
218
219 connect(m_reset_clear, &QPushButton::clicked, this, &MappingWindow::OnClearFieldsPressed);
220 connect(m_reset_default, &QPushButton::clicked, this, &MappingWindow::OnDefaultFieldsPressed);
221 connect(m_profiles_save, &QPushButton::clicked, this, &MappingWindow::OnSaveProfilePressed);
222 connect(m_profiles_load, &QPushButton::clicked, this, &MappingWindow::OnLoadProfilePressed);
223 connect(m_profiles_delete, &QAction::triggered, this, &MappingWindow::OnDeleteProfilePressed);
224 connect(m_profiles_open_folder, &QAction::triggered, this, &MappingWindow::OnOpenProfileFolder);
225
226 connect(m_profiles_combo, &QComboBox::currentIndexChanged, this, &MappingWindow::OnSelectProfile);
227 connect(m_profiles_combo, &QComboBox::editTextChanged, this,
228 &MappingWindow::OnProfileTextChanged);
229
230 // We currently use the "Close" button as an "Accept" button so we must save on reject.
231 connect(this, &QDialog::rejected, [this] { emit Save(); });
232 connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
233
234 connect(m_tab_widget, &QTabWidget::currentChanged, this, &MappingWindow::CancelMapping);
235 }
236
237 void MappingWindow::UpdateProfileIndex()
238 {
239 // Make sure currentIndex and currentData are accurate when the user manually types a name.
240
241 const auto current_text = m_profiles_combo->currentText();
242 const int text_index = m_profiles_combo->findText(current_text);
243 m_profiles_combo->setCurrentIndex(text_index);
244
245 if (text_index == -1)
246 m_profiles_combo->setCurrentText(current_text);
247 }
248
249 void MappingWindow::UpdateProfileButtonState()
250 {
251 // Make sure save/delete buttons are disabled for built-in profiles
252
253 bool builtin = false;
254 if (m_profiles_combo->findText(m_profiles_combo->currentText()) != -1)
255 {
256 const QString profile_path = m_profiles_combo->currentData().toString();
257 std::string sys_dir = File::GetSysDirectory();
258 sys_dir = ReplaceAll(sys_dir, "\\", DIR_SEP);
259 builtin = profile_path.startsWith(QString::fromStdString(sys_dir));
260 }
261
262 m_profiles_save->setEnabled(!builtin);
263 m_profiles_delete->setEnabled(!builtin);
264 }
265
266 void MappingWindow::OnSelectProfile(int)
267 {
268 UpdateProfileButtonState();
269 }
270
271 void MappingWindow::OnProfileTextChanged(const QString&)
272 {
273 UpdateProfileButtonState();
274 }
275
276 void MappingWindow::OnDeleteProfilePressed()
277 {
278 UpdateProfileIndex();
279
280 const QString profile_name = m_profiles_combo->currentText();
281 const QString profile_path = m_profiles_combo->currentData().toString();
282
283 if (m_profiles_combo->currentIndex() == -1 || !File::Exists(profile_path.toStdString()))
284 {
285 ModalMessageBox error(this);
286 error.setIcon(QMessageBox::Critical);
287 error.setWindowTitle(tr("Error"));
288 error.setText(tr("The profile '%1' does not exist").arg(profile_name));
289 error.exec();
290 return;
291 }
292
293 ModalMessageBox confirm(this);
294
295 confirm.setIcon(QMessageBox::Warning);
296 confirm.setWindowTitle(tr("Confirm"));
297 confirm.setText(tr("Are you sure that you want to delete '%1'?").arg(profile_name));
298 confirm.setInformativeText(tr("This cannot be undone!"));
299 confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
300
301 if (confirm.exec() != QMessageBox::Yes)
302 {
303 return;
304 }
305
306 m_profiles_combo->removeItem(m_profiles_combo->currentIndex());
307 m_profiles_combo->setCurrentIndex(-1);
308
309 File::Delete(profile_path.toStdString());
310
311 ModalMessageBox result(this);
312 result.setIcon(QMessageBox::Information);
313 result.setWindowModality(Qt::WindowModal);
314 result.setWindowTitle(tr("Success"));
315 result.setText(tr("Successfully deleted '%1'.").arg(profile_name));
316 }
317
318 void MappingWindow::OnLoadProfilePressed()
319 {
320 UpdateProfileIndex();
321
322 if (m_profiles_combo->currentIndex() == -1)
323 {
324 ModalMessageBox error(this);
325 error.setIcon(QMessageBox::Critical);
326 error.setWindowTitle(tr("Error"));
327 error.setText(tr("The profile '%1' does not exist").arg(m_profiles_combo->currentText()));
328 error.exec();
329 return;
330 }
331
332 const QString profile_path = m_profiles_combo->currentData().toString();
333
334 Common::IniFile ini;
335 ini.Load(profile_path.toStdString());
336
337 m_controller->LoadConfig(ini.GetOrCreateSection("Profile"));
338 m_controller->UpdateReferences(g_controller_interface);
339 m_controller->GetConfig()->GenerateControllerTextures();
340
341 const auto lock = GetController()->GetStateLock();
342 emit ConfigChanged();
343 }
344
345 void MappingWindow::OnSaveProfilePressed()
346 {
347 const QString profile_name = m_profiles_combo->currentText();
348
349 if (profile_name.isEmpty())
350 return;
351
352 const std::string profile_path =
353 m_config->GetUserProfileDirectoryPath() + profile_name.toStdString() + ".ini";
354
355 File::CreateFullPath(profile_path);
356
357 Common::IniFile ini;
358
359 m_controller->SaveConfig(ini.GetOrCreateSection("Profile"));
360 ini.Save(profile_path);
361
362 if (m_profiles_combo->findText(profile_name) == -1)
363 {
364 PopulateProfileSelection();
365 m_profiles_combo->setCurrentIndex(m_profiles_combo->findText(profile_name));
366 }
367 }
368
369 void MappingWindow::OnOpenProfileFolder()
370 {
371 std::string path = m_config->GetUserProfileDirectoryPath();
372 File::CreateDirs(path);
373 QUrl url = QUrl::fromLocalFile(QString::fromStdString(path));
374 QDesktopServices::openUrl(url);
375 }
376
377 void MappingWindow::OnSelectDevice(int)
378 {
379 // Original string is stored in the "user-data".
380 const auto device = m_devices_combo->currentData().toString().toStdString();
381
382 m_controller->SetDefaultDevice(device);
383
384 emit ConfigChanged();
385 m_controller->UpdateReferences(g_controller_interface);
386 }
387
388 bool MappingWindow::IsCreateOtherDeviceMappingsEnabled() const
389 {
390 return m_other_device_mappings->isChecked();
391 }
392
393 bool MappingWindow::IsWaitForAlternateMappingsEnabled() const
394 {
395 return m_wait_for_alternate_mappings->isChecked();
396 }
397
398 bool MappingWindow::IsIterativeMappingEnabled() const
399 {
400 return m_iterative_mapping->isChecked();
401 }
402
403 void MappingWindow::RefreshDevices()
404 {
405 g_controller_interface.RefreshDevices();
406 }
407
408 void MappingWindow::UpdateDeviceList()
409 {
410 const QSignalBlocker blocker(m_devices_combo);
411
412 m_devices_combo->clear();
413
414 for (const auto& name : g_controller_interface.GetAllDeviceStrings())
415 {
416 const auto qname = QString::fromStdString(name);
417 m_devices_combo->addItem(qname, qname);
418 }
419
420 const auto default_device = m_controller->GetDefaultDevice().ToString();
421
422 if (!default_device.empty())
423 {
424 const auto default_device_index =
425 m_devices_combo->findText(QString::fromStdString(default_device));
426
427 if (default_device_index != -1)
428 {
429 m_devices_combo->setCurrentIndex(default_device_index);
430 }
431 else
432 {
433 // Selected device is not currently attached.
434 m_devices_combo->insertSeparator(m_devices_combo->count());
435 const auto qname = QString::fromStdString(default_device);
436 m_devices_combo->addItem(QLatin1Char{'['} + tr("disconnected") + QStringLiteral("] ") + qname,
437 qname);
438 m_devices_combo->setCurrentIndex(m_devices_combo->count() - 1);
439 }
440 }
441 }
442
443 void MappingWindow::SetMappingType(MappingWindow::Type type)
444 {
445 MappingWidget* widget;
446
447 switch (type)
448 {
449 case Type::MAPPING_GC_GBA:
450 widget = new GBAPadEmu(this);
451 setWindowTitle(tr("Game Boy Advance at Port %1").arg(GetPort() + 1));
452 AddWidget(tr("Game Boy Advance"), widget);
453 break;
454 case Type::MAPPING_GC_KEYBOARD:
455 widget = new GCKeyboardEmu(this);
456 setWindowTitle(tr("GameCube Keyboard at Port %1").arg(GetPort() + 1));
457 AddWidget(tr("GameCube Keyboard"), widget);
458 break;
459 case Type::MAPPING_GC_BONGOS:
460 case Type::MAPPING_GC_STEERINGWHEEL:
461 case Type::MAPPING_GC_DANCEMAT:
462 case Type::MAPPING_GCPAD:
463 widget = CreateStandardControllerMappingWidget(this);
464 setWindowTitle(tr("GameCube Controller at Port %1").arg(GetPort() + 1));
465 AddWidget(tr("GameCube Controller"), widget);
466 break;
467 case Type::MAPPING_GC_MICROPHONE:
468 widget = new GCMicrophone(this);
469 setWindowTitle(tr("GameCube Microphone Slot %1")
470 .arg(GetPort() == 0 ? QLatin1Char{'A'} : QLatin1Char{'B'}));
471 AddWidget(tr("Microphone"), widget);
472 break;
473 case Type::MAPPING_WIIMOTE_EMU:
474 {
475 auto* extension = new WiimoteEmuExtension(this);
476 auto* extension_motion_input = new WiimoteEmuExtensionMotionInput(this);
477 auto* extension_motion_simulation = new WiimoteEmuExtensionMotionSimulation(this);
478 widget = new WiimoteEmuGeneral(this, extension);
479 setWindowTitle(tr("Wii Remote %1").arg(GetPort() + 1));
480 AddWidget(tr("General and Options"), widget);
481 AddWidget(tr("Motion Simulation"), new WiimoteEmuMotionControl(this));
482 AddWidget(tr("Motion Input"), new WiimoteEmuMotionControlIMU(this));
483 AddWidget(tr("Extension"), extension);
484 m_extension_motion_simulation_tab =
485 AddWidget(EXTENSION_MOTION_SIMULATION_TAB_NAME, extension_motion_simulation);
486 m_extension_motion_input_tab =
487 AddWidget(EXTENSION_MOTION_INPUT_TAB_NAME, extension_motion_input);
488 // Hide tabs by default. "Nunchuk" selection triggers an event to show them.
489 ShowExtensionMotionTabs(false);
490 break;
491 }
492 case Type::MAPPING_HOTKEYS:
493 {
494 widget = new HotkeyGeneral(this);
495 AddWidget(tr("General"), widget);
496 // i18n: TAS is short for tool-assisted speedrun. Read http://tasvideos.org/ for details.
497 // Frame advance is an example of a typical TAS tool.
498 AddWidget(tr("TAS Tools"), new HotkeyTAS(this));
499
500 AddWidget(tr("Debugging"), new HotkeyDebugging(this));
501
502 AddWidget(tr("Wii and Wii Remote"), new HotkeyWii(this));
503 AddWidget(tr("Controller Profile"), new HotkeyControllerProfile(this));
504 AddWidget(tr("Graphics"), new HotkeyGraphics(this));
505 AddWidget(tr("USB Emulation"), new HotkeyUSBEmu(this));
506 // i18n: Stereoscopic 3D
507 AddWidget(tr("3D"), new Hotkey3D(this));
508 AddWidget(tr("Save and Load State"), new HotkeyStates(this));
509 AddWidget(tr("Other State Management"), new HotkeyStatesOther(this));
510 AddWidget(tr("Game Boy Advance"), new HotkeyGBA(this));
511 setWindowTitle(tr("Hotkey Settings"));
512 break;
513 }
514 case Type::MAPPING_FREELOOK:
515 {
516 widget = new FreeLookGeneral(this);
517 AddWidget(tr("General"), widget);
518 AddWidget(tr("Rotation"), new FreeLookRotation(this));
519 setWindowTitle(tr("Free Look Controller %1").arg(GetPort() + 1));
520 }
521 break;
522 case Type::MAPPING_AM_BASEBOARD:
523 widget = CreateAMBaseboardMappingWidget(this);
524 setWindowTitle(tr("Triforce Baseboard at Port %1").arg(GetPort() + 1));
525 AddWidget(tr("Triforce Baseboard"), widget);
526 break;
527 default:
528 return;
529 }
530
531 widget->LoadSettings();
532
533 m_config = widget->GetConfig();
534
535 m_controller = m_config->GetController(GetPort());
536
537 PopulateProfileSelection();
538 }
539
540 void MappingWindow::PopulateProfileSelection()
541 {
542 m_profiles_combo->clear();
543
544 const std::string profiles_path = m_config->GetUserProfileDirectoryPath();
545 for (const auto& filename : Common::DoFileSearch(profiles_path, ".ini"))
546 {
547 std::string basename;
548 SplitPath(filename, nullptr, &basename, nullptr);
549 if (!basename.empty()) // Ignore files with an empty name to avoid multiple problems
550 m_profiles_combo->addItem(QString::fromStdString(basename), QString::fromStdString(filename));
551 }
552
553 m_profiles_combo->insertSeparator(m_profiles_combo->count());
554
555 for (const auto& filename : Common::DoFileSearch(m_config->GetSysProfileDirectoryPath(), ".ini"))
556 {
557 std::string basename;
558 SplitPath(filename, nullptr, &basename, nullptr);
559 if (!basename.empty())
560 {
561 // i18n: "Stock" refers to input profiles included with Dolphin
562 m_profiles_combo->addItem(tr("%1 (Stock)").arg(QString::fromStdString(basename)),
563 QString::fromStdString(filename));
564 }
565 }
566
567 m_profiles_combo->setCurrentIndex(-1);
568 }
569
570 QWidget* MappingWindow::AddWidget(const QString& name, QWidget* widget)
571 {
572 auto* const wrapper = GetWrappedWidget(widget);
573 m_tab_widget->addTab(wrapper, name);
574 return wrapper;
575 }
576
577 int MappingWindow::GetPort() const
578 {
579 return m_port;
580 }
581
582 ControllerEmu::EmulatedController* MappingWindow::GetController() const
583 {
584 return m_controller;
585 }
586
587 void MappingWindow::OnDefaultFieldsPressed()
588 {
589 m_controller->LoadDefaults(g_controller_interface);
590 m_controller->UpdateReferences(g_controller_interface);
591 m_controller->GetConfig()->GenerateControllerTextures();
592
593 const auto lock = GetController()->GetStateLock();
594 emit ConfigChanged();
595 emit Save();
596 }
597
598 void MappingWindow::OnClearFieldsPressed()
599 {
600 // Loading an empty inifile section clears everything.
601 Common::IniFile::Section sec;
602
603 // Keep the currently selected device.
604 const auto default_device = m_controller->GetDefaultDevice();
605 m_controller->LoadConfig(&sec);
606 m_controller->SetDefaultDevice(default_device);
607
608 m_controller->UpdateReferences(g_controller_interface);
609 m_controller->GetConfig()->GenerateControllerTextures();
610
611 const auto lock = GetController()->GetStateLock();
612 emit ConfigChanged();
613 emit Save();
614 }
615
616 void MappingWindow::ShowExtensionMotionTabs(bool show)
617 {
618 if (show)
619 {
620 m_tab_widget->addTab(m_extension_motion_simulation_tab, EXTENSION_MOTION_SIMULATION_TAB_NAME);
621 m_tab_widget->addTab(m_extension_motion_input_tab, EXTENSION_MOTION_INPUT_TAB_NAME);
622 }
623 else
624 {
625 m_tab_widget->removeTab(5);
626 m_tab_widget->removeTab(4);
627 }
628 }
629
630 void MappingWindow::ActivateExtensionTab()
631 {
632 m_tab_widget->setCurrentIndex(3);
633 }