bi change + completer in line edit
[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: 20
16
17     property variant parentField : rectangle1
18
19     function show(Boolean){
20         expanded = Boolean
21     }
22
23     function setStartValue(val, idx){
24         startValue = val
25         list1.currentIndex = idx
26     }
27
28     signal valueSelected(string selected);
29
30     Text {
31         id: text1
32         width: rectangle1.width-15
33         height: rectangle1.height*0.6;
34         text: list1.selected
35         anchors.centerIn: parent
36         font.pixelSize: rectangle1.height * .5;
37         onTextChanged: { rectangle1.valueSelected(text) }
38     }
39
40     Rectangle {
41         id: shadeDisable
42         width:  parent.width;
43         height: parent.height;
44         anchors.centerIn: parent;
45         radius: parent.radius
46         color: "grey";
47         opacity: 0.5
48     }
49
50     Image {
51         id: imageDown
52         z:15;
53         width: 11;
54         height: 0.5 * rectangle1.height;
55         anchors.top: parent.top
56         anchors.right: parent.right
57         anchors.topMargin: 4
58         anchors.rightMargin: 6
59         anchors.bottomMargin: 4
60         source: "qrc:/button/down_enable.png";
61
62         MouseArea{
63             id: imgMouseArea
64             anchors.fill: parent
65             onClicked: {
66                 rectangle1.show(!rectangle1.expanded)
67             }
68         }
69     }
70
71     MouseArea{
72         id: topMouseArea
73         z: 5
74         anchors.fill: parent
75         onClicked: {
76             rectangle1.show(!rectangle1.expanded)
77         }
78     }
79
80     ElementsListView{
81         id: list1
82         visible: false
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.rightMargin: 5
92         anchors.leftMargin: 5
93         anchors.bottomMargin: 10
94         anchors.topMargin: 10
95         anchors.fill: parent
96
97         highlightResizeSpeed: 1000
98         delegate: Component{
99             id: list1Delegate
100             Item {
101                 width: rectangle1.width
102                 height: contentText.height
103
104                 MouseArea{
105                     id: listMouseArea
106                     anchors.fill: parent
107                     z: 1
108                     onClicked: {
109                         list1.selectedValue(number, content)
110                     }
111                     hoverEnabled: true
112                     onEntered: {
113                         list1.currentIndex = number
114                     }
115                 }
116
117                 Row{
118                     anchors.fill: parent
119
120                     Text{
121                         id: contentText
122                         anchors.verticalCenter: parent.verticalCenter
123                         anchors.leftMargin: 5
124                         elide: Text.ElideRight;
125                         text: content
126                     }
127                 }
128             }
129         }
130
131     }
132
133     states: [
134         State {
135             name: "basic";
136             when: (rectangle1.expanded == false && rectangle1.disabled == false)
137             PropertyChanges { target: list1; z: 0; visible: false }
138             PropertyChanges { target: text1; z: 0; visible: true }
139             PropertyChanges { target: rectangle1; border.width: 1}
140             PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
141             PropertyChanges { target: imageDown; height: 0.5 * rectangle1.basicHeight}
142             PropertyChanges { target: shadeDisable; visible: false; z:-1}
143         },
144         State {
145             name: "expanded"
146             when: (rectangle1.expanded == true && rectangle1.disabled == false)
147             PropertyChanges { target: list1; z: 10; visible: true }
148             PropertyChanges { target: text1; z: 10; visible: false }
149             PropertyChanges { target: rectangle1; border.width: 1}
150             PropertyChanges { target: rectangle1; height: rectangle1.expandedHeight}
151             PropertyChanges { target: imageDown; height: 0.5 * rectangle1.basicHeight}
152             PropertyChanges { target: shadeDisable; visible: false; z: -1}
153             PropertyChanges { target: rectangle1; anchors.fill: parentField}
154         },
155         State {
156             name: "disabled";
157             when: rectangle1.disabled == true
158             PropertyChanges { target: list1; z: 0; visible: false }
159             PropertyChanges { target: text1; z: 0; visible: true }
160             PropertyChanges { target: rectangle1; border.width: 1}
161             PropertyChanges { target: rectangle1; expanded: false}
162             PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
163             PropertyChanges { target: imageDown; visible: true}
164             PropertyChanges { target: shadeDisable; visible: true; z:10}
165         }
166     ]
167
168 }
169