blob: 2e3120d188b156e94e1fa52631535a85e81c43be [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
Sébastien Blin1f915762020-08-03 13:27:42 -040074 /*
75 * Role::Picture
76 */
Sébastien Blinc75335f2020-08-04 20:54:02 -040077 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 Blin1f915762020-08-03 13:27:42 -040084 }
85
86 Text {
87 id: textUserAliasPopup
88
89 anchors.left: userImage.right
90 anchors.leftMargin: 10
91 anchors.top: itemCoboBackground.top
ababidf651a22020-07-30 13:38:57 +020092 anchors.topMargin: 15
Sébastien Blin1f915762020-08-03 13:27:42 -040093
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 Blin1f915762020-08-03 13:27:42 -0400104
105 text: textMetricsUsernamePopup.elidedText
106 font.pointSize: JamiTheme.textFontSize
ababidf651a22020-07-30 13:38:57 +0200107 color: JamiTheme.faddedLastInteractionFontColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400108 }
109
110 TextMetrics {
111 id: textMetricsUserAliasPopup
ababidf651a22020-07-30 13:38:57 +0200112 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400113 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
114 text: Alias
115 }
116
117 TextMetrics {
118 id: textMetricsUsernamePopup
ababidf651a22020-07-30 13:38:57 +0200119 elide: Text.ElideRight
Sébastien Blin1f915762020-08-03 13:27:42 -0400120 elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30
121 text: Username
122 }
123
124 background: Rectangle {
125 id: itemCoboBackground
ababidf651a22020-07-30 13:38:57 +0200126 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400127 implicitWidth: accountComboBox.width
128 implicitHeight: accountComboBox.height
Sébastien Blin1f915762020-08-03 13:27:42 -0400129 }
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: {
ababidf651a22020-07-30 13:38:57 +0200147 itemCoboBackground.color = JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400148 }
149 }
150 }
151
Sébastien Blinc75335f2020-08-04 20:54:02 -0400152 footer: Button {
Sébastien Blin1f915762020-08-03 13:27:42 -0400153 id: comboBoxFooterItem
154
155 implicitWidth: accountComboBox.width
156 implicitHeight: accountComboBox.height
157
Sébastien Blinc75335f2020-08-04 20:54:02 -0400158 background: Rectangle {
159 color: comboBoxFooterItem.hovered? JamiTheme.releaseColor : JamiTheme.backgroundColor
160 }
161
Sébastien Blin1f915762020-08-03 13:27:42 -0400162 text: qsTr("Add Account") + "+"
Sébastien Blin1f915762020-08-03 13:27:42 -0400163
164 onClicked: {
165 comboBoxPopup.close()
166 comboBoxPopup.newAccountButtonClicked()
167 }
168 }
169
170 ScrollIndicator.vertical: ScrollIndicator {}
171 }
172 background: Rectangle {
173 id: accountComboBoxPopup
ababidf651a22020-07-30 13:38:57 +0200174 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400175 CustomBorder {
176 commonBorder: false
ababidf651a22020-07-30 13:38:57 +0200177 lBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400178 rBorderwidth: 1
ababidf651a22020-07-30 13:38:57 +0200179 tBorderwidth: 1
Sébastien Blin1f915762020-08-03 13:27:42 -0400180 bBorderwidth: 1
181 borderColor: JamiTheme.tabbarBorderColor
182 }
183 }
184}