blob: 5c01efa18af3db4ffa4c9ff7f15edef37d8ae433 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001
2/*
3 * Copyright (C) 2020 by Savoir-faire Linux
4 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19import QtQuick 2.14
20import QtQuick.Controls 2.14
21import QtQuick.Layouts 1.14
22import net.jami.Models 1.0
23
24import "../../commoncomponents"
25
26Dialog {
27 id: userProfileDialog
28
29 property string responsibleConvUid: ""
30 property string contactPicBase64: ""
31 property string aliasText: ""
32 property string registeredNameText: ""
33 property string idText: ""
34
ababidf651a22020-07-30 13:38:57 +020035 property int preferredImgSize: 80
Sébastien Blin1f915762020-08-03 13:27:42 -040036 modal: true
37
Sébastien Blin1f915762020-08-03 13:27:42 -040038 /*
39 * Content height + margin.
40 */
ababidf651a22020-07-30 13:38:57 +020041 contentHeight: userProfileDialogLayout.implicitHeight + 60
42 contentWidth: userProfileDialogLayout.implicitWidth + 60
Sébastien Blin1f915762020-08-03 13:27:42 -040043
44 /*
45 * Fake focus to make sure that text edit lose focus on close.
46 */
47 FocusScope {
48 id: fakeFocusTextEdit
49 }
50
ababidf651a22020-07-30 13:38:57 +020051 contentItem: GridLayout {
Sébastien Blin1f915762020-08-03 13:27:42 -040052
ababidf651a22020-07-30 13:38:57 +020053 id: userProfileDialogLayout
54 columns: 2
55 rowSpacing: 10
56 columnSpacing: 10
Sébastien Blin1f915762020-08-03 13:27:42 -040057
58 Image {
59 id: contactImage
60
ababidf651a22020-07-30 13:38:57 +020061 Layout.alignment: Qt.AlignRight
62 Layout.preferredWidth: 130
Sébastien Blin1f915762020-08-03 13:27:42 -040063
ababidf651a22020-07-30 13:38:57 +020064 sourceSize.width: preferredImgSize
65 sourceSize.height: preferredImgSize
Sébastien Blin1f915762020-08-03 13:27:42 -040066
67 fillMode: Image.PreserveAspectFit
68 mipmap: true
69 }
70
Sébastien Blin1f915762020-08-03 13:27:42 -040071 /*
72 * Visible when user alias is not empty or equals to id.
73 */
74 Text {
75 id: contactAlias
76
ababidf651a22020-07-30 13:38:57 +020077 Layout.alignment: Qt.AlignLeft
Sébastien Blin1f915762020-08-03 13:27:42 -040078
ababidf651a22020-07-30 13:38:57 +020079 font.pointSize: JamiTheme.titleFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -040080 text: textMetricsContactAliasText.elidedText
81 visible: aliasText ? (aliasText === idText ? false : true) : false
ababidf651a22020-07-30 13:38:57 +020082
Sébastien Blin1f915762020-08-03 13:27:42 -040083 TextMetrics {
84 id: textMetricsContactAliasText
85 font: contactAlias.font
86 text: aliasText
ababidf651a22020-07-30 13:38:57 +020087 elideWidth: userProfileDialog.width-160
Sébastien Blin1f915762020-08-03 13:27:42 -040088 elide: Qt.ElideMiddle
89 }
90 }
91
ababidf651a22020-07-30 13:38:57 +020092 Item {
93 Layout.columnSpan: 2
94 height: 20
95 }
96
97 Text {
98 Layout.alignment: Qt.AlignRight
99 font.pointSize: JamiTheme.menuFontSize
100 text: qsTr("Informations")
101 }
102
103 Item { Layout.fillWidth: true }
104
105 Text {
106 Layout.alignment: Qt.AlignRight
107 font.pointSize: JamiTheme.textFontSize
108 text: qsTr("Username")
Sébastien Blin2d738d02020-08-07 12:10:26 -0400109 visible: registeredNameText ? (registeredNameText === idText ? false : true) : false
ababidf651a22020-07-30 13:38:57 +0200110 color: JamiTheme.faddedFontColor
111 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400112
113 /*
114 * Visible when user name is not empty or equals to alias.
115 */
116 Text {
117 id: contactDisplayName
118
ababidf651a22020-07-30 13:38:57 +0200119 Layout.alignment: Qt.AlignLeft
Sébastien Blin1f915762020-08-03 13:27:42 -0400120
ababidf651a22020-07-30 13:38:57 +0200121 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400122 text: textMetricsContactDisplayNameText.elidedText
Sébastien Blin2d738d02020-08-07 12:10:26 -0400123 visible: registeredNameText ? (registeredNameText === idText ? false : true) : false
Sébastien Blin1f915762020-08-03 13:27:42 -0400124
125 TextMetrics {
126 id: textMetricsContactDisplayNameText
127 font: contactDisplayName.font
128 text: registeredNameText
ababidf651a22020-07-30 13:38:57 +0200129 elideWidth: userProfileDialog.width-160
Sébastien Blin1f915762020-08-03 13:27:42 -0400130 elide: Qt.ElideMiddle
131 }
132 }
133
ababidf651a22020-07-30 13:38:57 +0200134 Text {
135 Layout.alignment: Qt.AlignRight
136 font.pointSize: JamiTheme.textFontSize
137 text: qsTr("ID")
138 color: JamiTheme.faddedFontColor
139 }
140
Sébastien Blin1f915762020-08-03 13:27:42 -0400141 TextEdit {
142 id: contactId
143
ababidf651a22020-07-30 13:38:57 +0200144 Layout.alignment: Qt.AlignLeft
Sébastien Blin1f915762020-08-03 13:27:42 -0400145
146 selectByMouse: true
147 readOnly: true
ababidf651a22020-07-30 13:38:57 +0200148 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400149 text: textMetricsContactIdText.elidedText
150
151 TextMetrics {
152 id: textMetricsContactIdText
153 font: contactId.font
154 text: idText
ababidf651a22020-07-30 13:38:57 +0200155 elideWidth: userProfileDialog.width-160
Sébastien Blin1f915762020-08-03 13:27:42 -0400156 elide: Qt.ElideMiddle
157 }
158 }
159
ababidf651a22020-07-30 13:38:57 +0200160 Text {
161 Layout.alignment: Qt.AlignRight
162 font.pointSize: JamiTheme.textFontSize
163 text: qsTr("QR Code")
164 color: JamiTheme.faddedFontColor
165 }
166
Sébastien Blin1f915762020-08-03 13:27:42 -0400167 Image {
168 id: contactQrImage
169
ababidf651a22020-07-30 13:38:57 +0200170 Layout.alignment: Qt.AlignBottom | Qt.AlignLeft
Sébastien Blin1f915762020-08-03 13:27:42 -0400171
172 fillMode: Image.PreserveAspectFit
ababidf651a22020-07-30 13:38:57 +0200173 sourceSize.width: preferredImgSize
174 sourceSize.height: preferredImgSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400175 mipmap: true
176 }
ababidf651a22020-07-30 13:38:57 +0200177
178 Item { height: 20 }
179
Sébastien Blin1f915762020-08-03 13:27:42 -0400180 }
181
182 background: Rectangle {
183 border.width: 0
184 radius: 10
185 }
186
187 onClosed: {
188 contactId.deselect()
189 fakeFocusTextEdit.focus = true
190 }
191
192 onResponsibleConvUidChanged: {
193 if (responsibleConvUid !== "")
194 contactQrImage.source = "image://qrImage/contact_" + responsibleConvUid
195 }
196
197 onContactPicBase64Changed: {
198 if (contactPicBase64 !== "")
199 contactImage.source = "data:image/png;base64," + contactPicBase64
200 }
201}