webView
[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.leftMargin: 5
116                         anchors.verticalCenter: parent.verticalCenter
117                         width: nameText.height + 4
118                         smooth: true
119                     }
120                     Text {
121                         id: nameText
122                         text: name
123                         anchors.leftMargin: 5
124                         anchors.verticalCenter: parent.verticalCenter
125                     }
126                 }
127             }
128
129         }
130         model: dictModel
131     }
132
133     //buttons
134
135     Item {
136         id: buttonsBox
137         width: parent.width
138         height: 30
139         anchors.bottom: parent.bottom
140         anchors.top: dictList.bottom
141         anchors.topMargin: 8
142
143         Button {
144             id: addButton
145             width: (parent.width - 4) / 4
146             height: buttonsBox.height
147             anchors.left: buttonsBox.left
148             anchors.leftMargin: 4
149             anchors.verticalCenter: parent.verticalCenter
150             textInButton: qsTr("Add")
151             onClicked: rectangle1.addButtonClicked
152         }
153
154         Button {
155             id: removeButton
156             width: (parent.width - 4) / 4
157             height: buttonsBox.height
158             anchors.left: addButton.right
159             anchors.leftMargin: 4
160             anchors.verticalCenter: parent.verticalCenter
161             textInButton: qsTr("Remove")
162             enabled: false
163             onClicked: rectangle1.removeButtonClicked
164         }
165
166         Button {
167             id: settingsButton
168             width: (parent.width - 4) / 4
169             height: buttonsBox.height
170             anchors.left: removeButton.right
171             anchors.leftMargin: 4
172             anchors.verticalCenter: parent.verticalCenter
173             textInButton: qsTr("Settings")
174             enabled: false
175             onClicked: rectangle1.settingsButtonClicked
176         }
177
178         Button {
179             id: saveButton
180             width: (parent.width - 4) / 4
181             height: buttonsBox.height
182             anchors.left: settingsButton.right
183             anchors.leftMargin: 4
184             anchors.right: buttonsBox.right
185             anchors.rightMargin: 4
186             anchors.verticalCenter: parent.verticalCenter
187             textInButton: qsTr("Save")
188             onClicked: rectangle1.saveButtonClicked
189         }
190
191     }
192
193 }