diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2018-11-28 15:17:48 +0200 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2018-11-29 09:39:37 +0000 |
commit | 840d2311279d4da54c5f5d8df1f7d6253cd256df (patch) | |
tree | ed0b555ab27d97708f817dc53c4aa599012ec4b0 | |
parent | 6970d6781d98c665bb2af878ed02aa87135913b6 (diff) |
Fix inspector slider decimal places count
With this patch inspector slider value shows only the needed amount
of decimals. Redundant decimal 0s are removed. So slider properties
can show 0 (like in the case of opacity), 1, 2, or 3 decimal places.
Task-number: QT3DS-2769
Change-Id: I76accd4e7c4b1e66d7a9cc1a428b20ec32fd1112
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r-- | src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml b/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml index f1aacbab..13e36516 100644 --- a/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml +++ b/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml @@ -44,7 +44,7 @@ Row { property alias sliderMin: slider.from property alias sliderMax: slider.to property bool intSlider: false - property int decimalSlider: 1 + property int decimalSlider: Math.min(precision(slider.stepSize), 3) property Item tabItem1: textField signal previewValue // Indicates desiredValue contains a preview value @@ -61,6 +61,14 @@ Row { root.commitValue(); } + // get the number of decimals in a float/double + function precision(a) { + if (!isFinite(a)) return 0; + var e = 1, p = 0; + while (Math.round(a * e) / e !== a) { e *= 10; p++; } + return p; + } + onValueChanged: { slider.value = value; textField.setTextFieldValue(); |