dolphin/Source/Core/DolphinQt2/Config/Mapping/MappingNumeric.cpp

38 lines
1.1 KiB
C++
Raw Normal View History

2017-05-20 15:53:17 +00:00
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt2/Config/Mapping/MappingNumeric.h"
#include "DolphinQt2/Config/Mapping/MappingWidget.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
MappingNumeric::MappingNumeric(MappingWidget* widget, ControllerEmu::NumericSetting* setting)
: m_parent(widget), m_setting(setting), m_range(setting->m_high - setting->m_low)
{
setRange(setting->m_low, setting->m_high);
2017-05-21 10:03:13 +00:00
setValue(setting->m_low + setting->GetValue() * m_range);
2017-05-20 15:53:17 +00:00
Connect();
}
void MappingNumeric::Connect()
{
connect(this, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](int value) {
2017-05-21 10:03:13 +00:00
m_setting->SetValue(static_cast<double>(value - m_setting->m_low) / m_range);
2017-05-20 15:53:17 +00:00
Update();
});
}
void MappingNumeric::Clear()
{
2017-05-21 10:03:13 +00:00
setValue(m_setting->m_low + (m_setting->m_low + m_setting->m_high) / 2);
2017-05-20 15:53:17 +00:00
Update();
}
void MappingNumeric::Update()
{
2017-05-21 10:03:13 +00:00
setValue(m_setting->m_low + m_setting->GetValue() * m_range);
2017-05-20 15:53:17 +00:00
m_parent->SaveSettings();
}