1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 22:53:53 +00:00
openmw/apps/opencs/model/prefs/intsetting.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
1.9 KiB
C++
Raw Normal View History

2015-12-08 16:21:58 +00:00
#include "intsetting.hpp"
#include <limits>
#include <QLabel>
2015-12-15 11:19:48 +00:00
#include <QMutexLocker>
2015-12-08 16:21:58 +00:00
#include <QSpinBox>
#include <components/settings/settings.hpp>
2022-10-19 17:02:00 +00:00
#include <apps/opencs/model/prefs/setting.hpp>
2015-12-08 16:21:58 +00:00
#include "category.hpp"
#include "state.hpp"
CSMPrefs::IntSetting::IntSetting(
2015-12-15 11:19:48 +00:00
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, int default_)
: Setting(parent, mutex, key, label)
, mMin(0)
, mMax(std::numeric_limits<int>::max())
2020-11-13 07:39:47 +00:00
, mDefault(default_)
, mWidget(nullptr)
2015-12-08 16:21:58 +00:00
{
}
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setRange(int min, int max)
{
mMin = min;
mMax = max;
return *this;
}
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setMin(int min)
{
mMin = min;
return *this;
}
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setMax(int max)
{
mMax = max;
return *this;
}
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setTooltip(const std::string& tooltip)
{
mTooltip = tooltip;
return *this;
}
std::pair<QWidget*, QWidget*> CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
{
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent);
mWidget = new QSpinBox(parent);
mWidget->setRange(mMin, mMax);
mWidget->setValue(mDefault);
2015-12-08 16:21:58 +00:00
if (!mTooltip.empty())
{
QString tooltip = QString::fromUtf8(mTooltip.c_str());
label->setToolTip(tooltip);
mWidget->setToolTip(tooltip);
2015-12-08 16:21:58 +00:00
}
connect(mWidget, qOverload<int>(&QSpinBox::valueChanged), this, &IntSetting::valueChanged);
2015-12-08 16:21:58 +00:00
return std::make_pair(label, mWidget);
}
void CSMPrefs::IntSetting::updateWidget()
{
if (mWidget)
{
mWidget->setValue(Settings::Manager::getInt(getKey(), getParent()->getKey()));
}
2015-12-08 16:21:58 +00:00
}
void CSMPrefs::IntSetting::valueChanged(int value)
{
2015-12-15 11:19:48 +00:00
{
QMutexLocker lock(getMutex());
Settings::Manager::setInt(getKey(), getParent()->getKey(), value);
2015-12-15 11:19:48 +00:00
}
2015-12-08 16:21:58 +00:00
getParent()->getState()->update(*this);
}