some change
[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     id: rectangle1
29     color: myPalette.base
30     anchors.fill: parent
31
32     function changeWordState(nr, state) {
33         wordList.currentIndex = nr
34         wordModel.setModelProperty(wordList.currentIndex, state, "isBookmarked")
35
36     }
37
38     function setEnabled(Boolean) { wordList.enabled = Boolean }  // slot
39
40     signal wordSelected(string word);
41     signal checkFocus();
42
43     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
44
45     ElementsListView{
46         id: wordList
47         width: rectangle1.width
48
49         anchors.fill: parent
50         highlightResizeSpeed: 1000
51
52         delegate: Component{
53             id: wordListDelegate
54             Item {
55                 onActiveFocusChanged: rectangle1.checkFocus();
56
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                 MouseArea{
65                     anchors.fill: parent
66                     onClicked: wordList.currentIndex = number
67                     onDoubleClicked: {
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                     pathToCheckedDicImage: CheckedPath
96                     pathToUncheckedDicImage: UncheckedPath
97                     anchors.verticalCenter: parent.verticalCenter
98                     onChanged: rectangle1.changeWordState(number, selected)
99                     visible: {
100                         if (word == "!@#$%"){
101                             false
102                         } else {
103                             true
104                         }
105                     }
106                 }
107             }
108         }
109
110         model: wordModel
111     }
112
113     states: [
114             State {
115                 name: "noFocus";
116                 when: ((!wordList.focus) && (!rectangle1.focus))
117                 PropertyChanges { target: wordList.highlightItem; opacity:0}
118            }
119     ]
120 }