Qt: Move controller setting popups into dialog

This commit is contained in:
Connor McLaughlin 2022-08-05 21:49:13 +10:00
parent 8d50ebe538
commit 8776bfe46d
7 changed files with 197 additions and 86 deletions

View File

@ -41,6 +41,8 @@ set(SRCS
controllerglobalsettingswidget.cpp
controllerglobalsettingswidget.h
controllerglobalsettingswidget.ui
controllermacroeditwidget.ui
controllermacrowidget.ui
controllersettingsdialog.cpp
controllersettingsdialog.h
controllersettingsdialog.ui

View File

@ -7,13 +7,13 @@
<x>0</x>
<y>0</y>
<width>833</width>
<height>562</height>
<height>617</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
<property name="leftMargin">
<number>0</number>
</property>
@ -38,22 +38,62 @@
<widget class="QComboBox" name="controllerType"/>
</item>
<item>
<widget class="QPushButton" name="settings">
<widget class="QToolButton" name="bindings">
<property name="text">
<string>Settings</string>
<string>Bindings</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset theme="checkbox-multiple-blank-line"/>
<iconset theme="gamepad-line">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="macros">
<widget class="QToolButton" name="settings">
<property name="text">
<string>Settings</string>
</property>
<property name="icon">
<iconset theme="checkbox-multiple-blank-line">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="macros">
<property name="text">
<string>Macros</string>
</property>
<property name="icon">
<iconset theme="flashlight-line"/>
<iconset theme="flashlight-line">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
@ -75,7 +115,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="automaticBinding">
<widget class="QToolButton" name="automaticBinding">
<property name="text">
<string>Automatic Mapping</string>
</property>
@ -83,10 +123,13 @@
<iconset theme="gamepad-line">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearBindings">
<widget class="QToolButton" name="clearBindings">
<property name="text">
<string>Clear Mapping</string>
</property>
@ -94,6 +137,9 @@
<iconset theme="file-reduce-line">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget>
</item>
</layout>
@ -101,6 +147,9 @@
</layout>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget" />
</item>
</layout>
</widget>
<resources>

View File

@ -26,10 +26,11 @@ ControllerBindingWidget::ControllerBindingWidget(QWidget* parent, ControllerSett
{
m_ui.setupUi(this);
populateControllerTypes();
populateBindingWidget();
populateWidgets();
connect(m_ui.controllerType, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ControllerBindingWidget::onTypeChanged);
connect(m_ui.bindings, &QPushButton::clicked, this, &ControllerBindingWidget::onBindingsClicked);
connect(m_ui.settings, &QPushButton::clicked, this, &ControllerBindingWidget::onSettingsClicked);
connect(m_ui.macros, &QPushButton::clicked, this, &ControllerBindingWidget::onMacrosClicked);
connect(m_ui.automaticBinding, &QPushButton::clicked, this, &ControllerBindingWidget::onAutomaticBindingClicked);
@ -40,7 +41,7 @@ ControllerBindingWidget::~ControllerBindingWidget() = default;
QIcon ControllerBindingWidget::getIcon() const
{
return m_current_widget->getIcon();
return m_bindings_widget->getIcon();
}
void ControllerBindingWidget::populateControllerTypes()
@ -67,49 +68,93 @@ void ControllerBindingWidget::populateControllerTypes()
}
}
void ControllerBindingWidget::populateBindingWidget()
void ControllerBindingWidget::populateWidgets()
{
const bool is_initializing = (m_current_widget == nullptr);
if (!is_initializing)
const bool is_initializing = (m_ui.stackedWidget->count() == 0);
if (m_bindings_widget)
{
m_ui.verticalLayout->removeWidget(m_current_widget);
delete m_current_widget;
m_current_widget = nullptr;
m_ui.stackedWidget->removeWidget(m_bindings_widget);
delete m_bindings_widget;
m_bindings_widget = nullptr;
}
if (m_settings_widget)
{
m_ui.stackedWidget->removeWidget(m_settings_widget);
delete m_settings_widget;
m_settings_widget = nullptr;
}
if (m_macros_widget)
{
m_ui.stackedWidget->removeWidget(m_macros_widget);
delete m_macros_widget;
m_macros_widget = nullptr;
}
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(m_controller_type);
m_ui.settings->setEnabled(cinfo && cinfo->num_settings > 0);
m_ui.macros->setEnabled(cinfo && cinfo->num_bindings > 0);
const bool has_settings = (cinfo && cinfo->num_settings > 0);
const bool has_macros = (cinfo && cinfo->num_bindings > 0);
m_ui.settings->setEnabled(has_settings);
m_ui.macros->setEnabled(has_macros);
switch (m_controller_type)
{
case ControllerType::AnalogController:
m_current_widget = ControllerBindingWidget_AnalogController::createInstance(this);
m_bindings_widget = ControllerBindingWidget_AnalogController::createInstance(this);
break;
case ControllerType::AnalogJoystick:
m_current_widget = ControllerBindingWidget_AnalogJoystick::createInstance(this);
m_bindings_widget = ControllerBindingWidget_AnalogJoystick::createInstance(this);
break;
case ControllerType::DigitalController:
m_current_widget = ControllerBindingWidget_DigitalController::createInstance(this);
m_bindings_widget = ControllerBindingWidget_DigitalController::createInstance(this);
break;
case ControllerType::GunCon:
m_current_widget = ControllerBindingWidget_GunCon::createInstance(this);
m_bindings_widget = ControllerBindingWidget_GunCon::createInstance(this);
break;
case ControllerType::NeGcon:
m_current_widget = ControllerBindingWidget_NeGcon::createInstance(this);
m_bindings_widget = ControllerBindingWidget_NeGcon::createInstance(this);
break;
default:
m_current_widget = new ControllerBindingWidget_Base(this);
m_bindings_widget = new ControllerBindingWidget_Base(this);
break;
}
m_ui.verticalLayout->addWidget(m_current_widget, 1);
m_ui.stackedWidget->addWidget(m_bindings_widget);
m_ui.stackedWidget->setCurrentWidget(m_bindings_widget);
if (has_settings)
{
m_settings_widget = new ControllerCustomSettingsWidget(this);
m_ui.stackedWidget->addWidget(m_settings_widget);
}
if (has_macros)
{
m_macros_widget = new ControllerMacroWidget(this);
m_ui.stackedWidget->addWidget(m_macros_widget);
}
updateHeaderToolButtons();
// no need to do this on first init, only changes
if (!is_initializing)
m_dialog->updateListDescription(m_port_number, this);
}
void ControllerBindingWidget::updateHeaderToolButtons()
{
const QWidget* current_widget = m_ui.stackedWidget->currentWidget();
const QSignalBlocker bindings_sb(m_ui.bindings);
const QSignalBlocker settings_sb(m_ui.settings);
const QSignalBlocker macros_sb(m_ui.macros);
const bool is_bindings = (current_widget == m_bindings_widget);
m_ui.bindings->setChecked(is_bindings);
m_ui.automaticBinding->setEnabled(is_bindings);
m_ui.clearBindings->setEnabled(is_bindings);
m_ui.macros->setChecked(current_widget == m_macros_widget);
m_ui.settings->setChecked((current_widget == m_settings_widget));
}
void ControllerBindingWidget::onTypeChanged()
{
bool ok;
@ -132,7 +177,7 @@ void ControllerBindingWidget::onTypeChanged()
g_emu_thread->applySettings();
}
populateBindingWidget();
populateWidgets();
}
void ControllerBindingWidget::onAutomaticBindingClicked()
@ -182,16 +227,28 @@ void ControllerBindingWidget::onClearBindingsClicked()
saveAndRefresh();
}
void ControllerBindingWidget::onBindingsClicked()
{
m_ui.stackedWidget->setCurrentWidget(m_bindings_widget);
updateHeaderToolButtons();
}
void ControllerBindingWidget::onSettingsClicked()
{
ControllerCustomSettingsDialog dialog(this);
dialog.exec();
if (!m_settings_widget)
return;
m_ui.stackedWidget->setCurrentWidget(m_settings_widget);
updateHeaderToolButtons();
}
void ControllerBindingWidget::onMacrosClicked()
{
ControllerMacroDialog dialog(this);
dialog.exec();
if (!m_macros_widget)
return;
m_ui.stackedWidget->setCurrentWidget(m_macros_widget);
updateHeaderToolButtons();
}
void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
@ -232,22 +289,22 @@ void ControllerBindingWidget::saveAndRefresh()
//////////////////////////////////////////////////////////////////////////
ControllerMacroDialog::ControllerMacroDialog(ControllerBindingWidget* parent) : QDialog(parent)
ControllerMacroWidget::ControllerMacroWidget(ControllerBindingWidget* parent) : QWidget(parent)
{
m_ui.setupUi(this);
setWindowTitle(tr("Controller Port %1 Macros").arg(parent->getPortNumber() + 1u));
createWidgets(parent);
}
ControllerMacroDialog::~ControllerMacroDialog() = default;
ControllerMacroWidget::~ControllerMacroWidget() = default;
void ControllerMacroDialog::updateListItem(u32 index)
void ControllerMacroWidget::updateListItem(u32 index)
{
m_ui.portList->item(static_cast<int>(index))
->setText(tr("Macro %1\n%2").arg(index + 1).arg(m_macros[index]->getSummary()));
}
void ControllerMacroDialog::createWidgets(ControllerBindingWidget* parent)
void ControllerMacroWidget::createWidgets(ControllerBindingWidget* parent)
{
for (u32 i = 0; i < NUM_MACROS; i++)
{
@ -260,16 +317,15 @@ void ControllerMacroDialog::createWidgets(ControllerBindingWidget* parent)
updateListItem(i);
}
m_ui.portList->setCurrentItem(0);
m_ui.portList->setCurrentRow(0);
m_ui.container->setCurrentIndex(0);
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &ControllerSettingsDialog::close);
connect(m_ui.portList, &QListWidget::currentRowChanged, m_ui.container, &QStackedWidget::setCurrentIndex);
}
//////////////////////////////////////////////////////////////////////////
ControllerMacroEditWidget::ControllerMacroEditWidget(ControllerMacroDialog* parent, ControllerBindingWidget* bwidget,
ControllerMacroEditWidget::ControllerMacroEditWidget(ControllerMacroWidget* parent, ControllerBindingWidget* bwidget,
u32 index)
: QWidget(parent), m_parent(parent), m_bwidget(bwidget), m_index(index)
{
@ -419,22 +475,29 @@ void ControllerMacroEditWidget::updateBinds()
//////////////////////////////////////////////////////////////////////////
ControllerCustomSettingsDialog::ControllerCustomSettingsDialog(ControllerBindingWidget* parent) : QDialog(parent)
ControllerCustomSettingsWidget::ControllerCustomSettingsWidget(ControllerBindingWidget* parent) : QWidget(parent)
{
QGridLayout* layout = new QGridLayout(this);
int row = createSettingWidgets(parent, layout);
QDialogButtonBox* bbox = new QDialogButtonBox(QDialogButtonBox::Close | QDialogButtonBox::RestoreDefaults, this);
connect(bbox, &QDialogButtonBox::rejected, this, &QDialog::accept);
connect(bbox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this,
&ControllerCustomSettingsDialog::restoreDefaults);
layout->addWidget(bbox, row++, 0, 1, 4);
QVBoxLayout* bottom_layout = new QVBoxLayout();
bottom_layout->setContentsMargins(0, 0, 0, 0);
QHBoxLayout* bottom_hlayout = new QHBoxLayout();
bottom_hlayout->setContentsMargins(0, 0, 0, 0);
QPushButton* restore_defaults = new QPushButton(tr("Restore Default Settings"), this);
restore_defaults->setIcon(QIcon::fromTheme(QStringLiteral("restart-line")));
connect(restore_defaults, &QPushButton::clicked, this, &ControllerCustomSettingsWidget::restoreDefaults);
bottom_hlayout->addWidget(restore_defaults);
bottom_hlayout->addStretch(1);
bottom_layout->addLayout(bottom_hlayout);
bottom_layout->addStretch(1);
layout->addLayout(bottom_layout, row++, 0, 1, 4);
}
ControllerCustomSettingsDialog::~ControllerCustomSettingsDialog() {}
ControllerCustomSettingsWidget::~ControllerCustomSettingsWidget() {}
int ControllerCustomSettingsDialog::createSettingWidgets(ControllerBindingWidget* parent, QGridLayout* layout)
int ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidget* parent, QGridLayout* layout)
{
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(parent->getControllerType());
if (!cinfo || cinfo->num_settings == 0)
@ -539,7 +602,7 @@ int ControllerCustomSettingsDialog::createSettingWidgets(ControllerBindingWidget
return current_row;
}
void ControllerCustomSettingsDialog::restoreDefaults()
void ControllerCustomSettingsWidget::restoreDefaults()
{
ControllerBindingWidget* parent = static_cast<ControllerBindingWidget*>(this->parent());
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(parent->getControllerType());
@ -689,16 +752,6 @@ void ControllerBindingWidget_Base::initBindingWidgets()
ControllerSettingWidgetBinder::BindWidgetToInputProfileNormalized(sif, widget, config_section, "AnalogSensitivity",
range, Controller::DEFAULT_STICK_SENSITIVITY);
}
#if 0
// FIXME
if (QDoubleSpinBox* widget = findChild<QDoubleSpinBox*>(QStringLiteral("SmallMotorScale")); widget)
ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "SmallMotorScale",
Controller::DEFAULT_MOTOR_SCALE);
if (QDoubleSpinBox* widget = findChild<QDoubleSpinBox*>(QStringLiteral("LargeMotorScale")); widget)
ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "LargeMotorScale",
Controller::DEFAULT_MOTOR_SCALE);
#endif
}
//////////////////////////////////////////////////////////////////////////

View File

@ -12,14 +12,15 @@
#include "ui_controllerbindingwidget_digital_controller.h"
#include "ui_controllerbindingwidget_guncon.h"
#include "ui_controllerbindingwidget_negcon.h"
#include "ui_controllermacrodialog.h"
#include "ui_controllermacrowidget.h"
#include "ui_controllermacroeditwidget.h"
class QVBoxLayout;
class InputBindingWidget;
class ControllerSettingsDialog;
class ControllerMacroDialog;
class ControllerCustomSettingsWidget;
class ControllerMacroWidget;
class ControllerMacroEditWidget;
class ControllerBindingWidget_Base;
@ -44,12 +45,14 @@ private Q_SLOTS:
void onTypeChanged();
void onAutomaticBindingClicked();
void onClearBindingsClicked();
void onBindingsClicked();
void onSettingsClicked();
void onMacrosClicked();
private:
void populateControllerTypes();
void populateBindingWidget();
void populateWidgets();
void updateHeaderToolButtons();
void doDeviceAutomaticBinding(const QString& device);
void saveAndRefresh();
@ -61,18 +64,20 @@ private:
ControllerType m_controller_type;
u32 m_port_number;
ControllerBindingWidget_Base* m_current_widget = nullptr;
ControllerBindingWidget_Base* m_bindings_widget = nullptr;
ControllerCustomSettingsWidget* m_settings_widget = nullptr;
ControllerMacroWidget* m_macros_widget = nullptr;
};
//////////////////////////////////////////////////////////////////////////
class ControllerMacroDialog : public QDialog
class ControllerMacroWidget : public QWidget
{
Q_OBJECT
public:
ControllerMacroDialog(ControllerBindingWidget* parent);
~ControllerMacroDialog();
ControllerMacroWidget(ControllerBindingWidget* parent);
~ControllerMacroWidget();
void updateListItem(u32 index);
@ -81,7 +86,7 @@ private:
void createWidgets(ControllerBindingWidget* parent);
Ui::ControllerMacroDialog m_ui;
Ui::ControllerMacroWidget m_ui;
ControllerSettingsDialog* m_dialog;
std::array<ControllerMacroEditWidget*, NUM_MACROS> m_macros;
};
@ -93,7 +98,7 @@ class ControllerMacroEditWidget : public QWidget
Q_OBJECT
public:
ControllerMacroEditWidget(ControllerMacroDialog* parent, ControllerBindingWidget* bwidget, u32 index);
ControllerMacroEditWidget(ControllerMacroWidget* parent, ControllerBindingWidget* bwidget, u32 index);
~ControllerMacroEditWidget();
QString getSummary() const;
@ -109,7 +114,7 @@ private:
Ui::ControllerMacroEditWidget m_ui;
ControllerMacroDialog* m_parent;
ControllerMacroWidget* m_parent;
ControllerBindingWidget* m_bwidget;
u32 m_index;
@ -119,13 +124,13 @@ private:
//////////////////////////////////////////////////////////////////////////
class ControllerCustomSettingsDialog : public QDialog
class ControllerCustomSettingsWidget : public QWidget
{
Q_OBJECT
public:
ControllerCustomSettingsDialog(ControllerBindingWidget* parent);
~ControllerCustomSettingsDialog();
ControllerCustomSettingsWidget(ControllerBindingWidget* parent);
~ControllerCustomSettingsWidget();
int createSettingWidgets(ControllerBindingWidget* parent, QGridLayout* layout);

View File

@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ControllerMacroDialog</class>
<widget class="QDialog" name="ControllerMacroDialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<class>ControllerMacroWidget</class>
<widget class="QWidget" name="ControllerMacroWidget">
<property name="geometry">
<rect>
<x>0</x>
@ -20,6 +17,18 @@
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QListWidget" name="portList">
<property name="sizePolicy">
@ -52,15 +61,7 @@
<widget class="QStackedWidget" name="container"/>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</item>
</layout>
</widget>

View File

@ -188,7 +188,7 @@
<QtUi Include="controllersettingsdialog.ui">
<FileType>Document</FileType>
</QtUi>
<QtUi Include="controllermacrodialog.ui">
<QtUi Include="controllermacrowidget.ui">
<FileType>Document</FileType>
</QtUi>
<QtUi Include="controllermacroeditwidget.ui">

View File

@ -27,7 +27,6 @@
<ClCompile Include="$(IntDir)moc_generalsettingswidget.cpp" />
<ClCompile Include="advancedsettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_advancedsettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_gamepropertiesdialog.cpp" />
<ClCompile Include="gdbconnection.cpp" />
<ClCompile Include="$(IntDir)moc_gdbconnection.cpp" />
<ClCompile Include="gdbserver.cpp" />
@ -186,6 +185,8 @@
<QtUi Include="controllerbindingwidget_analog_joystick.ui" />
<QtUi Include="controllerbindingwidget_negcon.ui" />
<QtUi Include="controllerbindingwidget_guncon.ui" />
<QtUi Include="controllermacrowidget.ui" />
<QtUi Include="controllermacroeditwidget.ui" />
</ItemGroup>
<ItemGroup>
<Natvis Include="qt5.natvis" />