blob: 5c587084714fbb797c6509a64371757dea79878a [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
26ComboBox {
27 id: accountComboBox
28
29 signal accountChanged(int index)
30 signal needToBackToWelcomePage(int index)
31 signal needToUpdateSmartList(string accountId)
32 signal newAccountButtonClicked
33 signal settingBtnClicked
34
35 currentIndex: 0
36
37 function backToWelcomePage(index) {
38 accountComboBox.needToBackToWelcomePage(index)
39 }
40
41 function updateSmartList(accountId) {
42 accountComboBox.needToUpdateSmartList(accountId)
43 }
44
45
46 /*
47 * Refresh every item in accountListModel.
48 */
49 function updateAccountListModel() {
50 accountListModel.dataChanged(accountListModel.index(0, 0),
51 accountListModel.index(
52 accountListModel.rowCount() - 1, 0))
53 }
54
55
56 /*
57 * Reset accountListModel.
58 */
59 function resetAccountListModel() {
60 accountListModel.reset()
61 }
62
63 Image {
64 id: userImageRoot
65
66 anchors.left: accountComboBox.left
ababidf651a22020-07-30 13:38:57 +020067 anchors.leftMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -040068 anchors.verticalCenter: accountComboBox.verticalCenter
69
ababidf651a22020-07-30 13:38:57 +020070 width: 30
71 height: 30
Sébastien Blin1f915762020-08-03 13:27:42 -040072
73 fillMode: Image.PreserveAspectFit
74
75
76 /*
77 * Base 64 format
78 */
79 source: {
80 if (currentIndex !== -1)
81 return "data:image/png;base64," + accountListModel.data(
82 accountListModel.index(
83 accountComboBox.currentIndex, 0), 259)
84 else
85 return source
86 }
87 mipmap: true
88
89 Rectangle {
90 id: presenseRect
91
92 anchors.right: userImageRoot.right
ababidf651a22020-07-30 13:38:57 +020093 anchors.rightMargin: -2
Sébastien Blin1f915762020-08-03 13:27:42 -040094 anchors.bottom: userImageRoot.bottom
ababidf651a22020-07-30 13:38:57 +020095 anchors.bottomMargin: -2
Sébastien Blin1f915762020-08-03 13:27:42 -040096
ababidf651a22020-07-30 13:38:57 +020097 width: 12
98 height: 12
Sébastien Blin1f915762020-08-03 13:27:42 -040099
100
101 /*
102 * Visible when account is registered, enum REGISTERED == 5.
103 */
104 visible: {
105 if (currentIndex !== -1)
106 return accountListModel.data(
107 accountListModel.index(
108 accountComboBox.currentIndex, 0), 261) === 5
109 else
110 return visible
111 }
112
113 Rectangle {
114 id: presenseCycle
115
116 anchors.centerIn: presenseRect
117
118 width: 10
119 height: 10
120
121 radius: 30
122 color: JamiTheme.presenceGreen
123 }
124
125 radius: 30
ababidf651a22020-07-30 13:38:57 +0200126 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400127 }
128 }
129
130 Text {
131 id: textUserAliasRoot
132
133 anchors.left: userImageRoot.right
ababidf651a22020-07-30 13:38:57 +0200134 anchors.leftMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -0400135 anchors.top: rootItemBackground.top
ababidf651a22020-07-30 13:38:57 +0200136 anchors.topMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -0400137
138 text: textMetricsUserAliasRoot.elidedText
139 font.pointSize: JamiTheme.textFontSize
140 }
141
ababidf651a22020-07-30 13:38:57 +0200142 Image {
Ming Rui Zhangc6b33692020-08-25 15:47:20 -0400143 id: arrowDropDown
144
ababidf651a22020-07-30 13:38:57 +0200145 anchors.left: textUserAliasRoot.right
146 anchors.verticalCenter: textUserAliasRoot.verticalCenter
147
148 width: 24
149 height: 24
150
151 fillMode: Image.PreserveAspectFit
152 mipmap: true
153 source: "qrc:/images/icons/round-arrow_drop_down-24px.svg"
154 }
155
156
Sébastien Blin1f915762020-08-03 13:27:42 -0400157 Text {
158 id: textUsernameRoot
159
160 anchors.left: userImageRoot.right
ababidf651a22020-07-30 13:38:57 +0200161 anchors.leftMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -0400162 anchors.top: textUserAliasRoot.bottom
Sébastien Blin1f915762020-08-03 13:27:42 -0400163
164 text: textMetricsUsernameRoot.elidedText
165 font.pointSize: JamiTheme.textFontSize
ababidf651a22020-07-30 13:38:57 +0200166 color: JamiTheme.faddedLastInteractionFontColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400167 }
168
169 TextMetrics {
170 id: textMetricsUserAliasRoot
171
172 font: textUserAliasRoot.font
ababidf651a22020-07-30 13:38:57 +0200173 elide: Text.ElideRight
Ming Rui Zhangc6b33692020-08-25 15:47:20 -0400174 elideWidth: accountComboBox.width - userImageRoot.width - settingsButton.width
175 - arrowDropDown.width - qrCodeGenerateButton.width - 55
Sébastien Blin1f915762020-08-03 13:27:42 -0400176
177
178 /*
179 * Role::Alias
180 */
181 text: {
182 if (currentIndex !== -1)
183 return accountListModel.data(accountListModel.index(
184 accountComboBox.currentIndex,
185 0), 257)
186 else
187 return text
188 }
189 }
190
191 TextMetrics {
192 id: textMetricsUsernameRoot
193
194 font: textUsernameRoot.font
ababidf651a22020-07-30 13:38:57 +0200195 elide: Text.ElideRight
Ming Rui Zhangc6b33692020-08-25 15:47:20 -0400196 elideWidth: accountComboBox.width - userImageRoot.width - settingsButton.width
197 - qrCodeGenerateButton.width - 55
Sébastien Blin1f915762020-08-03 13:27:42 -0400198
199
200 /*
201 * Role::Username
202 */
203 text: {
204 if (currentIndex !== -1)
205 return accountListModel.data(accountListModel.index(
206 accountComboBox.currentIndex,
207 0), 258)
208 else
209 return text
210 }
211 }
212
ababidf651a22020-07-30 13:38:57 +0200213
214
215 HoverableButton {
216 id: qrCodeGenerateButton
217
218 anchors.right: settingsButton.left
219 anchors.rightMargin: 10
220 anchors.verticalCenter: accountComboBox.verticalCenter
221
222 buttonImageHeight: height - 8
223 buttonImageWidth: width - 8
224 radius: height / 2
225 width: 24
226 height: 24
227
Yang Wangb97bde42020-08-07 11:24:18 -0400228 toolTipText: qsTr("Press to display QR code")
229 hoverEnabled: true
230
ababidf651a22020-07-30 13:38:57 +0200231 source: "qrc:/images/qrcode.png"
232 backgroundColor: "white"
233 onClicked: {
234 qrDialog.open()
235 }
236 }
237
Sébastien Blin1f915762020-08-03 13:27:42 -0400238 HoverableButton {
239 id: settingsButton
240
241 anchors.right: accountComboBox.right
242 anchors.rightMargin: 10
243 anchors.verticalCenter: accountComboBox.verticalCenter
244
245 buttonImageHeight: height - 8
246 buttonImageWidth: width - 8
Sébastien Blin1f915762020-08-03 13:27:42 -0400247 radius: height / 2
248 width: 25
249 height: 25
250
ababia284cae2020-08-10 12:33:34 +0200251 source: !mainViewWindow.inSettingsView ? "qrc:/images/icons/round-settings-24px.svg" :
252 "qrc:/images/icons/round-close-24px.svg"
Yang Wangb97bde42020-08-07 11:24:18 -0400253 toolTipText: !mainViewWindow.inSettingsView ?qsTr("Press to toggle to settings page") : qsTr("Press to toggle to call page")
254 hoverEnabled: true
255
ababidf651a22020-07-30 13:38:57 +0200256 backgroundColor: "white"
Sébastien Blin1f915762020-08-03 13:27:42 -0400257 onClicked: {
258 settingBtnClicked()
259 }
260 }
261
262 background: Rectangle {
263 id: rootItemBackground
264
265 implicitWidth: accountComboBox.width
266 implicitHeight: accountComboBox.height
ababidf651a22020-07-30 13:38:57 +0200267 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400268 }
269
270 MouseArea {
271 id: comboBoxRootMouseArea
272
273 anchors.fill: parent
274
275 hoverEnabled: true
276 propagateComposedEvents: true
277
278 onPressed: {
ababidf651a22020-07-30 13:38:57 +0200279 if (isMouseOnButton(mouse, qrCodeGenerateButton)) {
280 qrCodeGenerateButton.backgroundColor = JamiTheme.pressColor
281 qrCodeGenerateButton.clicked()
282 }if (isMouseOnButton(mouse, settingsButton)) {
Sébastien Blin1f915762020-08-03 13:27:42 -0400283 settingsButton.backgroundColor = JamiTheme.pressColor
284 settingsButton.clicked()
ababidf651a22020-07-30 13:38:57 +0200285 } else {
Sébastien Blin1f915762020-08-03 13:27:42 -0400286 rootItemBackground.color = JamiTheme.pressColor
ababidf651a22020-07-30 13:38:57 +0200287 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400288 }
ababidf651a22020-07-30 13:38:57 +0200289
Sébastien Blin1f915762020-08-03 13:27:42 -0400290 onReleased: {
ababidf651a22020-07-30 13:38:57 +0200291 if (isMouseOnButton(mouse, qrCodeGenerateButton)) {
292 qrCodeGenerateButton.backgroundColor = JamiTheme.releaseColor
293 } else if (isMouseOnButton(mouse, settingsButton)) {
Sébastien Blin1f915762020-08-03 13:27:42 -0400294 settingsButton.backgroundColor = JamiTheme.releaseColor
295 } else {
296 rootItemBackground.color = JamiTheme.releaseColor
297 if (comboBoxPopup.opened) {
298 accountComboBox.popup.close()
299 } else {
300 accountComboBox.popup.open()
301 }
302 }
303 }
304 onEntered: {
305 rootItemBackground.color = JamiTheme.hoverColor
306 }
307 onExited: {
ababidf651a22020-07-30 13:38:57 +0200308 rootItemBackground.color = JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400309 }
310 onMouseXChanged: {
Sébastien Blin1f915762020-08-03 13:27:42 -0400311 /*
ababidf651a22020-07-30 13:38:57 +0200312 * Manually making button hover.
Sébastien Blin1f915762020-08-03 13:27:42 -0400313 */
ababidf651a22020-07-30 13:38:57 +0200314 qrCodeGenerateButton.backgroundColor = (isMouseOnButton(mouse, qrCodeGenerateButton)) ?
315 JamiTheme.hoverColor : "white"
316
317 settingsButton.backgroundColor = (isMouseOnButton(mouse, settingsButton)) ?
318 JamiTheme.hoverColor : "white"
Sébastien Blin1f915762020-08-03 13:27:42 -0400319 }
ababidf651a22020-07-30 13:38:57 +0200320
321 function isMouseOnButton(mouse, button) {
Sébastien Blin1f915762020-08-03 13:27:42 -0400322 var mousePos = mapToItem(comboBoxRootMouseArea, mouse.x, mouse.y)
ababidf651a22020-07-30 13:38:57 +0200323 var qrButtonPos = mapToItem(comboBoxRootMouseArea,
324 button.x,
325 button.y)
326 if ((mousePos.x >= qrButtonPos.x
327 && mousePos.x <= qrButtonPos.x + button.width)
328 && (mousePos.y >= qrButtonPos.y
329 && mousePos.y <= qrButtonPos.y + button.height))
Sébastien Blin1f915762020-08-03 13:27:42 -0400330 return true
331 return false
332 }
333 }
334
335 indicator: null
336
337
338 /*
339 * Overwrite the combo box pop up to add footer (for add accounts).
340 */
341 popup: AccountComboBoxPopup {
342 id: comboBoxPopup
343
344 onAccountNeedToChange: {
345 accountComboBox.accountChanged(index)
346 }
347
348 onNewAccountButtonClicked: {
349 accountComboBox.newAccountButtonClicked()
350 }
351 }
352}