From d2353c79eabeec0cbcec531c94148527816a3d1a Mon Sep 17 00:00:00 2001 From: Bonta <40473493+Bonta0@users.noreply.github.com> Date: Sun, 4 Jul 2021 12:56:07 +0200 Subject: [PATCH] MappingWidget: Support for boxes with multiple columns --- .../Config/Mapping/MappingWidget.cpp | 48 +++++++++++++++---- .../DolphinQt/Config/Mapping/MappingWidget.h | 4 ++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp index da04403137..1206ad75ff 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -118,16 +119,7 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con } for (auto& control : group->controls) - { - auto* button = new MappingButton(this, control->control_ref.get(), !indicator); - - button->setMinimumWidth(100); - button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - const bool translate = control->translate == ControllerEmu::Translate; - const QString translated_name = - translate ? tr(control->ui_name.c_str()) : QString::fromStdString(control->ui_name); - form_layout->addRow(translated_name, button); - } + CreateControl(control.get(), form_layout, !indicator); for (auto& setting : group->numeric_settings) { @@ -186,6 +178,42 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con return group_box; } +QGroupBox* MappingWidget::CreateControlsBox(const QString& name, ControllerEmu::ControlGroup* group, + int columns) +{ + auto* group_box = new QGroupBox(name); + auto* hbox_layout = new QHBoxLayout(); + + group_box->setLayout(hbox_layout); + + std::vector form_layouts; + for (int i = 0; i < columns; ++i) + { + form_layouts.push_back(new QFormLayout()); + hbox_layout->addLayout(form_layouts[i]); + } + + for (size_t i = 0; i < group->controls.size(); ++i) + { + CreateControl(group->controls[i].get(), form_layouts[i % columns], true); + } + + return group_box; +} + +void MappingWidget::CreateControl(const ControllerEmu::Control* control, QFormLayout* layout, + bool indicator) +{ + auto* button = new MappingButton(this, control->control_ref.get(), indicator); + + button->setMinimumWidth(100); + button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + const bool translate = control->translate == ControllerEmu::Translate; + const QString translated_name = + translate ? tr(control->ui_name.c_str()) : QString::fromStdString(control->ui_name); + layout->addRow(translated_name, button); +} + ControllerEmu::EmulatedController* MappingWidget::GetController() const { return m_parent->GetController(); diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h index ed092c8c5e..ad55172f4a 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h +++ b/Source/Core/DolphinQt/Config/Mapping/MappingWidget.h @@ -16,6 +16,7 @@ class InputConfig; class MappingButton; class MappingNumeric; class MappingWindow; +class QFormLayout; class QPushButton; class QGroupBox; @@ -52,6 +53,9 @@ protected: QGroupBox* CreateGroupBox(ControllerEmu::ControlGroup* group); QGroupBox* CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group); + QGroupBox* CreateControlsBox(const QString& name, ControllerEmu::ControlGroup* group, + int columns); + void CreateControl(const ControllerEmu::Control* control, QFormLayout* layout, bool indicator); QPushButton* CreateSettingAdvancedMappingButton(ControllerEmu::NumericSettingBase& setting); private: