Browse Source

replaced most optioninputs with spinboxes

Malte Veerman 10 years ago
parent
commit
4fefa9ba35

+ 10 - 3
package/contents/scripts/units.js

@@ -31,7 +31,14 @@ function toCelsius(degrees, currentUnit) {
 
 function fromCelsius(degrees, newUnit) {
     var float = parseFloat(degrees);
-    if (newUnit == 1) { return round(float + 273.15, 2); }
-    if (newUnit == 2) { return round(float * 9 / 5 + 32, 2); }
-    return round(float, 2);
+    if (newUnit == 1) { return float + 273.15; }
+    if (newUnit == 2) { return float * 9 / 5 + 32; }
+    return float;
 }
+
+function fromKelvin(degrees, newUnit) {
+    var float = parseFloat(degrees);
+    if (newUnit == 0) { return float - 273.15; }
+    if (newUnit == 2) { return float * 9 / 5 - 459.67; }
+    return float;
+}

+ 18 - 37
package/contents/ui/KCM.qml

@@ -144,21 +144,13 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
-                id: intervalValue
+            SpinBox {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                inputMethodHints: Qt.ImhDigitsOnly
-                validator: IntValidator { bottom: 0 }
                 value: base.loader ? base.loader.interval : 1
-                type: "int"
-                
-                onTextChanged: {
-                    if (activeFocus && text && root.locale) {
-                        var value = Number.fromLocaleString(root.locale, text);
-                        if (value) base.loader.interval = value;
-                    }
-                }
+                suffix: " " + (value > 1 ? i18n("seconds") : i18n("second"))
+                minimumValue: 1.0
+                onValueChanged: base.loader.interval = value
             }
         }
         RowLayout {
@@ -171,21 +163,16 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
-                id: minTempValue
+            SpinBox {
+                id: minTempBox
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                inputMethodHints: Qt.ImhFormattedNumbersOnly
-                validator: DoubleValidator { top: base.maxTemp }
+                decimals: 2
+                maximumValue: maxTempBox.value
+                minimumValue: Units.fromKelvin(0, base.unit)
                 value: Units.fromCelsius(base.minTemp, base.unit)
-                type: "double"
-                
-                onTextChanged: {
-                    if (activeFocus && text && root.locale) {
-                        var value = Units.toCelsius(Number.fromLocaleString(locale, text), base.unit);
-                        if (value) base.minTemp = value;
-                    }
-                }
+                suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F") 
+                onValueChanged: base.minTemp = value
             }
         }
         RowLayout {
@@ -198,21 +185,16 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
-                id: maxTempValue
+            SpinBox {
+                id: maxTempBox
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                inputMethodHints: Qt.ImhFormattedNumbersOnly
-                validator: DoubleValidator { bottom: base.minTemp }
+                decimals: 2
+                maximumValue: Number.POSITIVE_INFINITY
+                minimumValue: minTempBox.value
                 value: Units.fromCelsius(base.maxTemp, base.unit)
-                type: "double"
-                
-                onTextChanged: {
-                    if (activeFocus && text && root.locale) {
-                        var value = Units.toCelsius(Number.fromLocaleString(locale, text), base.unit);
-                        if (value) base.maxTemp = value;
-                    }
-                }
+                suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
+                onValueChanged: base.maxTemp = value
             }
         }        
         RowLayout {
@@ -230,7 +212,6 @@ Item {
                 Layout.fillWidth: true
                 color: base.systemdCom.serviceExists ? "green" : "red"
                 value: base.serviceName
-                type: "string"
                 onTextChanged: base.serviceName = text
             }
         }

+ 2 - 10
package/contents/ui/OptionInput.qml

@@ -28,7 +28,6 @@ FocusScope {
     property alias color: textField.color
     property real margin: 6
     property var value
-    property string type: "int"
     property var locale: Qt.locale()
 
     id: root
@@ -36,15 +35,8 @@ FocusScope {
     implicitWidth: textField.implicitWidth + margin*2
     
     onValueChanged: {
-        if (type == "int" || type == "double") {
-            if (textField.text != Number(value).toLocaleString()) {
-                textField.text = Number(value).toLocaleString();
-            }
-        }
-        else if (type == "string") {
-            if (textField.text != value) {
-                textField.text = value;
-            }
+        if (textField.text != value) {
+            textField.text = value;
         }
     }
 

+ 18 - 36
package/contents/ui/SettingsTab.qml

@@ -52,21 +52,13 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
-                id: intervalValue
+            SpinBox {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                inputMethodHints: Qt.ImhDigitsOnly
-                validator: IntValidator { bottom: 0 }
                 value: gui.loader ? gui.loader.interval : 1
-                type: "int"
-                
-                onTextChanged: {
-                    if (activeFocus && text && root.locale) {
-                        var value = Number.fromLocaleString(root.locale, text);
-                        if (value) gui.loader.interval = value;
-                    }
-                }
+                suffix: " " + (value > 1 ? i18n("seconds") : i18n("second"))
+                minimumValue: 1.0
+                onValueChanged: gui.loader.interval = value
             }
         }
         RowLayout {
@@ -79,20 +71,16 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
+            SpinBox {
+                id: minTempBox
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                inputMethodHints: Qt.ImhFormattedNumbersOnly
-                validator: DoubleValidator { top: gui.maxTemp }
+                decimals: 2
+                maximumValue: maxTempBox.value
+                minimumValue: Units.fromKelvin(0, gui.unit)
                 value: Units.fromCelsius(gui.minTemp, gui.unit)
-                type: "double"
-                
-                onTextChanged: {
-                    if (activeFocus && text && root.locale) {
-                        var value = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit);
-                        if (value) gui.minTemp = value;
-                    }
-                }
+                suffix: gui.unit == 0 ? i18n("°C") : gui.unit == 1 ? i18n("K") : i18n("°F") 
+                onValueChanged: gui.minTemp = value
             }
         }
         RowLayout {
@@ -105,21 +93,16 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
-                id: maxTempValue
+            SpinBox {
+                id: maxTempBox
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                inputMethodHints: Qt.ImhFormattedNumbersOnly
-                validator: DoubleValidator { bottom: gui.minTemp }
+                decimals: 2
+                maximumValue: Number.POSITIVE_INFINITY
+                minimumValue: minTempBox.value
                 value: Units.fromCelsius(gui.maxTemp, gui.unit)
-                type: "double"
-                
-                onTextChanged: {
-                    if (activeFocus && text && root.locale) {
-                        var value = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit);
-                        if (value) gui.maxTemp = value;
-                    }
-                }
+                suffix: gui.unit == 0 ? i18n("°C") : gui.unit == 1 ? i18n("K") : i18n("°F")
+                onValueChanged: gui.maxTemp = value
             }
         }        
         Loader {
@@ -139,7 +122,6 @@ Item {
                     Layout.fillWidth: true
                     color: systemdCom.serviceExists ? "green" : "red"
                     value: gui.serviceName
-                    type: "string"
                     onTextChanged: gui.serviceName = text
                 }
             }