From c59bb67569bfe997f33410a6dafd2ef31749cd73 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 13 Jan 2022 05:51:57 +0100 Subject: Fix setting double values in setting spinboxes --- resources/qml/pages/UserSettingsPage.qml | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'resources') diff --git a/resources/qml/pages/UserSettingsPage.qml b/resources/qml/pages/UserSettingsPage.qml index 3701784d..71a90a27 100644 --- a/resources/qml/pages/UserSettingsPage.qml +++ b/resources/qml/pages/UserSettingsPage.qml @@ -118,7 +118,7 @@ Rectangle { } } DelegateChoice { - roleValue: UserSettingsModel.Number + roleValue: UserSettingsModel.Integer SpinBox { anchors.right: parent.right @@ -129,6 +129,42 @@ Rectangle { stepSize: model.valueStep value: model.value onValueChanged: model.value = value + editable: true + } + } + DelegateChoice { + roleValue: UserSettingsModel.Double + + SpinBox { + id: spinbox + + readonly property double div: 100 + readonly property int decimals: 2 + + anchors.right: parent.right + width: Math.min(parent.width, implicitWidth) + enabled: !deadTimer.running && model.enabled + from: model.valueLowerBound * div + to: model.valueUpperBound * div + stepSize: model.valueStep * div + value: model.value * div + onValueChanged: model.value = value/div + editable: true + + property real realValue: value / div + + validator: DoubleValidator { + bottom: Math.min(spinbox.from/spinbox.div, spinbox.to/spinbox.div) + top: Math.max(spinbox.from/spinbox.div, spinbox.to/spinbox.div) + } + + textFromValue: function(value, locale) { + return Number(value / spinbox.div).toLocaleString(locale, 'f', spinbox.decimals) + } + + valueFromText: function(text, locale) { + return Number.fromLocaleString(locale, text) * spinbox.div + } } } DelegateChoice { -- cgit 1.4.1