Qt GCPadWiiU: standalone dialog, not subclass of MappingWidget

It uses none of the functionality of MappingWidget or the parent MappingWindow, and complicates the definition of the MappingWidget interface.
This commit is contained in:
Michael M 2017-11-03 14:47:36 -07:00
parent 27e1577da9
commit a8b5eab4c4
5 changed files with 32 additions and 53 deletions

View File

@ -28,6 +28,7 @@
#include "Core/IOS/IOS.h" #include "Core/IOS/IOS.h"
#include "Core/IOS/USB/Bluetooth/BTReal.h" #include "Core/IOS/USB/Bluetooth/BTReal.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
#include "DolphinQt2/Config/Mapping/GCPadWiiU.h"
#include "DolphinQt2/Config/Mapping/MappingWindow.h" #include "DolphinQt2/Config/Mapping/MappingWindow.h"
#include "DolphinQt2/Settings.h" #include "DolphinQt2/Settings.h"
#include "UICommon/UICommon.h" #include "UICommon/UICommon.h"
@ -417,8 +418,8 @@ void ControllersWindow::OnGCPadConfigure()
type = MappingWindow::Type::MAPPING_GCPAD; type = MappingWindow::Type::MAPPING_GCPAD;
break; break;
case 2: // GameCube Adapter for Wii U case 2: // GameCube Adapter for Wii U
type = MappingWindow::Type::MAPPING_GCPAD_WIIU; GCPadWiiU(index, this).exec();
break; return;
case 3: // Steering Wheel case 3: // Steering Wheel
type = MappingWindow::Type::MAPPING_GC_STEERINGWHEEL; type = MappingWindow::Type::MAPPING_GC_STEERINGWHEEL;
break; break;

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <QCheckBox> #include <QCheckBox>
#include <QDialogButtonBox>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -11,7 +12,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "InputCommon/GCAdapter.h" #include "InputCommon/GCAdapter.h"
GCPadWiiU::GCPadWiiU(MappingWindow* window) : MappingWidget(window) GCPadWiiU::GCPadWiiU(int port, QWidget* parent) : QDialog(parent), m_port{port}
{ {
CreateLayout(); CreateLayout();
ConnectWidgets(); ConnectWidgets();
@ -21,15 +22,19 @@ GCPadWiiU::GCPadWiiU(MappingWindow* window) : MappingWidget(window)
void GCPadWiiU::CreateLayout() void GCPadWiiU::CreateLayout()
{ {
setWindowTitle(tr("GameCube Adapter for Wii U at Port %1").arg(m_port + 1));
const bool detected = GCAdapter::IsDetected(); const bool detected = GCAdapter::IsDetected();
m_layout = new QVBoxLayout(); m_layout = new QVBoxLayout();
m_status_label = new QLabel(detected ? tr("Adapter Detected") : tr("No Adapter Detected")); m_status_label = new QLabel(detected ? tr("Adapter Detected") : tr("No Adapter Detected"));
m_rumble = new QCheckBox(tr("Enable Rumble")); m_rumble = new QCheckBox(tr("Enable Rumble"));
m_simulate_bongos = new QCheckBox(tr("Simulate DK Bongos")); m_simulate_bongos = new QCheckBox(tr("Simulate DK Bongos"));
m_button_box = new QDialogButtonBox(QDialogButtonBox::Ok);
m_layout->addWidget(m_status_label); m_layout->addWidget(m_status_label);
m_layout->addWidget(m_rumble); m_layout->addWidget(m_rumble);
m_layout->addWidget(m_simulate_bongos); m_layout->addWidget(m_simulate_bongos);
m_layout->addWidget(m_button_box);
if (!detected) if (!detected)
{ {
@ -44,21 +49,17 @@ void GCPadWiiU::ConnectWidgets()
{ {
connect(m_rumble, &QCheckBox::toggled, this, &GCPadWiiU::SaveSettings); connect(m_rumble, &QCheckBox::toggled, this, &GCPadWiiU::SaveSettings);
connect(m_simulate_bongos, &QCheckBox::toggled, this, &GCPadWiiU::SaveSettings); connect(m_simulate_bongos, &QCheckBox::toggled, this, &GCPadWiiU::SaveSettings);
connect(m_button_box, &QDialogButtonBox::accepted, this, &GCPadWiiU::accept);
} }
void GCPadWiiU::LoadSettings() void GCPadWiiU::LoadSettings()
{ {
m_rumble->setChecked(SConfig::GetInstance().m_AdapterRumble[GetPort()]); m_rumble->setChecked(SConfig::GetInstance().m_AdapterRumble[m_port]);
m_simulate_bongos->setChecked(SConfig::GetInstance().m_AdapterKonga[GetPort()]); m_simulate_bongos->setChecked(SConfig::GetInstance().m_AdapterKonga[m_port]);
} }
void GCPadWiiU::SaveSettings() void GCPadWiiU::SaveSettings()
{ {
SConfig::GetInstance().m_AdapterRumble[GetPort()] = m_rumble->isChecked(); SConfig::GetInstance().m_AdapterRumble[m_port] = m_rumble->isChecked();
SConfig::GetInstance().m_AdapterKonga[GetPort()] = m_simulate_bongos->isChecked(); SConfig::GetInstance().m_AdapterKonga[m_port] = m_simulate_bongos->isChecked();
}
InputConfig* GCPadWiiU::GetConfig()
{
return nullptr;
} }

View File

@ -4,28 +4,30 @@
#pragma once #pragma once
#include "DolphinQt2/Config/Mapping/MappingWidget.h" #include <QDialog>
class QCheckBox; class QCheckBox;
class QLabel; class QLabel;
class QDialogButtonBox;
class QVBoxLayout; class QVBoxLayout;
class GCPadWiiU final : public MappingWidget class GCPadWiiU final : public QDialog
{ {
public: public:
explicit GCPadWiiU(MappingWindow* window); explicit GCPadWiiU(int port, QWidget* parent = nullptr);
InputConfig* GetConfig() override;
private: private:
void LoadSettings() override; void LoadSettings();
void SaveSettings() override; void SaveSettings();
void CreateLayout(); void CreateLayout();
void ConnectWidgets(); void ConnectWidgets();
int m_port;
QVBoxLayout* m_layout; QVBoxLayout* m_layout;
QLabel* m_status_label; QLabel* m_status_label;
QDialogButtonBox* m_button_box;
// Checkboxes // Checkboxes
QCheckBox* m_rumble; QCheckBox* m_rumble;

View File

@ -20,7 +20,6 @@
#include "Core/Core.h" #include "Core/Core.h"
#include "DolphinQt2/Config/Mapping/GCKeyboardEmu.h" #include "DolphinQt2/Config/Mapping/GCKeyboardEmu.h"
#include "DolphinQt2/Config/Mapping/GCPadEmu.h" #include "DolphinQt2/Config/Mapping/GCPadEmu.h"
#include "DolphinQt2/Config/Mapping/GCPadWiiU.h"
#include "DolphinQt2/Config/Mapping/Hotkey3D.h" #include "DolphinQt2/Config/Mapping/Hotkey3D.h"
#include "DolphinQt2/Config/Mapping/HotkeyGeneral.h" #include "DolphinQt2/Config/Mapping/HotkeyGeneral.h"
#include "DolphinQt2/Config/Mapping/HotkeyGraphics.h" #include "DolphinQt2/Config/Mapping/HotkeyGraphics.h"
@ -240,8 +239,6 @@ void MappingWindow::RefreshDevices()
void MappingWindow::SetMappingType(MappingWindow::Type type) void MappingWindow::SetMappingType(MappingWindow::Type type)
{ {
m_controller = nullptr;
MappingWidget* widget; MappingWidget* widget;
switch (type) switch (type)
@ -259,11 +256,6 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
setWindowTitle(tr("GameCube Controller at Port %1").arg(GetPort() + 1)); setWindowTitle(tr("GameCube Controller at Port %1").arg(GetPort() + 1));
AddWidget(tr("GameCube Controller"), widget); AddWidget(tr("GameCube Controller"), widget);
break; break;
case Type::MAPPING_GCPAD_WIIU:
widget = new GCPadWiiU(this);
setWindowTitle(tr("GameCube Adapter for Wii U at Port %1").arg(GetPort() + 1));
AddWidget(tr("GameCube Adapter for Wii U"), widget);
break;
case Type::MAPPING_WIIMOTE_EMU: case Type::MAPPING_WIIMOTE_EMU:
case Type::MAPPING_WIIMOTE_HYBRID: case Type::MAPPING_WIIMOTE_HYBRID:
{ {
@ -295,23 +287,18 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
m_config = widget->GetConfig(); m_config = widget->GetConfig();
if (m_config) m_controller = m_config->GetController(GetPort());
m_profiles_combo->addItem(QStringLiteral(""));
const std::string profiles_path =
File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + m_config->GetProfileName();
for (const auto& filename : Common::DoFileSearch({profiles_path}, {".ini"}))
{ {
m_controller = m_config->GetController(GetPort()); std::string basename;
m_profiles_combo->addItem(QStringLiteral("")); SplitPath(filename, nullptr, &basename, nullptr);
m_profiles_combo->addItem(QString::fromStdString(basename), QString::fromStdString(filename));
const std::string profiles_path =
File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + m_config->GetProfileName();
for (const auto& filename : Common::DoFileSearch({profiles_path}, {".ini"}))
{
std::string basename;
SplitPath(filename, nullptr, &basename, nullptr);
m_profiles_combo->addItem(QString::fromStdString(basename), QString::fromStdString(filename));
}
} }
SetLayoutComplex(type != Type::MAPPING_GCPAD_WIIU);
if (m_controller != nullptr) if (m_controller != nullptr)
RefreshDevices(); RefreshDevices();
} }
@ -321,15 +308,6 @@ void MappingWindow::AddWidget(const QString& name, QWidget* widget)
m_tab_widget->addTab(widget, name); m_tab_widget->addTab(widget, name);
} }
void MappingWindow::SetLayoutComplex(bool is_complex)
{
m_reset_box->setHidden(!is_complex);
m_profiles_box->setHidden(!is_complex);
m_devices_box->setHidden(!is_complex);
m_is_complex = is_complex;
}
int MappingWindow::GetPort() const int MappingWindow::GetPort() const
{ {
return m_port; return m_port;

View File

@ -37,7 +37,6 @@ public:
MAPPING_GC_DANCEMAT, MAPPING_GC_DANCEMAT,
MAPPING_GC_KEYBOARD, MAPPING_GC_KEYBOARD,
MAPPING_GCPAD, MAPPING_GCPAD,
MAPPING_GCPAD_WIIU,
MAPPING_GC_STEERINGWHEEL, MAPPING_GC_STEERINGWHEEL,
// Wii // Wii
MAPPING_WIIMOTE_EMU, MAPPING_WIIMOTE_EMU,
@ -65,7 +64,6 @@ private:
void CreateMainLayout(); void CreateMainLayout();
void ConnectWidgets(); void ConnectWidgets();
void SetLayoutComplex(bool is_complex);
void AddWidget(const QString& name, QWidget* widget); void AddWidget(const QString& name, QWidget* widget);
void RefreshDevices(); void RefreshDevices();
@ -107,7 +105,6 @@ private:
Type m_mapping_type; Type m_mapping_type;
const int m_port; const int m_port;
bool m_is_complex;
InputConfig* m_config; InputConfig* m_config;
ciface::Core::DeviceQualifier m_devq; ciface::Core::DeviceQualifier m_devq;
}; };