1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 21:53:52 +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.

87 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>
2022-09-22 18:26:05 +00:00
#include <QSpinBox>
2015-12-08 16:21:58 +00:00
#include <components/settings/settings.hpp>
#include "category.hpp"
#include "state.hpp"
2022-09-22 18:26:05 +00:00
CSMPrefs::IntSetting::IntSetting(
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())
, mDefault(default_)
, mWidget(nullptr)
{
}
2015-12-08 16:21:58 +00:00
2022-09-22 18:26:05 +00:00
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setRange(int min, int max)
2015-12-08 16:21:58 +00:00
{
mMin = min;
mMax = max;
return *this;
}
2022-09-22 18:26:05 +00:00
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setMin(int min)
2015-12-08 16:21:58 +00:00
{
mMin = min;
return *this;
}
2022-09-22 18:26:05 +00:00
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setMax(int max)
2015-12-08 16:21:58 +00:00
{
mMax = max;
return *this;
}
2022-09-22 18:26:05 +00:00
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setTooltip(const std::string& tooltip)
2015-12-08 16:21:58 +00:00
{
mTooltip = tooltip;
return *this;
}
2022-09-22 18:26:05 +00:00
std::pair<QWidget*, QWidget*> CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
2015-12-08 16:21:58 +00:00
{
2022-09-22 18:26:05 +00:00
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent);
2015-12-08 16:21:58 +00:00
2022-09-22 18:26:05 +00:00
mWidget = new QSpinBox(parent);
mWidget->setRange(mMin, mMax);
mWidget->setValue(mDefault);
2015-12-08 16:21:58 +00:00
if (!mTooltip.empty())
{
2022-09-22 18:26:05 +00:00
QString tooltip = QString::fromUtf8(mTooltip.c_str());
label->setToolTip(tooltip);
mWidget->setToolTip(tooltip);
2015-12-08 16:21:58 +00:00
}
2022-09-22 18:26:05 +00:00
connect(mWidget, qOverload<int>(&QSpinBox::valueChanged), this, &IntSetting::valueChanged);
2015-12-08 16:21:58 +00:00
2022-09-22 18:26:05 +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
}
2022-09-22 18:26:05 +00:00
void CSMPrefs::IntSetting::valueChanged(int value)
2015-12-08 16:21:58 +00:00
{
2015-12-15 11:19:48 +00:00
{
2022-09-22 18:26:05 +00:00
QMutexLocker lock(getMutex());
Settings::Manager::setInt(getKey(), getParent()->getKey(), value);
2015-12-15 11:19:48 +00:00
}
2022-09-22 18:26:05 +00:00
getParent()->getState()->update(*this);
2015-12-08 16:21:58 +00:00
}