From 3b5eb2d24beb3f1267078229c2cef8d3b0003223 Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Wed, 23 Dec 2020 22:53:43 -0500 Subject: [PATCH 1/6] Partial fix for spinner boxes not using the _step property of SpinnerPreference. (https://github.com/vircadia/vircadia/issues/117) - In SpinBoxPreference.qml, SpinBox was missing "realStepSize: preference.step". - Had to change FloatPreference::step from float to double, because there is some truncation happening somewhere. For example, a step of 0.01f was acting like 0.00 because (0.01f < 0.01). - Changed FloatPreference::decimals (number of decimal places) from float to uint, because it seemed to make more sense. - Changed the 'User real-world height' spinbox to use a resolution of 1cm (for display and step) rather than 1mm. - Remaining bug: the up & down buttons of the spinbox fail to change the value, at some values, though the mouse wheel always works. Repro: Settings > Controls > User real-world height Hover the mouse over the box and and scroll the mouse wheel down until the value is at 1.15. Click the up button a few times and observe that the number can't be increased. Scroll the mouse wheel forward and observe that the number increases correctly. - Todo: Change all calls to FloatPreference::setStep to pass doubles, if this change to its parameter type is kept. --- .../dialogs/preferences/SpinBoxPreference.qml | 1 + interface/src/ui/PreferencesDialog.cpp | 4 ++-- libraries/shared/src/Preferences.h | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml b/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml index 1b080c2759..5b3a28cd1d 100644 --- a/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml +++ b/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml @@ -51,6 +51,7 @@ Preference { decimals: preference.decimals minimumValue: preference.min maximumValue: preference.max + realStepSize: preference.step width: 100 anchors { verticalCenter: parent.verticalCenter diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 79d9ebaa5c..a372239249 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -465,8 +465,8 @@ void setupPreferences() { auto preference = new SpinnerPreference(VR_MOVEMENT, "User real-world height (meters)", getter, setter); preference->setMin(1.0f); preference->setMax(2.2f); - preference->setDecimals(3); - preference->setStep(0.001f); + preference->setDecimals(2); + preference->setStep(0.01); preferences->addPreference(preference); } diff --git a/libraries/shared/src/Preferences.h b/libraries/shared/src/Preferences.h index 9147117792..2b82a7f3fe 100644 --- a/libraries/shared/src/Preferences.h +++ b/libraries/shared/src/Preferences.h @@ -152,8 +152,8 @@ 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(float step READ getStep CONSTANT) - Q_PROPERTY(float decimals READ getDecimals CONSTANT) + Q_PROPERTY(double step READ getStep CONSTANT) + Q_PROPERTY(uint decimals READ getDecimals CONSTANT) public: using Getter = std::function; @@ -178,11 +178,11 @@ public: float getMax() const { return _max; } void setMax(float max) { _max = max; }; - float getStep() const { return _step; } - void setStep(float step) { _step = step; }; + double getStep() const { return _step; } + void setStep(double step) { _step = step; }; - float getDecimals() const { return _decimals; } - void setDecimals(float decimals) { _decimals = decimals; }; + uint getDecimals() const { return _decimals; } + void setDecimals(uint decimals) { _decimals = decimals; }; signals: void valueChanged(); @@ -194,10 +194,10 @@ protected: const Getter _getter; const Setter _setter; - float _decimals { 0 }; + uint _decimals { 0 }; float _min { 0 }; float _max { 1 }; - float _step { 0.1f }; + double _step { 0.1 }; }; class IntPreference : public Preference { From da2a3f67cfa9b08ef1af882094336394e29efb54 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 16 Jan 2021 11:04:07 +1300 Subject: [PATCH 2/6] Fix QML spinbox not stepping for some values --- interface/resources/qml/controlsUit/SpinBox.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/controlsUit/SpinBox.qml b/interface/resources/qml/controlsUit/SpinBox.qml index a888bbd07c..1ba9a02d40 100644 --- a/interface/resources/qml/controlsUit/SpinBox.qml +++ b/interface/resources/qml/controlsUit/SpinBox.qml @@ -97,11 +97,11 @@ SpinBox { } textFromValue: function(value, locale) { - return parseFloat(value / factor).toFixed(decimals); + return (value / factor).toFixed(decimals); } valueFromText: function(text, locale) { - return Number.fromLocaleString(locale, text) * factor; + return Math.round(Number.fromLocaleString(locale, text) * factor); } From a2e4b81ed8ed234491806070c4294d63b0fa26de Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Mon, 1 Feb 2021 20:26:18 -0500 Subject: [PATCH 3/6] * 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 { From 26369ca2a98da0680481a097739309e3ad42fb9d Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Mon, 22 Feb 2021 22:34:04 -0500 Subject: [PATCH 4/6] Fix for some spinner boxes not changing value when using their buttons or the mouse wheel. Changed the default value of FloatPreference::_step from 0.1f to 1, because FloatPreference::_decimals defaults to 0. Also because before this branch, all spinners used a step of 1 rather than SpinnerPreference::_step. Spinners such as Settings > General > Desktop Tablet Scale / VR Tablet Scale work again. --- libraries/shared/src/Preferences.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/Preferences.h b/libraries/shared/src/Preferences.h index 125cd0ae2c..a195dc457f 100644 --- a/libraries/shared/src/Preferences.h +++ b/libraries/shared/src/Preferences.h @@ -197,7 +197,7 @@ protected: uint _decimals { 0 }; float _min { 0 }; float _max { 1 }; - float _step { 0.1f }; + float _step { 1 }; }; class IntPreference : public Preference { From 8b2aa93198a662e3ad51802ce3a3a3ad09bede69 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 5 Apr 2021 12:14:52 +1200 Subject: [PATCH 5/6] Fix step size in combined slider/spinner QML control --- .../qml/dialogs/preferences/SpinnerSliderPreference.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml b/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml index cbc804d9d7..bf7ea08d3a 100644 --- a/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml +++ b/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml @@ -76,6 +76,7 @@ Preference { realValue: preference.value minimumValue: preference.min maximumValue: preference.max + realStepSize: preference.step width: 100 onValueChanged: { slider.value = realValue; From f0eb6a3fcd1e380c268b53028d5eafbabd33ae61 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 5 Apr 2021 12:15:08 +1200 Subject: [PATCH 6/6] Adjust numbers of decimals and step sizes in Settings dialogs --- interface/src/ui/PreferencesDialog.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index cbfc4d0779..c2f1abdd94 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -362,10 +362,10 @@ void setupPreferences() { auto getter = [myAvatar]()->float { return qApp->getCamera().getSensitivity(); }; auto setter = [myAvatar](float value) { qApp->getCamera().setSensitivity(value); }; auto preference = new SpinnerSliderPreference(VR_MOVEMENT, "Camera Sensitivity", getter, setter); - preference->setMin(0.01f); + preference->setMin(0.1f); preference->setMax(5.0f); preference->setStep(0.1f); - preference->setDecimals(2); + preference->setDecimals(1); preferences->addPreference(preference); } { @@ -385,7 +385,7 @@ void setupPreferences() { preference->setMin(6.0f); preference->setMax(30.0f); preference->setStep(1); - preference->setDecimals(2); + preference->setDecimals(0); preferences->addPreference(preference); } { @@ -478,7 +478,7 @@ void setupPreferences() { preference->setMin(1.0f); preference->setMax(360.0f); preference->setStep(1); - preference->setDecimals(1); + preference->setDecimals(0); preferences->addPreference(preference); } { @@ -488,7 +488,7 @@ void setupPreferences() { preference->setMin(1.0f); preference->setMax(360.0f); preference->setStep(1); - preference->setDecimals(1); + preference->setDecimals(0); preferences->addPreference(preference); }