add revert button image. Add new comboBox feature - cancel and return to latest selec...
[mdictionary] / src / mdictionary / qml / GoogleDialog.qml
1 import Qt 4.7
2
3 Rectangle{
4     property bool newPlugin:false;
5
6     function setInfo(string){
7         infoLabel.text = string;
8     }
9     function setStartValues(startFrom, startTo, startFromIndex, startToIndex){
10         comboFrom.setStartValue(startFrom, startFromIndex)
11         comboTo.setStartValue(startTo, startToIndex)
12     }
13     function revertLang(){
14         var tmpidx = comboFrom.index
15         comboFrom.index = comboTo.index
16         comboTo.index = tmpidx
17
18         var tmpval = comboFrom.value
19         comboFrom.value = comboTo.value
20         comboTo.value = tmpval
21     }
22
23     function setNew(bool){
24         newPlugin=bool;
25     }
26
27     signal saveButtonClicked(string langFrom, string langTo);
28
29     height: infoLabel.height + fromLabel.height + toLabel.height + saveButton.height + 50
30     width: 200
31
32     id:rectangle1
33
34
35
36     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
37     color : myPalette.window;
38
39
40     Text {
41         id: infoLabel
42         height: paintedHeight+5;
43         anchors.right: parent.right
44         anchors.left: parent.left
45         anchors.top: parent.top
46         wrapMode: Text.Wrap;
47         transformOrigin: Item.Left
48         font.pixelSize: 12
49         z: 15
50     }
51
52     Text {
53         id: fromLabel
54         text: qsTr("From: ")
55         height: paintedHeight+5;
56         anchors.top: infoLabel.bottom
57         anchors.left: parent.left
58         wrapMode: Text.Wrap;
59         transformOrigin: Item.Left
60         font.pixelSize: 12
61     }
62
63     Text {
64         id: toLabel
65         text: qsTr("To: ")
66         height: paintedHeight+5;
67         anchors.top: fromLabel.bottom
68         anchors.left: parent.left
69         wrapMode: Text.Wrap;
70         transformOrigin: Item.Left
71         font.pixelSize: 12
72     }
73
74     ComboBox{
75         id: comboFrom
76         model: comboBoxModel
77         anchors.left: parent.left
78         anchors.leftMargin: {
79             if (fromLabel.width < 30 && toLabel.width < 30){
80                 return 30
81             }
82             else if (fromLabel.width > toLabel.width){
83                 return fromLabel.width + 10
84             }
85             else {
86                 return toLabel.width + 10
87             }
88         }
89
90         anchors.top: infoLabel.bottom
91         anchors.right: revertButton.left
92         anchors.rightMargin: 10
93         expanded: false
94         basicHeight: fromLabel.height
95         expandedHeight: parent.height - comboFrom.x - saveButton.height -20
96     }
97
98     ComboBox{
99         id: comboTo
100         model:  comboBoxModel
101         anchors.left: parent.left
102         anchors.leftMargin: {
103             if (fromLabel.width < 30 && toLabel.width < 30){
104                 return 30
105             }
106             else if (fromLabel.width > toLabel.width){
107                 return fromLabel.width + 10
108             }
109             else {
110                 return toLabel.width + 10
111             }
112         }
113
114         anchors.right: revertButton.left
115         anchors.rightMargin: 10
116         anchors.top: comboFrom.bottom
117         expanded: false
118         basicHeight: fromLabel.height
119         expandedHeight: parent.height - comboTo.x - saveButton.height - 20 - fromLabel.height
120     }
121
122     IconButton{
123         id: revertButton
124         width: height
125         height: fromLabel.height
126         anchors.top: fromLabel.top
127         anchors.topMargin: fromLabel.height /2
128         anchors.right: parent.right
129         pathToIcon: "qrc:/button/revert.png"
130         onClicked: { rectangle1.revertLang() }
131     }
132
133     Button {
134         id: saveButton
135         height: 30
136         z: 1
137         anchors.bottom: parent.bottom
138         anchors.right: parent.right
139         anchors.left: parent.left
140         onClicked: {
141             rectangle1.saveButtonClicked(comboFrom.value, comboTo.value);
142         }
143     }
144
145     states: [
146         State {
147             name: "new"
148             when: newPlugin==true
149             PropertyChanges { target: saveButton; textInButton: qsTr("Add") }
150         },
151         State {
152             name: "edit"
153             when: newPlugin==false
154             PropertyChanges { target: saveButton; textInButton: qsTr("Save settings") }
155         }
156     ]
157 }
158