moment/src/gui/MainPane/Account.qml

150 lines
4.1 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Layouts 1.12
2019-12-28 00:06:42 +11:00
import Clipboard 0.1
import "../Base"
HTileDelegate {
id: account
spacing: 0
topPadding: model.index > 0 ? theme.spacing / 2 : 0
bottomPadding: topPadding
2019-12-11 06:17:41 +11:00
backgroundColor: theme.mainPane.account.background
opacity: collapsed && ! mainPane.filter ?
2019-12-11 06:17:41 +11:00
theme.mainPane.account.collapsedOpacity : 1
title.color: theme.mainPane.account.name
title.text: model.display_name || model.id
title.font.pixelSize: theme.fontSize.big
title.leftPadding: theme.spacing
image: HUserAvatar {
userId: model.id
displayName: model.display_name
mxc: model.avatar_url
}
contextMenu: HMenu {
HMenuItem {
icon.name: "copy-user-id"
text: qsTr("Copy user ID")
onTriggered: Clipboard.text = model.id
}
HMenuItemPopupSpawner {
icon.name: "sign-out"
icon.color: theme.colors.negativeBackground
text: qsTr("Sign out")
popup: "Popups/SignOutPopup.qml"
properties: { "userId": model.id }
}
}
onActivated: pageLoader.showPage(
"AccountSettings/AccountSettings", { "userId": model.id }
)
readonly property alias addChat: addChat
readonly property bool collapsed:
(window.uiState.collapseAccounts[model.id] || false) &&
! mainPane.filter
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
}
function setCollapse(collapse) {
window.uiState.collapseAccounts[model.id] = collapse
window.uiStateChanged()
}
function toggleCollapse() {
setCollapse(! collapsed)
}
Behavior on opacity { HNumberAnimation {} }
// 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 21:44:53 +11:00
HButton {
id: addChat
2019-12-05 00:08:38 +11:00
iconItem.small: true
2019-11-10 02:10:00 +11:00
icon.name: "add-chat"
2019-11-07 21:44:53 +11:00
backgroundColor: "transparent"
toolTip.text: qsTr("Add new chat")
onClicked: pageLoader.showPage(
"AddChat/AddChat", {userId: model.id},
)
2019-11-07 21:44:53 +11:00
leftPadding: theme.spacing / 2
rightPadding: leftPadding
opacity: expand.loading ? 0 : 1
visible: opacity > 0 && Layout.maximumWidth > 0
2019-11-07 21:44:53 +11:00
Layout.fillHeight: true
Layout.maximumWidth:
account.width >= 100 * theme.uiScale ? implicitWidth : 0
2019-11-07 21:44:53 +11:00
Behavior on Layout.maximumWidth { HNumberAnimation {} }
2019-12-16 19:42:41 +11:00
Behavior on opacity { HNumberAnimation {} }
2019-11-07 21:44:53 +11:00
}
HButton {
id: expand
loading:
! model.first_sync_done || model.profile_updated < new Date(1)
2019-12-05 00:08:38 +11:00
iconItem.small: true
icon.name: "expand"
backgroundColor: "transparent"
toolTip.text: collapsed ? qsTr("Expand") : qsTr("Collapse")
onClicked: account.toggleCollapse()
2019-11-07 21:44:53 +11:00
leftPadding: theme.spacing / 2
rightPadding: leftPadding
opacity: ! loading && mainPane.filter ? 0 : 1
visible: opacity > 0 && Layout.maximumWidth > 0
2019-11-07 21:44:53 +11:00
Layout.fillHeight: true
Layout.maximumWidth:
account.width >= 120 * theme.uiScale ? implicitWidth : 0
2019-11-07 21:44:53 +11:00
iconItem.transform: Rotation {
2019-11-07 21:44:53 +11:00
origin.x: expand.iconItem.width / 2
origin.y: expand.iconItem.height / 2
2019-08-28 05:00:50 +10:00
angle: expand.loading ? 0 : collapsed ? 180 : 90
Behavior on angle { HNumberAnimation {} }
}
Behavior on Layout.maximumWidth { HNumberAnimation {} }
2019-12-16 19:42:41 +11:00
Behavior on opacity { HNumberAnimation {} }
}
}