blob: 0322bb01f4a6641e550369ed460e4afe9b2d2a19 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
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
19import QtQuick 2.15
20import QtQuick.Window 2.15
21import QtQuick.Controls 2.15
22import QtQuick.Controls.Universal 2.12
23import QtQuick.Layouts 1.3
24import QtGraphicalEffects 1.14
25import QtQuick.Controls.Styles 1.4
26import net.jami.Models 1.0
27
28import "../../commoncomponents"
29
30ItemDelegate {
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
ababi6fa08612020-08-10 19:13:28 +020060 spacing: 8
Sébastien Blin1f915762020-08-03 13:27:42 -040061
62 Label{
63 id: labelContactAvatar
64
65 Layout.alignment: Qt.AlignVCenter
66
ababi6fa08612020-08-10 19:13:28 +020067 Layout.leftMargin: 16
68 Layout.rightMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -040069
ababi6fa08612020-08-10 19:13:28 +020070 Layout.minimumWidth: 32
71 Layout.preferredWidth: 32
72 Layout.maximumWidth: 32
Sébastien Blin1f915762020-08-03 13:27:42 -040073
ababi6fa08612020-08-10 19:13:28 +020074 Layout.minimumHeight: 32
75 Layout.preferredHeight: 32
76 Layout.maximumHeight: 32
Sébastien Blin1f915762020-08-03 13:27:42 -040077
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 Blin1f915762020-08-03 13:27:42 -0400102 ColumnLayout{
103 Layout.fillWidth: true
104 Layout.fillHeight: true
105
Sébastien Blin1f915762020-08-03 13:27:42 -0400106 Layout.alignment: Qt.AlignVCenter
107
Sébastien Blin1f915762020-08-03 13:27:42 -0400108 Label{
109 id: labelContactName
110
111 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400112
ababi6fa08612020-08-10 19:13:28 +0200113 Layout.minimumHeight: 24
114 Layout.preferredHeight: 24
115 Layout.maximumHeight: 24
Sébastien Blin1f915762020-08-03 13:27:42 -0400116
ababi6fa08612020-08-10 19:13:28 +0200117 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400118 font.kerning: true
119
120 horizontalAlignment: Text.AlignLeft
121 verticalAlignment: Text.AlignVCenter
122
ababi6fa08612020-08-10 19:13:28 +0200123 text: labelContactNameElidedText.elidedText
124 }
125
126 TextMetrics {
127 id: labelContactNameElidedText
128 elide: Text.ElideRight
129 elideWidth: deviceItemDelegate.width - 80
Sébastien Blin1f915762020-08-03 13:27:42 -0400130 text: contactName === "" ? qsTr("name") : contactName
131 }
132
133 Label{
134 id: labelContactId
135
136 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400137
ababi6fa08612020-08-10 19:13:28 +0200138 Layout.minimumHeight: 24
139 Layout.preferredHeight: 24
140 Layout.maximumHeight: 24
Sébastien Blin1f915762020-08-03 13:27:42 -0400141
ababi6fa08612020-08-10 19:13:28 +0200142 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400143 font.kerning: true
144
145 horizontalAlignment: Qt.AlignLeft
146 verticalAlignment: Qt.AlignVCenter
147
ababi6fa08612020-08-10 19:13:28 +0200148 text: labelContactIdElidedText.elidedText
149 }
150
151 TextMetrics {
152 id: labelContactIdElidedText
153 elide: Text.ElideRight
154 elideWidth: deviceItemDelegate.width - 80
Sébastien Blin1f915762020-08-03 13:27:42 -0400155 text: contactID === "" ? qsTr("id") : contactID
156 }
157 }
158
159 HoverableRadiusButton{
160 id: btnReAddContact
161
ababi6fa08612020-08-10 19:13:28 +0200162 Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
163 Layout.rightMargin: 8
Sébastien Blin1f915762020-08-03 13:27:42 -0400164
ababi6fa08612020-08-10 19:13:28 +0200165 Layout.minimumWidth: 32
166 Layout.preferredWidth: 32
167 Layout.maximumWidth: 32
Sébastien Blin1f915762020-08-03 13:27:42 -0400168
ababi6fa08612020-08-10 19:13:28 +0200169 Layout.minimumHeight: 32
170 Layout.preferredHeight: 32
171 Layout.maximumHeight: 32
Sébastien Blin1f915762020-08-03 13:27:42 -0400172
ababi6fa08612020-08-10 19:13:28 +0200173 buttonImageHeight: height - 8
174 buttonImageWidth: width - 8
Sébastien Blin1f915762020-08-03 13:27:42 -0400175
ababi6fa08612020-08-10 19:13:28 +0200176 source: "qrc:/images/icons/ic_person_add_black_24dp_2x.png"
Sébastien Blin1f915762020-08-03 13:27:42 -0400177
ababi6fa08612020-08-10 19:13:28 +0200178 radius: height / 2
179 width: 25
180 height: 25
181
182 backgroundColor: "transparent"
Sébastien Blin1f915762020-08-03 13:27:42 -0400183
184 ToolTip.visible: isHovering
185 ToolTip.text: qsTr("Add as contact")
186
187 onClicked: {
188 btnReAddContactClicked()
189 }
190 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400191 }
192}
193