Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
#include "doublesetting.hpp"
#include <limits>
#include <QDoubleSpinBox>#include <QLabel>#include <QMutexLocker>
#include <components/settings/settings.hpp>
#include <apps/opencs/model/prefs/setting.hpp>
#include "category.hpp"#include "state.hpp"
CSMPrefs::DoubleSetting::DoubleSetting( Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index) : TypedSetting(parent, mutex, key, label, index) , mPrecision(2) , mMin(0) , mMax(std::numeric_limits<double>::max()) , mWidget(nullptr){}
CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setPrecision(int precision){ mPrecision = precision; return *this;}
CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setRange(double min, double max){ mMin = min; mMax = max; return *this;}
CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setMin(double min){ mMin = min; return *this;}
CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setMax(double max){ mMax = max; return *this;}
CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setTooltip(const std::string& tooltip){ mTooltip = tooltip; return *this;}
CSMPrefs::SettingWidgets CSMPrefs::DoubleSetting::makeWidgets(QWidget* parent){ QLabel* label = new QLabel(getLabel(), parent);
mWidget = new QDoubleSpinBox(parent); mWidget->setDecimals(mPrecision); mWidget->setRange(mMin, mMax); mWidget->setValue(getValue());
if (!mTooltip.empty()) { QString tooltip = QString::fromUtf8(mTooltip.c_str()); label->setToolTip(tooltip); mWidget->setToolTip(tooltip); }
connect(mWidget, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &DoubleSetting::valueChanged);
return SettingWidgets{ .mLabel = label, .mInput = mWidget };}
void CSMPrefs::DoubleSetting::updateWidget(){ if (mWidget) mWidget->setValue(getValue());}
void CSMPrefs::DoubleSetting::valueChanged(double value){ setValue(value); getParent()->getState()->update(*this);}