From a2e4b81ed8ed234491806070c4294d63b0fa26de Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Mon, 1 Feb 2021 20:26:18 -0500 Subject: [PATCH] * Add more rounding in SpinBox.qml, allowing FloatPreference::step to work reliably for the spinners without needing double precision (suggestion from ctrlaltdavid: https://github.com/vircadia/vircadia/pull/930#issuecomment-765838930). * Change FloatPreference::step from double back to float. --- interface/resources/qml/controlsUit/SpinBox.qml | 6 +++--- interface/src/ui/PreferencesDialog.cpp | 2 +- libraries/shared/src/Preferences.h | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/interface/resources/qml/controlsUit/SpinBox.qml b/interface/resources/qml/controlsUit/SpinBox.qml index 1ba9a02d40..719b0d00c1 100644 --- a/interface/resources/qml/controlsUit/SpinBox.qml +++ b/interface/resources/qml/controlsUit/SpinBox.qml @@ -73,9 +73,9 @@ SpinBox { } } - stepSize: realStepSize * factor - to : realTo*factor - from : realFrom*factor + stepSize: Math.round(realStepSize * factor) + to : Math.round(realTo*factor) + from : Math.round(realFrom*factor) font.family: "Fira Sans SemiBold" font.pixelSize: hifi.fontSizes.textFieldInput diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index a372239249..50f9600411 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -466,7 +466,7 @@ void setupPreferences() { preference->setMin(1.0f); preference->setMax(2.2f); preference->setDecimals(2); - preference->setStep(0.01); + preference->setStep(0.01f); preferences->addPreference(preference); } diff --git a/libraries/shared/src/Preferences.h b/libraries/shared/src/Preferences.h index 2b82a7f3fe..125cd0ae2c 100644 --- a/libraries/shared/src/Preferences.h +++ b/libraries/shared/src/Preferences.h @@ -152,7 +152,7 @@ class FloatPreference : public Preference { Q_PROPERTY(float value READ getValue WRITE setValue NOTIFY valueChanged) Q_PROPERTY(float min READ getMin CONSTANT) Q_PROPERTY(float max READ getMax CONSTANT) - Q_PROPERTY(double step READ getStep CONSTANT) + Q_PROPERTY(float step READ getStep CONSTANT) Q_PROPERTY(uint decimals READ getDecimals CONSTANT) public: @@ -178,11 +178,11 @@ public: float getMax() const { return _max; } void setMax(float max) { _max = max; }; - double getStep() const { return _step; } - void setStep(double step) { _step = step; }; + float getStep() const { return _step; } + void setStep(float step) { _step = step; }; - uint getDecimals() const { return _decimals; } - void setDecimals(uint decimals) { _decimals = decimals; }; + float getDecimals() const { return _decimals; } + void setDecimals(float decimals) { _decimals = decimals; }; signals: void valueChanged(); @@ -197,7 +197,7 @@ protected: uint _decimals { 0 }; float _min { 0 }; float _max { 1 }; - double _step { 0.1 }; + float _step { 0.1f }; }; class IntPreference : public Preference {