MappingWidget: Support for boxes with multiple columns

This commit is contained in:
Bonta 2021-07-04 12:56:07 +02:00
parent 27eab609dc
commit d2353c79ea
2 changed files with 42 additions and 10 deletions

View File

@ -6,6 +6,7 @@
#include <QCheckBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
@ -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<QFormLayout*> 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();

View File

@ -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: