qml ComboBox component and GoogleDialog complete
[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:4;
51         width: 11;
52         height: 0.5 * rectangle1.height;
53         anchors.top: parent.top
54         anchors.right: parent.right
55         anchors.bottom: parent.bottom
56         anchors.topMargin: 4
57         anchors.rightMargin: 6
58         anchors.bottomMargin: 4
59         source: "qrc:/button/down_enable.png";
60     }
61
62     MouseArea{
63         id: topMouseArea
64         z: 5
65         anchors.fill: parent
66         onClicked: {
67             rectangle1.show(!rectangle1.expanded)
68         }
69     }
70
71     ElementsListView{
72         id: list1
73         width: parent.width
74         visible: false
75         z: 0
76         property string selected: rectangle1.startValue
77
78         function selectedValue(nr, value) {
79             currentIndex = nr
80             selected = value
81             rectangle1.show(false)
82         }
83
84         anchors.left: parent.left
85         anchors.verticalCenter: parent.verticalCenter
86         highlightResizeSpeed: 1000
87
88         delegate: Component{
89             id: list1Delegate
90             Item {
91                 width: rectangle1.width
92                 height: contentText.height
93
94                 MouseArea{
95                     id: listMouseArea
96                     anchors.fill: parent
97                     z: 1
98                     onClicked: {
99                         list1.selectedValue(number, content)
100                     }
101                     hoverEnabled: true
102                     onEntered: {
103                         list1.currentIndex = number
104                     }
105                 }
106
107                 Row{
108                     anchors.fill: parent
109
110                     Text{
111                         id: contentText
112                         anchors.verticalCenter: parent.verticalCenter
113                         anchors.leftMargin: 5
114                         text: content
115                     }
116                 }
117             }
118         }
119
120     }
121
122     states: [
123         State {
124             name: "basic";
125             when: (rectangle1.expanded == false && rectangle1.disabled == false)
126             PropertyChanges { target: list1; z: 0; visible: false }
127             PropertyChanges { target: text1; z: 0; visible: true }
128             PropertyChanges { target: rectangle1; border.width: 1}
129             PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
130             PropertyChanges { target: imageDown; visible: true}
131             PropertyChanges { target: shadeDisable; visible: false; z:-1}
132         },
133         State {
134             name: "expanded"
135             when: (rectangle1.expanded == true && rectangle1.disabled == false)
136             PropertyChanges { target: list1; z: 10; visible: true }
137             PropertyChanges { target: text1; z: 10; visible: false }
138             PropertyChanges { target: rectangle1; border.width: 0}
139             PropertyChanges { target: rectangle1; height: rectangle1.expandedHeight}
140             PropertyChanges { target: imageDown; visible: false}
141             PropertyChanges { target: shadeDisable; visible: false; z: -1}
142         },
143         State {
144             name: "disabled";
145             when: rectangle1.disabled == true
146             PropertyChanges { target: list1; z: 0; visible: false }
147             PropertyChanges { target: text1; z: 0; visible: true }
148             PropertyChanges { target: rectangle1; border.width: 1}
149             PropertyChanges { target: rectangle1; expanded: false}
150             PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
151             PropertyChanges { target: imageDown; visible: true}
152             PropertyChanges { target: shadeDisable; visible: true; z:10}
153         }
154     ]
155
156 }
157