34112a7e2f2dd9c2c0d311b26a69b4641abb057b
[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 int maxValue:500;
8 //    property int minValue:0;
9     property alias value:text1.text
10     property bool expanded: false
11
12     function show(Boolean){
13         //mozna jeszcze to w tle ukrywać
14         expanded = Boolean
15     }
16
17     signal valueSelected(string selected); //?
18
19 //    function stringToInt(string){
20 //        var value=0;
21 //        var pow10=1;
22 //        for (var i=string.length-1;i>=0;i--){
23 //            value+=(string.charCodeAt(i)-48)*pow10;
24 //            pow10= pow10*10;
25 //        }
26 //        if(value>maxValue)
27 //            return maxValue;
28 //        if(value<minValue)
29 //            return minValue;
30 //        return value;
31 //    }
32
33     Text {
34         id: text1
35         x: 1
36         width: rectangle1.width-15
37         height: rectangle1.height*0.6;
38         text: list1.selected
39         anchors.centerIn: parent
40         font.pixelSize: rectangle1.height * .5;
41         onTextChanged: {} //stub, tu reakcja na zmianę wyboru z listy
42     }
43
44 //    TextInput {
45 //        id: text_input1
46 //        x: 1
47 //        width: rectangle1.width-15
48 //        height: rectangle1.height*0.6;
49 //        text: "123"
50 //        anchors.centerIn: parent
51 //        validator: IntValidator{bottom: minValue; top: maxValue;}
52 //        transformOrigin: Item.Left
53 //        selectByMouse: true;
54 //        font.pixelSize: rectangle1.height * .5;
55 //        onCursorPositionChanged:  moveCursorSelection(cursorPosition);
56 //        onTextChanged: rectangle1.valueChange(stringToInt(text_input1.text));
57 //        onFocusChanged: {
58 //            if(focus==false)
59 //               text=stringToInt(text);
60 //        }
61 //    }
62
63     Rectangle {
64         id: shadeDisable
65         width:  parent.width;
66         height: parent.height;
67         anchors.centerIn: parent;
68         radius: parent.radius
69         color: "grey";
70         opacity: 0
71     }
72
73     Image {
74         id: imageUp
75         z:4;
76         width: 11;
77         height: 6;
78         anchors.right: parent.right
79         anchors.top: parent.top
80         anchors.rightMargin: 2
81         anchors.topMargin: 2
82         source: "qrc:/button/up_enable.png";
83     }
84
85     Image {
86         id: imageDown
87         z:4;
88         width: 11;
89         height: 6;
90         anchors.right: parent.right
91         anchors.bottom: parent.bottom
92         anchors.rightMargin: 2
93         anchors.bottomMargin: 2
94         source: "qrc:/button/down_enable.png";
95     }
96
97     MouseArea{
98         id: topMouseArea
99         z: 5
100         anchors.fill: parent
101         onClicked: {
102             rectangle1.show(!rectangle1.expanded)
103         }
104     }
105
106     ElementsListView{
107         id: list1
108         width: parent.width
109         visible: false
110         z: 0
111         property string selected: startValue//inicjowane z cpp
112
113         function selectedValue(nr, value) {
114             currentIndex = nr
115             selected = value
116             rectangle1.show(false)
117         }
118
119         anchors.left: parent.left
120         anchors.verticalCenter: parent.verticalCenter
121         highlightResizeSpeed: 1000
122         model: comboBoxModel
123
124         delegate: Component{
125             id: list1Delegate
126             Item {
127                 width: rectangle1.width
128                 height: contentText.height
129
130                 MouseArea{
131                     id: listMouseArea
132                     anchors.fill: parent
133                     z: 1
134                     onClicked: {
135                         list1.selectedValue(number, content)
136                     }
137                     hoverEnabled: true
138                     onEntered: {
139                         list1.currentIndex = number
140                     }
141                 }
142
143                 Row{
144                     anchors.fill: parent
145
146                     Text{
147                         id: contentText
148                         anchors.verticalCenter: parent.verticalCenter
149                         anchors.leftMargin: 5
150                         text: content
151                     }
152                 }
153             }
154         }
155
156     }
157
158     states: [
159         State {
160             name: "basic";
161             when: rectangle1.expanded = false
162             PropertyChanges { target: list1; z: 0; visible: false }
163             PropertyChanges {target: listMouseArea; z: 1 }
164         },
165         State {
166             name: "expanded"
167             when: rectangle1.expanded = true
168             PropertyChanges { target: list1; z: 10; visible: true }
169             PropertyChanges {target: listMouseArea; z: 11 }
170         }
171     ]
172
173 }
174