code clean
[mdictionary] / src / mdictionary / qml / XdxfDialog.qml
1 import Qt 4.7
2
3 Rectangle{
4     id:rectangle1
5     width: 220
6     height: textPlugin.height + textFrom.height + textTo.height + textDescription.height + textInfo.height +90
7
8     property bool newPlugin:false;
9     property int focusIndex:-1;
10
11     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
12     color : myPalette.window;
13     focus: true;
14
15     function setPlugin(string){
16         textPlugin.text = qsTr("Plugin") + ": " + string;
17     }
18     function setFrom(string){
19         textFrom.text = qsTr("From") + ": " + string;
20     }
21     function setTo(string){
22         textTo.text = qsTr("To") + ": " + string;
23     }
24     function setDescription(string){
25         textDescription.text = qsTr("Description") + ": " + string;
26     }
27     function setInfo(string){
28         textInfo.text = string;
29     }
30     function setButtonText(string){
31         saveButton.textInButton=string;
32     }
33     function setCheckedOptimalize(bool){
34         optimalizeCheckbox.selected=bool;
35     }
36     function setCheckedStrip(bool){
37         stripCheckbox.selected=bool;
38     }
39     function setNew(bool){
40         newPlugin=bool;
41     }
42     function setPath(string){
43         textPath.text=string;
44     }
45
46     function setFocus(){
47         if(focusIndex==0){
48             browseButton.focus= true;
49             if(!browseButton.opacity)
50                 focusIndex++;
51         }
52         if(focusIndex==1){
53             downloadButton.focus=true;
54             if(!downloadButton.opacity)
55                 focusIndex++;
56         }
57         if(focusIndex==2){
58             optimalizeCheckbox.focus = true
59             if(!optimalizeCheckbox.enabled)
60                 focusIndex++;
61         }
62         if(focusIndex==3){
63             stripCheckbox.focus = true
64             if(!stripCheckbox.enabled)
65                 focusIndex++;
66         }
67         if(focusIndex==4){
68             saveButton.focus = true
69             if(!saveButton.enabled)
70                 focusIndex++;
71         }
72         if(focusIndex>4){
73             focusIndex=-1;
74             focus=true;
75         }
76     }
77
78     Keys.onTabPressed: {
79         focusIndex++;
80         setFocus();
81     }
82
83     signal saveButtonClicked();
84     signal downloadButtonClicked();
85     signal browseButtonClicked();
86     signal optimalizeCheckboxChanged(bool Boolean);
87     signal stripCheckboxChanged(bool Boolean);
88
89     Text {
90         id: textPlugin
91         width: rectangle1.width
92         height: paintedHeight+5;
93         text: "Plugin: "
94         wrapMode: Text.Wrap;
95         transformOrigin: Item.Left
96         anchors.horizontalCenter: parent.horizontalCenter
97         font.pixelSize: 12
98     }
99
100     Text {
101         id: textFrom
102         width:rectangle1.width
103         height: paintedHeight+5;
104         text: "From: "
105         wrapMode: Text.Wrap;
106         anchors.top: textPlugin.bottom
107         anchors.horizontalCenter: parent.horizontalCenter
108         font.pixelSize: 12
109     }
110
111     Text {
112         id: textTo
113         width: rectangle1.width
114         height: paintedHeight+5;
115         text: "To: "
116         wrapMode: Text.Wrap;
117         anchors.top: textFrom.bottom
118         transformOrigin: Item.Left
119         anchors.horizontalCenter: parent.horizontalCenter
120         font.pixelSize: 12
121     }
122
123     Text {
124         id: textDescription
125         width: rectangle1.width
126         height: paintedHeight+5;
127         text: "Description: "
128         wrapMode: Text.Wrap;
129         anchors.top: textTo.bottom
130         transformOrigin: Item.Left
131         anchors.horizontalCenter: parent.horizontalCenter
132         font.pixelSize: 12
133     }
134
135     Text {
136         id: textInfo
137         width: rectangle1.width
138         height: (paintedHeight+5)>150?150:paintedHeight+5;
139         text: ": "
140         wrapMode: Text.Wrap;
141         anchors.top: textDescription.bottom
142         transformOrigin: Item.Left
143         anchors.horizontalCenter: parent.horizontalCenter
144         font.pixelSize: 12
145     }
146
147
148     Rectangle {
149         anchors.right: parent.right
150         anchors.left: parent.left
151         anchors.bottom: saveButton.bottom
152         anchors.top: optimalizeCheckbox.top
153
154         id: rectangle2
155         color: myPalette.window
156         anchors.topMargin: -2
157     }
158
159     Checkbox {
160         id: optimalizeCheckbox
161         width: 20
162         height: 20
163         anchors.bottom: stripCheckbox.top
164         anchors.bottomMargin: 5
165         anchors.left: parent.left
166         anchors.leftMargin: 5
167         onChanged: rectangle1.optimalizeCheckboxChanged(selected);
168         onFocusChanged: if(focus) focusIndex=2;
169     }
170
171     Checkbox {
172         id: stripCheckbox
173         width: 20
174         height: 20
175         anchors.bottom: saveButton.top
176         anchors.bottomMargin: 15
177         anchors.horizontalCenter: optimalizeCheckbox.horizontalCenter
178         onChanged: rectangle1.stripCheckboxChanged(selected);
179         onFocusChanged: if(focus) focusIndex=3;
180     }
181
182     Text {
183         id: textOptimalize
184         width: 80
185         height: 20
186         text: qsTr("Optimize")
187         anchors.left: optimalizeCheckbox.right
188         anchors.leftMargin: 5
189         anchors.verticalCenterOffset: 3
190         anchors.verticalCenter: optimalizeCheckbox.verticalCenter
191         font.pixelSize: 12
192     }
193
194     Text {
195         id: textStrip
196         width: 80
197         height: 20
198         text: qsTr("Strip accents")
199         anchors.verticalCenterOffset: 3
200         anchors.verticalCenter: stripCheckbox.verticalCenter
201         anchors.horizontalCenter: textOptimalize.horizontalCenter
202         font.pixelSize: 12
203     }
204
205     Button {
206         id: saveButton
207         height: 30
208         anchors.bottom: parent.bottom
209         textInButton: qsTr("Save")
210         anchors.right: parent.right
211         anchors.left: parent.left
212         onClicked: rectangle1.saveButtonClicked();
213     }
214
215     Text {
216         id: textPath
217         height: paintedHeight+5;
218         text: qsTr("Dictionary file: not selected")
219         wrapMode: Text.Wrap;
220         anchors.top: parent.top
221         anchors.topMargin: 10
222         anchors.right: browseButton.left
223         anchors.rightMargin: 0
224         anchors.left: parent.left
225         anchors.leftMargin: 0
226         font.pixelSize: 12
227         opacity: 0
228     }
229
230     Button {
231         id: browseButton
232         width: 80;
233         height: 25;
234         textInButton: qsTr("Browse");
235         anchors.top: parent.top
236         anchors.topMargin: 10
237         anchors.right: parent.right
238         anchors.rightMargin: 10
239         opacity: 0
240         onClicked: rectangle1.browseButtonClicked();
241     }
242
243     Button {
244         id: downloadButton
245         width: 80;
246         height: 25;
247         textInButton: qsTr("Download");
248         anchors.right: parent.right
249         anchors.rightMargin: 10
250         anchors.top: browseButton.bottom
251         anchors.topMargin: 10
252         opacity: 0
253         onClicked: rectangle1.downloadButtonClicked();
254     }
255
256
257     states: [
258         State {
259             name: "Stan1"
260             when: newPlugin==true
261             PropertyChanges { target: textPlugin; opacity: 0}
262             PropertyChanges { target: textFrom; opacity: 0}
263             PropertyChanges { target: textTo; opacity: 0}
264             PropertyChanges { target: textDescription; opacity: 0}
265             PropertyChanges { target: textInfo; opacity: 0}
266
267             PropertyChanges { target: textPath; opacity: 1}
268             PropertyChanges { target: browseButton; opacity: 1 }
269             PropertyChanges { target: downloadButton; opacity: 1}
270         }
271     ]
272 }