cb972fabd851a98788bc4bb705358d588ad8a595
[mdictionary] / src / mdictionary / qml / WordListWidget.qml
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21 /*!
22     author: Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
23 */
24
25 import Qt 4.7
26
27 Rectangle {
28
29     function changeWordState(nr, state) {
30         wordList.currentIndex = nr
31         wordModel.setModelProperty(wordList.currentIndex, state, "isBookmarked")
32
33     }
34
35     function setEnabled(Boolean) { wordList.enabled = Boolean }
36     function setWordListEmpty(Boolean) { wordList.empty = Boolean }
37
38     signal wordSelected(string word);
39
40     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
41
42     id: rectangle1
43     color: myPalette.base
44     anchors.fill: parent
45
46     ElementsListView{
47         id: wordList
48         width: rectangle1.width
49
50         anchors.fill: parent
51         highlightResizeSpeed: 1000
52         property bool empty: false
53
54         delegate: Component{
55             id: wordListDelegate
56             Item {
57                 width: rectangle1.width
58                 height: {
59                     if (wordText.height + 4 > check.height)
60                             return wordText.height + 4;
61                     else
62                             return check.height;
63                 }
64
65                 MouseArea{
66                     anchors.fill: parent
67                     onClicked: {
68                         wordList.currentIndex = number
69                         rectangle1.wordSelected(word)
70                     }
71                 }
72
73
74                 Text {
75                     id: wordText
76                     anchors.verticalCenter: parent.verticalCenter
77                     text:
78                     {
79                         if (word == "!@#$%"){
80                             qsTr("Can't find any matching words")
81                         } else {
82                             word
83                         }
84                     }
85                 }
86
87                 Checkbox{
88                     id: check
89                     width: wordText.height
90                     selected: isBookmarked
91                     pathToCheckedImage: CheckedPath
92                     pathToUncheckedImage: UncheckedPath
93                     anchors.right: parent.right
94                     anchors.rightMargin: 5
95
96                     anchors.verticalCenter: parent.verticalCenter
97                     onChanged: rectangle1.changeWordState(number, selected)
98                     visible: {
99                         if (word == "!@#$%"){
100                             false
101                         } else {
102                             true
103                         }
104                     }
105                 }
106
107             }
108
109         }
110
111         Text {
112             id: emptyText
113             anchors.top: parent.top
114             anchors.left: parent.left
115             text: qsTr("Can't find any matching words")
116         }
117
118         model: wordModel
119
120         states: [
121             State {
122                 name: "empty"
123                 when: (wordList.empty == true);
124                 PropertyChanges { target: emptyText; visible: true}
125             },
126             State {
127                 name: "non-empty"
128                 when: (wordList.empty == false);
129                 PropertyChanges { target: emptyText; visible: false}
130             }
131         ]
132     }
133 }