1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +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.

82 lines
1.7 KiB
C++
Raw Normal View History

2015-12-08 17:21:58 +01:00
#include "intsetting.hpp"
#include <limits>
#include <QLabel>
2015-12-15 12:19:48 +01:00
#include <QMutexLocker>
2015-12-08 17:21:58 +01:00
#include <QSpinBox>
#include <components/settings/settings.hpp>
2022-10-19 19:02:00 +02:00
#include <apps/opencs/model/prefs/setting.hpp>
2015-12-08 17:21:58 +01:00
#include "category.hpp"
#include "state.hpp"
CSMPrefs::IntSetting::IntSetting(
Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index)
2023-11-12 00:52:09 +01:00
: TypedSetting(parent, mutex, key, label, index)
, mMin(0)
, mMax(std::numeric_limits<int>::max())
2020-11-13 11:39:47 +04:00
, mWidget(nullptr)
2015-12-08 17:21:58 +01: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;
}
CSMPrefs::SettingWidgets CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
2015-12-08 17:21:58 +01:00
{
QLabel* label = new QLabel(getLabel(), parent);
2015-12-08 17:21:58 +01:00
mWidget = new QSpinBox(parent);
mWidget->setRange(mMin, mMax);
2023-11-12 00:52:09 +01:00
mWidget->setValue(getValue());
2015-12-08 17:21:58 +01:00
if (!mTooltip.empty())
{
QString tooltip = QString::fromUtf8(mTooltip.c_str());
label->setToolTip(tooltip);
mWidget->setToolTip(tooltip);
2015-12-08 17:21:58 +01:00
}
connect(mWidget, qOverload<int>(&QSpinBox::valueChanged), this, &IntSetting::valueChanged);
2015-12-08 17:21:58 +01:00
return SettingWidgets{ .mLabel = label, .mInput = mWidget };
}
void CSMPrefs::IntSetting::updateWidget()
{
if (mWidget)
2023-11-12 00:52:09 +01:00
mWidget->setValue(getValue());
2015-12-08 17:21:58 +01:00
}
void CSMPrefs::IntSetting::valueChanged(int value)
{
2023-11-12 00:52:09 +01:00
setValue(value);
2015-12-08 17:21:58 +01:00
getParent()->getState()->update(*this);
}