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 | ComboBox { |
| 27 | id: accountComboBox |
| 28 | |
| 29 | signal accountChanged(int index) |
| 30 | signal needToBackToWelcomePage(int index) |
| 31 | signal needToUpdateSmartList(string accountId) |
| 32 | signal newAccountButtonClicked |
| 33 | signal settingBtnClicked |
| 34 | |
| 35 | currentIndex: 0 |
| 36 | |
| 37 | function backToWelcomePage(index) { |
| 38 | accountComboBox.needToBackToWelcomePage(index) |
| 39 | } |
| 40 | |
| 41 | function updateSmartList(accountId) { |
| 42 | accountComboBox.needToUpdateSmartList(accountId) |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * Refresh every item in accountListModel. |
| 48 | */ |
| 49 | function updateAccountListModel() { |
| 50 | accountListModel.dataChanged(accountListModel.index(0, 0), |
| 51 | accountListModel.index( |
| 52 | accountListModel.rowCount() - 1, 0)) |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * Reset accountListModel. |
| 58 | */ |
| 59 | function resetAccountListModel() { |
| 60 | accountListModel.reset() |
| 61 | } |
| 62 | |
| 63 | Image { |
| 64 | id: userImageRoot |
| 65 | |
| 66 | anchors.left: accountComboBox.left |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 67 | anchors.leftMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 68 | anchors.verticalCenter: accountComboBox.verticalCenter |
| 69 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 70 | width: 30 |
| 71 | height: 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 72 | |
| 73 | fillMode: Image.PreserveAspectFit |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | * Base 64 format |
| 78 | */ |
| 79 | source: { |
| 80 | if (currentIndex !== -1) |
| 81 | return "data:image/png;base64," + accountListModel.data( |
| 82 | accountListModel.index( |
| 83 | accountComboBox.currentIndex, 0), 259) |
| 84 | else |
| 85 | return source |
| 86 | } |
| 87 | mipmap: true |
| 88 | |
| 89 | Rectangle { |
| 90 | id: presenseRect |
| 91 | |
| 92 | anchors.right: userImageRoot.right |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 93 | anchors.rightMargin: -2 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 94 | anchors.bottom: userImageRoot.bottom |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 95 | anchors.bottomMargin: -2 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 96 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 97 | width: 12 |
| 98 | height: 12 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 99 | |
| 100 | |
| 101 | /* |
| 102 | * Visible when account is registered, enum REGISTERED == 5. |
| 103 | */ |
| 104 | visible: { |
| 105 | if (currentIndex !== -1) |
| 106 | return accountListModel.data( |
| 107 | accountListModel.index( |
| 108 | accountComboBox.currentIndex, 0), 261) === 5 |
| 109 | else |
| 110 | return visible |
| 111 | } |
| 112 | |
| 113 | Rectangle { |
| 114 | id: presenseCycle |
| 115 | |
| 116 | anchors.centerIn: presenseRect |
| 117 | |
| 118 | width: 10 |
| 119 | height: 10 |
| 120 | |
| 121 | radius: 30 |
| 122 | color: JamiTheme.presenceGreen |
| 123 | } |
| 124 | |
| 125 | radius: 30 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 126 | color: JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | Text { |
| 131 | id: textUserAliasRoot |
| 132 | |
| 133 | anchors.left: userImageRoot.right |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 134 | anchors.leftMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 135 | anchors.top: rootItemBackground.top |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 136 | anchors.topMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 137 | |
| 138 | text: textMetricsUserAliasRoot.elidedText |
| 139 | font.pointSize: JamiTheme.textFontSize |
| 140 | } |
| 141 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 142 | Image { |
Ming Rui Zhang | c6b3369 | 2020-08-25 15:47:20 -0400 | [diff] [blame] | 143 | id: arrowDropDown |
| 144 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 145 | anchors.left: textUserAliasRoot.right |
| 146 | anchors.verticalCenter: textUserAliasRoot.verticalCenter |
| 147 | |
| 148 | width: 24 |
| 149 | height: 24 |
| 150 | |
| 151 | fillMode: Image.PreserveAspectFit |
| 152 | mipmap: true |
| 153 | source: "qrc:/images/icons/round-arrow_drop_down-24px.svg" |
| 154 | } |
| 155 | |
| 156 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 157 | Text { |
| 158 | id: textUsernameRoot |
| 159 | |
| 160 | anchors.left: userImageRoot.right |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 161 | anchors.leftMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 162 | anchors.top: textUserAliasRoot.bottom |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 163 | |
| 164 | text: textMetricsUsernameRoot.elidedText |
| 165 | font.pointSize: JamiTheme.textFontSize |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 166 | color: JamiTheme.faddedLastInteractionFontColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | TextMetrics { |
| 170 | id: textMetricsUserAliasRoot |
| 171 | |
| 172 | font: textUserAliasRoot.font |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 173 | elide: Text.ElideRight |
Ming Rui Zhang | c6b3369 | 2020-08-25 15:47:20 -0400 | [diff] [blame] | 174 | elideWidth: accountComboBox.width - userImageRoot.width - settingsButton.width |
| 175 | - arrowDropDown.width - qrCodeGenerateButton.width - 55 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 176 | |
| 177 | |
| 178 | /* |
| 179 | * Role::Alias |
| 180 | */ |
| 181 | text: { |
| 182 | if (currentIndex !== -1) |
| 183 | return accountListModel.data(accountListModel.index( |
| 184 | accountComboBox.currentIndex, |
| 185 | 0), 257) |
| 186 | else |
| 187 | return text |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | TextMetrics { |
| 192 | id: textMetricsUsernameRoot |
| 193 | |
| 194 | font: textUsernameRoot.font |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 195 | elide: Text.ElideRight |
Ming Rui Zhang | c6b3369 | 2020-08-25 15:47:20 -0400 | [diff] [blame] | 196 | elideWidth: accountComboBox.width - userImageRoot.width - settingsButton.width |
| 197 | - qrCodeGenerateButton.width - 55 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 198 | |
| 199 | |
| 200 | /* |
| 201 | * Role::Username |
| 202 | */ |
| 203 | text: { |
| 204 | if (currentIndex !== -1) |
| 205 | return accountListModel.data(accountListModel.index( |
| 206 | accountComboBox.currentIndex, |
| 207 | 0), 258) |
| 208 | else |
| 209 | return text |
| 210 | } |
| 211 | } |
| 212 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 213 | |
| 214 | |
| 215 | HoverableButton { |
| 216 | id: qrCodeGenerateButton |
| 217 | |
| 218 | anchors.right: settingsButton.left |
| 219 | anchors.rightMargin: 10 |
| 220 | anchors.verticalCenter: accountComboBox.verticalCenter |
| 221 | |
| 222 | buttonImageHeight: height - 8 |
| 223 | buttonImageWidth: width - 8 |
| 224 | radius: height / 2 |
| 225 | width: 24 |
| 226 | height: 24 |
| 227 | |
Yang Wang | b97bde4 | 2020-08-07 11:24:18 -0400 | [diff] [blame] | 228 | toolTipText: qsTr("Press to display QR code") |
| 229 | hoverEnabled: true |
| 230 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 231 | source: "qrc:/images/qrcode.png" |
| 232 | backgroundColor: "white" |
| 233 | onClicked: { |
| 234 | qrDialog.open() |
| 235 | } |
| 236 | } |
| 237 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 238 | HoverableButton { |
| 239 | id: settingsButton |
| 240 | |
| 241 | anchors.right: accountComboBox.right |
| 242 | anchors.rightMargin: 10 |
| 243 | anchors.verticalCenter: accountComboBox.verticalCenter |
| 244 | |
| 245 | buttonImageHeight: height - 8 |
| 246 | buttonImageWidth: width - 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 247 | radius: height / 2 |
| 248 | width: 25 |
| 249 | height: 25 |
| 250 | |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 251 | source: !mainViewWindow.inSettingsView ? "qrc:/images/icons/round-settings-24px.svg" : |
| 252 | "qrc:/images/icons/round-close-24px.svg" |
Yang Wang | b97bde4 | 2020-08-07 11:24:18 -0400 | [diff] [blame] | 253 | toolTipText: !mainViewWindow.inSettingsView ?qsTr("Press to toggle to settings page") : qsTr("Press to toggle to call page") |
| 254 | hoverEnabled: true |
| 255 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 256 | backgroundColor: "white" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 257 | onClicked: { |
| 258 | settingBtnClicked() |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | background: Rectangle { |
| 263 | id: rootItemBackground |
| 264 | |
| 265 | implicitWidth: accountComboBox.width |
| 266 | implicitHeight: accountComboBox.height |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 267 | color: JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | MouseArea { |
| 271 | id: comboBoxRootMouseArea |
| 272 | |
| 273 | anchors.fill: parent |
| 274 | |
| 275 | hoverEnabled: true |
| 276 | propagateComposedEvents: true |
| 277 | |
| 278 | onPressed: { |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 279 | if (isMouseOnButton(mouse, qrCodeGenerateButton)) { |
| 280 | qrCodeGenerateButton.backgroundColor = JamiTheme.pressColor |
| 281 | qrCodeGenerateButton.clicked() |
| 282 | }if (isMouseOnButton(mouse, settingsButton)) { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 283 | settingsButton.backgroundColor = JamiTheme.pressColor |
| 284 | settingsButton.clicked() |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 285 | } else { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 286 | rootItemBackground.color = JamiTheme.pressColor |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 287 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 288 | } |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 289 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 290 | onReleased: { |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 291 | if (isMouseOnButton(mouse, qrCodeGenerateButton)) { |
| 292 | qrCodeGenerateButton.backgroundColor = JamiTheme.releaseColor |
| 293 | } else if (isMouseOnButton(mouse, settingsButton)) { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 294 | settingsButton.backgroundColor = JamiTheme.releaseColor |
| 295 | } else { |
| 296 | rootItemBackground.color = JamiTheme.releaseColor |
| 297 | if (comboBoxPopup.opened) { |
| 298 | accountComboBox.popup.close() |
| 299 | } else { |
| 300 | accountComboBox.popup.open() |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | onEntered: { |
| 305 | rootItemBackground.color = JamiTheme.hoverColor |
| 306 | } |
| 307 | onExited: { |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 308 | rootItemBackground.color = JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 309 | } |
| 310 | onMouseXChanged: { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 311 | /* |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 312 | * Manually making button hover. |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 313 | */ |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 314 | qrCodeGenerateButton.backgroundColor = (isMouseOnButton(mouse, qrCodeGenerateButton)) ? |
| 315 | JamiTheme.hoverColor : "white" |
| 316 | |
| 317 | settingsButton.backgroundColor = (isMouseOnButton(mouse, settingsButton)) ? |
| 318 | JamiTheme.hoverColor : "white" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 319 | } |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 320 | |
| 321 | function isMouseOnButton(mouse, button) { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 322 | var mousePos = mapToItem(comboBoxRootMouseArea, mouse.x, mouse.y) |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 323 | var qrButtonPos = mapToItem(comboBoxRootMouseArea, |
| 324 | button.x, |
| 325 | button.y) |
| 326 | if ((mousePos.x >= qrButtonPos.x |
| 327 | && mousePos.x <= qrButtonPos.x + button.width) |
| 328 | && (mousePos.y >= qrButtonPos.y |
| 329 | && mousePos.y <= qrButtonPos.y + button.height)) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 330 | return true |
| 331 | return false |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | indicator: null |
| 336 | |
| 337 | |
| 338 | /* |
| 339 | * Overwrite the combo box pop up to add footer (for add accounts). |
| 340 | */ |
| 341 | popup: AccountComboBoxPopup { |
| 342 | id: comboBoxPopup |
| 343 | |
| 344 | onAccountNeedToChange: { |
| 345 | accountComboBox.accountChanged(index) |
| 346 | } |
| 347 | |
| 348 | onNewAccountButtonClicked: { |
| 349 | accountComboBox.newAccountButtonClicked() |
| 350 | } |
| 351 | } |
| 352 | } |