nheko/resources/qml/RoomList.qml

358 lines
12 KiB
QML
Raw Normal View History

2021-05-14 23:35:34 +02:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
2021-05-21 21:19:03 +02:00
import QtQuick 2.13
2021-05-14 23:35:34 +02:00
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3
import im.nheko 1.0
Page {
2021-05-19 19:34:10 +02:00
ListView {
2021-05-21 21:19:03 +02:00
id: roomlist
2021-05-19 19:34:10 +02:00
anchors.left: parent.left
anchors.right: parent.right
height: parent.height
model: Rooms
ScrollHelper {
flickable: parent
anchors.fill: parent
enabled: !Settings.mobileMode
}
2021-05-21 21:19:03 +02:00
Connections {
onActiveTimelineChanged: {
roomlist.positionViewAtIndex(Rooms.roomidToIndex(TimelineManager.timeline.roomId()), ListView.Contain);
console.log("Test" + TimelineManager.timeline.roomId() + " " + Rooms.roomidToIndex(TimelineManager.timeline.roomId));
}
target: TimelineManager
}
2021-05-19 19:34:10 +02:00
delegate: Rectangle {
2021-05-21 21:19:03 +02:00
id: roomItem
property color background: Nheko.colors.window
property color importantText: Nheko.colors.text
property color unimportantText: Nheko.colors.buttonText
property color bubbleBackground: Nheko.colors.highlight
property color bubbleText: Nheko.colors.highlightedText
color: background
height: Math.ceil(fontMetrics.lineSpacing * 2.3 + Nheko.paddingMedium * 2)
2021-05-19 19:34:10 +02:00
width: ListView.view.width
2021-05-21 21:19:03 +02:00
state: "normal"
states: [
State {
name: "highlight"
2021-05-22 11:23:16 +02:00
when: hovered.hovered && !(TimelineManager.timeline && model.roomId == TimelineManager.timeline.roomId())
2021-05-21 21:19:03 +02:00
PropertyChanges {
target: roomItem
background: Nheko.colors.dark
importantText: Nheko.colors.brightText
unimportantText: Nheko.colors.brightText
bubbleBackground: Nheko.colors.highlight
bubbleText: Nheko.colors.highlightedText
}
2021-05-19 19:34:10 +02:00
2021-05-21 21:19:03 +02:00
},
State {
name: "selected"
when: TimelineManager.timeline && model.roomId == TimelineManager.timeline.roomId()
PropertyChanges {
target: roomItem
background: Nheko.colors.highlight
importantText: Nheko.colors.highlightedText
unimportantText: Nheko.colors.highlightedText
bubbleBackground: Nheko.colors.highlightedText
bubbleText: Nheko.colors.highlight
}
}
]
2021-05-19 19:34:10 +02:00
2021-05-21 21:19:03 +02:00
HoverHandler {
id: hovered
}
TapHandler {
onSingleTapped: TimelineManager.setHistoryView(model.roomId)
}
RowLayout {
2021-05-19 19:34:10 +02:00
spacing: Nheko.paddingMedium
anchors.fill: parent
anchors.margins: Nheko.paddingMedium
Avatar {
2021-05-21 21:19:03 +02:00
// In the future we could show an online indicator by setting the userid for the avatar
2021-05-19 19:34:10 +02:00
//userid: Nheko.currentUser.userid
id: avatar
Layout.alignment: Qt.AlignVCenter
2021-05-21 21:19:03 +02:00
height: Math.ceil(fontMetrics.lineSpacing * 2.3)
width: Math.ceil(fontMetrics.lineSpacing * 2.3)
2021-05-19 19:34:10 +02:00
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
displayName: model.roomName
}
ColumnLayout {
id: textContent
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
Layout.minimumWidth: 100
width: parent.width - avatar.width
Layout.preferredWidth: parent.width - avatar.width
2021-05-21 21:19:03 +02:00
spacing: Nheko.paddingSmall
2021-05-19 19:34:10 +02:00
RowLayout {
Layout.fillWidth: true
spacing: 0
ElidedLabel {
Layout.alignment: Qt.AlignBottom
2021-05-21 21:19:03 +02:00
color: roomItem.importantText
2021-05-19 19:34:10 +02:00
elideWidth: textContent.width - timestamp.width - Nheko.paddingMedium
2021-05-21 21:19:03 +02:00
fullText: model.roomName
2021-05-22 10:16:42 +02:00
textFormat: Text.RichText
2021-05-19 19:34:10 +02:00
}
Item {
Layout.fillWidth: true
}
Label {
id: timestamp
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
font.pixelSize: fontMetrics.font.pixelSize * 0.9
2021-05-21 21:19:03 +02:00
color: roomItem.unimportantText
2021-05-22 00:57:14 +02:00
text: model.time
2021-05-19 19:34:10 +02:00
}
}
RowLayout {
Layout.fillWidth: true
spacing: 0
ElidedLabel {
2021-05-21 21:19:03 +02:00
color: roomItem.unimportantText
2021-05-19 19:34:10 +02:00
font.weight: Font.Thin
font.pixelSize: fontMetrics.font.pixelSize * 0.9
2021-05-21 21:19:03 +02:00
elideWidth: textContent.width - (notificationBubble.visible ? notificationBubble.width : 0) - Nheko.paddingSmall
2021-05-19 19:34:10 +02:00
fullText: model.lastMessage
2021-05-22 10:16:42 +02:00
textFormat: Text.RichText
2021-05-19 19:34:10 +02:00
}
Item {
Layout.fillWidth: true
}
Rectangle {
id: notificationBubble
2021-05-21 21:19:03 +02:00
visible: model.notificationCount > 0
2021-05-19 19:34:10 +02:00
Layout.alignment: Qt.AlignRight
2021-05-21 21:19:03 +02:00
height: fontMetrics.averageCharacterWidth * 3
2021-05-19 19:34:10 +02:00
width: height
radius: height / 2
2021-05-21 21:19:03 +02:00
color: model.hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground
2021-05-19 19:34:10 +02:00
Label {
2021-05-21 21:19:03 +02:00
anchors.centerIn: parent
width: parent.width * 0.8
height: parent.height * 0.8
2021-05-19 19:34:10 +02:00
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
fontSizeMode: Text.Fit
2021-05-21 21:19:03 +02:00
font.bold: true
font.pixelSize: fontMetrics.font.pixelSize * 0.8
color: model.hasLoudNotification ? "white" : roomItem.bubbleText
text: model.notificationCount > 99 ? "99+" : model.notificationCount
2021-05-19 19:34:10 +02:00
}
}
}
}
}
Rectangle {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
height: parent.height - Nheko.paddingSmall * 2
width: 3
color: Nheko.colors.highlight
visible: model.hasUnreadMessages
}
}
}
2021-05-14 23:35:34 +02:00
background: Rectangle {
color: Nheko.theme.sidebarBackground
}
header: ColumnLayout {
spacing: 0
Rectangle {
color: Nheko.colors.window
Layout.fillWidth: true
Layout.alignment: Qt.AlignBottom
Layout.preferredHeight: userInfoGrid.implicitHeight + 2 * Nheko.paddingMedium
Layout.minimumHeight: 40
TapHandler {
onSingleTapped: {
Nheko.updateUserProfile();
var userProfile = userProfileComponent.createObject(timelineRoot, {
"profile": Nheko.currentUser
});
userProfile.show();
}
}
2021-05-14 23:35:34 +02:00
RowLayout {
id: userInfoGrid
spacing: Nheko.paddingMedium
anchors.fill: parent
anchors.margins: Nheko.paddingMedium
Avatar {
id: avatar
Layout.alignment: Qt.AlignVCenter
2021-05-19 19:34:10 +02:00
Layout.preferredWidth: fontMetrics.lineSpacing * 2
Layout.preferredHeight: fontMetrics.lineSpacing * 2
2021-05-14 23:35:34 +02:00
url: Nheko.currentUser.avatarUrl.replace("mxc://", "image://MxcImage/")
displayName: Nheko.currentUser.displayName
userid: Nheko.currentUser.userid
}
ColumnLayout {
id: col
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
2021-05-19 19:34:10 +02:00
width: parent.width - avatar.width - logoutButton.width - Nheko.paddingMedium * 2
Layout.preferredWidth: parent.width - avatar.width - logoutButton.width - Nheko.paddingMedium * 2
2021-05-14 23:35:34 +02:00
spacing: 0
2021-05-19 19:34:10 +02:00
ElidedLabel {
2021-05-14 23:35:34 +02:00
Layout.alignment: Qt.AlignBottom
font.pointSize: fontMetrics.font.pointSize * 1.1
font.weight: Font.DemiBold
2021-05-19 19:34:10 +02:00
fullText: Nheko.currentUser.displayName
elideWidth: col.width
2021-05-14 23:35:34 +02:00
}
2021-05-19 19:34:10 +02:00
ElidedLabel {
2021-05-14 23:35:34 +02:00
Layout.alignment: Qt.AlignTop
color: Nheko.colors.buttonText
font.weight: Font.Thin
font.pointSize: fontMetrics.font.pointSize * 0.9
2021-05-19 19:34:10 +02:00
elideWidth: col.width
fullText: Nheko.currentUser.userid
2021-05-14 23:35:34 +02:00
}
}
Item {
}
ImageButton {
id: logoutButton
Layout.alignment: Qt.AlignVCenter
image: ":/icons/icons/ui/power-button-off.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("Logout")
}
}
}
Rectangle {
color: Nheko.theme.separator
height: 2
Layout.fillWidth: true
}
}
footer: ColumnLayout {
spacing: 0
Rectangle {
color: Nheko.theme.separator
height: 1
Layout.fillWidth: true
}
Rectangle {
color: Nheko.colors.window
Layout.fillWidth: true
Layout.alignment: Qt.AlignBottom
Layout.preferredHeight: buttonRow.implicitHeight
Layout.minimumHeight: 40
RowLayout {
id: buttonRow
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: Nheko.paddingMedium
ImageButton {
Layout.alignment: Qt.AlignBottom | Qt.AlignLeft
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/plus-black-symbol.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("Start a new chat")
Layout.margins: Nheko.paddingMedium
}
ImageButton {
Layout.alignment: Qt.AlignBottom | Qt.AlignHCenter
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/speech-bubbles-comment-option.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("Room directory")
Layout.margins: Nheko.paddingMedium
}
ImageButton {
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/settings.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("User settings")
Layout.margins: Nheko.paddingMedium
}
}
}
}
}