blob: 072d9a6eb2056932822911cec0360fa75ab857a3 [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
35 modal: true
36
37
38 /*
39 * Content height + margin.
40 */
41 contentHeight: userProfileDialogUpperPartColumnLayout.implicitHeight + 30
42
43
44 /*
45 * Fake focus to make sure that text edit lose focus on close.
46 */
47 FocusScope {
48 id: fakeFocusTextEdit
49 }
50
51 ColumnLayout {
52 id: userProfileDialogUpperPartColumnLayout
53
54 anchors.centerIn: parent
55
56 spacing: 15
57
58 Image {
59 id: contactImage
60
61 Layout.alignment: Qt.AlignCenter
62
63 width: 150
64 height: 150
65
66 fillMode: Image.PreserveAspectFit
67 mipmap: true
68 }
69
70
71 /*
72 * Visible when user alias is not empty or equals to id.
73 */
74 Text {
75 id: contactAlias
76
77 Layout.alignment: Qt.AlignCenter
78
79 font.pointSize: JamiTheme.textFontSize
80 text: textMetricsContactAliasText.elidedText
81 visible: aliasText ? (aliasText === idText ? false : true) : false
82 TextMetrics {
83 id: textMetricsContactAliasText
84 font: contactAlias.font
85 text: aliasText
86 elideWidth: userProfileDialog.width - 30
87 elide: Qt.ElideMiddle
88 }
89 }
90
91
92 /*
93 * Visible when user name is not empty or equals to alias.
94 */
95 Text {
96 id: contactDisplayName
97
98 Layout.alignment: Qt.AlignCenter
99
100 font.pointSize: JamiTheme.textFontSize - 1
101 text: textMetricsContactDisplayNameText.elidedText
102 visible: registeredNameText ? (registeredNameText === aliasText ? false : true) : false
103 color: JamiTheme.faddedFontColor
104
105 TextMetrics {
106 id: textMetricsContactDisplayNameText
107 font: contactDisplayName.font
108 text: registeredNameText
109 elideWidth: userProfileDialog.width - 30
110 elide: Qt.ElideMiddle
111 }
112 }
113
114 TextEdit {
115 id: contactId
116
117 Layout.alignment: Qt.AlignCenter
118
119 horizontalAlignment: Text.AlignHCenter
120 verticalAlignment: Text.AlignVCenter
121
122 selectByMouse: true
123 readOnly: true
124 font.pointSize: JamiTheme.textFontSize - 1
125 text: textMetricsContactIdText.elidedText
126
127 TextMetrics {
128 id: textMetricsContactIdText
129 font: contactId.font
130 text: idText
131 elideWidth: userProfileDialog.width - 30
132 elide: Qt.ElideMiddle
133 }
134 }
135
136 Image {
137 id: contactQrImage
138
139 Layout.alignment: Qt.AlignBottom | Qt.AlignCenter
140
141 width: 150
142 height: 150
143
144 fillMode: Image.PreserveAspectFit
145 sourceSize.width: 150
146 sourceSize.height: 150
147 mipmap: true
148 }
149 }
150
151 background: Rectangle {
152 border.width: 0
153 radius: 10
154 }
155
156 onClosed: {
157 contactId.deselect()
158 fakeFocusTextEdit.focus = true
159 }
160
161 onResponsibleConvUidChanged: {
162 if (responsibleConvUid !== "")
163 contactQrImage.source = "image://qrImage/contact_" + responsibleConvUid
164 }
165
166 onContactPicBase64Changed: {
167 if (contactPicBase64 !== "")
168 contactImage.source = "data:image/png;base64," + contactPicBase64
169 }
170}