Replace HInteractiveRectangle by HTiledelegate
This commit is contained in:
@@ -3,157 +3,73 @@ import QtQuick.Layouts 1.12
|
||||
import "../Base"
|
||||
import "../utils.js" as Utils
|
||||
|
||||
HInteractiveRectangle {
|
||||
HTileDelegate {
|
||||
id: roomDelegate
|
||||
color: theme.sidePane.room.background
|
||||
visible: height > 0
|
||||
height: rowLayout.height
|
||||
spacing: sidePane.currentSpacing
|
||||
backgroundColor: theme.sidePane.room.background
|
||||
opacity: model.data.left ? theme.sidePane.room.leftRoomOpacity : 1
|
||||
isCurrent: window.uiState.page == "Chat/Chat.qml" &&
|
||||
window.uiState.pageProperties.userId == model.user_id &&
|
||||
window.uiState.pageProperties.roomId == model.data.room_id
|
||||
|
||||
|
||||
Behavior on opacity { HNumberAnimation {} }
|
||||
|
||||
|
||||
readonly property var delegateModel: model
|
||||
|
||||
readonly property bool forceExpand:
|
||||
Boolean(accountRoomList.filter)
|
||||
|
||||
readonly property bool isCurrent:
|
||||
window.uiState.page == "Chat/Chat.qml" &&
|
||||
window.uiState.pageProperties.userId == model.user_id &&
|
||||
window.uiState.pageProperties.roomId == model.data.room_id
|
||||
readonly property var eventDate:
|
||||
model.data.last_event ? model.data.last_event.date : null
|
||||
|
||||
|
||||
onIsCurrentChanged: if (isCurrent) beHighlighted()
|
||||
onActivated: pageLoader.showRoom(model.user_id, model.data.room_id)
|
||||
|
||||
|
||||
function beHighlighted() {
|
||||
accountRoomList.currentIndex = model.index
|
||||
image: HRoomAvatar {
|
||||
displayName: model.data.display_name
|
||||
avatarUrl: model.data.avatar_url
|
||||
}
|
||||
|
||||
function activate() {
|
||||
pageLoader.showRoom(model.user_id, model.data.room_id)
|
||||
title.color: theme.sidePane.room.name
|
||||
title.text: model.data.display_name || "<i>Empty room</i>"
|
||||
title.textFormat: model.data.display_name? Text.PlainText : Text.StyledText
|
||||
|
||||
additionalInfo.children: HIcon {
|
||||
svgName: "invite-received"
|
||||
|
||||
visible: Layout.maximumWidth > 0
|
||||
Layout.maximumWidth:
|
||||
model.data.inviter_id && ! model.data.left ?
|
||||
implicitWidth : 0
|
||||
|
||||
Behavior on Layout.maximumWidth { HNumberAnimation {} }
|
||||
}
|
||||
|
||||
rightInfo.color: theme.sidePane.room.lastEventDate
|
||||
rightInfo.text: {
|
||||
! eventDate ? "" :
|
||||
|
||||
// Component.onCompleted won't work for this
|
||||
Timer {
|
||||
interval: 100
|
||||
repeat: true
|
||||
running: accountRoomList.currentIndex == -1
|
||||
onTriggered: if (isCurrent) beHighlighted()
|
||||
Utils.dateIsToday(eventDate) ?
|
||||
Utils.formatTime(eventDate, false) : // no seconds
|
||||
|
||||
eventDate.getFullYear() == new Date().getFullYear() ?
|
||||
Qt.formatDate(eventDate, "d MMM") : // e.g. "5 Dec"
|
||||
|
||||
eventDate.getFullYear()
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: accountRoomList
|
||||
onHideHoverHighlight: roomDelegate.hovered = false
|
||||
}
|
||||
subtitle.color: theme.sidePane.room.subtitle
|
||||
subtitle.textFormat: Text.StyledText
|
||||
subtitle.text: {
|
||||
if (! model.data.last_event) { return "" }
|
||||
|
||||
TapHandler {
|
||||
onTapped: {
|
||||
accountRoomList.highlightRangeMode = ListView.NoHighlightRange
|
||||
accountRoomList.highlightMoveDuration = 0
|
||||
activate()
|
||||
accountRoomList.highlightRangeMode = ListView.ApplyRange
|
||||
accountRoomList.highlightMoveDuration = theme.animationDuration
|
||||
}
|
||||
}
|
||||
let ev = model.data.last_event
|
||||
|
||||
HRowLayout {
|
||||
id: rowLayout
|
||||
|
||||
spacing: sidePane.currentSpacing
|
||||
x: sidePane.currentSpacing
|
||||
width: parent.width - sidePane.currentSpacing * 1.75
|
||||
height: roomName.height + subtitle.height + sidePane.currentSpacing
|
||||
|
||||
HRoomAvatar {
|
||||
id: roomAvatar
|
||||
displayName: model.data.display_name
|
||||
avatarUrl: model.data.avatar_url
|
||||
if (ev.event_type === "RoomMessageEmote" ||
|
||||
! ev.event_type.startsWith("RoomMessage")) {
|
||||
return Utils.processedEventText(ev)
|
||||
}
|
||||
|
||||
HColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
HRowLayout {
|
||||
spacing: rowLayout.spacing
|
||||
|
||||
HLabel {
|
||||
id: roomName
|
||||
color: theme.sidePane.room.name
|
||||
text: model.data.display_name || "<i>Empty room</i>"
|
||||
textFormat:
|
||||
model.data.display_name?
|
||||
Text.PlainText : Text.StyledText
|
||||
elide: Text.ElideRight
|
||||
verticalAlignment: Qt.AlignVCenter
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
HIcon {
|
||||
svgName: "invite-received"
|
||||
|
||||
visible: Layout.maximumWidth > 0
|
||||
Layout.maximumWidth:
|
||||
model.data.inviter_id && ! model.data.left ?
|
||||
implicitWidth : 0
|
||||
Behavior on Layout.maximumWidth { HNumberAnimation {} }
|
||||
}
|
||||
|
||||
HLabel {
|
||||
readonly property var evDate:
|
||||
model.data.last_event ?
|
||||
model.data.last_event.date : null
|
||||
|
||||
id: lastEventDate
|
||||
font.pixelSize: theme.fontSize.small
|
||||
color: theme.sidePane.room.lastEventDate
|
||||
|
||||
text: ! evDate ? "" :
|
||||
|
||||
Utils.dateIsToday(evDate) ?
|
||||
Utils.formatTime(evDate, false) : // no seconds
|
||||
|
||||
evDate.getFullYear() == new Date().getFullYear() ?
|
||||
Qt.formatDate(evDate, "d MMM") : // e.g. "5 Dec"
|
||||
|
||||
evDate.getFullYear()
|
||||
|
||||
visible: Layout.maximumWidth > 0
|
||||
Layout.maximumWidth:
|
||||
text && roomDelegate.width >= 200 ? implicitWidth : 0
|
||||
Behavior on Layout.maximumWidth { HNumberAnimation {} }
|
||||
}
|
||||
}
|
||||
|
||||
HRichLabel {
|
||||
id: subtitle
|
||||
color: theme.sidePane.room.subtitle
|
||||
visible: Boolean(text)
|
||||
textFormat: Text.StyledText
|
||||
font.pixelSize: theme.fontSize.small
|
||||
elide: Text.ElideRight
|
||||
|
||||
text: {
|
||||
if (! model.data.last_event) { return "" }
|
||||
|
||||
let ev = model.data.last_event
|
||||
|
||||
if (ev.event_type === "RoomMessageEmote" ||
|
||||
! ev.event_type.startsWith("RoomMessage")) {
|
||||
return Utils.processedEventText(ev)
|
||||
}
|
||||
|
||||
return Utils.coloredNameHtml(
|
||||
ev.sender_name, ev.sender_id
|
||||
) + ": " + ev.inline_content
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
return Utils.coloredNameHtml(
|
||||
ev.sender_name, ev.sender_id
|
||||
) + ": " + ev.inline_content
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user