fix bug with empty dictionary list. Add first version of WordListView (qml)
[mdictionary] / src / mdictionary / qml / WordListWidget.qml
1 import Qt 4.7
2
3 Rectangle {
4
5     function changeWordState(nr, state) {
6         wordList.currentIndex = nr
7         wordModel.setModelProperty(wordList.currentIndex, state, "isBookmarked")
8
9     }
10
11 //    function setEnabled(Boolean) { wordList.enabled = Boolean; println(wordList.enabled) }  // slot
12
13     signal wordSelected(string word);
14     //?
15 //    signal addToBookmarks(int nr);
16 //    signal removeFromBookmarks(int nr);
17
18     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
19
20     id: rectangle1
21     color: myPalette.base
22     anchors.fill: parent
23
24     ElementsListView{
25         id: wordList
26         width: rectangle1.width
27 //        height: rectangle1.height
28         anchors.fill: parent
29         highlightResizeSpeed: 1000
30
31         delegate: Component{
32             id: wordListDelegate
33             Item {
34                 width: rectangle1.width
35                 height: {
36                     if (wordText.height + 4 > check.height)
37                             return wordText.height + 4;
38                     else
39                             return check.height;
40                 }
41                 Row {
42                     anchors.fill: parent
43
44                     Text {
45                         id: wordText
46                         text:
47                         {
48                             if (word == "!@#$%"){
49                                 qsTr("Can't find any matching words")
50                             } else {
51                                 word
52                             }
53                         }
54
55                         MouseArea{
56                             anchors.fill: parent
57                             onClicked: {
58                                 wordList.currentIndex = number
59                                 console.log("lolol")
60                                 rectangle1.wordSelected(word)
61                             }
62                         }
63                     }
64
65                     Checkbox{
66                         id: check
67                         width: wordText.height
68                         selected: isBookmarked
69                         pathToCheckedImage: CheckedPath
70                         pathToUncheckedImage: UncheckedPath
71                         anchors.leftMargin: 5
72                         anchors.verticalCenter: parent.verticalCenter
73                         onChanged: rectangle1.changeWordState(number, selected)
74                         visible: {
75                             if (word == "!@#$%"){
76                                 false
77                             } else {
78                                 true
79                             }
80                         }
81                     }
82
83                 }
84             }
85
86         }
87
88         model: wordModel
89     }
90 }