| 1 |
/* |
| 2 |
* Copyright (C) 2012-2015 Canonical, Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
import QtContacts 5.0 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
import Lomiri.Components.ListItems 1.3 as ListItem |
| 21 |
import "Contacts.js" as ContactsJS |
| 22 |
|
| 23 |
ListItemWithActions { |
| 24 |
id: root |
| 25 |
|
| 26 |
property bool showAvatar: true |
| 27 |
property bool isCurrentItem: false |
| 28 |
property string defaultAvatarUrl: "" |
| 29 |
property bool flicking: false |
| 30 |
property int contactIndex: ListView.view ? index : -1 |
| 31 |
readonly property string displayLabel: contact ? ContactsJS.formatToDisplay(contact, "") : "" |
| 32 |
|
| 33 |
signal clicked(int index, QtObject contact) |
| 34 |
signal pressAndHold(int index, QtObject contact) |
| 35 |
|
| 36 |
implicitHeight: defaultHeight |
| 37 |
width: parent ? parent.width : 0 |
| 38 |
|
| 39 |
onItemClicked: root.clicked(index, contact) |
| 40 |
onItemPressAndHold: root.pressAndHold(index, contact) |
| 41 |
onFlickingChanged: { |
| 42 |
if (flicking) { |
| 43 |
resetSwipe() |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
Item { |
| 48 |
id: delegate |
| 49 |
|
| 50 |
anchors { |
| 51 |
left: parent.left |
| 52 |
right: parent.right |
| 53 |
} |
| 54 |
height: units.gu(6) |
| 55 |
|
| 56 |
ContactAvatar { |
| 57 |
id: avatar |
| 58 |
|
| 59 |
contactElement: contact |
| 60 |
fallbackDisplayName: root.displayLabel |
| 61 |
anchors { |
| 62 |
left: parent.left |
| 63 |
top: parent.top |
| 64 |
bottom: parent.bottom |
| 65 |
} |
| 66 |
width: root.showAvatar ? height : 0 |
| 67 |
visible: width > 0 |
| 68 |
} |
| 69 |
|
| 70 |
Label { |
| 71 |
id: name |
| 72 |
objectName: "nameLabel" |
| 73 |
|
| 74 |
anchors { |
| 75 |
left: avatar.right |
| 76 |
leftMargin: units.gu(2) |
| 77 |
verticalCenter: parent.verticalCenter |
| 78 |
right: parent.right |
| 79 |
} |
| 80 |
color: theme.palette.normal.backgroundText |
| 81 |
text: root.displayLabel != "" ? root.displayLabel : i18n.dtr("lomiri-addressbook-app", "No name") |
| 82 |
elide: Text.ElideRight |
| 83 |
} |
| 84 |
} |
| 85 |
} |