From 08d055ca2309d0230ce3659682c7e98735a2497f Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Sat, 26 Mar 2016 14:35:03 -0400 Subject: [PATCH] Allow setting precision of double preferences. Also increase precision of camera sensitivity. --- apps/opencs/model/prefs/doublesetting.cpp | 9 ++++++++- apps/opencs/model/prefs/doublesetting.hpp | 3 +++ apps/opencs/model/prefs/state.cpp | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/prefs/doublesetting.cpp b/apps/opencs/model/prefs/doublesetting.cpp index 7c247777d..531196174 100644 --- a/apps/opencs/model/prefs/doublesetting.cpp +++ b/apps/opencs/model/prefs/doublesetting.cpp @@ -15,10 +15,16 @@ CSMPrefs::DoubleSetting::DoubleSetting (Category *parent, Settings::Manager *values, QMutex *mutex, const std::string& key, const std::string& label, double default_) : Setting (parent, values, mutex, key, label), - mMin (0), mMax (std::numeric_limits::max()), + mPrecision(2), mMin (0), mMax (std::numeric_limits::max()), mDefault (default_) {} +CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setPrecision(int precision) +{ + mPrecision = precision; + return *this; +} + CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setRange (double min, double max) { mMin = min; @@ -49,6 +55,7 @@ std::pair CSMPrefs::DoubleSetting::makeWidgets (QWidget *p QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent); QDoubleSpinBox *widget = new QDoubleSpinBox (parent); + widget->setDecimals(mPrecision); widget->setRange (mMin, mMax); widget->setValue (mDefault); diff --git a/apps/opencs/model/prefs/doublesetting.hpp b/apps/opencs/model/prefs/doublesetting.hpp index 3868f014e..6fe6b772a 100644 --- a/apps/opencs/model/prefs/doublesetting.hpp +++ b/apps/opencs/model/prefs/doublesetting.hpp @@ -9,6 +9,7 @@ namespace CSMPrefs { Q_OBJECT + int mPrecision; double mMin; double mMax; std::string mTooltip; @@ -21,6 +22,8 @@ namespace CSMPrefs double default_); // defaults to [0, std::numeric_limits::max()] + DoubleSetting& setPrecision (int precision); + DoubleSetting& setRange (double min, double max); DoubleSetting& setMin (double min); diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 2a4d9e8a0..fd6c7b6ed 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -172,7 +172,7 @@ void CSMPrefs::State::declare() inputButtons.add (left).add (cLeft).add (right).add (cRight).add (middle).add (cMiddle); declareEnum ("p-navi", "Primary Camera Navigation Button", left).addValues (inputButtons); declareEnum ("s-navi", "Secondary Camera Navigation Button", cLeft).addValues (inputButtons); - declareDouble ("p-navi-sensitivity", "Camera Sensitivity", 1/650.).setRange(-2.0, 2.0); + declareDouble ("p-navi-sensitivity", "Camera Sensitivity", 1/650.).setPrecision(4).setRange(-2.0, 2.0); declareDouble ("s-navi-sensitivity", "Secondary Camera Movement Sensitivity", 50.0).setRange(-1000.0, 1000.0); declareDouble ("navi-wheel-factor", "Camera Zoom Sensitivity", 8).setRange(-100.0, 100.0); declareDouble ("navi-free-lin-speed", "Free Camera Linear Speed", 1000.0).setRange(1.0, 10000.0);