mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:23:53 +00:00
added double settings
This commit is contained in:
parent
c61d717e41
commit
9ca5a1b647
5 changed files with 147 additions and 1 deletions
|
@ -138,7 +138,7 @@ opencs_hdrs_noqt (model/settings
|
|||
)
|
||||
|
||||
opencs_units (model/prefs
|
||||
state setting intsetting
|
||||
state setting intsetting doublesetting
|
||||
)
|
||||
|
||||
opencs_units_noqt (model/prefs
|
||||
|
|
69
apps/opencs/model/prefs/doublesetting.cpp
Normal file
69
apps/opencs/model/prefs/doublesetting.cpp
Normal file
|
@ -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);
|
||||
}
|
39
apps/opencs/model/prefs/doublesetting.hpp
Normal file
39
apps/opencs/model/prefs/doublesetting.hpp
Normal file
|
@ -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
|
|
@ -6,6 +6,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "intsetting.hpp"
|
||||
#include "doublesetting.hpp"
|
||||
|
||||
CSMPrefs::State *CSMPrefs::State::sThis = 0;
|
||||
|
||||
|
@ -81,6 +82,21 @@ void CSMPrefs::State::declare()
|
|||
declareCategory ("General Input");
|
||||
|
||||
declareCategory ("3D Scene Input");
|
||||
// p-navi
|
||||
// s-navi
|
||||
// p-edit
|
||||
// s-edit
|
||||
// p-select
|
||||
// s-select
|
||||
// context-select
|
||||
declareDouble ("drag-factor", "Mouse sensitivity during drag operations", 1.0).
|
||||
setRange (0.001, 100.0);
|
||||
declareDouble ("drag-wheel-factor", "Mouse wheel sensitivity during drag operations", 1.0).
|
||||
setRange (0.001, 100.0);
|
||||
declareDouble ("drag-shift-factor",
|
||||
"Shift-acceleration factor during drag operations", 4.0).
|
||||
setTooltip ("Acceleration factor during drag operations while holding down shift").
|
||||
setRange (0.001, 100.0);
|
||||
|
||||
declareCategory ("Tooltips");
|
||||
// scene
|
||||
|
@ -124,6 +140,26 @@ CSMPrefs::IntSetting& CSMPrefs::State::declareInt (const std::string& key,
|
|||
return *setting;
|
||||
}
|
||||
|
||||
CSMPrefs::DoubleSetting& CSMPrefs::State::declareDouble (const std::string& key,
|
||||
const std::string& label, double default_)
|
||||
{
|
||||
if (mCurrentCategory==mCategories.end())
|
||||
throw std::logic_error ("no category for setting");
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << default_;
|
||||
setDefault (key, stream.str());
|
||||
|
||||
default_ = mSettings.getFloat (key, mCurrentCategory->second.getKey());
|
||||
|
||||
CSMPrefs::DoubleSetting *setting =
|
||||
new CSMPrefs::DoubleSetting (&mCurrentCategory->second, &mSettings, key, label, default_);
|
||||
|
||||
mCurrentCategory->second.addSetting (setting);
|
||||
|
||||
return *setting;
|
||||
}
|
||||
|
||||
void CSMPrefs::State::setDefault (const std::string& key, const std::string& default_)
|
||||
{
|
||||
Settings::CategorySetting fullKey (mCurrentCategory->second.getKey(), key);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
namespace CSMPrefs
|
||||
{
|
||||
class IntSetting;
|
||||
class DoubleSetting;
|
||||
|
||||
class State : public QObject
|
||||
{
|
||||
|
@ -51,6 +52,7 @@ namespace CSMPrefs
|
|||
void declareCategory (const std::string& key);
|
||||
|
||||
IntSetting& declareInt (const std::string& key, const std::string& label, int default_);
|
||||
DoubleSetting& declareDouble (const std::string& key, const std::string& label, double default_);
|
||||
|
||||
void setDefault (const std::string& key, const std::string& default_);
|
||||
|
||||
|
|
Loading…
Reference in a new issue