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