features of DictManagerWidget restored in qml version.
[mdictionary] / src / mdictionary / qml / DictManagerWidget.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     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
29
30     function setEnableRemove(Boolean) { removeButton.enabled = Boolean }
31     function setEnableSettings(Boolean) { settingsButton.enabled = Boolean }
32     function changeDictionaryState(nr, state) {
33         dictList.currentIndex = nr
34         dictModel.setModelProperty(dictList.currentIndex, state, "isSelected")
35         rectangle1.setEnableRemove(true)
36         rectangle1.setEnableSettings(true)
37     }
38
39     signal addButtonClicked;
40     signal removeButtonClicked;
41     signal settingsButtonClicked;
42     signal saveButtonClicked;
43     signal itemActivated(int nr);
44
45     id: rectangle1
46     color: myPalette.base
47     anchors.fill: parent
48
49     ElementsListView{
50         id: dictList
51         width: rectangle1.width
52 //        height: rectangle1.height
53         anchors.top: parent.top
54         anchors.bottom: buttonsBox.top
55         anchors.bottomMargin: buttonsBox.height + buttonsBox.anchors.topMargin
56         highlightResizeSpeed: 1000
57         delegate: Component{
58             id: dictListDelegate
59             Item {
60                 width: rectangle1.width
61                 height: {
62                     if (nameText.height + 4 > logo.height)
63                             return nameText.height + 4;
64                     else
65                             return logo.height;
66                 }
67                 MouseArea{
68                     anchors.fill: parent
69                     onClicked: {
70                         dictList.currentIndex = number
71                         rectangle1.setEnableRemove(true)
72                         rectangle1.setEnableSettings(true)
73                         dictModel.itemSelected(dictList.currentIndex)
74                     }
75                     onDoubleClicked: {
76                         rectangle1.itemActivated(dictList.currentIndex)
77                     }
78                 }
79                 Row {
80                     anchors.fill: parent
81                     Checkbox{
82                         id: check
83                         width: nameText.height
84                         selected: isSelected
85                         onChanged: rectangle1.changeDictionaryState(number, selected)
86                     }
87
88
89                     Image {
90                         id: logo
91                         source: iconPath
92                         height: {
93                             var aspectRatio = sourceSize.height / sourceSize.width
94                             return logo.width * aspectRatio
95                         }
96                         anchors.leftMargin: 5
97                         anchors.verticalCenter: parent.verticalCenter
98                         width: nameText.height + 4
99                         smooth: true
100                     }
101                     Text {
102                         id: nameText
103                         text: name
104                         anchors.leftMargin: 5
105                         anchors.verticalCenter: parent.verticalCenter
106                     }
107                 }
108             }
109
110         }
111         model: dictModel
112     }
113
114     //buttons
115
116     Item {
117         id: buttonsBox
118         width: parent.width
119         height: 30
120         anchors.bottom: parent.bottom
121         anchors.top: dictList.bottom
122         anchors.topMargin: 8
123
124         Button {
125             id: addButton
126             width: (parent.width - 4) / 4
127             height: buttonsBox.height
128             anchors.left: buttonsBox.left
129             anchors.leftMargin: 4
130             anchors.verticalCenter: parent.verticalCenter
131             textInButton: qsTr("Add")
132             onClicked: addButtonClicked();
133         }
134
135         Button {
136             id: removeButton
137             width: (parent.width - 4) / 4
138             height: buttonsBox.height
139             anchors.left: addButton.right
140             anchors.leftMargin: 4
141             anchors.verticalCenter: parent.verticalCenter
142             textInButton: qsTr("Remove")
143             enabled: false
144             onClicked: removeButtonClicked();
145         }
146
147         Button {
148             id: settingsButton
149             width: (parent.width - 4) / 4
150             height: buttonsBox.height
151             anchors.left: removeButton.right
152             anchors.leftMargin: 4
153             anchors.verticalCenter: parent.verticalCenter
154             textInButton: qsTr("Settings")
155             enabled: false
156             onClicked: settingsButtonClicked();
157         }
158
159         Button {
160             id: saveButton
161             width: (parent.width - 4) / 4
162             height: buttonsBox.height
163             anchors.left: settingsButton.right
164             anchors.leftMargin: 4
165             anchors.right: buttonsBox.right
166             anchors.rightMargin: 4
167             anchors.verticalCenter: parent.verticalCenter
168             textInButton: qsTr("Save")
169             onClicked: saveButtonClicked()
170         }
171
172     }
173
174 }