Export Checkbox as separate qml file
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 30 Dec 2010 12:16:00 +0000 (13:16 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 30 Dec 2010 12:16:00 +0000 (13:16 +0100)
src/mdictionary/mdictionary.pro
src/mdictionary/qml/Checkbox.qml [new file with mode: 0644]
src/mdictionary/qml/DictManagerWidget.qml

index d01fcc4..d2b6f46 100644 (file)
@@ -94,7 +94,8 @@ OTHER_FILES += \
     qml/WordListWidget.qml \
     qml/TranslationView.qml \
     qml/FlickableWebView.qml \
-    qml/ScrollBar.qml
+    qml/ScrollBar.qml \
+    qml/Checkbox.qml
 
 target.path = $$BIN_DIR
 INSTALLS += target
@@ -197,6 +198,7 @@ unix {
         qmls.files += ./qml/TranslationView.qml
         qmls.files += ./qml/FlickableWebView.qml
         qmls.files += ./qml/ScrollBar.qml
+        qmls.files += ./qml/Checkbox.qml
     }
        
     INSTALLS += desktop icon64 shared service css css_images qmls
diff --git a/src/mdictionary/qml/Checkbox.qml b/src/mdictionary/qml/Checkbox.qml
new file mode 100644 (file)
index 0000000..1af756f
--- /dev/null
@@ -0,0 +1,35 @@
+import Qt 4.7
+
+Image {
+    id: checkbox
+    property bool selected
+    signal changed
+    height: {
+        var aspectRatio = sourceSize.height / sourceSize.width
+        return checkbox.width * aspectRatio
+    }
+    width: sourceSize.width
+    smooth: true
+    states: [
+        State {
+            name: "checked";
+            when: (checkbox.selected == true);
+
+            PropertyChanges { target: checkbox; source: "qrc:/button/checkboxChecked.png" }
+        },
+        State {
+            name: "unchecked";
+            when: (checkbox.selected == false);
+
+            PropertyChanges { target: checkbox; source: "qrc:/button/checkbox.png" }
+        }
+    ]
+    MouseArea{
+        id: area
+        anchors.fill: parent
+        onClicked: {
+            checkbox.selected = !checkbox.selected
+            changed()
+        }
+    }
+}
index ace01c9..7cb44f3 100644 (file)
@@ -29,6 +29,12 @@ Rectangle {
 
     function setEnableRemove(Boolean) { removeButton.enabled = Boolean }
     function setEnableSettings(Boolean) { settingsButton.enabled = Boolean }
+    function changeDictionaryState(nr, state) {
+        dictList.currentIndex = nr
+        dictModel.setModelProperty(dictList.currentIndex, state, "isSelected")
+        rectangle1.setEnableRemove(true)
+        rectangle1.setEnableSettings(true)
+    }
 
     signal addButtonClicked;
     signal removeButtonClicked;
@@ -61,6 +67,7 @@ Rectangle {
                 MouseArea{
                     anchors.fill: parent
                     onClicked: {
+                        console.log("aaaaa")
                         dictList.currentIndex = number
                         rectangle1.setEnableRemove(true)
                         rectangle1.setEnableSettings(true)
@@ -71,40 +78,14 @@ Rectangle {
                 }
                 Row {
                     anchors.fill: parent
-                    Image {
-                        id: checkbox
-                        height: {
-                            var aspectRatio = sourceSize.height / sourceSize.width
-                            return checkbox.width * aspectRatio
-                        }
-                        anchors.verticalCenter: parent.verticalCenter
+                    Checkbox{
+                        id: check
                         width: nameText.height
-                        smooth: true
-                        states: [
-                            State {
-                                name: "checked";
-                                when: (isSelected == true);
-
-                                PropertyChanges { target: checkbox; source: "qrc:/button/checkboxChecked.png" }
-                            },
-                            State {
-                                name: "unchecked";
-                                when: (isSelected == false);
-
-                                PropertyChanges { target: checkbox; source: "qrc:/button/checkbox.png" }
-                            }
-                        ]
-                        MouseArea{
-                            anchors.fill: parent
-                            onClicked: {
-                                dictList.currentIndex = number
-                                dictModel.setModelProperty(dictList.currentIndex, !isSelected, "isSelected")
-                                rectangle1.setEnableRemove(true)
-                                rectangle1.setEnableSettings(true)
-                            }
-                        }
+                        selected: isSelected
+                        onChanged: rectangle1.changeDictionaryState(number, selected)
                     }
 
+
                     Image {
                         id: logo
                         source: iconPath