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>
|
|
|
|
|
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"
|
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
CSMPrefs::IntSetting::IntSetting(
|
2023-11-11 23:52:09 +00:00
|
|
|
Category* parent, QMutex* mutex, const std::string& key, const QString& label, Settings::Index& index)
|
|
|
|
: TypedSetting(parent, mutex, key, label, index)
|
2022-09-22 18:26:05 +00:00
|
|
|
, mMin(0)
|
|
|
|
, mMax(std::numeric_limits<int>::max())
|
|
|
|
, 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;
|
|
|
|
}
|
|
|
|
|
2023-11-10 12:28:10 +00:00
|
|
|
CSMPrefs::SettingWidgets CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
|
2015-12-08 16:21:58 +00:00
|
|
|
{
|
2023-11-10 12:09:37 +00:00
|
|
|
QLabel* label = new QLabel(getLabel(), 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);
|
2023-11-11 23:52:09 +00:00
|
|
|
mWidget->setValue(getValue());
|
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
|
|
|
|
2023-12-13 23:28:43 +00:00
|
|
|
return SettingWidgets{ .mLabel = label, .mInput = mWidget };
|
2017-05-09 07:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::IntSetting::updateWidget()
|
|
|
|
{
|
|
|
|
if (mWidget)
|
2023-11-11 23:52:09 +00:00
|
|
|
mWidget->setValue(getValue());
|
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
|
|
|
{
|
2023-11-11 23:52:09 +00:00
|
|
|
setValue(value);
|
2022-09-22 18:26:05 +00:00
|
|
|
getParent()->getState()->update(*this);
|
2015-12-08 16:21:58 +00:00
|
|
|
}
|