diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2013-07-19 15:23:01 -0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-26 15:14:10 +0200 |
commit | 8e9575f36c5cdfac374480c9fc20699c6bc82ba7 (patch) | |
tree | 465a35c9bc4a4435583eda81c25679986296e335 /examples | |
parent | 103993321e86b7e7698b5e6953991af1bb7f430e (diff) |
Added support to preferredDetails on QML Contact.
Expose all functions related to preferredDetails
into QML contacts.
Task-number: QTBUG-32515
Change-Id: I93491cd8ef25cecd891334c7bc17cbb52773acd8
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/contacts/qmlcontactslistview/ContactEditor.qml | 39 | ||||
-rw-r--r-- | examples/contacts/qmlcontactslistview/DetailEditWidget.qml | 35 |
2 files changed, 68 insertions, 6 deletions
diff --git a/examples/contacts/qmlcontactslistview/ContactEditor.qml b/examples/contacts/qmlcontactslistview/ContactEditor.qml index 81e5f97f3..9cce57926 100644 --- a/examples/contacts/qmlcontactslistview/ContactEditor.qml +++ b/examples/contacts/qmlcontactslistview/ContactEditor.qml @@ -39,9 +39,25 @@ Rectangle { leftMargin: 10 topMargin: 10 } - DetailEditWidget { id: nameField; label: "Name "; value: contact ? contact.name.firstName : " "} - DetailEditWidget { id: emailField; label: "Email Address "; value: contact ? contact.email.emailAddress : " "} - DetailEditWidget { id: phoneField; label: "Phone Number "; value: contact ? contact.phoneNumber.number : " "} + DetailEditWidget { + id: nameField + label: "Name " + value: contact ? contact.name.firstName : " " + } + DetailEditWidget { + id: emailField + label: "Email Address " + value: contact ? contact.email.emailAddress : " " + showPreferredField: true + isPreferred: contact ? contact.isPreferredDetail("MESSAGE", contact.email) : false + } + DetailEditWidget { + id: phoneField + label: "Phone Number " + value: contact ? contact.phoneNumber.number : " " + showPreferredField: true + isPreferred: contact ? contact.isPreferredDetail("CALL", contact.phoneNumber) : false + } } // ![Widgets for manipulating contact details] @@ -52,7 +68,9 @@ Rectangle { function updateContact() { // read in values from the input fields - var values = [nameField.value, emailField.value, phoneField.value] + var values = [nameField.value, + emailField.value, emailField.requestPreferred || emailField.isPreferred, + phoneField.value, phoneField.requestPreferred || phoneField.isPreferred] if (!contact) { // create new contact var newContact = Qt.createQmlObject("import QtContacts 5.0; Contact{ }", contactEditor) setDetailValues(newContact, values) @@ -60,8 +78,8 @@ Rectangle { contactsModel.saveContact(newContact) statusBar.updateMsg("new contact successfully created") } else { // update existing contact + setDetailValues(contact, values) if (contact.modified) { - setDetailValues(contact, values) contact.save() statusBar.updateMsg("contact successfully updated") } else { @@ -73,7 +91,14 @@ Rectangle { function setDetailValues(c, values) { c.name.firstName = values[0] c.email.emailAddress = values[1] - c.phoneNumber.number = values[2] + c.phoneNumber.number = values[3] + if (values[2]) { + c.setPreferredDetail("MESSAGE", c.email) + } + + if (values[4]) { + c.setPreferredDetail("CALL", c.phoneNumber) + } } function cancel() { @@ -84,6 +109,8 @@ Rectangle { nameField.inputFocus = false emailField.inputFocus = false phoneField.inputFocus = false + emailField.requestPreferred = false + phoneField.requestPreferred = false nameField.color = "black" emailField.color = "black" phoneField.color = "black" diff --git a/examples/contacts/qmlcontactslistview/DetailEditWidget.qml b/examples/contacts/qmlcontactslistview/DetailEditWidget.qml index e481941e5..4f490e272 100644 --- a/examples/contacts/qmlcontactslistview/DetailEditWidget.qml +++ b/examples/contacts/qmlcontactslistview/DetailEditWidget.qml @@ -34,6 +34,9 @@ Item { property alias value: valueText.text property alias color: valueText.color property alias inputFocus: valueText.focus + property bool isPreferred: false + property bool requestPreferred: false + property bool showPreferredField: false property string old @@ -48,6 +51,7 @@ Item { } Rectangle { + id: inputField width: 180 height: 20 anchors.left: label.right @@ -77,5 +81,36 @@ Item { } } } + + Text { + id: labelFav + + anchors.left: inputField.right + anchors.leftMargin: 5 + + font { + family: "Helvetica" + pixelSize: 15 + bold: true + italic: true + } + text: "favorite:" + visible: showPreferredField + } + + Rectangle { + anchors.left: labelFav.right + anchors.leftMargin: 5 + anchors.verticalCenter: labelFav.verticalCenter + width: 10 + height: 10 + color: isPreferred || requestPreferred ? "black" : "white" + visible: showPreferredField + + MouseArea { + anchors.fill: parent + onClicked: requestPreferred = !requestPreferred + } + } } // ![Custom DetailsEditWidget is used for entering new or modifying existing contact detlais] |