145ad895ecf56334a819cdfd2f97c471125792f5
[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         console.log("LOOOOOL")
31         wordList.currentIndex = nr
32         wordModel.setModelProperty(wordList.currentIndex, state, "isBookmarked")
33
34     }
35
36     function setEnabled(Boolean) { wordList.enabled = Boolean }
37     function setWordListEmpty(Boolean) { wordList.empty = Boolean }
38     function setFocus() {
39         console.log("juhu")
40         wordList.setFocus()
41 //        activeFocus = true
42         console.log(focus + "a " + activeFocus)
43         console.log(wordList.focus + "b " + wordList.activeFocus)
44     }
45
46     signal wordSelected(string word);
47
48     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
49
50     id: rectangle1
51     color: myPalette.base
52     anchors.fill: parent
53
54     ElementsListView{
55         id: wordList
56         width: rectangle1.width
57
58         anchors.fill: parent
59         highlightResizeSpeed: 1000
60         property bool empty: false
61
62         onCurrentIndexChanged: {
63             console.log("111!!!WTF " + currentIndex)
64         }
65
66         delegate: Component{
67             id: wordListDelegate
68             Item {
69                 width: rectangle1.width
70                 height: {
71                     if (wordText.height + 4 > check.height)
72                             return wordText.height + 4;
73                     else
74                             return check.height;
75                 }
76
77                 MouseArea{
78                     anchors.fill: parent
79                     onClicked: {
80                         wordList.currentIndex = index// number
81                         rectangle1.wordSelected(word)
82                     }
83                 }
84
85
86                 Text {
87                     id: wordText
88                     anchors.verticalCenter: parent.verticalCenter
89                     text: word
90                 }
91
92                 Checkbox{
93                     id: check
94                     width: wordText.height
95                     selected: isBookmarked
96                     pathToCheckedImage: CheckedPath
97                     pathToUncheckedImage: UncheckedPath
98                     anchors.right: parent.right
99                     anchors.rightMargin: 5
100
101                     anchors.verticalCenter: parent.verticalCenter
102                     onChanged: rectangle1.changeWordState(number, selected)
103                 }
104
105             }
106
107         }
108
109         Text {
110             id: emptyText
111             anchors.top: parent.top
112             anchors.left: parent.left
113             text: qsTr("Can't find any matching words")
114         }
115
116         Rectangle {
117             id: shadeDisable
118             anchors.centerIn: parent;
119             color: "grey";
120             opacity: 0
121             width:  parent.width;
122             height: parent.height;
123         }
124
125         model: wordModel
126
127         states: [
128             State {
129                 name: "empty"
130                 when: (wordList.empty == true);
131                 PropertyChanges { target: emptyText; visible: true}
132             },
133             State {
134                 name: "non-empty"
135                 when: (wordList.empty == false);
136                 PropertyChanges { target: emptyText; visible: false}
137             },
138             State {
139                 name: "enabled"
140                 when: (wordList.enabled == true);
141                 PropertyChanges { target: shadeDisable; z: 30; opacity: 0.5 }
142             },
143             State {
144                 name: "disabled"
145                 when: (wordList.enabled == false);
146                 PropertyChanges { target: shadeDisable; z: 30; opacity: 0.0 }
147             }
148         ]
149     }
150 }