DolphinQ: Mapping UI cleanups.

This commit is contained in:
Jordan Woyak
2019-03-14 20:27:49 -05:00
parent 011ecd92e8
commit 9cb17b062c
16 changed files with 185 additions and 224 deletions

View File

@ -13,13 +13,13 @@
#include <QTabWidget>
#include <QVBoxLayout>
#include "Core/Core.h"
#include "Common/FileSearch.h"
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/StringUtil.h"
#include "Core/Core.h"
#include "DolphinQt/Config/Mapping/GCKeyboardEmu.h"
#include "DolphinQt/Config/Mapping/GCMicrophone.h"
#include "DolphinQt/Config/Mapping/GCPadEmu.h"
@ -58,6 +58,8 @@ MappingWindow::MappingWindow(QWidget* parent, Type type, int port_num)
CreateMainLayout();
ConnectWidgets();
SetMappingType(type);
emit ConfigChanged();
}
void MappingWindow::CreateDevicesLayout()
@ -141,17 +143,21 @@ void MappingWindow::ConnectWidgets()
{
connect(&Settings::Instance(), &Settings::DevicesChanged, this,
&MappingWindow::OnGlobalDevicesChanged);
connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(m_devices_refresh, &QPushButton::clicked, this, &MappingWindow::RefreshDevices);
connect(this, &MappingWindow::ConfigChanged, this, &MappingWindow::OnGlobalDevicesChanged);
connect(m_devices_combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MappingWindow::OnDeviceChanged);
this, &MappingWindow::OnSelectDevice);
connect(m_devices_refresh, &QPushButton::clicked, this, &MappingWindow::RefreshDevices);
connect(m_reset_clear, &QPushButton::clicked, this, &MappingWindow::OnClearFieldsPressed);
connect(m_reset_default, &QPushButton::clicked, this, &MappingWindow::OnDefaultFieldsPressed);
connect(m_profiles_save, &QPushButton::clicked, this, &MappingWindow::OnSaveProfilePressed);
connect(m_profiles_load, &QPushButton::clicked, this, &MappingWindow::OnLoadProfilePressed);
connect(m_profiles_delete, &QPushButton::clicked, this, &MappingWindow::OnDeleteProfilePressed);
// We currently use the "Close" button as an "Accept" button so we must save on reject.
connect(this, &QDialog::rejected, [this] { emit Save(); });
connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
void MappingWindow::OnDeleteProfilePressed()
@ -206,9 +212,7 @@ void MappingWindow::OnLoadProfilePressed()
m_controller->LoadConfig(ini.GetOrCreateSection("Profile"));
m_controller->UpdateReferences(g_controller_interface);
emit Update();
RefreshDevices();
emit ConfigChanged();
}
void MappingWindow::OnSaveProfilePressed()
@ -235,13 +239,16 @@ void MappingWindow::OnSaveProfilePressed()
}
}
void MappingWindow::OnDeviceChanged(int index)
void MappingWindow::OnSelectDevice(int index)
{
if (IsMappingAllDevices())
return;
const auto device = m_devices_combo->currentText().toStdString();
// Original string is stored in the "user-data".
const auto device = m_devices_combo->currentData().toString().toStdString();
m_controller->SetDefaultDevice(device);
m_controller->UpdateReferences(g_controller_interface);
}
bool MappingWindow::IsMappingAllDevices() const
@ -256,26 +263,42 @@ void MappingWindow::RefreshDevices()
void MappingWindow::OnGlobalDevicesChanged()
{
const auto old_state = m_devices_combo->blockSignals(true);
m_devices_combo->clear();
Core::RunAsCPUThread([&] {
m_controller->UpdateReferences(g_controller_interface);
for (const auto& name : g_controller_interface.GetAllDeviceStrings())
{
const auto qname = QString::fromStdString(name);
m_devices_combo->addItem(qname, qname);
}
const auto default_device = m_controller->GetDefaultDevice().ToString();
m_devices_combo->insertSeparator(m_devices_combo->count());
if (!default_device.empty())
m_devices_combo->addItem(QString::fromStdString(default_device));
const auto default_device = m_controller->GetDefaultDevice().ToString();
for (const auto& name : g_controller_interface.GetAllDeviceStrings())
if (!default_device.empty())
{
const auto default_device_index =
m_devices_combo->findText(QString::fromStdString(default_device));
if (default_device_index != -1)
{
if (name != default_device)
m_devices_combo->addItem(QString::fromStdString(name));
m_devices_combo->setCurrentIndex(default_device_index);
}
else
{
// Selected device is not currently attached.
const auto qname = QString::fromStdString(default_device);
m_devices_combo->addItem(
QStringLiteral("[") + tr("disconnected") + QStringLiteral("] ") + qname, qname);
m_devices_combo->setCurrentIndex(m_devices_combo->count() - 1);
}
}
m_devices_combo->addItem(tr("All devices"));
m_devices_combo->addItem(tr("All devices"));
m_devices_combo->setCurrentIndex(0);
});
m_devices_combo->blockSignals(old_state);
}
void MappingWindow::SetMappingType(MappingWindow::Type type)
@ -372,16 +395,11 @@ ControllerEmu::EmulatedController* MappingWindow::GetController() const
return m_controller;
}
std::shared_ptr<ciface::Core::Device> MappingWindow::GetDevice() const
{
return g_controller_interface.FindDevice(GetController()->GetDefaultDevice());
}
void MappingWindow::OnDefaultFieldsPressed()
{
m_controller->LoadDefaults(g_controller_interface);
m_controller->UpdateReferences(g_controller_interface);
emit Update();
emit ConfigChanged();
emit Save();
}
@ -389,9 +407,14 @@ void MappingWindow::OnClearFieldsPressed()
{
// Loading an empty inifile section clears everything.
IniFile::Section sec;
// Keep the currently selected device.
const auto default_device = m_controller->GetDefaultDevice();
m_controller->LoadConfig(&sec);
m_controller->SetDefaultDevice(default_device);
m_controller->UpdateReferences(g_controller_interface);
emit Update();
emit ConfigChanged();
emit Save();
}