blob: f10b4f5990f7169d166e74297e093aba68d4f4ca [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
Sébastien Blinacb1cf02020-08-17 22:38:19 -040092 accountStatus: Status
Ming Rui Zhange5a75ad2020-08-31 14:54:11 -040093 }
Sébastien Blin1f915762020-08-03 13:27:42 -040094 }
95
96 Text {
97 id: textUserAliasPopup
98
99 anchors.left: userImage.right
100 anchors.leftMargin: 10
101 anchors.top: itemCoboBackground.top
ababidf651a22020-07-30 13:38:57 +0200102 anchors.topMargin: 15
Sébastien Blin1f915762020-08-03 13:27:42 -0400103
104 text: textMetricsUserAliasPopup.elidedText
105 font.pointSize: JamiTheme.textFontSize
106 }
107
108 Text {
109 id: textUsernamePopup
110
111 anchors.left: userImage.right
112 anchors.leftMargin: 10
113 anchors.top: textUserAliasPopup.bottom
Sébastien Blin1f915762020-08-03 13:27:42 -0400114
115 text: textMetricsUsernamePopup.elidedText
116 font.pointSize: JamiTheme.textFontSize
ababidf651a22020-07-30 13:38:57 +0200117 color: JamiTheme.faddedLastInteractionFontColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400118 }
119
120 TextMetrics {
121 id: textMetricsUserAliasPopup
ababidf651a22020-07-30 13:38:57 +0200122 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400123 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
124 text: Alias
125 }
126
127 TextMetrics {
128 id: textMetricsUsernamePopup
ababidf651a22020-07-30 13:38:57 +0200129 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400130 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
131 text: Username
132 }
133
134 background: Rectangle {
135 id: itemCoboBackground
ababidf651a22020-07-30 13:38:57 +0200136 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400137 implicitWidth: accountComboBox.width
138 implicitHeight: accountComboBox.height
Sébastien Blin1f915762020-08-03 13:27:42 -0400139 }
140
141 MouseArea {
142 anchors.fill: parent
143 hoverEnabled: true
144 onPressed: {
145 itemCoboBackground.color = JamiTheme.pressColor
146 }
147 onReleased: {
148 itemCoboBackground.color = JamiTheme.releaseColor
149 currentIndex = index
150 comboBoxPopup.close()
151 comboBoxPopup.accountNeedToChange(index)
152 }
153 onEntered: {
154 itemCoboBackground.color = JamiTheme.hoverColor
155 }
156 onExited: {
ababidf651a22020-07-30 13:38:57 +0200157 itemCoboBackground.color = JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400158 }
159 }
160 }
161
Sébastien Blinc75335f2020-08-04 20:54:02 -0400162 footer: Button {
Sébastien Blin1f915762020-08-03 13:27:42 -0400163 id: comboBoxFooterItem
164
165 implicitWidth: accountComboBox.width
166 implicitHeight: accountComboBox.height
167
Sébastien Blinc75335f2020-08-04 20:54:02 -0400168 background: Rectangle {
169 color: comboBoxFooterItem.hovered? JamiTheme.releaseColor : JamiTheme.backgroundColor
170 }
171
Sébastien Blin1f915762020-08-03 13:27:42 -0400172 text: qsTr("Add Account") + "+"
Sébastien Blin1f915762020-08-03 13:27:42 -0400173
174 onClicked: {
175 comboBoxPopup.close()
176 comboBoxPopup.newAccountButtonClicked()
177 }
178 }
179
180 ScrollIndicator.vertical: ScrollIndicator {}
181 }
182 background: Rectangle {
183 id: accountComboBoxPopup
ababidf651a22020-07-30 13:38:57 +0200184 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400185 CustomBorder {
186 commonBorder: false
ababidf651a22020-07-30 13:38:57 +0200187 lBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400188 rBorderwidth: 1
ababidf651a22020-07-30 13:38:57 +0200189 tBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400190 bBorderwidth: 1
191 borderColor: JamiTheme.tabbarBorderColor
192 }
193 }
194}