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