331bd73422d0e2e60dd533eb3ee35c1f8b4b10dc
[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         console.log("tab");
59         focusIndex++;
60         setFocus();
61     }
62
63     Keys.onPressed: {
64         console.log("taaaa");
65     }
66
67     signal saveButtonClicked(string langFrom, string langTo);
68
69     SystemPalette {
70         id: myPalette;
71         colorGroup:SystemPalette.Active
72     }
73
74     Item {
75         id: comboField
76         anchors.bottomMargin: 6
77         anchors.rightMargin: 0
78         anchors.left: fromLabel.right
79         anchors.right: revertButton.left
80         anchors.bottom: saveButton.top
81         anchors.top: parent.top
82         anchors.leftMargin: 2
83         z:2;
84     }
85
86     Text {
87         id: infoLabel
88         height: paintedHeight+5;
89         anchors.right: parent.right
90         anchors.left: parent.left
91         anchors.top: parent.top
92         wrapMode: Text.Wrap;
93         transformOrigin: Item.Left
94         font.pixelSize: 12
95     }
96
97
98     Text {
99         id: fromLabel
100         text: qsTr("From: ")
101         height: paintedHeight+5;
102         anchors.top: infoLabel.bottom
103         anchors.left: parent.left
104         wrapMode: Text.Wrap;
105         transformOrigin: Item.Left
106         font.pixelSize: 12
107     }
108
109     Text {
110         id: toLabel
111         text: qsTr("To: ")
112         anchors.topMargin: 3
113         height: paintedHeight+5;
114         anchors.top: fromLabel.bottom
115         anchors.left: parent.left
116         wrapMode: Text.Wrap;
117         transformOrigin: Item.Left
118         font.pixelSize: 12
119     }
120
121     ComboBox{
122         id: comboFrom
123         model: comboBoxModel
124         anchors.right: revertButton.left
125         anchors.rightMargin: 5
126         anchors.left: fromLabel.right
127         anchors.leftMargin: 10
128         anchors.verticalCenter: fromLabel.verticalCenter
129
130         parentField: comboField
131         expanded: false
132         basicHeight: fromLabel.height
133         onExpandedChanged: {
134             if(expanded==true)
135                 z=2;
136             else
137                 z=0;
138         }
139     }
140
141     ComboBox{
142         id: comboTo
143         model:  comboBoxModel
144         anchors.right: revertButton.left
145         anchors.rightMargin: 5
146         anchors.left: fromLabel.right
147         anchors.leftMargin: 10
148         anchors.verticalCenter: toLabel.verticalCenter
149
150         parentField: comboField;
151         expanded: false
152         basicHeight: fromLabel.height
153
154         onExpandedChanged: {
155             if(expanded==true)
156                 z=2;
157             else
158                 z=0;
159         }
160     }
161
162     IconButton{
163         id: revertButton
164         width: height
165         height: fromLabel.height
166         anchors.top: fromLabel.bottom
167         anchors.topMargin: -8
168         anchors.right: parent.right
169         pathToIcon: "qrc:/button/revert.png"
170         onClicked: { rectangle1.revertLang() }
171     }
172
173     Button {
174         id: saveButton
175         height: 30
176         anchors.bottom: parent.bottom
177         anchors.right: parent.right
178         anchors.left: parent.left
179         onClicked: {
180             rectangle1.saveButtonClicked(comboFrom.value, comboTo.value);
181         }
182     }
183
184     MouseArea {
185         id: mouse_area1
186         anchors.fill: parent
187         z:-1
188         onClicked: {
189             comboTo.expanded=false;
190             comboFrom.expanded=false;
191         }
192     }
193
194
195
196     states: [
197         State {
198             name: "new"
199             when: newPlugin==true
200             PropertyChanges { target: saveButton; textInButton: qsTr("Add") }
201         },
202         State {
203             name: "edit"
204             when: newPlugin==false
205             PropertyChanges { target: saveButton; textInButton: qsTr("Save settings") }
206         }
207     ]
208 }
209