add revert button image. Add new comboBox feature - cancel and return to latest selec...
[mdictionary] / src / mdictionary / qml / ComboBox.qml
1 import Qt 4.7
2
3 Rectangle {
4     id: rectangle1
5     radius: 10
6     border.color: "#000666";
7     property alias value:text1.text
8     property alias index: list1.currentIndex
9     property alias model: list1.model
10     property bool expanded: false
11     property bool disabled: false
12     property int expandedHeight
13     property int basicHeight
14     property string startValue
15     height: basicHeight
16
17     function show(Boolean){
18         expanded = Boolean
19     }
20
21     function setStartValue(val, idx){
22         startValue = val
23         list1.currentIndex = idx
24     }
25
26     signal valueSelected(string selected);
27
28     Text {
29         id: text1
30         width: rectangle1.width-15
31         height: rectangle1.height*0.6;
32         text: list1.selected
33         anchors.centerIn: parent
34         font.pixelSize: rectangle1.height * .5;
35         onTextChanged: { rectangle1.valueSelected(text) }
36     }
37
38     Rectangle {
39         id: shadeDisable
40         width:  parent.width;
41         height: parent.height;
42         anchors.centerIn: parent;
43         radius: parent.radius
44         color: "grey";
45         opacity: 0.5
46     }
47
48     Image {
49         id: imageDown
50         z:15;
51         width: 11;
52         height: 0.5 * rectangle1.height;
53         anchors.top: parent.top
54         anchors.right: parent.right
55         anchors.topMargin: 4
56         anchors.rightMargin: 6
57         anchors.bottomMargin: 4
58         source: "qrc:/button/down_enable.png";
59
60         MouseArea{
61             id: imgMouseArea
62             anchors.fill: parent
63             onClicked: {
64                 rectangle1.show(!rectangle1.expanded)
65             }
66         }
67     }
68
69     MouseArea{
70         id: topMouseArea
71         z: 5
72         anchors.fill: parent
73         onClicked: {
74             rectangle1.show(!rectangle1.expanded)
75         }
76     }
77
78     ElementsListView{
79         id: list1
80         width: parent.width
81         visible: false
82         z: 0
83         property string selected: rectangle1.startValue
84
85         function selectedValue(nr, value) {
86             currentIndex = nr
87             selected = value
88             rectangle1.show(false)
89         }
90
91         anchors.left: parent.left
92         anchors.verticalCenter: parent.verticalCenter
93         highlightResizeSpeed: 1000
94
95         delegate: Component{
96             id: list1Delegate
97             Item {
98                 width: rectangle1.width
99                 height: contentText.height
100
101                 MouseArea{
102                     id: listMouseArea
103                     anchors.fill: parent
104                     z: 1
105                     onClicked: {
106                         list1.selectedValue(number, content)
107                     }
108                     hoverEnabled: true
109                     onEntered: {
110                         list1.currentIndex = number
111                     }
112                 }
113
114                 Row{
115                     anchors.fill: parent
116
117                     Text{
118                         id: contentText
119                         anchors.verticalCenter: parent.verticalCenter
120                         anchors.leftMargin: 5
121                         text: content
122                     }
123                 }
124             }
125         }
126
127     }
128
129     states: [
130         State {
131             name: "basic";
132             when: (rectangle1.expanded == false && rectangle1.disabled == false)
133             PropertyChanges { target: list1; z: 0; visible: false }
134             PropertyChanges { target: text1; z: 0; visible: true }
135             PropertyChanges { target: rectangle1; border.width: 1}
136             PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
137             PropertyChanges { target: imageDown; height: 0.5 * rectangle1.basicHeight}
138             PropertyChanges { target: shadeDisable; visible: false; z:-1}
139         },
140         State {
141             name: "expanded"
142             when: (rectangle1.expanded == true && rectangle1.disabled == false)
143             PropertyChanges { target: list1; z: 10; visible: true }
144             PropertyChanges { target: text1; z: 10; visible: false }
145             PropertyChanges { target: rectangle1; border.width: 0}
146             PropertyChanges { target: rectangle1; height: rectangle1.expandedHeight}
147             PropertyChanges { target: imageDown; height: 0.5 * rectangle1.basicHeight}
148             PropertyChanges { target: shadeDisable; visible: false; z: -1}
149         },
150         State {
151             name: "disabled";
152             when: rectangle1.disabled == true
153             PropertyChanges { target: list1; z: 0; visible: false }
154             PropertyChanges { target: text1; z: 0; visible: true }
155             PropertyChanges { target: rectangle1; border.width: 1}
156             PropertyChanges { target: rectangle1; expanded: false}
157             PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
158             PropertyChanges { target: imageDown; visible: true}
159             PropertyChanges { target: shadeDisable; visible: true; z:10}
160         }
161     ]
162
163 }
164