Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019-2020 by Savoir-faire Linux |
| 3 | * Author: Yang Wang <yang.wang@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | import QtQuick 2.15 |
| 20 | import QtQuick.Window 2.15 |
| 21 | import QtQuick.Controls 2.15 |
| 22 | import QtQuick.Controls.Universal 2.12 |
| 23 | import QtQuick.Layouts 1.3 |
| 24 | import QtGraphicalEffects 1.14 |
| 25 | import QtQuick.Controls.Styles 1.4 |
| 26 | import net.jami.Models 1.0 |
| 27 | |
| 28 | import "../../commoncomponents" |
| 29 | |
| 30 | ItemDelegate { |
| 31 | id: deviceItemDelegate |
| 32 | |
| 33 | property string contactName : "" |
| 34 | property string contactID: "" |
| 35 | property string contactPicture_base64:"" |
| 36 | |
| 37 | signal btnReAddContactClicked |
| 38 | |
| 39 | function btnReAddContactEnter(){ |
| 40 | btnReAddContact.enterBtn() |
| 41 | } |
| 42 | |
| 43 | function btnReAddContactExit(){ |
| 44 | btnReAddContact.exitBtn() |
| 45 | } |
| 46 | |
| 47 | function btnReAddContactPress(){ |
| 48 | btnReAddContact.pressBtn() |
| 49 | } |
| 50 | |
| 51 | function btnReAddContactRelease(){ |
| 52 | btnReAddContact.releaseBtn() |
| 53 | } |
| 54 | |
| 55 | highlighted: ListView.isCurrentItem |
| 56 | |
| 57 | RowLayout{ |
| 58 | anchors.fill: parent |
| 59 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 60 | spacing: 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 61 | |
| 62 | Label{ |
| 63 | id: labelContactAvatar |
| 64 | |
| 65 | Layout.alignment: Qt.AlignVCenter |
| 66 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 67 | Layout.leftMargin: 16 |
| 68 | Layout.rightMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 69 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 70 | Layout.minimumWidth: 32 |
| 71 | Layout.preferredWidth: 32 |
| 72 | Layout.maximumWidth: 32 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 73 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 74 | Layout.minimumHeight: 32 |
| 75 | Layout.preferredHeight: 32 |
| 76 | Layout.maximumHeight: 32 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 77 | |
| 78 | background: Rectangle{ |
| 79 | anchors.fill: parent |
| 80 | color: "transparent" |
| 81 | Image { |
| 82 | id: avatarImg |
| 83 | |
| 84 | anchors.fill: parent |
| 85 | source: "data:image/png;base64," + contactPicture_base64 |
| 86 | fillMode: Image.PreserveAspectCrop |
| 87 | layer.enabled: true |
| 88 | layer.effect: OpacityMask { |
| 89 | maskSource: Rectangle{ |
| 90 | width: avatarImg.width |
| 91 | height: avatarImg.height |
| 92 | radius: { |
| 93 | var size = ((avatarImg.width <= avatarImg.height)? avatarImg.width:avatarImg.height) |
| 94 | return size /2 |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 102 | ColumnLayout{ |
| 103 | Layout.fillWidth: true |
| 104 | Layout.fillHeight: true |
| 105 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 106 | Layout.alignment: Qt.AlignVCenter |
| 107 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 108 | Label{ |
| 109 | id: labelContactName |
| 110 | |
| 111 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 112 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 113 | Layout.minimumHeight: 24 |
| 114 | Layout.preferredHeight: 24 |
| 115 | Layout.maximumHeight: 24 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 116 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 117 | font.pointSize: JamiTheme.textFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 118 | font.kerning: true |
| 119 | |
| 120 | horizontalAlignment: Text.AlignLeft |
| 121 | verticalAlignment: Text.AlignVCenter |
| 122 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 123 | text: labelContactNameElidedText.elidedText |
| 124 | } |
| 125 | |
| 126 | TextMetrics { |
| 127 | id: labelContactNameElidedText |
| 128 | elide: Text.ElideRight |
| 129 | elideWidth: deviceItemDelegate.width - 80 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 130 | text: contactName === "" ? qsTr("name") : contactName |
| 131 | } |
| 132 | |
| 133 | Label{ |
| 134 | id: labelContactId |
| 135 | |
| 136 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 137 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 138 | Layout.minimumHeight: 24 |
| 139 | Layout.preferredHeight: 24 |
| 140 | Layout.maximumHeight: 24 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 141 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 142 | font.pointSize: JamiTheme.textFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 143 | font.kerning: true |
| 144 | |
| 145 | horizontalAlignment: Qt.AlignLeft |
| 146 | verticalAlignment: Qt.AlignVCenter |
| 147 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 148 | text: labelContactIdElidedText.elidedText |
| 149 | } |
| 150 | |
| 151 | TextMetrics { |
| 152 | id: labelContactIdElidedText |
| 153 | elide: Text.ElideRight |
| 154 | elideWidth: deviceItemDelegate.width - 80 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 155 | text: contactID === "" ? qsTr("id") : contactID |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | HoverableRadiusButton{ |
| 160 | id: btnReAddContact |
| 161 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 162 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight |
| 163 | Layout.rightMargin: 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 164 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 165 | Layout.minimumWidth: 32 |
| 166 | Layout.preferredWidth: 32 |
| 167 | Layout.maximumWidth: 32 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 168 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 169 | Layout.minimumHeight: 32 |
| 170 | Layout.preferredHeight: 32 |
| 171 | Layout.maximumHeight: 32 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 172 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 173 | buttonImageHeight: height - 8 |
| 174 | buttonImageWidth: width - 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 175 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 176 | source: "qrc:/images/icons/ic_person_add_black_24dp_2x.png" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 177 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 178 | radius: height / 2 |
| 179 | width: 25 |
| 180 | height: 25 |
| 181 | |
| 182 | backgroundColor: "transparent" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 183 | |
| 184 | ToolTip.visible: isHovering |
| 185 | ToolTip.text: qsTr("Add as contact") |
| 186 | |
| 187 | onClicked: { |
| 188 | btnReAddContactClicked() |
| 189 | } |
| 190 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |