mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-11 16:49:28 +02:00
InputCommon: Allow controller settings specified with input expresions.
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
|
||||
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
||||
|
||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||
@ -12,24 +14,20 @@
|
||||
MappingDouble::MappingDouble(MappingWidget* parent, ControllerEmu::NumericSetting<double>* setting)
|
||||
: QDoubleSpinBox(parent), m_setting(*setting)
|
||||
{
|
||||
setRange(m_setting.GetMinValue(), m_setting.GetMaxValue());
|
||||
setDecimals(2);
|
||||
|
||||
setFixedWidth(WIDGET_MAX_WIDTH);
|
||||
|
||||
if (const auto ui_suffix = m_setting.GetUISuffix())
|
||||
setSuffix(QLatin1Char{' '} + tr(ui_suffix));
|
||||
|
||||
if (const auto ui_description = m_setting.GetUIDescription())
|
||||
setToolTip(tr(ui_description));
|
||||
|
||||
connect(this, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
||||
[this, parent](double value) {
|
||||
m_setting.SetValue(value);
|
||||
ConfigChanged();
|
||||
parent->SaveSettings();
|
||||
});
|
||||
|
||||
connect(parent, &MappingWidget::ConfigChanged, this, &MappingDouble::ConfigChanged);
|
||||
connect(parent, &MappingWidget::Update, this, &MappingDouble::Update);
|
||||
}
|
||||
|
||||
// Overriding QDoubleSpinBox's fixup to set the default value when input is cleared.
|
||||
@ -41,6 +39,36 @@ void MappingDouble::fixup(QString& input) const
|
||||
void MappingDouble::ConfigChanged()
|
||||
{
|
||||
const QSignalBlocker blocker(this);
|
||||
|
||||
QString suffix;
|
||||
|
||||
if (const auto ui_suffix = m_setting.GetUISuffix())
|
||||
suffix += QLatin1Char{' '} + tr(ui_suffix);
|
||||
|
||||
if (m_setting.IsSimpleValue())
|
||||
{
|
||||
setRange(m_setting.GetMinValue(), m_setting.GetMaxValue());
|
||||
setButtonSymbols(ButtonSymbols::UpDownArrows);
|
||||
}
|
||||
else
|
||||
{
|
||||
constexpr auto inf = std::numeric_limits<double>::infinity();
|
||||
setRange(-inf, inf);
|
||||
setButtonSymbols(ButtonSymbols::NoButtons);
|
||||
suffix += QString::fromUtf8(" 🎮");
|
||||
}
|
||||
|
||||
setSuffix(suffix);
|
||||
|
||||
setValue(m_setting.GetValue());
|
||||
}
|
||||
|
||||
void MappingDouble::Update()
|
||||
{
|
||||
if (m_setting.IsSimpleValue() || hasFocus())
|
||||
return;
|
||||
|
||||
const QSignalBlocker blocker(this);
|
||||
setValue(m_setting.GetValue());
|
||||
}
|
||||
|
||||
@ -49,14 +77,31 @@ MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bo
|
||||
{
|
||||
connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
|
||||
m_setting.SetValue(value != 0);
|
||||
ConfigChanged();
|
||||
parent->SaveSettings();
|
||||
});
|
||||
|
||||
connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
|
||||
connect(parent, &MappingWidget::Update, this, &MappingBool::Update);
|
||||
}
|
||||
|
||||
void MappingBool::ConfigChanged()
|
||||
{
|
||||
const QSignalBlocker blocker(this);
|
||||
|
||||
if (m_setting.IsSimpleValue())
|
||||
setText({});
|
||||
else
|
||||
setText(QString::fromUtf8("🎮"));
|
||||
|
||||
setChecked(m_setting.GetValue());
|
||||
}
|
||||
|
||||
void MappingBool::Update()
|
||||
{
|
||||
if (m_setting.IsSimpleValue())
|
||||
return;
|
||||
|
||||
const QSignalBlocker blocker(this);
|
||||
setChecked(m_setting.GetValue());
|
||||
}
|
||||
|
Reference in New Issue
Block a user