blob: 7f0974ab06fd2ed351e73ddf5532156664097581 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001
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 */
19import QtQuick 2.14
20import QtQuick.Controls 2.14
21import QtQuick.Layouts 1.14
22import net.jami.Models 1.0
23
24import "../../commoncomponents"
25
26Popup {
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
ababia284cae2020-08-10 12:33:34 +020043 return Math.min(accountComboBox.height *
44 Math.min(5, accountListModel.rowCount() + 1),
45 mainViewSidePanelRect.height)
Sébastien Blin1f915762020-08-03 13:27:42 -040046 }
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
ababidf651a22020-07-30 13:38:57 +020065 anchors.leftMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -040066 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
ababidf651a22020-07-30 13:38:57 +020088 anchors.topMargin: 15
Sébastien Blin1f915762020-08-03 13:27:42 -040089
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 Blin1f915762020-08-03 13:27:42 -0400100
101 text: textMetricsUsernamePopup.elidedText
102 font.pointSize: JamiTheme.textFontSize
ababidf651a22020-07-30 13:38:57 +0200103 color: JamiTheme.faddedLastInteractionFontColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400104 }
105
106 TextMetrics {
107 id: textMetricsUserAliasPopup
ababidf651a22020-07-30 13:38:57 +0200108 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400109 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
110 text: Alias
111 }
112
113 TextMetrics {
114 id: textMetricsUsernamePopup
ababidf651a22020-07-30 13:38:57 +0200115 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400116 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
117 text: Username
118 }
119
120 background: Rectangle {
121 id: itemCoboBackground
ababidf651a22020-07-30 13:38:57 +0200122 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400123 implicitWidth: accountComboBox.width
124 implicitHeight: accountComboBox.height
Sébastien Blin1f915762020-08-03 13:27:42 -0400125 }
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: {
ababidf651a22020-07-30 13:38:57 +0200143 itemCoboBackground.color = JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400144 }
145 }
146 }
147
148 footer: HoverableButton {
149 id: comboBoxFooterItem
150
151 implicitWidth: accountComboBox.width
152 implicitHeight: accountComboBox.height
153
154 text: qsTr("Add Account") + "+"
ababidf651a22020-07-30 13:38:57 +0200155 backgroundColor: JamiTheme.backgroundColor
156 onExitColor: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400157
158 onClicked: {
159 comboBoxPopup.close()
160 comboBoxPopup.newAccountButtonClicked()
161 }
162 }
163
164 ScrollIndicator.vertical: ScrollIndicator {}
165 }
166 background: Rectangle {
167 id: accountComboBoxPopup
ababidf651a22020-07-30 13:38:57 +0200168 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400169 CustomBorder {
170 commonBorder: false
ababidf651a22020-07-30 13:38:57 +0200171 lBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400172 rBorderwidth: 1
ababidf651a22020-07-30 13:38:57 +0200173 tBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400174 bBorderwidth: 1
175 borderColor: JamiTheme.tabbarBorderColor
176 }
177 }
178}