first version of ComboBox
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Tue, 25 Jan 2011 07:46:01 +0000 (08:46 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Tue, 25 Jan 2011 07:46:01 +0000 (08:46 +0100)
src/mdictionary/mdictionary.pro
src/mdictionary/qml/ComboBox.qml [new file with mode: 0644]

index 68ae08d..bf2966b 100644 (file)
@@ -102,7 +102,8 @@ OTHER_FILES += \
     qml/Checkbox.qml \
     qml/MySpinBox.qml \
     qml/SettingsWidget.qml \
-    qml/HistoryListDialog.qml
+    qml/HistoryListDialog.qml \
+    qml/ComboBox.qml
 
 target.path = $$BIN_DIR
 INSTALLS += target
@@ -200,6 +201,7 @@ unix {
         qmls.files += ./qml/Checkbox.qml
         qmls.files += ./qml/MySpinBox.qml
         qmls.files += ./qml/SettingsWidget.qml
+        qmls.files += ./qml/ComboBox.qml
     }
     else:maemo5 {
         qmls.path = $$DATA_DIR/qml
@@ -225,6 +227,7 @@ unix {
         qmls.files += ./qml/MySpinBox.qml
         qmls.files += ./qml/SettingsWidget.qml
         qmls.files += ./qml/HistoryListDialog.qml
+        qmls.files += ./qml/ComboBox.qml
     }
        
     INSTALLS += desktop icon64 shared service css css_images qmls
diff --git a/src/mdictionary/qml/ComboBox.qml b/src/mdictionary/qml/ComboBox.qml
new file mode 100644 (file)
index 0000000..34112a7
--- /dev/null
@@ -0,0 +1,174 @@
+import Qt 4.7
+
+Rectangle {
+    id: rectangle1
+    radius: 10
+    border.color: "#000666";
+//    property int maxValue:500;
+//    property int minValue:0;
+    property alias value:text1.text
+    property bool expanded: false
+
+    function show(Boolean){
+        //mozna jeszcze to w tle ukrywać
+        expanded = Boolean
+    }
+
+    signal valueSelected(string selected); //?
+
+//    function stringToInt(string){
+//        var value=0;
+//        var pow10=1;
+//        for (var i=string.length-1;i>=0;i--){
+//            value+=(string.charCodeAt(i)-48)*pow10;
+//            pow10= pow10*10;
+//        }
+//        if(value>maxValue)
+//            return maxValue;
+//        if(value<minValue)
+//            return minValue;
+//        return value;
+//    }
+
+    Text {
+        id: text1
+        x: 1
+        width: rectangle1.width-15
+        height: rectangle1.height*0.6;
+        text: list1.selected
+        anchors.centerIn: parent
+        font.pixelSize: rectangle1.height * .5;
+        onTextChanged: {} //stub, tu reakcja na zmianę wyboru z listy
+    }
+
+//    TextInput {
+//        id: text_input1
+//        x: 1
+//        width: rectangle1.width-15
+//        height: rectangle1.height*0.6;
+//        text: "123"
+//        anchors.centerIn: parent
+//        validator: IntValidator{bottom: minValue; top: maxValue;}
+//        transformOrigin: Item.Left
+//        selectByMouse: true;
+//        font.pixelSize: rectangle1.height * .5;
+//        onCursorPositionChanged:  moveCursorSelection(cursorPosition);
+//        onTextChanged: rectangle1.valueChange(stringToInt(text_input1.text));
+//        onFocusChanged: {
+//            if(focus==false)
+//               text=stringToInt(text);
+//        }
+//    }
+
+    Rectangle {
+        id: shadeDisable
+        width:  parent.width;
+        height: parent.height;
+        anchors.centerIn: parent;
+        radius: parent.radius
+        color: "grey";
+        opacity: 0
+    }
+
+    Image {
+        id: imageUp
+        z:4;
+        width: 11;
+        height: 6;
+        anchors.right: parent.right
+        anchors.top: parent.top
+        anchors.rightMargin: 2
+        anchors.topMargin: 2
+        source: "qrc:/button/up_enable.png";
+    }
+
+    Image {
+        id: imageDown
+        z:4;
+        width: 11;
+        height: 6;
+        anchors.right: parent.right
+        anchors.bottom: parent.bottom
+        anchors.rightMargin: 2
+        anchors.bottomMargin: 2
+        source: "qrc:/button/down_enable.png";
+    }
+
+    MouseArea{
+        id: topMouseArea
+        z: 5
+        anchors.fill: parent
+        onClicked: {
+            rectangle1.show(!rectangle1.expanded)
+        }
+    }
+
+    ElementsListView{
+        id: list1
+        width: parent.width
+        visible: false
+        z: 0
+        property string selected: startValue//inicjowane z cpp
+
+        function selectedValue(nr, value) {
+            currentIndex = nr
+            selected = value
+            rectangle1.show(false)
+        }
+
+        anchors.left: parent.left
+        anchors.verticalCenter: parent.verticalCenter
+        highlightResizeSpeed: 1000
+        model: comboBoxModel
+
+        delegate: Component{
+            id: list1Delegate
+            Item {
+                width: rectangle1.width
+                height: contentText.height
+
+                MouseArea{
+                    id: listMouseArea
+                    anchors.fill: parent
+                    z: 1
+                    onClicked: {
+                        list1.selectedValue(number, content)
+                    }
+                    hoverEnabled: true
+                    onEntered: {
+                        list1.currentIndex = number
+                    }
+                }
+
+                Row{
+                    anchors.fill: parent
+
+                    Text{
+                        id: contentText
+                        anchors.verticalCenter: parent.verticalCenter
+                        anchors.leftMargin: 5
+                        text: content
+                    }
+                }
+            }
+        }
+
+    }
+
+    states: [
+        State {
+            name: "basic";
+            when: rectangle1.expanded = false
+            PropertyChanges { target: list1; z: 0; visible: false }
+            PropertyChanges {target: listMouseArea; z: 1 }
+        },
+        State {
+            name: "expanded"
+            when: rectangle1.expanded = true
+            PropertyChanges { target: list1; z: 10; visible: true }
+            PropertyChanges {target: listMouseArea; z: 11 }
+        }
+    ]
+
+}
+