2019-12-19 07:46:16 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-08-18 03:27:00 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-27 09:06:42 -04:00
|
|
|
import Clipboard 0.1
|
2019-08-18 03:27:00 -04:00
|
|
|
import "../Base"
|
|
|
|
|
2019-08-21 04:39:07 -04:00
|
|
|
HTileDelegate {
|
2019-12-02 16:29:29 -04:00
|
|
|
id: account
|
2019-08-21 04:39:07 -04:00
|
|
|
spacing: 0
|
2019-12-08 14:43:41 -04:00
|
|
|
topPadding: model.index > 0 ? theme.spacing / 2 : 0
|
2019-08-21 04:39:07 -04:00
|
|
|
bottomPadding: topPadding
|
2019-12-02 16:29:29 -04:00
|
|
|
|
2019-12-10 15:17:41 -04:00
|
|
|
backgroundColor: theme.mainPane.account.background
|
2020-02-03 16:19:42 -04:00
|
|
|
opacity: collapsed && ! mainPane.filter ?
|
2019-12-10 15:17:41 -04:00
|
|
|
theme.mainPane.account.collapsedOpacity : 1
|
2019-08-18 03:27:00 -04:00
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
title.color: theme.mainPane.account.name
|
|
|
|
title.text: model.display_name || model.id
|
|
|
|
title.font.pixelSize: theme.fontSize.big
|
|
|
|
title.leftPadding: theme.spacing
|
2019-08-19 14:28:12 -04:00
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
image: HUserAvatar {
|
|
|
|
userId: model.id
|
|
|
|
displayName: model.display_name
|
|
|
|
mxc: model.avatar_url
|
|
|
|
}
|
2019-08-23 10:53:54 -04:00
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
contextMenu: HMenu {
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy-user-id"
|
|
|
|
text: qsTr("Copy user ID")
|
|
|
|
onTriggered: Clipboard.text = model.id
|
|
|
|
}
|
2019-08-18 03:27:00 -04:00
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
HMenuItemPopupSpawner {
|
|
|
|
icon.name: "sign-out"
|
|
|
|
icon.color: theme.colors.negativeBackground
|
|
|
|
text: qsTr("Sign out")
|
2019-08-21 04:39:07 -04:00
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
popup: "Popups/SignOutPopup.qml"
|
|
|
|
properties: { "userId": model.id }
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 04:39:07 -04:00
|
|
|
|
2020-03-07 09:45:52 -04:00
|
|
|
onActivated: pageLoader.showPage(
|
|
|
|
"AccountSettings/AccountSettings", { "userId": model.id }
|
|
|
|
)
|
2019-08-19 10:28:49 -04:00
|
|
|
|
|
|
|
|
2020-02-13 05:56:10 -04:00
|
|
|
readonly property alias addChat: addChat
|
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
readonly property bool collapsed:
|
2020-03-07 10:15:54 -04:00
|
|
|
(window.uiState.collapseAccounts[model.id] || false) &&
|
|
|
|
! mainPane.filter
|
2019-08-18 03:27:00 -04:00
|
|
|
|
2020-02-13 06:58:13 -04:00
|
|
|
readonly property bool shouldBeSelected:
|
|
|
|
(
|
|
|
|
window.uiState.page === "Pages/AddChat/AddChat.qml" ||
|
|
|
|
window.uiState.page === "Pages/AccountSettings/AccountSettings.qml"
|
|
|
|
) &&
|
|
|
|
window.uiState.pageProperties.userId === model.id
|
|
|
|
|
|
|
|
|
|
|
|
function becomeSelected() {
|
|
|
|
accountRooms.roomList.currentIndex = -1
|
|
|
|
mainPaneList.currentIndex = index
|
|
|
|
}
|
2019-08-19 13:09:05 -04:00
|
|
|
|
2020-03-07 11:28:51 -04:00
|
|
|
function setCollapse(collapse) {
|
|
|
|
window.uiState.collapseAccounts[model.id] = collapse
|
2019-08-18 03:27:00 -04:00
|
|
|
window.uiStateChanged()
|
|
|
|
}
|
|
|
|
|
2020-03-07 11:28:51 -04:00
|
|
|
function toggleCollapse() {
|
|
|
|
setCollapse(! collapsed)
|
|
|
|
}
|
|
|
|
|
2019-08-19 13:09:05 -04:00
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-08-21 04:39:07 -04:00
|
|
|
|
2020-02-13 06:58:13 -04:00
|
|
|
|
|
|
|
// Trying to set the current item to ourself usually won't work from the
|
|
|
|
// first time, when this delegate is being initialized
|
|
|
|
Timer {
|
|
|
|
interval: 100
|
|
|
|
repeat: true
|
|
|
|
running: shouldBeSelected && mainPaneList.currentIndex === -1
|
|
|
|
triggeredOnStart: true
|
|
|
|
onTriggered: becomeSelected()
|
|
|
|
}
|
|
|
|
|
2019-11-07 06:44:53 -04:00
|
|
|
HButton {
|
|
|
|
id: addChat
|
2019-12-04 09:08:38 -04:00
|
|
|
iconItem.small: true
|
2019-11-09 11:10:00 -04:00
|
|
|
icon.name: "add-chat"
|
2019-11-07 06:44:53 -04:00
|
|
|
backgroundColor: "transparent"
|
|
|
|
toolTip.text: qsTr("Add new chat")
|
2020-03-07 09:45:52 -04:00
|
|
|
onClicked: pageLoader.showPage(
|
|
|
|
"AddChat/AddChat", {userId: model.id},
|
|
|
|
)
|
2019-11-07 06:44:53 -04:00
|
|
|
|
|
|
|
leftPadding: theme.spacing / 2
|
|
|
|
rightPadding: leftPadding
|
|
|
|
|
|
|
|
opacity: expand.loading ? 0 : 1
|
2019-12-21 14:25:17 -04:00
|
|
|
visible: opacity > 0 && Layout.maximumWidth > 0
|
2019-11-07 06:44:53 -04:00
|
|
|
|
|
|
|
Layout.fillHeight: true
|
2019-12-21 14:25:17 -04:00
|
|
|
Layout.maximumWidth:
|
2019-12-02 16:29:29 -04:00
|
|
|
account.width >= 100 * theme.uiScale ? implicitWidth : 0
|
2019-11-07 06:44:53 -04:00
|
|
|
|
2019-12-21 14:25:17 -04:00
|
|
|
Behavior on Layout.maximumWidth { HNumberAnimation {} }
|
2019-12-16 04:42:41 -04:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-11-07 06:44:53 -04:00
|
|
|
}
|
|
|
|
|
2019-08-21 04:39:07 -04:00
|
|
|
HButton {
|
|
|
|
id: expand
|
2019-12-02 16:29:29 -04:00
|
|
|
loading:
|
|
|
|
! model.first_sync_done || model.profile_updated < new Date(1)
|
2019-12-04 09:08:38 -04:00
|
|
|
iconItem.small: true
|
2019-08-21 15:45:13 -04:00
|
|
|
icon.name: "expand"
|
2019-08-21 04:39:07 -04:00
|
|
|
backgroundColor: "transparent"
|
2019-08-22 09:27:26 -04:00
|
|
|
toolTip.text: collapsed ? qsTr("Expand") : qsTr("Collapse")
|
2019-12-02 16:29:29 -04:00
|
|
|
onClicked: account.toggleCollapse()
|
2019-08-21 04:39:07 -04:00
|
|
|
|
2019-11-07 06:44:53 -04:00
|
|
|
leftPadding: theme.spacing / 2
|
|
|
|
rightPadding: leftPadding
|
|
|
|
|
2020-02-03 16:19:42 -04:00
|
|
|
opacity: ! loading && mainPane.filter ? 0 : 1
|
2019-12-21 14:25:17 -04:00
|
|
|
visible: opacity > 0 && Layout.maximumWidth > 0
|
2019-08-21 04:39:07 -04:00
|
|
|
|
2019-11-07 06:44:53 -04:00
|
|
|
Layout.fillHeight: true
|
2019-12-21 14:25:17 -04:00
|
|
|
Layout.maximumWidth:
|
2019-12-02 16:29:29 -04:00
|
|
|
account.width >= 120 * theme.uiScale ? implicitWidth : 0
|
2019-12-21 14:25:17 -04:00
|
|
|
|
2019-11-07 06:44:53 -04:00
|
|
|
|
2019-08-21 15:45:13 -04:00
|
|
|
iconItem.transform: Rotation {
|
2019-11-07 06:44:53 -04:00
|
|
|
origin.x: expand.iconItem.width / 2
|
|
|
|
origin.y: expand.iconItem.height / 2
|
2019-08-27 15:00:50 -04:00
|
|
|
angle: expand.loading ? 0 : collapsed ? 180 : 90
|
2019-08-21 04:39:07 -04:00
|
|
|
|
|
|
|
Behavior on angle { HNumberAnimation {} }
|
2019-08-19 18:32:43 -04:00
|
|
|
}
|
2019-08-18 03:27:00 -04:00
|
|
|
|
2019-12-21 14:25:17 -04:00
|
|
|
Behavior on Layout.maximumWidth { HNumberAnimation {} }
|
2019-12-16 04:42:41 -04:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-08-18 03:27:00 -04:00
|
|
|
}
|
|
|
|
}
|