Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | |
| 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 | */ |
| 19 | import QtQuick 2.14 |
| 20 | import QtQuick.Controls 2.14 |
| 21 | import QtQuick.Layouts 1.14 |
| 22 | import net.jami.Models 1.0 |
| 23 | |
| 24 | import "../../commoncomponents" |
| 25 | |
| 26 | Dialog { |
| 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 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 35 | property int preferredImgSize: 80 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 36 | modal: true |
| 37 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 38 | /* |
| 39 | * Content height + margin. |
| 40 | */ |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 41 | contentHeight: userProfileDialogLayout.implicitHeight + 60 |
| 42 | contentWidth: userProfileDialogLayout.implicitWidth + 60 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Fake focus to make sure that text edit lose focus on close. |
| 46 | */ |
| 47 | FocusScope { |
| 48 | id: fakeFocusTextEdit |
| 49 | } |
| 50 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 51 | contentItem: GridLayout { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 52 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 53 | id: userProfileDialogLayout |
| 54 | columns: 2 |
| 55 | rowSpacing: 10 |
| 56 | columnSpacing: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 57 | |
| 58 | Image { |
| 59 | id: contactImage |
| 60 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 61 | Layout.alignment: Qt.AlignRight |
| 62 | Layout.preferredWidth: 130 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 63 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 64 | sourceSize.width: preferredImgSize |
| 65 | sourceSize.height: preferredImgSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 66 | |
| 67 | fillMode: Image.PreserveAspectFit |
| 68 | mipmap: true |
| 69 | } |
| 70 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 71 | /* |
| 72 | * Visible when user alias is not empty or equals to id. |
| 73 | */ |
| 74 | Text { |
| 75 | id: contactAlias |
| 76 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 77 | Layout.alignment: Qt.AlignLeft |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 78 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 79 | font.pointSize: JamiTheme.titleFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 80 | text: textMetricsContactAliasText.elidedText |
| 81 | visible: aliasText ? (aliasText === idText ? false : true) : false |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 82 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 83 | TextMetrics { |
| 84 | id: textMetricsContactAliasText |
| 85 | font: contactAlias.font |
| 86 | text: aliasText |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 87 | elideWidth: userProfileDialog.width-160 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 88 | elide: Qt.ElideMiddle |
| 89 | } |
| 90 | } |
| 91 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 92 | 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") |
| 109 | visible: registeredNameText ? (registeredNameText === aliasText ? false : true) : false |
| 110 | color: JamiTheme.faddedFontColor |
| 111 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Visible when user name is not empty or equals to alias. |
| 115 | */ |
| 116 | Text { |
| 117 | id: contactDisplayName |
| 118 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 119 | Layout.alignment: Qt.AlignLeft |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 120 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 121 | font.pointSize: JamiTheme.textFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 122 | text: textMetricsContactDisplayNameText.elidedText |
| 123 | visible: registeredNameText ? (registeredNameText === aliasText ? false : true) : false |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 124 | |
| 125 | TextMetrics { |
| 126 | id: textMetricsContactDisplayNameText |
| 127 | font: contactDisplayName.font |
| 128 | text: registeredNameText |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 129 | elideWidth: userProfileDialog.width-160 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 130 | elide: Qt.ElideMiddle |
| 131 | } |
| 132 | } |
| 133 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 134 | Text { |
| 135 | Layout.alignment: Qt.AlignRight |
| 136 | font.pointSize: JamiTheme.textFontSize |
| 137 | text: qsTr("ID") |
| 138 | color: JamiTheme.faddedFontColor |
| 139 | } |
| 140 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 141 | TextEdit { |
| 142 | id: contactId |
| 143 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 144 | Layout.alignment: Qt.AlignLeft |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 145 | |
| 146 | selectByMouse: true |
| 147 | readOnly: true |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 148 | font.pointSize: JamiTheme.textFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 149 | text: textMetricsContactIdText.elidedText |
| 150 | |
| 151 | TextMetrics { |
| 152 | id: textMetricsContactIdText |
| 153 | font: contactId.font |
| 154 | text: idText |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 155 | elideWidth: userProfileDialog.width-160 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 156 | elide: Qt.ElideMiddle |
| 157 | } |
| 158 | } |
| 159 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 160 | Text { |
| 161 | Layout.alignment: Qt.AlignRight |
| 162 | font.pointSize: JamiTheme.textFontSize |
| 163 | text: qsTr("QR Code") |
| 164 | color: JamiTheme.faddedFontColor |
| 165 | } |
| 166 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 167 | Image { |
| 168 | id: contactQrImage |
| 169 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 170 | Layout.alignment: Qt.AlignBottom | Qt.AlignLeft |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 171 | |
| 172 | fillMode: Image.PreserveAspectFit |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 173 | sourceSize.width: preferredImgSize |
| 174 | sourceSize.height: preferredImgSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 175 | mipmap: true |
| 176 | } |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame^] | 177 | |
| 178 | Item { height: 20 } |
| 179 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 180 | } |
| 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 | } |