Add keyboard support to comboBox, HistoryList. Fix some issues with keyboard support.
[mdictionary] / src / mdictionary / qml / WordListWidget.qml
index 742cf49..e4168f9 100644 (file)
@@ -25,6 +25,9 @@
 import Qt 4.7
 
 Rectangle {
+    id: rectangle1
+    color: myPalette.base
+    anchors.fill: parent
 
     function changeWordState(nr, state) {
         wordList.currentIndex = nr
@@ -43,13 +46,10 @@ Rectangle {
 
     signal wordSelected(string word);
     signal wordSelectedByIndex(int nr);
+    signal checkFocus();
 
     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
 
-    id: rectangle1
-    color: myPalette.base
-    anchors.fill: parent
-
     ElementsListView{
         id: wordList
         width: rectangle1.width
@@ -59,6 +59,9 @@ Rectangle {
         property bool empty: false
 
         Keys.onPressed: {
+            if ((currentIndex < 0 || currentIndex >= count) && (event.key == Qt.Key_Up || event.key == Qt.Key_Down)){
+                currentIndex = 0
+            }
             if (event.key == Qt.Key_Space && currentIndex >= 0){
                 rectangle1.changeWordStateByIndex();
             } else if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
@@ -69,6 +72,8 @@ Rectangle {
         delegate: Component{
             id: wordListDelegate
             Item {
+                onActiveFocusChanged: rectangle1.checkFocus();
+
                 width: rectangle1.width
                 height: {
                     if (wordText.height + 4 > check.height)
@@ -76,11 +81,11 @@ Rectangle {
                     else
                             return check.height;
                 }
-
                 MouseArea{
                     anchors.fill: parent
-                    onClicked: {
-                        wordList.currentIndex = index
+                    onClicked: wordList.currentIndex = index 
+                    onDoubleClicked: {
+                        wordList.currentIndex = number
                         rectangle1.wordSelected(word)
                     }
                 }
@@ -100,13 +105,12 @@ Rectangle {
                     pathToUncheckedImage: UncheckedPath
                     anchors.right: parent.right
                     anchors.rightMargin: 5
-
+                    pathToCheckedDicImage: CheckedPath
+                    pathToUncheckedDicImage: UncheckedPath
                     anchors.verticalCenter: parent.verticalCenter
                     onChanged: rectangle1.changeWordState(number, selected)
                 }
-
             }
-
         }
 
         Text {
@@ -150,4 +154,12 @@ Rectangle {
             }
         ]
     }
+
+    states: [
+            State {
+                name: "noFocus";
+                when: ((!wordList.focus) && (!rectangle1.focus))
+                PropertyChanges { target: wordList.highlightItem; opacity:0}
+           }
+    ]
 }