blob: 813cb8e775f89fa8ece613ae4d9eb1fb9db2882f [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 {
Sébastien Blin1f915762020-08-03 13:27:42 -040060 Image {
61 id: userImage
62
63 anchors.left: parent.left
ababidf651a22020-07-30 13:38:57 +020064 anchors.leftMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -040065 anchors.verticalCenter: parent.verticalCenter
66
67 width: 30
Ming Rui Zhange5a75ad2020-08-31 14:54:11 -040068 height: 30
Sébastien Blin1f915762020-08-03 13:27:42 -040069
70 fillMode: Image.PreserveAspectFit
71 mipmap: true
72
Sébastien Blin1f915762020-08-03 13:27:42 -040073 /*
74 * Role::Picture
75 */
Sébastien Blinc75335f2020-08-04 20:54:02 -040076 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 Zhange5a75ad2020-08-31 14:54:11 -040083
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 Blin1f915762020-08-03 13:27:42 -040099 }
100
101 Text {
102 id: textUserAliasPopup
103
104 anchors.left: userImage.right
105 anchors.leftMargin: 10
106 anchors.top: itemCoboBackground.top
ababidf651a22020-07-30 13:38:57 +0200107 anchors.topMargin: 15
Sébastien Blin1f915762020-08-03 13:27:42 -0400108
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 Blin1f915762020-08-03 13:27:42 -0400119
120 text: textMetricsUsernamePopup.elidedText
121 font.pointSize: JamiTheme.textFontSize
ababidf651a22020-07-30 13:38:57 +0200122 color: JamiTheme.faddedLastInteractionFontColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400123 }
124
125 TextMetrics {
126 id: textMetricsUserAliasPopup
ababidf651a22020-07-30 13:38:57 +0200127 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400128 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
129 text: Alias
130 }
131
132 TextMetrics {
133 id: textMetricsUsernamePopup
ababidf651a22020-07-30 13:38:57 +0200134 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400135 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
136 text: Username
137 }
138
139 background: Rectangle {
140 id: itemCoboBackground
ababidf651a22020-07-30 13:38:57 +0200141 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400142 implicitWidth: accountComboBox.width
143 implicitHeight: accountComboBox.height
Sébastien Blin1f915762020-08-03 13:27:42 -0400144 }
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: {
ababidf651a22020-07-30 13:38:57 +0200162 itemCoboBackground.color = JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400163 }
164 }
165 }
166
Sébastien Blinc75335f2020-08-04 20:54:02 -0400167 footer: Button {
Sébastien Blin1f915762020-08-03 13:27:42 -0400168 id: comboBoxFooterItem
169
170 implicitWidth: accountComboBox.width
171 implicitHeight: accountComboBox.height
172
Sébastien Blinc75335f2020-08-04 20:54:02 -0400173 background: Rectangle {
174 color: comboBoxFooterItem.hovered? JamiTheme.releaseColor : JamiTheme.backgroundColor
175 }
176
Sébastien Blin1f915762020-08-03 13:27:42 -0400177 text: qsTr("Add Account") + "+"
Sébastien Blin1f915762020-08-03 13:27:42 -0400178
179 onClicked: {
180 comboBoxPopup.close()
181 comboBoxPopup.newAccountButtonClicked()
182 }
183 }
184
185 ScrollIndicator.vertical: ScrollIndicator {}
186 }
187 background: Rectangle {
188 id: accountComboBoxPopup
ababidf651a22020-07-30 13:38:57 +0200189 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400190 CustomBorder {
191 commonBorder: false
ababidf651a22020-07-30 13:38:57 +0200192 lBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400193 rBorderwidth: 1
ababidf651a22020-07-30 13:38:57 +0200194 tBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400195 bBorderwidth: 1
196 borderColor: JamiTheme.tabbarBorderColor
197 }
198 }
199}