Qt: Display deadzone/sensitivity/etc as whole number instead of decimal

This commit is contained in:
Connor McLaughlin 2022-10-21 21:01:30 +10:00
parent b154579c0d
commit 6def728888

View file

@ -574,10 +574,29 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge
{ {
QDoubleSpinBox* sb = new QDoubleSpinBox(this); QDoubleSpinBox* sb = new QDoubleSpinBox(this);
sb->setObjectName(QString::fromUtf8(si.name)); sb->setObjectName(QString::fromUtf8(si.name));
if (si.multiplier != 0.0f && si.multiplier != 1.0f)
{
const float multiplier = si.multiplier;
sb->setMinimum(si.FloatMinValue() * multiplier);
sb->setMaximum(si.FloatMaxValue() * multiplier);
sb->setSingleStep(si.FloatStepValue() * multiplier);
if (std::abs(si.multiplier - 100.0f) < 0.01f)
{
sb->setDecimals(0);
sb->setSuffix(QStringLiteral("%"));
}
SettingWidgetBinder::BindWidgetToNormalizedSetting(sif, sb, section, std::move(key_name), si.multiplier,
si.FloatDefaultValue() * multiplier);
}
else
{
sb->setMinimum(si.FloatMinValue()); sb->setMinimum(si.FloatMinValue());
sb->setMaximum(si.FloatMaxValue()); sb->setMaximum(si.FloatMaxValue());
sb->setSingleStep(si.FloatStepValue()); sb->setSingleStep(si.FloatStepValue());
SettingWidgetBinder::BindWidgetToFloatSetting(sif, sb, section, std::move(key_name), si.FloatDefaultValue()); SettingWidgetBinder::BindWidgetToFloatSetting(sif, sb, section, std::move(key_name), si.FloatDefaultValue());
}
layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.display_name), this), current_row, 0); layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.display_name), this), current_row, 0);
layout->addWidget(sb, current_row, 1, 1, 3); layout->addWidget(sb, current_row, 1, 1, 3);
current_row++; current_row++;
@ -667,8 +686,13 @@ void ControllerCustomSettingsWidget::restoreDefaults()
{ {
QDoubleSpinBox* widget = findChild<QDoubleSpinBox*>(QString::fromStdString(si.name)); QDoubleSpinBox* widget = findChild<QDoubleSpinBox*>(QString::fromStdString(si.name));
if (widget) if (widget)
{
if (si.multiplier != 0.0f && si.multiplier != 1.0f)
widget->setValue(si.FloatDefaultValue() * si.multiplier);
else
widget->setValue(si.FloatDefaultValue()); widget->setValue(si.FloatDefaultValue());
} }
}
break; break;
case SettingInfo::Type::String: case SettingInfo::Type::String: