Skip to content

Commit

Permalink
[phone] Add contact search and browse
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorgino committed Dec 29, 2017
1 parent 7c45376 commit 229cd3b
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 113 deletions.
218 changes: 124 additions & 94 deletions qml/Phone/Contacts.qml
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import QtQuick 2.0
import QtContacts 5.0
import QtGraphicalEffects 1.0
import QtContacts 5.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3

Item {
id: __root
property int contactCardHeight: 50
signal dial(Contact contact)
property string dialed_num: ""
property bool isSearching: (dialed_num.length > 0)
signal dial(string number)
clip: true

StackView{
id:contactView
anchors.fill: parent
initialItem: browsingArea
anchors.fill: parent
}
Component {
id:browsingArea
Item {
ContactModel {
id: contactsModel
ListView {
id: contactsView
model: ContactModel {
autoUpdate: true
manager: "memory"
filter:DetailFilter {
id:numberFilter
value:dialed_num
detail: ContactDetail.PhoneNumber
field:PhoneNumber.Number
matchFlags: Filter.MatchContains
}
Component.onCompleted: {
contactsModel.importContacts("file:/home/gino/.config/viktorgino/viktorgino's HeadUnit Desktop/contacts/contacts.vcf")
importContacts("file:"+telephonyManager.contactsFolder+"/contacts.vcf")
}

sortOrders: [
SortOrder {
detail: ContactDetail.Name
Expand All @@ -32,106 +43,126 @@ Item {
}
]
}
focus: true
clip: true
delegate: Item {
id: delRect
width: parent.width
height: __root.contactCardHeight

Component {
id: contactDelegate
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
//__root.dial(contact)
if(__root.isSearching){
__root.dial(number.num)
} else {
contactView.push(contactInfo,{"contact":contact})
}
}
}

Item {
id: delRect
width: parent.width
height: __root.contactCardHeight
Text {
id: name
color: "#ffffff"
anchors {
verticalCenter: parent.verticalCenter
left: imageWrapper.right
leftMargin: 6
}
text: contact.name.firstName + " " + contact.name.lastName
elide: Text.ElideRight
font.pointSize: parent.height * 0.2
font.family: "Times New Roman"
font.bold: true
}
Rectangle{
id: imageWrapper
width: height
radius: height/2
clip: true
anchors.top: parent.top
anchors.topMargin: 6
anchors.bottom: parent.bottom
anchors.bottomMargin: 6
anchors.left: parent.left
anchors.leftMargin: 6
color:"#00BCD4"

MouseArea {
id: mouseArea

Item {
anchors.fill: parent
onClicked: {
//__root.dial(contact)
contactView.push(contactInfo,{"contact":contact})
layer.enabled: true
layer.effect: OpacityMask {
maskSource: imageWrapper
}
}

Text {
color: "#ffffff"
anchors {
verticalCenter: parent.verticalCenter
left: imageWrapper.right
leftMargin: 6
Text {
x: -height/5
color: "#66ffffff"
text: contact.name.firstName.charAt(0).toUpperCase()
font.pixelSize: parent.height * 1.4
anchors.bottomMargin: 0
anchors.top: image.top
anchors.bottom: parent.bottom
anchors.topMargin: 0
font.bold: true
clip: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
}
text: contact.name.firstName + " " + contact.name.lastName
elide: Text.ElideRight
font.pointSize: parent.height * 0.2
font.family: "Times New Roman"
font.bold: true
}
Rectangle{
id: imageWrapper
width: height
radius: height/2
clip: true
anchors.top: parent.top
anchors.topMargin: 6
anchors.bottom: parent.bottom
anchors.bottomMargin: 6
anchors.left: parent.left
anchors.leftMargin: 6
color:"#00BCD4"

Text {
x: height/4
color: "#4cffffff"
text: contact.name.lastName.charAt(0).toUpperCase()
font.pixelSize: parent.height * 1.4
anchors.bottom: parent.bottom
anchors.top: parent.top
font.bold: true
clip: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignRight
}

Item {
Image {
id: image
anchors.fill: parent
layer.enabled: true
layer.effect: OpacityMask {
maskSource: imageWrapper
}

Text {
x: -height/5
color: "#66ffffff"
text: contact.name.firstName.charAt(0).toUpperCase()
font.pixelSize: parent.height * 1.4
anchors.bottomMargin: 0
anchors.top: image.top
anchors.bottom: parent.bottom
anchors.topMargin: 0
font.bold: true
clip: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
}
source: contact.avatar.imageUrl
fillMode: Image.PreserveAspectCrop
}
}

Text {
x: height/4
color: "#4cffffff"
text: contact.name.lastName.charAt(0).toUpperCase()
font.pixelSize: parent.height * 1.4
anchors.bottom: parent.bottom
anchors.top: parent.top
font.bold: true
clip: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignRight
}
}

Image {
id: image
anchors.fill: parent
source: contact.avatar.imageUrl
fillMode: Image.PreserveAspectCrop
Text {
id: number
color: "#ffffff"
property string num : {
if(__root.isSearching){
for(var i = 0; contact.phoneNumbers.length > i; i++){
if(contact.phoneNumbers[i].number.includes(__root.dialed_num)){
return contact.phoneNumbers[i].number;
}
}
}

return "";
}
text: {
var numIndex = num.indexOf(__root.dialed_num);
return num.substring(0, numIndex) + "<b>" + __root.dialed_num + "</b>" + num.substring(numIndex+__root.dialed_num.length, num.length);
}

anchors.top: name.bottom
anchors.topMargin: 0
anchors.right: parent.right
anchors.rightMargin: 8
anchors.left: imageWrapper.right
anchors.leftMargin: 8
font.pointSize: parent.height * 0.15
}
}

ListView {
id: contactsView
anchors.fill: parent
model: contactsModel
focus: true
clip: true
delegate: contactDelegate
}
}
}
Expand Down Expand Up @@ -266,12 +297,13 @@ Item {
switch(modelData.subTypes[0]){
case PhoneNumber.Mobile :
return qsTr("Mobile")
case PhoneNumber.Unknown :
return qsTr("Other")
case PhoneNumber.Landline :
return qsTr("Landline")
case PhoneNumber.Fax :
return qsTr("Fax")
case PhoneNumber.Unknown :
default:
return qsTr("Other")
}
}
anchors.topMargin: 0
Expand All @@ -290,16 +322,14 @@ Item {
id: mouseArea
anchors.fill: parent
onClicked: {
__root.dial(contact)
__root.dial(modelData.number)
}
}
}
}

Button {
id: button
x: 8
y: 8
text: qsTr("Back")
anchors.top: parent.top
anchors.topMargin: 8
Expand Down
3 changes: 2 additions & 1 deletion qml/Phone/Dialer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Item {
anchors.bottomMargin: 0
signal dial(string number)
signal hangup()
property alias dialed_num: dialer_num.text

TextField {
id: dialer_num
text: "+"
text: ""
anchors.leftMargin: 2
font.pointSize: 30
anchors.left: parent.left
Expand Down
Loading

0 comments on commit 229cd3b

Please sign in to comment.