Merge RoomList & AccountBar account delegates code

This commit is contained in:
miruka 2020-05-14 18:42:50 -04:00
parent bbb74b7b90
commit ad7bce657c
6 changed files with 76 additions and 97 deletions

View File

@ -1,6 +1,6 @@
# TODO # TODO
- merge AccountBar account and RoomList account delegates code - better initial highlight position when filtering
- fix python getting stuck when loading large room - fix python getting stuck when loading large room
- fix accounts in room list not getting their profile updated if mirage starts - fix accounts in room list not getting their profile updated if mirage starts
@ -12,7 +12,7 @@
- fix: there are rooms without messages on first sync - fix: there are rooms without messages on first sync
- avatar loading performance problem? - avatar loading performance problem?
- update docstrings - update docstrings and readme
- update flatpak nio required version - update flatpak nio required version
- final test - final test

View File

@ -9,13 +9,13 @@ HTile {
topPadding: padded ? spacing / (compact ? 4 : 2) : 0 topPadding: padded ? spacing / (compact ? 4 : 2) : 0
bottomPadding: topPadding bottomPadding: topPadding
onLeftClicked: { // onLeftClicked: {
view.highlightRangeMode = ListView.NoHighlightRange // view.highlightRangeMode = ListView.NoHighlightRange
view.highlightMoveDuration = 0 // view.highlightMoveDuration = 0
activated() // activated()
view.highlightRangeMode = ListView.ApplyRange // view.highlightRangeMode = ListView.ApplyRange
view.highlightMoveDuration = theme.animationDuration // view.highlightMoveDuration = theme.animationDuration
} // }
signal activated() signal activated()

View File

@ -5,16 +5,15 @@ import QtQuick.Layouts 1.12
import "../Base" import "../Base"
import "../Base/HTile" import "../Base/HTile"
HTileDelegate { HTile {
id: account id: account
backgroundColor: theme.mainPane.listView.account.background backgroundColor: theme.mainPane.listView.account.background
leftPadding: theme.spacing
rightPadding: 0 // the right buttons have padding
contentItem: ContentRow { contentItem: ContentRow {
tile: account tile: account
spacing: 0 spacing: 0
opacity: collapsed ? theme.mainPane.listView.account.collapsedOpacity : 1 opacity:
collapsed ? theme.mainPane.listView.account.collapsedOpacity : 1
Behavior on opacity { HNumberAnimation {} } Behavior on opacity { HNumberAnimation {} }
@ -25,9 +24,45 @@ HTileDelegate {
mxc: model.avatar_url mxc: model.avatar_url
radius: theme.mainPane.listView.account.avatarRadius radius: theme.mainPane.listView.account.avatarRadius
compact: account.compact compact: account.compact
Layout.alignment: Qt.AlignCenter
HLoader {
anchors.fill: parent
z: 9998
opacity: model.first_sync_done ? 0 : 1
active: opacity > 0
sourceComponent: Rectangle {
radius: avatar.radius
color: utils.hsluv(0, 0, 0, 0.6)
HBusyIndicator {
anchors.centerIn: parent
width: parent.width / 2
height: width
}
}
Behavior on opacity { HNumberAnimation {} }
}
MessageIndicator {
id: totalMessageIndicator
anchors.right: parent.right
anchors.bottom: parent.bottom
z: 9999
indicatorTheme:
theme.mainPane.accountBar.account.unreadIndicator
unreads: model.total_unread
mentions: model.total_mentions
}
} }
TitleLabel { TitleLabel {
id: title
text: model.display_name || model.id text: model.display_name || model.id
color: color:
hovered ? hovered ?
@ -59,7 +94,7 @@ HTileDelegate {
account.width >= 100 * theme.uiScale ? implicitWidth : 0 account.width >= 100 * theme.uiScale ? implicitWidth : 0
HShortcut { HShortcut {
enabled: isCurrent enabled: enableKeybinds
sequences: window.settings.keys.addNewChat sequences: window.settings.keys.addNewChat
onActivated: addChat.clicked() onActivated: addChat.clicked()
} }
@ -98,20 +133,20 @@ HTileDelegate {
contextMenu: AccountContextMenu { userId: model.id } contextMenu: AccountContextMenu { userId: model.id }
onLeftClicked: {
pageLoader.showPage(
"AccountSettings/AccountSettings", { "userId": model.id }
)
}
property bool enableKeybinds: false
property bool isCurrent: false
property bool filterActive: false property bool filterActive: false
readonly property bool collapsed: readonly property bool collapsed:
(window.uiState.collapseAccounts[model.id] || false) && (window.uiState.collapseAccounts[model.id] || false) &&
! filterActive ! filterActive
readonly property alias avatar: title
readonly property alias totalMessageIndicator: totalMessageIndicator
readonly property alias title: title
readonly property alias addChat: addChat
readonly property alias expand: expand
function setCollapse(collapse) { function setCollapse(collapse) {
window.uiState.collapseAccounts[model.id] = collapse window.uiState.collapseAccounts[model.id] = collapse
@ -126,13 +161,13 @@ HTileDelegate {
HShortcut { HShortcut {
enabled: isCurrent enabled: enableKeybinds
sequences: window.settings.keys.accountSettings sequences: window.settings.keys.accountSettings
onActivated: leftClicked() onActivated: leftClicked()
} }
HShortcut { HShortcut {
enabled: isCurrent enabled: enableKeybinds
sequences: window.settings.keys.toggleCollapseAccount sequences: window.settings.keys.toggleCollapseAccount
onActivated: toggleCollapse() onActivated: toggleCollapse()
} }

View File

@ -38,79 +38,18 @@ Rectangle {
model: ModelStore.get("matching_accounts") model: ModelStore.get("matching_accounts")
delegate: HTile { delegate: Account {
id: tile
width: accountList.cellWidth width: accountList.cellWidth
height: accountList.cellHeight height: accountList.cellHeight
padded: false padded: false
backgroundColor: theme.mainPane.accountBar.account.background compact: false
filterActive: Boolean(roomList.filter)
contentItem: Item { title.visible: false
id: tileContent addChat.visible: false
expand.visible: false
HUserAvatar { onLeftClicked: roomList.goToAccount(model.id)
id: avatar
anchors.centerIn: parent
userId: model.id
displayName: model.display_name
mxc: model.avatar_url
// compact: tile.compact
radius: theme.mainPane.accountBar.account.avatarRadius
opacity:
tile.collapsed ?
theme.mainPane.accountBar.account.collapsedOpacity :
1
Behavior on opacity { HNumberAnimation {} }
}
MessageIndicator {
anchors.right: parent.right
anchors.bottom: parent.bottom
indicatorTheme:
theme.mainPane.accountBar.account.unreadIndicator
unreads: model.total_unread
mentions: model.total_mentions
}
HLoader {
anchors.centerIn: parent
width: avatar.width
height: avatar.height
opacity: model.first_sync_done ? 0 : 1
active: opacity > 0
sourceComponent: Rectangle {
radius: avatar.radius
color: utils.hsluv(0, 0, 0, 0.5)
HBusyIndicator {
anchors.centerIn: parent
width: tileContent.width / 2
height: width
}
}
Behavior on opacity { HNumberAnimation {} }
}
}
contextMenu: AccountContextMenu { userId: model.id }
onLeftClicked: {
accountList.highlightRangeMode = GridView.NoHighlightRange
accountList.highlightMoveDuration = 0
roomList.goToAccount(model.id)
accountList.highlightRangeMode = GridView.ApplyRange
accountList.highlightMoveDuration = theme.animationDuration
}
readonly property bool collapsed:
(window.uiState.collapseAccounts[model.id] || false) &&
! roomList.filter
} }
highlight: Item { highlight: Item {

View File

@ -17,11 +17,20 @@ HListView {
roleValue: "Account" roleValue: "Account"
Account { Account {
width: roomList.width width: roomList.width
leftPadding: theme.spacing
rightPadding: 0 // the right buttons have padding
filterActive: Boolean(filter) filterActive: Boolean(filter)
isCurrent: enableKeybinds:
currentIndexModel && currentIndexModel &&
(currentIndexModel.for_account || currentIndexModel.id) === (currentIndexModel.for_account || currentIndexModel.id) ===
model.id model.id
totalMessageIndicator.visible: false
onLeftClicked: pageLoader.showPage(
"AccountSettings/AccountSettings", {userId: model.id}
)
} }
} }
@ -29,7 +38,7 @@ HListView {
roleValue: "Room" roleValue: "Room"
Room { Room {
width: roomList.width width: roomList.width
onActivated: showItemAtIndex(model.index) onLeftClicked: showItemAtIndex(model.index)
} }
} }
} }

View File

@ -283,10 +283,6 @@ mainPane:
color background: colors.mediumBackground color background: colors.mediumBackground
account: account:
real collapsedOpacity: 0.3
color background: "transparent"
int avatarRadius: controls.avatar.radius
color selectedBackground: colors.accentBackground color selectedBackground: colors.accentBackground
real selectedBackgroundOpacity: 0.3 real selectedBackgroundOpacity: 0.3
color selectedBorder: colors.strongAccentElement color selectedBorder: colors.strongAccentElement