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> |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 5 | * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | import QtQuick 2.14 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import QtQuick.Layouts 1.14 |
| 23 | import QtQuick.Controls.Universal 2.12 |
| 24 | import QtGraphicalEffects 1.14 |
| 25 | import net.jami.Models 1.0 |
| 26 | |
| 27 | import "../../commoncomponents" |
| 28 | |
| 29 | Rectangle { |
| 30 | id: videoCallPageRect |
| 31 | |
| 32 | property string bestName: "Best Name" |
| 33 | property string bestId: "Best Id" |
| 34 | property variant clickPos: "1,1" |
| 35 | property int previewMargin: 15 |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 36 | property int previewMarginY: previewMargin + 56 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 37 | property int previewToX: 0 |
| 38 | property int previewToY: 0 |
| 39 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 40 | property var linkedWebview: null |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 41 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 42 | signal needToShowInFullScreen |
| 43 | |
| 44 | function updateUI(accountId, convUid) { |
Sébastien Blin | 6607e0e | 2020-07-24 15:15:47 -0400 | [diff] [blame] | 45 | videoCallOverlay.handleParticipantsInfo(CallAdapter.getConferencesInfos()) |
| 46 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 47 | bestName = ClientWrapper.utilsAdaptor.getBestName(accountId, convUid) |
| 48 | |
| 49 | var id = ClientWrapper.utilsAdaptor.getBestId(accountId, convUid) |
| 50 | bestId = (bestName !== id) ? id : "" |
| 51 | } |
| 52 | |
| 53 | function setDistantRendererId(id) { |
| 54 | distantRenderer.setRendererId(id) |
| 55 | } |
| 56 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 57 | function setLinkedWebview(webViewId) { |
| 58 | linkedWebview = webViewId |
| 59 | linkedWebview.needToHideConversationInCall.disconnect( |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 60 | closeInCallConversation) |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 61 | linkedWebview.needToHideConversationInCall.connect( |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 62 | closeInCallConversation) |
| 63 | } |
| 64 | |
| 65 | function closeInCallConversation() { |
| 66 | if (inVideoCallMessageWebViewStack.visible) { |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 67 | linkedWebview.resetMessagingHeaderBackButtonSource( |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 68 | true) |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 69 | linkedWebview.setMessagingHeaderButtonsVisible(true) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 70 | inVideoCallMessageWebViewStack.visible = false |
| 71 | inVideoCallMessageWebViewStack.clear() |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | function closeContextMenuAndRelatedWindows() { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 76 | videoCallOverlay.closePotentialContactPicker() |
| 77 | } |
| 78 | |
Sébastien Blin | 6607e0e | 2020-07-24 15:15:47 -0400 | [diff] [blame] | 79 | function handleParticipantsInfo(infos) { |
| 80 | if (infos.length === 0) { |
| 81 | bestName = ClientWrapper.utilsAdaptor.getBestName(accountId, convUid) |
| 82 | } else { |
| 83 | bestName = "" |
| 84 | } |
| 85 | videoCallOverlay.handleParticipantsInfo(infos) |
| 86 | } |
| 87 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 88 | function previewMagneticSnap() { |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * Calculate the position where the previewRenderer should attach to. |
| 93 | */ |
| 94 | var previewRendererCenter = Qt.point( |
| 95 | previewRenderer.x + previewRenderer.width / 2, |
| 96 | previewRenderer.y + previewRenderer.height / 2) |
| 97 | var distantRendererCenter = Qt.point( |
| 98 | distantRenderer.x + distantRenderer.width / 2, |
| 99 | distantRenderer.y + distantRenderer.height / 2) |
| 100 | |
| 101 | if (previewRendererCenter.x >= distantRendererCenter.x) { |
| 102 | if (previewRendererCenter.y >= distantRendererCenter.y) { |
| 103 | |
| 104 | |
| 105 | /* |
| 106 | * Bottom right. |
| 107 | */ |
| 108 | previewToX = Qt.binding(function () { |
| 109 | return videoCallPageMainRect.width - previewRenderer.width - previewMargin |
| 110 | }) |
| 111 | previewToY = Qt.binding(function () { |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 112 | return videoCallPageMainRect.height - previewRenderer.height - previewMarginY |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 113 | }) |
| 114 | } else { |
| 115 | |
| 116 | |
| 117 | /* |
| 118 | * Top right. |
| 119 | */ |
| 120 | previewToX = Qt.binding(function () { |
| 121 | return videoCallPageMainRect.width - previewRenderer.width - previewMargin |
| 122 | }) |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 123 | previewToY = previewMarginY |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 124 | } |
| 125 | } else { |
| 126 | if (previewRendererCenter.y >= distantRendererCenter.y) { |
| 127 | |
| 128 | |
| 129 | /* |
| 130 | * Bottom left. |
| 131 | */ |
| 132 | previewToX = previewMargin |
| 133 | previewToY = Qt.binding(function () { |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 134 | return videoCallPageMainRect.height - previewRenderer.height - previewMarginY |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 135 | }) |
| 136 | } else { |
| 137 | |
| 138 | |
| 139 | /* |
| 140 | * Top left. |
| 141 | */ |
| 142 | previewToX = previewMargin |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 143 | previewToY = previewMarginY |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | previewRenderer.state = "geoChanging" |
| 147 | } |
| 148 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 149 | anchors.fill: parent |
| 150 | |
| 151 | SplitView { |
| 152 | id: mainColumnLayout |
| 153 | |
| 154 | anchors.fill: parent |
| 155 | |
| 156 | orientation: Qt.Vertical |
| 157 | |
| 158 | handle: Rectangle { |
| 159 | implicitWidth: videoCallPageRect.width |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 160 | implicitHeight: JamiTheme.splitViewHandlePreferredWidth |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 161 | color: SplitHandle.pressed ? JamiTheme.pressColor : (SplitHandle.hovered ? JamiTheme.hoverColor : JamiTheme.tabbarBorderColor) |
| 162 | } |
| 163 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 164 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 165 | Rectangle { |
| 166 | id: videoCallPageMainRect |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 167 | SplitView.preferredHeight: (videoCallPageRect.height / 3) * 2 |
| 168 | SplitView.minimumHeight: videoCallPageRect.height / 2 + 20 |
| 169 | SplitView.fillWidth: true |
| 170 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 171 | MouseArea { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 172 | anchors.fill: parent |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 173 | hoverEnabled: true |
| 174 | propagateComposedEvents: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 175 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 176 | acceptedButtons: Qt.LeftButton |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 177 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 178 | onDoubleClicked: { |
| 179 | needToShowInFullScreen() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 182 | CallOverlay { |
| 183 | id: videoCallOverlay |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 184 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 185 | anchors.fill: parent |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 186 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 187 | Connections { |
| 188 | target: CallAdapter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 189 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 190 | function onUpdateTimeText(time) { |
| 191 | videoCallOverlay.timeText = time |
| 192 | videoCallOverlay.setRecording(CallAdapter.isRecordingThisCall()) |
| 193 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 194 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 195 | function onUpdateOverlay(isPaused, isAudioOnly, isAudioMuted, isVideoMuted, isRecording, isSIP, isConferenceCall, bestName) { |
| 196 | videoCallOverlay.showOnHoldImage(isPaused) |
| 197 | videoCallOverlay.updateButtonStatus(isPaused, |
| 198 | isAudioOnly, |
| 199 | isAudioMuted, |
| 200 | isVideoMuted, |
| 201 | isRecording, isSIP, |
| 202 | isConferenceCall) |
| 203 | videoCallPageRect.bestName = bestName |
| 204 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 205 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 206 | function onShowOnHoldLabel(isPaused) { |
| 207 | videoCallOverlay.showOnHoldImage(isPaused) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 208 | } |
| 209 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 210 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 211 | onOverlayChatButtonClicked: { |
| 212 | if (inVideoCallMessageWebViewStack.visible) { |
| 213 | linkedWebview.resetMessagingHeaderBackButtonSource( |
| 214 | true) |
| 215 | linkedWebview.setMessagingHeaderButtonsVisible( |
| 216 | true) |
| 217 | inVideoCallMessageWebViewStack.visible = false |
| 218 | inVideoCallMessageWebViewStack.clear() |
| 219 | } else { |
| 220 | linkedWebview.resetMessagingHeaderBackButtonSource( |
| 221 | false) |
| 222 | linkedWebview.setMessagingHeaderButtonsVisible( |
| 223 | false) |
| 224 | inVideoCallMessageWebViewStack.visible = true |
| 225 | inVideoCallMessageWebViewStack.push( |
| 226 | linkedWebview) |
| 227 | } |
| 228 | } |
| 229 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 230 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 231 | DistantRenderer { |
| 232 | id: distantRenderer |
| 233 | |
| 234 | anchors.centerIn: videoCallPageMainRect |
| 235 | z: -1 |
| 236 | |
| 237 | width: videoCallPageMainRect.width |
| 238 | height: videoCallPageMainRect.height |
Sébastien Blin | 6607e0e | 2020-07-24 15:15:47 -0400 | [diff] [blame] | 239 | |
| 240 | onOffsetChanged: { |
| 241 | videoCallOverlay.handleParticipantsInfo(CallAdapter.getConferencesInfos()) |
| 242 | } |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | VideoCallPreviewRenderer { |
| 246 | id: previewRenderer |
| 247 | |
| 248 | |
| 249 | /* |
| 250 | * Property is used in the {} expression for height (extra dependency), |
| 251 | * it will not affect the true height expression, since expression |
| 252 | * at last will be taken only, but it will force the height to update |
| 253 | * and reevaluate getPreviewImageScalingFactor(). |
| 254 | */ |
| 255 | property int previewImageScalingFactorUpdated: 0 |
| 256 | |
| 257 | Connections { |
| 258 | target: CallAdapter |
| 259 | |
| 260 | onPreviewVisibilityNeedToChange: previewRenderer.visible = visible |
| 261 | } |
| 262 | |
| 263 | width: videoCallPageMainRect.width / 4 |
| 264 | height: { |
| 265 | previewImageScalingFactorUpdated |
| 266 | return previewRenderer.width * previewRenderer.getPreviewImageScalingFactor() |
| 267 | } |
| 268 | x: videoCallPageMainRect.width - previewRenderer.width - previewMargin |
| 269 | y: videoCallPageMainRect.height - previewRenderer.height - previewMargin - 56 /* Avoid overlay */ |
| 270 | z: -1 |
| 271 | |
| 272 | states: [ |
| 273 | State { |
| 274 | name: "geoChanging" |
| 275 | PropertyChanges { |
| 276 | target: previewRenderer |
| 277 | x: previewToX |
| 278 | y: previewToY |
| 279 | } |
| 280 | } |
| 281 | ] |
| 282 | |
| 283 | transitions: Transition { |
| 284 | PropertyAnimation { |
| 285 | properties: "x,y" |
| 286 | easing.type: Easing.OutExpo |
| 287 | duration: 250 |
| 288 | |
| 289 | onStopped: { |
| 290 | previewRenderer.state = "" |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | MouseArea { |
| 296 | id: dragMouseArea |
| 297 | |
| 298 | anchors.fill: previewRenderer |
| 299 | |
| 300 | onPressed: { |
| 301 | clickPos = Qt.point(mouse.x, mouse.y) |
| 302 | } |
| 303 | |
| 304 | onReleased: { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 305 | previewRenderer.state = "" |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 306 | previewMagneticSnap() |
| 307 | } |
| 308 | |
| 309 | onPositionChanged: { |
| 310 | |
| 311 | |
| 312 | /* |
| 313 | * Calculate mouse position relative change. |
| 314 | */ |
| 315 | var delta = Qt.point(mouse.x - clickPos.x, |
| 316 | mouse.y - clickPos.y) |
| 317 | var deltaW = previewRenderer.x + delta.x + previewRenderer.width |
| 318 | var deltaH = previewRenderer.y + delta.y + previewRenderer.height |
| 319 | |
| 320 | |
| 321 | /* |
| 322 | * Check if the previewRenderer exceeds the border of videoCallPageMainRect. |
| 323 | */ |
| 324 | if (deltaW < videoCallPageMainRect.width |
| 325 | && previewRenderer.x + delta.x > 1) |
| 326 | previewRenderer.x += delta.x |
| 327 | if (deltaH < videoCallPageMainRect.height |
| 328 | && previewRenderer.y + delta.y > 1) |
| 329 | previewRenderer.y += delta.y |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 330 | } |
| 331 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 332 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 333 | onPreviewImageAvailable: { |
| 334 | previewImageScalingFactorUpdated++ |
| 335 | previewImageScalingFactorUpdated-- |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 336 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | color: "transparent" |
| 341 | } |
| 342 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 343 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 344 | StackView { |
| 345 | id: inVideoCallMessageWebViewStack |
| 346 | |
| 347 | SplitView.preferredHeight: videoCallPageRect.height / 3 |
| 348 | SplitView.fillWidth: true |
| 349 | |
| 350 | visible: false |
| 351 | |
| 352 | clip: true |
| 353 | } |
| 354 | } |
| 355 | |
Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 356 | onBestNameChanged: { |
| 357 | ContactAdapter.setCalleeDisplayName(bestName) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | color: "black" |
| 361 | } |