bi change + completer in line edit
[mdictionary] / src / mdictionary / qml / MySpinBox.qml
index 9f0d47c..54fe47d 100644 (file)
@@ -7,16 +7,22 @@ Rectangle {
     property int maxValue:500;
     property int minValue:0;
     property alias value:text_input1.text
+    property bool isTextInMinValue:true;
+    property string textInMinValue:"inf";
+    property int singleStep: 2;
 
     signal valueChange(int intiger);
 
     function stringToInt(string){
         var value=0;
         var pow10=1;
-        for (var i=string.length-1;i>=0;i--){
-            value+=(string.charCodeAt(i)-48)*pow10;
-            pow10= pow10*10;
-        }
+        if(isTextInMinValue && textInMinValue==string)
+            value=minValue;
+        else
+            for (var i=string.length-1;i>=0;i--){
+                value+=(string.charCodeAt(i)-48)*pow10;
+                pow10= pow10*10;
+            }
         if(value>maxValue)
             return maxValue;
         if(value<minValue)
@@ -36,7 +42,12 @@ Rectangle {
         selectByMouse: true;
         font.pixelSize: rectangle1.height * .5;
         onCursorPositionChanged:  moveCursorSelection(cursorPosition);
-        onTextChanged: rectangle1.valueChange(stringToInt(text_input1.text));
+        onTextChanged:{
+            if(isTextInMinValue && text_input1.text!="" && stringToInt(text_input1.text)==minValue)
+                text_input1.text=textInMinValue;
+
+            rectangle1.valueChange(stringToInt(text_input1.text));
+        }
         onFocusChanged: {
             if(focus==false)
                text=stringToInt(text);
@@ -50,7 +61,7 @@ Rectangle {
         repeat: true
         onTriggered:{
             if(mouseAreaUp.pressedButtons==Qt.LeftButton)
-                text_input1.text=((stringToInt(text_input1.text)+1)>maxValue)?(maxValue):(stringToInt(text_input1.text)+1);
+                text_input1.text=((stringToInt(text_input1.text)+singleStep)>maxValue)?(maxValue):(stringToInt(text_input1.text)+singleStep);
             else
                 running=false;
         }
@@ -62,8 +73,11 @@ Rectangle {
         running: false;
         repeat: true
         onTriggered:{
-            if(mouseAreaDown.pressedButtons==Qt.LeftButton)
-                text_input1.text=((stringToInt(text_input1.text)-1)<minValue)?(minValue):(stringToInt(text_input1.text)-1);
+            if(mouseAreaDown.pressedButtons==Qt.LeftButton){
+                text_input1.text=((stringToInt(text_input1.text)-singleStep)<minValue)?(minValue):(stringToInt(text_input1.text)-singleStep);
+                if(isTextInMinValue && stringToInt(text_input1.text)==minValue)
+                    text_input1.text=textInMinValue
+            }
             else
                 running=false;
         }
@@ -110,7 +124,7 @@ Rectangle {
         height: rectangle1.height/2;
         anchors.right: parent.right
         anchors.top: parent.top
-        onClicked: text_input1.text=((stringToInt(text_input1.text)+1)>maxValue)?(maxValue):(stringToInt(text_input1.text)+1);
+        onClicked: text_input1.text=((stringToInt(text_input1.text)+singleStep)>maxValue)?(maxValue):(stringToInt(text_input1.text)+singleStep);
         onPressAndHold:{
             timerUp.restart;
             timerUp.running=true;
@@ -124,19 +138,15 @@ Rectangle {
         height: rectangle1.height/2;
         anchors.right: parent.right
         anchors.bottom: parent.bottom
-        onClicked: text_input1.text=((stringToInt(text_input1.text)-1)<minValue)?(minValue):(stringToInt(text_input1.text)-1);
+        onClicked:{
+            text_input1.text=((stringToInt(text_input1.text)-singleStep)<minValue)?(minValue):(stringToInt(text_input1.text)-singleStep);
+            if(isTextInMinValue && stringToInt(text_input1.text)==minValue)
+                text_input1.text=textInMinValue
+        }
         onPressAndHold:{
             timerDown.restart;
             timerDown.running=true;
         }
     }
-
-   /* states: [
-        State {
-            name: "DisableState"; when: rectangle1.enabled==false;
-            PropertyChanges { target: shadeDisable; z: 3; opacity: 0.5 }
-        }
-    ]
-    */
 }