Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
[mdictionary] / src / mdictionary / qml / WordListWidget.qml
index 9383549..4cd5f97 100644 (file)
@@ -32,12 +32,20 @@ Rectangle {
     function changeWordState(nr, state) {
         wordList.currentIndex = nr
         wordModel.setModelProperty(wordList.currentIndex, state, "isBookmarked")
+    }
 
+    function changeWordStateByIndex() {
+        wordModel.setModelPropertyByIndex(wordList.currentIndex, "isBookmarked")
     }
 
-    function setEnabled(Boolean) { wordList.enabled = Boolean }  // slot
+    function setEnabled(Boolean) { wordList.enabled = Boolean }
+    function setWordListEmpty(Boolean) { wordList.empty = Boolean }
+    function setFocus() {
+        wordList.setFocus()
+    }
 
     signal wordSelected(string word);
+    signal wordSelectedByIndex(int nr);
     signal checkFocus();
 
     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
@@ -48,6 +56,15 @@ Rectangle {
 
         anchors.fill: parent
         highlightResizeSpeed: 1000
+        property bool empty: false
+
+        Keys.onPressed: {
+            if (event.key == Qt.Key_Space && currentIndex >= 0){
+                rectangle1.changeWordStateByIndex();
+            } else if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
+                rectangle1.wordSelectedByIndex(currentIndex)
+            }
+        }
 
         delegate: Component{
             id: wordListDelegate
@@ -63,7 +80,7 @@ Rectangle {
                 }
                 MouseArea{
                     anchors.fill: parent
-                    onClicked: wordList.currentIndex = number
+                    onClicked: wordList.currentIndex = index 
                     onDoubleClicked: {
                         wordList.currentIndex = number
                         rectangle1.wordSelected(word)
@@ -74,14 +91,7 @@ Rectangle {
                 Text {
                     id: wordText
                     anchors.verticalCenter: parent.verticalCenter
-                    text:
-                    {
-                        if (word == "!@#$%"){
-                            qsTr("Can't find any matching words")
-                        } else {
-                            word
-                        }
-                    }
+                    text: word
                 }
 
                 Checkbox{
@@ -96,18 +106,50 @@ Rectangle {
                     pathToUncheckedDicImage: UncheckedPath
                     anchors.verticalCenter: parent.verticalCenter
                     onChanged: rectangle1.changeWordState(number, selected)
-                    visible: {
-                        if (word == "!@#$%"){
-                            false
-                        } else {
-                            true
-                        }
-                    }
                 }
             }
         }
 
+        Text {
+            id: emptyText
+            anchors.top: parent.top
+            anchors.left: parent.left
+            text: qsTr("Can't find any matching words")
+        }
+
+        Rectangle {
+            id: shadeDisable
+            anchors.centerIn: parent;
+            color: "grey";
+            opacity: 0
+            width:  parent.width;
+            height: parent.height;
+        }
+
         model: wordModel
+
+        states: [
+            State {
+                name: "empty"
+                when: (wordList.empty == true);
+                PropertyChanges { target: emptyText; visible: true}
+            },
+            State {
+                name: "non-empty"
+                when: (wordList.empty == false);
+                PropertyChanges { target: emptyText; visible: false}
+            },
+            State {
+                name: "enabled"
+                when: (wordList.enabled == true);
+                PropertyChanges { target: shadeDisable; z: 30; opacity: 0.5 }
+            },
+            State {
+                name: "disabled"
+                when: (wordList.enabled == false);
+                PropertyChanges { target: shadeDisable; z: 30; opacity: 0.0 }
+            }
+        ]
     }
 
     states: [