add focus in qml
[mdictionary] / src / mdictionary / qml / SettingsWidget.qml
index b51f788..5f32049 100644 (file)
@@ -7,6 +7,9 @@ Rectangle {
 
     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
     color : myPalette.window;
+    focus: true;
+    property int focusIndex:-1;
+
 
     signal historySizeValueChanged(int intiger);
     signal searchResulValueChanged(int intiger);
@@ -40,6 +43,42 @@ Rectangle {
     function setCheckedDictionaries(bool){
         dictionariesCheckBox.selected=bool;
     }
+    function setFocus(){
+        if(focusIndex==0){
+            searchSpinbox.setFocus();
+            if(!searchSpinbox.enabled)
+                focusIndex++;
+        }
+        if(focusIndex==1){
+            historySpinbox.setFocus();
+            if(!historySpinbox.enabled)
+                focusIndex++;
+        }
+        if(focusIndex==2){
+            bookmarkCheckBox.focus = true
+            if(!bookmarkCheckBox.enabled)
+                focusIndex++;
+        }
+        if(focusIndex==3){
+            dictionariesCheckBox.focus = true
+            if(!dictionariesCheckBox.enabled)
+                focusIndex++;
+        }
+        if(focusIndex==4){
+            saveButton.focus = true
+            if(!saveButton.enabled)
+                focusIndex++;
+        }
+        if(focusIndex>4){
+            focusIndex=-1;
+            focus=true;
+        }
+    }
+
+    Keys.onTabPressed: {
+        focusIndex++;
+        setFocus();
+    }
 
     Text {
         id: textSearch
@@ -107,6 +146,7 @@ Rectangle {
         anchors.left: textSearch.right
         anchors.leftMargin: 20
         onValueChange: rectangle1.searchResulValueChanged(intiger);
+        onFocusChanged: if(focus) focusIndex=0;
     }
 
     MySpinBox {
@@ -117,6 +157,7 @@ Rectangle {
         anchors.top: searchSpinbox.bottom
         anchors.topMargin: 10
         onValueChange: rectangle1.historySizeValueChanged(intiger);
+        onFocusChanged: if(focus) focusIndex=1;
     }
 
     Checkbox {
@@ -128,6 +169,7 @@ Rectangle {
         anchors.top: textSearchIn.bottom
         anchors.topMargin: 0
         onChanged: rectangle1.bookmarksCheckBoxChanged(selected);
+        onFocusChanged: if(focus) focusIndex=2;
     }
 
     Checkbox {
@@ -138,6 +180,7 @@ Rectangle {
         anchors.top: bookmarkCheckBox.bottom
         anchors.topMargin: 3
         onChanged: rectangle1.dictionariesCheckBoxChanged(selected);
+        onFocusChanged: if(focus) focusIndex=3;
     }
 
     Button {
@@ -149,6 +192,7 @@ Rectangle {
         anchors.right: parent.right
         anchors.rightMargin: 5
         textInButton: qsTr("Save")
-        //onClicked: rectangle1.saveButtonClicked();
+        onClicked: rectangle1.saveButtonClicked();
+        onFocusChanged: if(focus) focusIndex=4;
     }
 }