From faedc064fe7cc5f513b3c0e4bf9c118cb970e3d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Ka=C5=BAmierczak?= Date: Thu, 30 Dec 2010 13:16:00 +0100 Subject: [PATCH] Export Checkbox as separate qml file --- src/mdictionary/mdictionary.pro | 4 ++- src/mdictionary/qml/Checkbox.qml | 35 +++++++++++++++++++++++ src/mdictionary/qml/DictManagerWidget.qml | 43 ++++++++--------------------- 3 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 src/mdictionary/qml/Checkbox.qml diff --git a/src/mdictionary/mdictionary.pro b/src/mdictionary/mdictionary.pro index d01fcc4..d2b6f46 100644 --- a/src/mdictionary/mdictionary.pro +++ b/src/mdictionary/mdictionary.pro @@ -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 index 0000000..1af756f --- /dev/null +++ b/src/mdictionary/qml/Checkbox.qml @@ -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() + } + } +} diff --git a/src/mdictionary/qml/DictManagerWidget.qml b/src/mdictionary/qml/DictManagerWidget.qml index ace01c9..7cb44f3 100644 --- a/src/mdictionary/qml/DictManagerWidget.qml +++ b/src/mdictionary/qml/DictManagerWidget.qml @@ -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 -- 1.7.9.5