2017-05-20 15:53:17 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-10-18 19:54:02 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
2018-05-13 19:17:46 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
MappingDouble::MappingDouble(MappingWidget* parent, ControllerEmu::NumericSetting<double>* setting)
|
|
|
|
: QDoubleSpinBox(parent), m_setting(*setting)
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
setDecimals(2);
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
if (const auto ui_description = m_setting.GetUIDescription())
|
|
|
|
setToolTip(tr(ui_description));
|
|
|
|
|
2019-07-30 13:35:46 +00:00
|
|
|
connect(this, qOverload<double>(&QDoubleSpinBox::valueChanged), this,
|
2019-03-27 00:31:03 +00:00
|
|
|
[this, parent](double value) {
|
|
|
|
m_setting.SetValue(value);
|
2019-10-18 19:54:02 +00:00
|
|
|
ConfigChanged();
|
2019-03-15 01:27:49 +00:00
|
|
|
parent->SaveSettings();
|
2017-05-20 15:53:17 +00:00
|
|
|
});
|
2019-03-15 01:27:49 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
connect(parent, &MappingWidget::ConfigChanged, this, &MappingDouble::ConfigChanged);
|
2019-10-18 19:54:02 +00:00
|
|
|
connect(parent, &MappingWidget::Update, this, &MappingDouble::Update);
|
2019-03-27 00:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overriding QDoubleSpinBox's fixup to set the default value when input is cleared.
|
|
|
|
void MappingDouble::fixup(QString& input) const
|
|
|
|
{
|
|
|
|
input = QString::number(m_setting.GetDefaultValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingDouble::ConfigChanged()
|
|
|
|
{
|
2019-04-27 15:51:57 +00:00
|
|
|
const QSignalBlocker blocker(this);
|
2019-10-18 19:54:02 +00:00
|
|
|
|
|
|
|
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);
|
2019-03-27 00:31:03 +00:00
|
|
|
setValue(m_setting.GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bool>* setting)
|
|
|
|
: QCheckBox(parent), m_setting(*setting)
|
|
|
|
{
|
2021-05-06 08:50:29 +00:00
|
|
|
if (const auto ui_description = m_setting.GetUIDescription())
|
|
|
|
setToolTip(tr(ui_description));
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
|
|
|
|
m_setting.SetValue(value != 0);
|
2019-10-18 19:54:02 +00:00
|
|
|
ConfigChanged();
|
2019-03-27 00:31:03 +00:00
|
|
|
parent->SaveSettings();
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
|
2019-10-18 19:54:02 +00:00
|
|
|
connect(parent, &MappingWidget::Update, this, &MappingBool::Update);
|
2020-01-18 17:19:32 +00:00
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
void MappingBool::ConfigChanged()
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
2019-04-27 15:51:57 +00:00
|
|
|
const QSignalBlocker blocker(this);
|
2019-10-18 19:54:02 +00:00
|
|
|
|
|
|
|
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);
|
2019-03-27 00:31:03 +00:00
|
|
|
setChecked(m_setting.GetValue());
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|