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