77fef8d608781f5ab10135f6fb6968e8619d795c
[mdictionary] / src / mdictionary / qml / GoogleDialog.qml
1 import Qt 4.7
2
3 Rectangle{
4     id:rectangle1
5     height: infoLabel.height + fromLabel.height + toLabel.height + saveButton.height + 50
6     width: 200
7     color : myPalette.window;
8     focus: true;
9     property int focusIndex:-1;
10
11     property bool newPlugin:false;
12
13     function setInfo(string){
14         infoLabel.text = string;
15     }
16     function setStartValues(startFrom, startTo, startFromIndex, startToIndex){
17         comboFrom.setStartValue(startFrom, startFromIndex)
18         comboTo.setStartValue(startTo, startToIndex)
19     }
20     function revertLang(){
21         var tmpidx = comboFrom.index
22         comboFrom.index = comboTo.index
23         comboTo.index = tmpidx
24
25         var tmpval = comboFrom.value
26         comboFrom.value = comboTo.value
27         comboTo.value = tmpval
28     }
29
30     function setNew(bool){
31         newPlugin=bool;
32     }
33
34     function setFocus(){
35         if(focusIndex==0){
36             console.log("01");
37         }
38         if(focusIndex==1){
39             console.log("02");
40         }
41         if(focusIndex==2){
42             revertButton.focus = true
43             if(!revertButton.enabled)
44                 focusIndex++;
45         }
46         if(focusIndex==3){
47             saveButton.focus = true
48             if(!saveButton.enabled)
49                 focusIndex++;
50         }
51         if(focusIndex>3){
52             focusIndex=-1;
53             focus=true;
54         }
55     }
56
57     Keys.onTabPressed: {
58         focusIndex++;
59         setFocus();
60     }
61
62     signal saveButtonClicked(string langFrom, string langTo);
63
64     SystemPalette {
65         id: myPalette;
66         colorGroup:SystemPalette.Active
67     }
68
69     Item {
70         id: comboField
71         anchors.bottomMargin: 6
72         anchors.rightMargin: 0
73         anchors.left: fromLabel.right
74         anchors.right: revertButton.left
75         anchors.bottom: saveButton.top
76         anchors.top: parent.top
77         anchors.leftMargin: 2
78         z:2;
79     }
80
81     Text {
82         id: infoLabel
83         height: paintedHeight+5;
84         anchors.right: parent.right
85         anchors.left: parent.left
86         anchors.top: parent.top
87         wrapMode: Text.Wrap;
88         transformOrigin: Item.Left
89         font.pixelSize: 12
90     }
91
92
93     Text {
94         id: fromLabel
95         text: qsTr("From: ")
96         height: paintedHeight+5;
97         anchors.top: infoLabel.bottom
98         anchors.left: parent.left
99         wrapMode: Text.Wrap;
100         transformOrigin: Item.Left
101         font.pixelSize: 12
102     }
103
104     Text {
105         id: toLabel
106         text: qsTr("To: ")
107         anchors.topMargin: 3
108         height: paintedHeight+5;
109         anchors.top: fromLabel.bottom
110         anchors.left: parent.left
111         wrapMode: Text.Wrap;
112         transformOrigin: Item.Left
113         font.pixelSize: 12
114     }
115
116     ComboBox{
117         id: comboFrom
118         model: comboBoxModel
119         anchors.right: revertButton.left
120         anchors.rightMargin: 5
121         anchors.left: fromLabel.right
122         anchors.leftMargin: 10
123         anchors.verticalCenter: fromLabel.verticalCenter
124
125         parentField: comboField
126         expanded: false
127         basicHeight: fromLabel.height
128         onExpandedChanged: {
129             if(expanded==true)
130                 z=2;
131             else
132                 z=0;
133         }
134     }
135
136     ComboBox{
137         id: comboTo
138         model:  comboBoxModel
139         anchors.right: revertButton.left
140         anchors.rightMargin: 5
141         anchors.left: fromLabel.right
142         anchors.leftMargin: 10
143         anchors.verticalCenter: toLabel.verticalCenter
144
145         parentField: comboField;
146         expanded: false
147         basicHeight: fromLabel.height
148
149         onExpandedChanged: {
150             if(expanded==true)
151                 z=2;
152             else
153                 z=0;
154         }
155     }
156
157     IconButton{
158         id: revertButton
159         width: height
160         height: fromLabel.height
161         anchors.top: fromLabel.bottom
162         anchors.topMargin: -8
163         anchors.right: parent.right
164         pathToIcon: "qrc:/button/revert.png"
165         onClicked: { rectangle1.revertLang() }
166     }
167
168     Button {
169         id: saveButton
170         height: 30
171         anchors.bottom: parent.bottom
172         anchors.right: parent.right
173         anchors.left: parent.left
174         onClicked: {
175             rectangle1.saveButtonClicked(comboFrom.value, comboTo.value);
176         }
177     }
178
179     MouseArea {
180         id: mouse_area1
181         anchors.fill: parent
182         z:-1
183         onClicked: {
184             comboTo.expanded=false;
185             comboFrom.expanded=false;
186         }
187     }
188
189
190
191     states: [
192         State {
193             name: "new"
194             when: newPlugin==true
195             PropertyChanges { target: saveButton; textInButton: qsTr("Add") }
196         },
197         State {
198             name: "edit"
199             when: newPlugin==false
200             PropertyChanges { target: saveButton; textInButton: qsTr("Save settings") }
201         }
202     ]
203 }
204