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.Window 2.14 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import QtQuick.Layouts 1.14 |
| 23 | import QtQuick.Controls.Universal 2.12 |
| 24 | import net.jami.Models 1.0 |
| 25 | |
| 26 | import "../../commoncomponents" |
| 27 | |
| 28 | |
| 29 | /* |
| 30 | * IncomingCallPage as a seperate window, |
| 31 | * exist at the right bottom, as a notification to user that |
| 32 | * a call is incoming. |
| 33 | */ |
| 34 | Window { |
| 35 | id: incomingCallPage |
| 36 | |
| 37 | property int minWidth: 300 |
| 38 | property int minHeight: 400 |
| 39 | |
| 40 | |
| 41 | /* |
| 42 | * The unique identifier for incomingCallPage |
| 43 | */ |
| 44 | property string responsibleAccountId: "" |
| 45 | property string responsibleConvUid: "" |
| 46 | |
| 47 | property string contactImgSource: "" |
| 48 | property string bestName: "Best Name" |
| 49 | property string bestId: "Best Id" |
| 50 | |
| 51 | property int buttonPreferredSize: 50 |
| 52 | property variant clickPos: "1,1" |
| 53 | |
| 54 | function updateUI() { |
| 55 | incomingCallPage.contactImgSource = "data:image/png;base64," |
| 56 | + ClientWrapper.utilsAdaptor.getContactImageString(responsibleAccountId, |
| 57 | responsibleConvUid) |
| 58 | incomingCallPage.bestName = ClientWrapper.utilsAdaptor.getBestName( |
| 59 | responsibleAccountId, responsibleConvUid) |
| 60 | var id = ClientWrapper.utilsAdaptor.getBestId(responsibleAccountId, |
| 61 | responsibleConvUid) |
| 62 | incomingCallPage.bestId = (incomingCallPage.bestName !== id) ? id : "" |
| 63 | } |
| 64 | |
| 65 | function updatePositionToRightBottom() { |
| 66 | |
| 67 | |
| 68 | /* |
| 69 | * Screen right bottom, |
| 70 | * since the qt screen.virtualY, virtualX does not work properly, |
| 71 | * we need to calculate the screen x, y ourselves, by |
| 72 | * using to fact that window will always be in the middle if no x or y |
| 73 | * specificed. |
| 74 | * ex: https://doc.qt.io/qt-5/qscreen.html#geometry-prop |
| 75 | */ |
| 76 | var virtualX = (incomingCallPage.x + width / 2) - screen.width / 2 |
| 77 | incomingCallPage.x = virtualX + screen.width - width |
| 78 | incomingCallPage.y = screen.height - height - 50 |
| 79 | } |
| 80 | |
| 81 | minimumWidth: minWidth |
| 82 | minimumHeight: minHeight |
| 83 | |
| 84 | maximumWidth: minWidth + 300 |
| 85 | maximumHeight: minHeight + 300 |
| 86 | |
| 87 | flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint |
| 88 | screen: Qt.application.screens[0] |
| 89 | |
| 90 | Rectangle { |
| 91 | id: incomingCallPageColumnLayoutMainRect |
| 92 | |
| 93 | anchors.fill: parent |
| 94 | |
| 95 | radius: 15 |
| 96 | color: "black" |
| 97 | |
| 98 | |
| 99 | /* |
| 100 | * Simulate window drag. (top with height 30). |
| 101 | */ |
| 102 | MouseArea { |
| 103 | id: dragMouseArea |
| 104 | |
| 105 | anchors.left: incomingCallPageColumnLayoutMainRect.left |
| 106 | anchors.top: incomingCallPageColumnLayoutMainRect.top |
| 107 | |
| 108 | width: incomingCallPageColumnLayoutMainRect.width - closeButton.width - 10 |
| 109 | height: 30 |
| 110 | |
| 111 | onPressed: { |
| 112 | clickPos = Qt.point(mouse.x, mouse.y) |
| 113 | } |
| 114 | |
| 115 | onPositionChanged: { |
| 116 | var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y) |
| 117 | incomingCallPage.x += delta.x |
| 118 | incomingCallPage.y += delta.y |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | HoverableButton { |
| 123 | id: closeButton |
| 124 | |
| 125 | anchors.top: incomingCallPageColumnLayoutMainRect.top |
| 126 | anchors.topMargin: 10 |
| 127 | anchors.right: incomingCallPageColumnLayoutMainRect.right |
| 128 | anchors.rightMargin: 10 |
| 129 | |
| 130 | width: 30 |
| 131 | height: 30 |
| 132 | |
| 133 | radius: 30 |
| 134 | source: "qrc:/images/icons/ic_close_white_24dp.png" |
| 135 | backgroundColor: "black" |
| 136 | onEnterColor: JamiTheme.closeButtonLighterBlack |
| 137 | onExitColor: "black" |
| 138 | onPressColor: JamiTheme.declineButtonPressedRed |
| 139 | onReleaseColor: "black" |
| 140 | |
| 141 | onClicked: { |
| 142 | incomingCallPage.close() |
| 143 | CallAdapter.refuseACall(responsibleAccountId, |
| 144 | responsibleConvUid) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | ColumnLayout { |
| 149 | id: incomingCallPageColumnLayout |
| 150 | |
| 151 | anchors.fill: parent |
| 152 | |
| 153 | Image { |
| 154 | id: contactImg |
| 155 | |
| 156 | Layout.alignment: Qt.AlignCenter |
| 157 | Layout.topMargin: 30 |
| 158 | |
| 159 | Layout.preferredWidth: 100 |
| 160 | Layout.preferredHeight: 100 |
| 161 | |
| 162 | fillMode: Image.PreserveAspectFit |
| 163 | source: contactImgSource |
| 164 | } |
| 165 | |
| 166 | Rectangle { |
| 167 | id: incomingCallPageTextRect |
| 168 | |
| 169 | Layout.alignment: Qt.AlignCenter |
| 170 | Layout.topMargin: 5 |
| 171 | |
| 172 | Layout.preferredWidth: incomingCallPage.width |
| 173 | Layout.preferredHeight: jamiBestNameText.height + jamiBestIdText.height |
| 174 | + talkToYouText.height + 20 |
| 175 | |
| 176 | ColumnLayout { |
| 177 | id: incomingCallPageTextRectColumnLayout |
| 178 | |
| 179 | Text { |
| 180 | id: jamiBestNameText |
| 181 | |
| 182 | Layout.alignment: Qt.AlignCenter |
| 183 | Layout.preferredWidth: incomingCallPageTextRect.width |
| 184 | Layout.preferredHeight: 50 |
| 185 | |
| 186 | font.pointSize: JamiTheme.textFontSize + 3 |
| 187 | |
| 188 | horizontalAlignment: Text.AlignHCenter |
| 189 | verticalAlignment: Text.AlignVCenter |
| 190 | |
| 191 | text: textMetricsjamiBestNameText.elidedText |
| 192 | color: "white" |
| 193 | |
| 194 | TextMetrics { |
| 195 | id: textMetricsjamiBestNameText |
| 196 | font: jamiBestNameText.font |
| 197 | text: bestName |
| 198 | elideWidth: incomingCallPageTextRect.width - 30 |
| 199 | elide: Qt.ElideMiddle |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | Text { |
| 204 | id: jamiBestIdText |
| 205 | |
| 206 | Layout.alignment: Qt.AlignCenter |
| 207 | Layout.preferredWidth: incomingCallPageTextRect.width |
| 208 | Layout.preferredHeight: 30 |
| 209 | |
| 210 | font.pointSize: JamiTheme.textFontSize |
| 211 | |
| 212 | horizontalAlignment: Text.AlignHCenter |
| 213 | verticalAlignment: Text.AlignVCenter |
| 214 | |
| 215 | text: textMetricsjamiBestIdText.elidedText |
| 216 | color: "white" |
| 217 | |
| 218 | TextMetrics { |
| 219 | id: textMetricsjamiBestIdText |
| 220 | font: jamiBestIdText.font |
| 221 | text: bestId |
| 222 | elideWidth: incomingCallPageTextRect.width - 30 |
| 223 | elide: Qt.ElideMiddle |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | Text { |
| 228 | id: talkToYouText |
| 229 | |
| 230 | Layout.alignment: Qt.AlignCenter |
| 231 | Layout.preferredWidth: incomingCallPageTextRect.width |
| 232 | Layout.preferredHeight: 30 |
| 233 | |
| 234 | font.pointSize: JamiTheme.textFontSize |
| 235 | |
| 236 | horizontalAlignment: Text.AlignHCenter |
| 237 | verticalAlignment: Text.AlignVCenter |
| 238 | color: "white" |
| 239 | |
| 240 | text: "is calling you" |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | color: "transparent" |
| 245 | } |
| 246 | |
| 247 | RowLayout { |
| 248 | id: incomingCallPageRowLayout |
| 249 | |
| 250 | Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom |
| 251 | Layout.bottomMargin: 5 |
| 252 | |
| 253 | Layout.preferredWidth: incomingCallPage.width - 100 |
| 254 | Layout.preferredHeight: buttonPreferredSize |
| 255 | |
| 256 | ColumnLayout { |
| 257 | id: callAnswerButtonColumnLayout |
| 258 | |
| 259 | Layout.alignment: Qt.AlignLeft |
| 260 | |
| 261 | HoverableButton { |
| 262 | id: callAnswerButton |
| 263 | |
| 264 | Layout.alignment: Qt.AlignCenter |
| 265 | |
| 266 | Layout.preferredWidth: buttonPreferredSize |
| 267 | Layout.preferredHeight: buttonPreferredSize |
| 268 | |
| 269 | backgroundColor: JamiTheme.acceptButtonGreen |
| 270 | onEnterColor: JamiTheme.acceptButtonHoverGreen |
| 271 | onPressColor: JamiTheme.acceptButtonPressedGreen |
| 272 | onReleaseColor: JamiTheme.acceptButtonHoverGreen |
| 273 | onExitColor: JamiTheme.acceptButtonGreen |
| 274 | |
| 275 | buttonImageHeight: buttonPreferredSize / 2 |
| 276 | buttonImageWidth: buttonPreferredSize / 2 |
| 277 | source: "qrc:/images/icons/ic_check_white_18dp_2x.png" |
| 278 | radius: 30 |
| 279 | |
| 280 | onClicked: { |
| 281 | incomingCallPage.close() |
| 282 | CallAdapter.acceptACall(responsibleAccountId, |
| 283 | responsibleConvUid) |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | Text { |
| 288 | id: answerText |
| 289 | |
| 290 | Layout.alignment: Qt.AlignCenter |
| 291 | |
| 292 | font.pointSize: JamiTheme.textFontSize - 2 |
| 293 | text: qsTr("Answer") |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | ColumnLayout { |
| 298 | id: callDeclineButtonColumnLayout |
| 299 | |
| 300 | Layout.alignment: Qt.AlignRight |
| 301 | |
| 302 | HoverableButton { |
| 303 | id: callDeclineButton |
| 304 | |
| 305 | Layout.alignment: Qt.AlignCenter |
| 306 | |
| 307 | Layout.preferredWidth: buttonPreferredSize |
| 308 | Layout.preferredHeight: buttonPreferredSize |
| 309 | |
| 310 | backgroundColor: JamiTheme.declineButtonRed |
| 311 | onEnterColor: JamiTheme.declineButtonHoverRed |
| 312 | onPressColor: JamiTheme.declineButtonPressedRed |
| 313 | onReleaseColor: JamiTheme.declineButtonHoverRed |
| 314 | onExitColor: JamiTheme.declineButtonRed |
| 315 | |
| 316 | buttonImageHeight: buttonPreferredSize / 2 |
| 317 | buttonImageWidth: buttonPreferredSize / 2 |
| 318 | source: "qrc:/images/icons/ic_close_white_24dp.png" |
| 319 | radius: 30 |
| 320 | |
| 321 | onClicked: { |
| 322 | incomingCallPage.close() |
| 323 | CallAdapter.refuseACall(responsibleAccountId, |
| 324 | responsibleConvUid) |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | Text { |
| 329 | id: ignoreText |
| 330 | |
| 331 | Layout.alignment: Qt.AlignCenter |
| 332 | |
| 333 | font.pointSize: JamiTheme.textFontSize - 2 |
| 334 | text: qsTr("Ignore") |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | color: "transparent" |
| 342 | } |