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 { |
| 60 | |
| 61 | Image { |
| 62 | id: userImage |
| 63 | |
| 64 | anchors.left: parent.left |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 65 | anchors.leftMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 66 | anchors.verticalCenter: parent.verticalCenter |
| 67 | |
| 68 | width: 30 |
| 69 | height: parent.height |
| 70 | |
| 71 | fillMode: Image.PreserveAspectFit |
| 72 | mipmap: true |
| 73 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 74 | /* |
| 75 | * Role::Picture |
| 76 | */ |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 77 | source: { |
| 78 | var data = accountListModel.data(accountListModel.index(index, 0), 259) |
| 79 | if (data === undefined) { |
| 80 | return "" |
| 81 | } |
| 82 | return "data:image/png;base64," + data |
| 83 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | Text { |
| 87 | id: textUserAliasPopup |
| 88 | |
| 89 | anchors.left: userImage.right |
| 90 | anchors.leftMargin: 10 |
| 91 | anchors.top: itemCoboBackground.top |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 92 | anchors.topMargin: 15 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 93 | |
| 94 | text: textMetricsUserAliasPopup.elidedText |
| 95 | font.pointSize: JamiTheme.textFontSize |
| 96 | } |
| 97 | |
| 98 | Text { |
| 99 | id: textUsernamePopup |
| 100 | |
| 101 | anchors.left: userImage.right |
| 102 | anchors.leftMargin: 10 |
| 103 | anchors.top: textUserAliasPopup.bottom |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 104 | |
| 105 | text: textMetricsUsernamePopup.elidedText |
| 106 | font.pointSize: JamiTheme.textFontSize |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 107 | color: JamiTheme.faddedLastInteractionFontColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | TextMetrics { |
| 111 | id: textMetricsUserAliasPopup |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 112 | elide: Text.ElideRight |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 113 | elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30 |
| 114 | text: Alias |
| 115 | } |
| 116 | |
| 117 | TextMetrics { |
| 118 | id: textMetricsUsernamePopup |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 119 | elide: Text.ElideRight |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 120 | elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30 |
| 121 | text: Username |
| 122 | } |
| 123 | |
| 124 | background: Rectangle { |
| 125 | id: itemCoboBackground |
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 | implicitWidth: accountComboBox.width |
| 128 | implicitHeight: accountComboBox.height |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | MouseArea { |
| 132 | anchors.fill: parent |
| 133 | hoverEnabled: true |
| 134 | onPressed: { |
| 135 | itemCoboBackground.color = JamiTheme.pressColor |
| 136 | } |
| 137 | onReleased: { |
| 138 | itemCoboBackground.color = JamiTheme.releaseColor |
| 139 | currentIndex = index |
| 140 | comboBoxPopup.close() |
| 141 | comboBoxPopup.accountNeedToChange(index) |
| 142 | } |
| 143 | onEntered: { |
| 144 | itemCoboBackground.color = JamiTheme.hoverColor |
| 145 | } |
| 146 | onExited: { |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 147 | itemCoboBackground.color = JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 152 | footer: Button { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 153 | id: comboBoxFooterItem |
| 154 | |
| 155 | implicitWidth: accountComboBox.width |
| 156 | implicitHeight: accountComboBox.height |
| 157 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 158 | background: Rectangle { |
| 159 | color: comboBoxFooterItem.hovered? JamiTheme.releaseColor : JamiTheme.backgroundColor |
| 160 | } |
| 161 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 162 | text: qsTr("Add Account") + "+" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 163 | |
| 164 | onClicked: { |
| 165 | comboBoxPopup.close() |
| 166 | comboBoxPopup.newAccountButtonClicked() |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | ScrollIndicator.vertical: ScrollIndicator {} |
| 171 | } |
| 172 | background: Rectangle { |
| 173 | id: accountComboBoxPopup |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 174 | color: JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 175 | CustomBorder { |
| 176 | commonBorder: false |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 177 | lBorderwidth: 1 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 178 | rBorderwidth: 1 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 179 | tBorderwidth: 1 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 180 | bBorderwidth: 1 |
| 181 | borderColor: JamiTheme.tabbarBorderColor |
| 182 | } |
| 183 | } |
| 184 | } |