mirror of https://github.com/OpenMW/openmw.git
added double settings
parent
c61d717e41
commit
9ca5a1b647
@ -0,0 +1,69 @@
|
||||
|
||||
#include "doublesetting.hpp"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QDoubleSpinBox>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
#include "category.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
CSMPrefs::DoubleSetting::DoubleSetting (Category *parent, Settings::Manager *values,
|
||||
const std::string& key, const std::string& label, double default_)
|
||||
: Setting (parent, values, key, label), mMin (0), mMax (std::numeric_limits<double>::max()),
|
||||
mDefault (default_)
|
||||
{}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::pair<QWidget *, QWidget *> CSMPrefs::DoubleSetting::makeWidgets (QWidget *parent)
|
||||
{
|
||||
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
|
||||
QDoubleSpinBox *widget = new QDoubleSpinBox (parent);
|
||||
widget->setRange (mMin, mMax);
|
||||
widget->setValue (mDefault);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||
label->setToolTip (tooltip);
|
||||
widget->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (valueChanged (double)), this, SLOT (valueChanged (double)));
|
||||
|
||||
return std::make_pair (label, widget);
|
||||
}
|
||||
|
||||
void CSMPrefs::DoubleSetting::valueChanged (double value)
|
||||
{
|
||||
getValues().setFloat (getKey(), getParent()->getKey(), value);
|
||||
getParent()->getState()->update (*this);
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#ifndef CSM_PREFS_DOUBLESETTING_H
|
||||
#define CSM_PREFS_DOUBLESETTING_H
|
||||
|
||||
#include "setting.hpp"
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class DoubleSetting : public Setting
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
double mMin;
|
||||
double mMax;
|
||||
std::string mTooltip;
|
||||
double mDefault;
|
||||
|
||||
public:
|
||||
|
||||
DoubleSetting (Category *parent, Settings::Manager *values,
|
||||
const std::string& key, const std::string& label, double default_);
|
||||
|
||||
DoubleSetting& setRange (double min, double max);
|
||||
|
||||
DoubleSetting& setMin (double min);
|
||||
|
||||
DoubleSetting& setMax (double max);
|
||||
|
||||
DoubleSetting& setTooltip (const std::string& tooltip);
|
||||
|
||||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged (double value);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue