@@ -370,101 +370,13 @@ void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
370370
371371void ControllerBindingWidget::onMultipleDeviceAutomaticBindingTriggered ()
372372{
373- // force a refresh after mapping
374- if (doMultipleDeviceAutomaticBinding (this , m_dialog, m_port_number))
375- onTypeChanged ();
376- }
377-
378- bool ControllerBindingWidget::doMultipleDeviceAutomaticBinding (QWidget* parent, ControllerSettingsWindow* parent_dialog,
379- u32 port)
380- {
381- QDialog dialog (parent);
382-
383- QVBoxLayout* layout = new QVBoxLayout (&dialog);
384- QLabel help (tr (" Select the devices from the list below that you want to bind to this controller." ), &dialog);
385- layout->addWidget (&help);
386-
387- QListWidget list (&dialog);
388- list.setSelectionMode (QListWidget::SingleSelection);
389- layout->addWidget (&list);
390-
391- for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel ()->getDeviceList ())
392- {
393- QListWidgetItem* item = new QListWidgetItem;
394- item->setText (QStringLiteral (" %1 (%2)" ).arg (dev.identifier ).arg (dev.display_name ));
395- item->setData (Qt::UserRole, dev.identifier );
396- item->setIcon (InputDeviceListModel::getIconForKey (dev.key ));
397- item->setFlags (item->flags () | Qt::ItemIsUserCheckable);
398- item->setCheckState (Qt::Unchecked);
399- list.addItem (item);
400- }
401-
402- QDialogButtonBox bb (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
403- connect (&bb, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
404- connect (&bb, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
405- layout->addWidget (&bb);
406-
407- if (dialog.exec () == QDialog::Rejected)
408- return false ;
409-
410- auto lock = Host::GetSettingsLock ();
411- const bool global = (!parent_dialog || parent_dialog->isEditingGlobalSettings ());
412- SettingsInterface& si =
413- *(global ? Host::Internal::GetBaseSettingsLayer () : parent_dialog->getEditingSettingsInterface ());
414-
415- // first device should clear mappings
416- bool tried_any = false ;
417- bool mapped_any = false ;
418- const int count = list.count ();
419- for (int i = 0 ; i < count; i++)
420- {
421- QListWidgetItem* item = list.item (i);
422- if (item->checkState () != Qt::Checked)
423- continue ;
424-
425- tried_any = true ;
426-
427- const QString identifier = item->data (Qt::UserRole).toString ();
428- std::vector<std::pair<GenericInputBinding, std::string>> mapping =
429- InputManager::GetGenericBindingMapping (identifier.toStdString ());
430- if (mapping.empty ())
431- {
432- lock.unlock ();
433- QtUtils::MessageBoxCritical (
434- parent, tr (" Automatic Mapping" ),
435- tr (" No generic bindings were generated for device '%1'. The controller/source may not "
436- " support automatic mapping." )
437- .arg (identifier));
438- lock.lock ();
439- continue ;
440- }
441-
442- mapped_any |= InputManager::MapController (si, port, mapping, !mapped_any);
443- }
444-
445- lock.unlock ();
446-
447- if (!tried_any)
448- {
449- QtUtils::MessageBoxInformation (parent, tr (" Automatic Mapping" ), tr (" No devices were selected." ));
450- return false ;
451- }
373+ QDialog* const dialog = new MultipleDeviceAutobindDialog (this , m_dialog, m_port_number);
374+ dialog->setAttribute (Qt::WA_DeleteOnClose);
452375
453- if (mapped_any)
454- {
455- if (global)
456- {
457- QtHost::SaveGameSettings (&si, false );
458- g_emu_thread->reloadGameSettings (false );
459- }
460- else
461- {
462- QtHost::QueueSettingsSave ();
463- g_emu_thread->reloadInputBindings ();
464- }
465- }
376+ // force a refresh after mapping
377+ connect (dialog, &QDialog::accepted, this , [this ] { onTypeChanged (); });
466378
467- return mapped_any ;
379+ dialog-> open () ;
468380}
469381
470382void ControllerBindingWidget::saveAndRefresh ()
@@ -1079,3 +991,98 @@ ControllerCustomSettingsDialog::ControllerCustomSettingsDialog(QWidget* parent,
1079991}
1080992
1081993ControllerCustomSettingsDialog::~ControllerCustomSettingsDialog () = default ;
994+
995+ MultipleDeviceAutobindDialog::MultipleDeviceAutobindDialog (QWidget* parent, ControllerSettingsWindow* settings_window,
996+ u32 port)
997+ : QDialog(parent), m_settings_window(settings_window), m_port(port)
998+ {
999+ QVBoxLayout* layout = new QVBoxLayout (this );
1000+ layout->addWidget (new QLabel (tr (" Select the devices from the list below that you want to bind to this controller." )));
1001+
1002+ m_list = new QListWidget;
1003+ m_list->setSelectionMode (QListWidget::SingleSelection);
1004+ layout->addWidget (m_list);
1005+
1006+ for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel ()->getDeviceList ())
1007+ {
1008+ QListWidgetItem* item = new QListWidgetItem;
1009+ item->setIcon (InputDeviceListModel::getIconForKey (dev.key ));
1010+ item->setText (QStringLiteral (" %1 (%2)" ).arg (dev.identifier ).arg (dev.display_name ));
1011+ item->setData (Qt::UserRole, dev.identifier );
1012+ item->setFlags (item->flags () | Qt::ItemIsUserCheckable);
1013+ item->setCheckState (Qt::Unchecked);
1014+ m_list->addItem (item);
1015+ }
1016+
1017+ QDialogButtonBox* bb = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
1018+ connect (bb, &QDialogButtonBox::accepted, this , &MultipleDeviceAutobindDialog::doAutomaticBinding);
1019+ connect (bb, &QDialogButtonBox::rejected, this , &QDialog::reject);
1020+ layout->addWidget (bb);
1021+ }
1022+
1023+ MultipleDeviceAutobindDialog::~MultipleDeviceAutobindDialog () = default ;
1024+
1025+ void MultipleDeviceAutobindDialog::doAutomaticBinding ()
1026+ {
1027+ auto lock = Host::GetSettingsLock ();
1028+ const bool global = (!m_settings_window || m_settings_window->isEditingGlobalSettings ());
1029+ SettingsInterface* si =
1030+ global ? Host::Internal::GetBaseSettingsLayer () : m_settings_window->getEditingSettingsInterface ();
1031+
1032+ // first device should clear mappings
1033+ bool tried_any = false ;
1034+ bool mapped_any = false ;
1035+ const int count = m_list->count ();
1036+ for (int i = 0 ; i < count; i++)
1037+ {
1038+ const QListWidgetItem* item = m_list->item (i);
1039+ if (item->checkState () != Qt::Checked)
1040+ continue ;
1041+
1042+ tried_any = true ;
1043+
1044+ const QString identifier = item->data (Qt::UserRole).toString ();
1045+ std::vector<std::pair<GenericInputBinding, std::string>> mapping =
1046+ InputManager::GetGenericBindingMapping (identifier.toStdString ());
1047+ if (mapping.empty ())
1048+ {
1049+ lock.unlock ();
1050+ QtUtils::MessageBoxCritical (
1051+ this , tr (" Automatic Mapping" ),
1052+ tr (" No generic bindings were generated for device '%1'. The controller/source may not "
1053+ " support automatic mapping." )
1054+ .arg (identifier));
1055+ lock.lock ();
1056+ continue ;
1057+ }
1058+
1059+ mapped_any |= InputManager::MapController (*si, m_port, mapping, !mapped_any);
1060+ }
1061+
1062+ lock.unlock ();
1063+
1064+ if (!tried_any)
1065+ {
1066+ QtUtils::MessageBoxInformation (this , tr (" Automatic Mapping" ), tr (" No devices were selected." ));
1067+ return ;
1068+ }
1069+
1070+ if (mapped_any)
1071+ {
1072+ if (global)
1073+ {
1074+ QtHost::SaveGameSettings (si, false );
1075+ g_emu_thread->reloadGameSettings (false );
1076+ }
1077+ else
1078+ {
1079+ QtHost::QueueSettingsSave ();
1080+ g_emu_thread->reloadInputBindings ();
1081+ }
1082+ accept ();
1083+ }
1084+ else
1085+ {
1086+ reject ();
1087+ }
1088+ }
0 commit comments