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 | Rectangle { |
| 27 | id: messagingHeaderRect |
| 28 | |
| 29 | property int buttonPreferredSize: 30 |
| 30 | property string userAliasLabelText: "" |
| 31 | property string userUserNameLabelText: "" |
| 32 | property string backToWelcomeViewButtonSource: "qrc:/images/icons/ic_arrow_back_24px.svg" |
| 33 | property bool sendContactRequestButtonVisible: true |
| 34 | |
| 35 | signal backToWelcomeViewButtonClicked |
| 36 | signal needToHideConversationInCall |
| 37 | signal sendContactRequestButtonClicked |
| 38 | |
| 39 | function resetBackToWelcomeViewButtonSource(reset) { |
| 40 | backToWelcomeViewButtonSource = reset ? "qrc:/images/icons/ic_arrow_back_24px.svg" : "qrc:/images/icons/round-close-24px.svg" |
| 41 | } |
| 42 | |
| 43 | function toggleMessagingHeaderButtonsVisible(visible) { |
| 44 | startAAudioCallButton.visible = visible |
| 45 | startAVideoCallButton.visible = visible |
| 46 | } |
| 47 | |
| 48 | RowLayout { |
| 49 | id: messagingHeaderRectRowLayout |
| 50 | |
| 51 | anchors.fill: parent |
| 52 | |
| 53 | HoverableButton { |
| 54 | id: backToWelcomeViewButton |
| 55 | |
| 56 | Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft |
| 57 | Layout.leftMargin: 10 |
| 58 | Layout.preferredWidth: buttonPreferredSize |
| 59 | Layout.preferredHeight: buttonPreferredSize |
| 60 | |
| 61 | radius: 30 |
| 62 | source: backToWelcomeViewButtonSource |
| 63 | backgroundColor: "white" |
| 64 | onExitColor: "white" |
| 65 | |
| 66 | onClicked: { |
| 67 | if (backToWelcomeViewButtonSource === "qrc:/images/icons/ic_arrow_back_24px.svg") |
| 68 | messagingHeaderRect.backToWelcomeViewButtonClicked() |
| 69 | else |
| 70 | messagingHeaderRect.needToHideConversationInCall() |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | Rectangle { |
| 75 | id: userNameOrIdRect |
| 76 | |
| 77 | Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft |
| 78 | |
| 79 | |
| 80 | /* |
| 81 | * Width + margin. |
| 82 | */ |
| 83 | Layout.preferredWidth: messagingHeaderRect.width |
| 84 | - backToWelcomeViewButton.width - buttonGroup.width - 45 |
| 85 | Layout.preferredHeight: messagingHeaderRect.height |
| 86 | Layout.leftMargin: 10 |
| 87 | |
| 88 | color: "transparent" |
| 89 | |
| 90 | ColumnLayout { |
| 91 | id: userNameOrIdColumnLayout |
| 92 | |
| 93 | Label { |
| 94 | id: userAliasLabel |
| 95 | |
| 96 | Layout.alignment: Qt.AlignVCenter |
| 97 | Layout.preferredWidth: userNameOrIdRect.width |
| 98 | Layout.preferredHeight: textMetricsuserAliasLabel.boundingRect.height |
| 99 | Layout.topMargin: userNameOrIdRect.height / 2 - userAliasLabel.height - 4 |
| 100 | |
| 101 | font.pointSize: JamiTheme.textFontSize - 1 |
| 102 | |
| 103 | horizontalAlignment: Text.AlignLeft |
| 104 | verticalAlignment: Text.AlignVCenter |
| 105 | |
| 106 | text: textMetricsuserAliasLabel.elidedText |
| 107 | } |
| 108 | |
| 109 | TextMetrics { |
| 110 | id: textMetricsuserAliasLabel |
| 111 | |
| 112 | font: userAliasLabel.font |
| 113 | text: userAliasLabelText |
| 114 | elideWidth: userNameOrIdRect.width |
| 115 | elide: Qt.ElideMiddle |
| 116 | } |
| 117 | |
| 118 | Label { |
| 119 | id: userUserNameLabel |
| 120 | |
| 121 | Layout.alignment: Qt.AlignVCenter |
| 122 | Layout.preferredWidth: userNameOrIdRect.width |
| 123 | Layout.preferredHeight: textMetricsuserUserNameLabel.boundingRect.height |
| 124 | |
| 125 | font.pointSize: JamiTheme.textFontSize - 2 |
| 126 | color: JamiTheme.faddedFontColor |
| 127 | |
| 128 | horizontalAlignment: Text.AlignLeft |
| 129 | verticalAlignment: Text.AlignVCenter |
| 130 | |
| 131 | text: textMetricsuserUserNameLabel.elidedText |
| 132 | } |
| 133 | |
| 134 | TextMetrics { |
| 135 | id: textMetricsuserUserNameLabel |
| 136 | |
| 137 | font: userUserNameLabel.font |
| 138 | text: userUserNameLabelText |
| 139 | elideWidth: userNameOrIdRect.width |
| 140 | elide: Qt.ElideMiddle |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | Rectangle { |
| 146 | id: buttonGroup |
| 147 | |
| 148 | Layout.alignment: Qt.AlignRight | Qt.AlignVCenter |
| 149 | Layout.preferredWidth: buttonPreferredSize * 3 + 18 |
| 150 | Layout.preferredHeight: buttonPreferredSize |
| 151 | Layout.rightMargin: 20 |
| 152 | |
| 153 | color: "transparent" |
| 154 | |
| 155 | HoverableButton { |
| 156 | id: startAAudioCallButton |
| 157 | |
| 158 | anchors.right: startAVideoCallButton.left |
| 159 | anchors.verticalCenter: buttonGroup.verticalCenter |
| 160 | |
| 161 | height: buttonPreferredSize |
| 162 | width: buttonPreferredSize |
| 163 | |
| 164 | radius: 30 |
| 165 | source: "qrc:/images/icons/ic_phone_24px.svg" |
| 166 | backgroundColor: "white" |
| 167 | onExitColor: "white" |
| 168 | |
| 169 | onClicked: { |
| 170 | messagingHeaderRect.sendContactRequestButtonClicked() |
| 171 | CallAdapter.placeAudioOnlyCall() |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | HoverableButton { |
| 176 | id: startAVideoCallButton |
| 177 | |
| 178 | anchors.right: sendContactRequestButton.left |
| 179 | anchors.leftMargin: 5 |
| 180 | anchors.verticalCenter: buttonGroup.verticalCenter |
| 181 | |
| 182 | height: buttonPreferredSize |
| 183 | width: buttonPreferredSize |
| 184 | |
| 185 | radius: 30 |
| 186 | source: "qrc:/images/icons/ic_video_call_24px.svg" |
| 187 | backgroundColor: "white" |
| 188 | onExitColor: "white" |
| 189 | |
| 190 | onClicked: { |
| 191 | messagingHeaderRect.sendContactRequestButtonClicked() |
| 192 | CallAdapter.placeCall() |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | HoverableButton { |
| 197 | id: sendContactRequestButton |
| 198 | |
| 199 | anchors.leftMargin: 5 |
| 200 | anchors.right: buttonGroup.right |
| 201 | anchors.rightMargin: 8 |
| 202 | anchors.verticalCenter: buttonGroup.verticalCenter |
| 203 | |
| 204 | height: buttonPreferredSize |
| 205 | width: buttonPreferredSize |
| 206 | |
| 207 | visible: sendContactRequestButtonVisible |
| 208 | radius: 30 |
| 209 | source: "qrc:/images/icons/ic_person_add_black_24dp_2x.png" |
| 210 | backgroundColor: "white" |
| 211 | onExitColor: "white" |
| 212 | |
| 213 | onClicked: { |
| 214 | messagingHeaderRect.sendContactRequestButtonClicked() |
| 215 | sendContactRequestButtonVisible = false |
| 216 | } |
| 217 | |
| 218 | onVisibleChanged: { |
| 219 | if (sendContactRequestButton.visible) { |
| 220 | sendContactRequestButton.width = buttonPreferredSize |
| 221 | } else { |
| 222 | sendContactRequestButton.width = 0 |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | CustomBorder { |
| 230 | commonBorder: false |
| 231 | lBorderwidth: 0 |
| 232 | rBorderwidth: 0 |
| 233 | tBorderwidth: 0 |
| 234 | bBorderwidth: 1 |
| 235 | borderColor: JamiTheme.tabbarBorderColor |
| 236 | } |
| 237 | } |