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 | Popup { |
| 27 | id: comboBoxPopup |
| 28 | |
| 29 | property bool toogleUpdatePopupHeight: false |
| 30 | |
| 31 | signal accountNeedToChange(int index) |
| 32 | signal newAccountButtonClicked |
| 33 | |
| 34 | y: accountComboBox.height - 1 |
| 35 | implicitWidth: accountComboBox.width - 1 |
| 36 | |
| 37 | |
| 38 | /* |
| 39 | * Hack - limite the accounts that can be shown. |
| 40 | */ |
| 41 | implicitHeight: { |
| 42 | comboBoxPopup.visible |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 43 | return Math.min(accountComboBox.height * |
| 44 | Math.min(5, accountListModel.rowCount() + 1), |
| 45 | mainViewSidePanelRect.height) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 46 | } |
| 47 | padding: 0 |
| 48 | |
| 49 | contentItem: ListView { |
| 50 | id: comboBoxPopupListView |
| 51 | |
| 52 | |
| 53 | /* |
| 54 | * In list view, index is an interger. |
| 55 | */ |
| 56 | clip: true |
| 57 | model: accountListModel |
| 58 | implicitHeight: contentHeight |
| 59 | delegate: ItemDelegate { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 60 | Image { |
| 61 | id: userImage |
| 62 | |
| 63 | anchors.left: parent.left |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 64 | anchors.leftMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 65 | anchors.verticalCenter: parent.verticalCenter |
| 66 | |
| 67 | width: 30 |
Ming Rui Zhang | e5a75ad | 2020-08-31 14:54:11 -0400 | [diff] [blame] | 68 | height: 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 69 | |
| 70 | fillMode: Image.PreserveAspectFit |
| 71 | mipmap: true |
| 72 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 73 | /* |
| 74 | * Role::Picture |
| 75 | */ |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 76 | source: { |
| 77 | var data = accountListModel.data(accountListModel.index(index, 0), 259) |
| 78 | if (data === undefined) { |
| 79 | return "" |
| 80 | } |
| 81 | return "data:image/png;base64," + data |
| 82 | } |
Ming Rui Zhang | e5a75ad | 2020-08-31 14:54:11 -0400 | [diff] [blame] | 83 | |
| 84 | AccountPresenceCycle { |
| 85 | id: accountPresenseCycle |
| 86 | |
| 87 | anchors.right: userImage.right |
| 88 | anchors.rightMargin: -2 |
| 89 | anchors.bottom: userImage.bottom |
| 90 | anchors.bottomMargin: -2 |
| 91 | |
| 92 | // Visible when account is registered. |
| 93 | visible: { |
| 94 | return accountListModel.data( |
| 95 | accountListModel.index(index, 0), 261) |
| 96 | === Account.Status.REGISTERED |
| 97 | } |
| 98 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | Text { |
| 102 | id: textUserAliasPopup |
| 103 | |
| 104 | anchors.left: userImage.right |
| 105 | anchors.leftMargin: 10 |
| 106 | anchors.top: itemCoboBackground.top |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 107 | anchors.topMargin: 15 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 108 | |
| 109 | text: textMetricsUserAliasPopup.elidedText |
| 110 | font.pointSize: JamiTheme.textFontSize |
| 111 | } |
| 112 | |
| 113 | Text { |
| 114 | id: textUsernamePopup |
| 115 | |
| 116 | anchors.left: userImage.right |
| 117 | anchors.leftMargin: 10 |
| 118 | anchors.top: textUserAliasPopup.bottom |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 119 | |
| 120 | text: textMetricsUsernamePopup.elidedText |
| 121 | font.pointSize: JamiTheme.textFontSize |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 122 | color: JamiTheme.faddedLastInteractionFontColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | TextMetrics { |
| 126 | id: textMetricsUserAliasPopup |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 127 | elide: Text.ElideRight |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 128 | elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30 |
| 129 | text: Alias |
| 130 | } |
| 131 | |
| 132 | TextMetrics { |
| 133 | id: textMetricsUsernamePopup |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 134 | elide: Text.ElideRight |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 135 | elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30 |
| 136 | text: Username |
| 137 | } |
| 138 | |
| 139 | background: Rectangle { |
| 140 | id: itemCoboBackground |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 141 | color: JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 142 | implicitWidth: accountComboBox.width |
| 143 | implicitHeight: accountComboBox.height |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | MouseArea { |
| 147 | anchors.fill: parent |
| 148 | hoverEnabled: true |
| 149 | onPressed: { |
| 150 | itemCoboBackground.color = JamiTheme.pressColor |
| 151 | } |
| 152 | onReleased: { |
| 153 | itemCoboBackground.color = JamiTheme.releaseColor |
| 154 | currentIndex = index |
| 155 | comboBoxPopup.close() |
| 156 | comboBoxPopup.accountNeedToChange(index) |
| 157 | } |
| 158 | onEntered: { |
| 159 | itemCoboBackground.color = JamiTheme.hoverColor |
| 160 | } |
| 161 | onExited: { |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 162 | itemCoboBackground.color = JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 167 | footer: Button { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 168 | id: comboBoxFooterItem |
| 169 | |
| 170 | implicitWidth: accountComboBox.width |
| 171 | implicitHeight: accountComboBox.height |
| 172 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 173 | background: Rectangle { |
| 174 | color: comboBoxFooterItem.hovered? JamiTheme.releaseColor : JamiTheme.backgroundColor |
| 175 | } |
| 176 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 177 | text: qsTr("Add Account") + "+" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 178 | |
| 179 | onClicked: { |
| 180 | comboBoxPopup.close() |
| 181 | comboBoxPopup.newAccountButtonClicked() |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | ScrollIndicator.vertical: ScrollIndicator {} |
| 186 | } |
| 187 | background: Rectangle { |
| 188 | id: accountComboBoxPopup |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 189 | color: JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 190 | CustomBorder { |
| 191 | commonBorder: false |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 192 | lBorderwidth: 1 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 193 | rBorderwidth: 1 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 194 | tBorderwidth: 1 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 195 | bBorderwidth: 1 |
| 196 | borderColor: JamiTheme.tabbarBorderColor |
| 197 | } |
| 198 | } |
| 199 | } |