~phablet-team/messaging-app/select-part-of-message

« back to all changes in this revision

Viewing changes to src/qml/ContactSearchList.qml

  • Committer: Tiago Salem Herrmann
  • Date: 2017-02-08 21:04:29 UTC
  • mfrom: (639.12.11 sort-thread)
  • Revision ID: tiago.herrmann@canonical.com-20170208210429-kk2s6v6jbxj8qnmr
merge parent

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import QtContacts 5.0
21
21
 
22
22
import Ubuntu.Components 1.3
23
 
import Ubuntu.Components.ListItems 1.3 as ListItem
24
23
import Ubuntu.Contacts 0.1
25
24
 
26
 
ListView {
 
25
UbuntuListView {
27
26
    id: root
28
27
 
29
28
    // FIXME: change the Ubuntu.Contacts model to search for more fields
30
29
    property alias filterTerm: contactModel.filterTerm
31
 
    onFilterTermChanged: console.debug("FILTER :" + filterTerm)
32
30
 
33
31
    signal contactPicked(string identifier, string label, string avatar)
34
 
 
35
 
    model: ContactListModel {
 
32
    signal focusUp()
 
33
 
 
34
    ContactDetailPhoneNumberTypeModel {
 
35
        id: phoneTypeModel
 
36
    }
 
37
 
 
38
    ContactListModel {
36
39
        id: contactModel
37
40
 
 
41
        property var proxyModel: []
 
42
 
38
43
        manager: "galera"
39
44
        view: root
40
45
        autoUpdate: false
61
66
            detailTypesHint: [ ContactDetail.DisplayLabel,
62
67
                               ContactDetail.PhoneNumber ]
63
68
        }
64
 
    }
65
 
 
66
 
    ContactDetailPhoneNumberTypeModel {
67
 
        id: phoneTypeModel
68
 
    }
69
 
 
70
 
    delegate: Item {
 
69
 
 
70
        onContactsChanged: {
 
71
            var proxy = []
 
72
            for (var i=0; i < contacts.length; i++) {
 
73
                for (var p=0; p < contacts[i].phoneNumbers.length; p++) {
 
74
                    proxy.push({"contact": contacts[i], "phoneIndex": p})
 
75
                }
 
76
            }
 
77
            contactModel.proxyModel = proxy
 
78
        }
 
79
    }
 
80
 
 
81
    model: contactModel.proxyModel
 
82
    delegate: ListItem {
71
83
        anchors {
72
84
            left: parent.left
73
85
            right: parent.right
74
86
        }
75
 
        height: phoneRepeater.count * units.gu(6)
76
 
        Column {
77
 
            anchors.fill: parent
78
 
 
79
 
            Repeater {
80
 
                id: phoneRepeater
81
 
 
82
 
                model: contact.phoneNumbers.length
83
 
 
84
 
                delegate: MouseArea {
85
 
                    anchors {
86
 
                        left: parent.left
87
 
                        right: parent.right
88
 
                    }
89
 
                    height: units.gu(6)
90
 
 
91
 
                    onClicked: root.contactPicked(contact.phoneNumbers[index].number, contact.displayLabel.label, contact.avatar.url)
92
 
 
93
 
                    Column {
94
 
                        anchors.right: parent.right
95
 
                        anchors.left: parent.left
96
 
                        anchors.verticalCenter: parent.verticalCenter
97
 
                        height: childrenRect.height
98
 
                        spacing: units.gu(.5)
99
 
 
100
 
                        Label {
101
 
                            anchors {
102
 
                                left: parent.left
103
 
                                leftMargin: units.gu(2)
104
 
                                right: parent.right
105
 
                            }
106
 
                            height: units.gu(2)
107
 
                            text: {
108
 
                                // this is necessary to keep the string in the original format
109
 
                                var originalText = contact.displayLabel.label
110
 
                                var lowerSearchText =  filterTerm.toLowerCase()
111
 
                                var lowerText = originalText.toLowerCase()
112
 
                                var searchIndex = lowerText.indexOf(lowerSearchText)
113
 
                                if (searchIndex !== -1) {
114
 
                                    var piece = originalText.substr(searchIndex, lowerSearchText.length)
115
 
                                    return originalText.replace(piece, "<b>" + piece + "</b>")
116
 
                                } else {
117
 
                                    return originalText
118
 
                                }
119
 
                            }
120
 
                            fontSize: "medium"
121
 
                            color: Theme.palette.normal.backgroundText
122
 
                        }
123
 
                        Label {
124
 
                            anchors {
125
 
                                left: parent.left
126
 
                                leftMargin: units.gu(2)
127
 
                                right: parent.right
128
 
                            }
129
 
                            height: units.gu(2)
130
 
                            text: {
131
 
                                var phoneDetail = contact.phoneNumbers[index]
132
 
                                return ("%1 %2").arg(phoneTypeModel.get(phoneTypeModel.getTypeIndex(phoneDetail)).label)
133
 
                                                .arg(phoneDetail.number)
134
 
                            }
135
 
                            color: Theme.palette.normal.backgroundSecondaryText
136
 
                        }
137
 
 
138
 
                        ListItem.ThinDivider {}
139
 
                    }
 
87
        height: itemLayout.height
 
88
 
 
89
        onClicked: root.contactPicked(modelData.contact.phoneNumbers[modelData.phoneIndex].number,
 
90
                                      modelData.contact.displayLabel.label, modelData.contact.avatar.url)
 
91
 
 
92
        ListItemLayout {
 
93
            id: itemLayout
 
94
 
 
95
            title.text: {
 
96
                // this is necessary to keep the string in the original format
 
97
                var originalText = modelData.contact.displayLabel.label
 
98
                var lowerSearchText =  filterTerm.toLowerCase()
 
99
                var lowerText = originalText.toLowerCase()
 
100
                var searchIndex = lowerText.indexOf(lowerSearchText)
 
101
                if (searchIndex !== -1) {
 
102
                   var piece = originalText.substr(searchIndex, lowerSearchText.length)
 
103
                   return originalText.replace(piece, "<b>" + piece + "</b>")
 
104
                } else {
 
105
                   return originalText
140
106
                }
141
107
            }
 
108
            title.fontSize: "medium"
 
109
            title.color: Theme.palette.normal.backgroundText
 
110
 
 
111
            subtitle.text: {
 
112
                var phoneDetail = modelData.contact.phoneNumbers[modelData.phoneIndex]
 
113
                return ("%1 %2").arg(phoneTypeModel.get(phoneTypeModel.getTypeIndex(phoneDetail)).label)
 
114
                                .arg(phoneDetail.number)
 
115
            }
 
116
            subtitle.color: Theme.palette.normal.backgroundSecondaryText
142
117
        }
143
118
    }
 
119
 
 
120
    Keys.onUpPressed: {
 
121
        if (currentIndex == 0)
 
122
            focusUp()
 
123
 
 
124
        event.accepted  = false
 
125
    }
144
126
}