matrixion/resources/qml/TimelineView.qml

277 lines
7.4 KiB
QML
Raw Normal View History

import QtQuick 2.6
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.2
2019-09-07 02:33:46 +03:00
import QtGraphicalEffects 1.0
2019-09-18 21:34:30 +03:00
import QtQuick.Window 2.2
2019-08-30 20:29:25 +03:00
import com.github.nheko 1.0
2019-08-30 20:29:25 +03:00
Rectangle {
anchors.fill: parent
2019-09-07 02:33:46 +03:00
SystemPalette { id: colors; colorGroup: SystemPalette.Active }
SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Disabled }
2019-09-19 22:53:24 +03:00
property int avatarSize: 32
2019-09-07 02:33:46 +03:00
color: colors.window
2019-08-30 20:29:25 +03:00
Text {
2019-08-31 23:43:31 +03:00
visible: !timelineManager.timeline
2019-08-30 20:29:25 +03:00
anchors.centerIn: parent
text: qsTr("No room open")
font.pointSize: 24
2019-09-07 02:33:46 +03:00
color: colors.windowText
2019-08-30 20:29:25 +03:00
}
2019-08-31 00:20:53 +03:00
ListView {
id: chat
2019-09-09 22:42:33 +03:00
cacheBuffer: parent.height
2019-08-31 23:43:31 +03:00
visible: timelineManager.timeline != null
2019-08-31 00:20:53 +03:00
anchors.fill: parent
2019-09-18 21:34:30 +03:00
model: timelineManager.timeline
onModelChanged: {
if (model) {
currentIndex = model.currentIndex
if (model.currentIndex == count - 1) {
positionViewAtEnd()
} else {
positionViewAtIndex(model.currentIndex, ListView.End)
}
}
}
ScrollBar.vertical: ScrollBar {
id: scrollbar
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
2019-09-18 21:34:30 +03:00
onPressedChanged: if (!pressed) chat.updatePosition()
}
2019-08-31 23:43:31 +03:00
2019-09-18 21:34:30 +03:00
property bool atBottom: false
onCountChanged: {
if (atBottom && Window.active) {
var newIndex = count - 1 // last index
positionViewAtEnd()
currentIndex = newIndex
model.currentIndex = newIndex
}
}
function updatePosition() {
for (var y = chat.contentY + chat.height; y > chat.height; y -= 5) {
var i = chat.itemAt(100, y);
if (!i) continue;
if (!i.isFullyVisible()) continue;
chat.model.currentIndex = i.getIndex();
chat.currentIndex = i.getIndex()
atBottom = i.getIndex() == count - 1;
console.log("bottom:" + atBottom)
break;
}
}
onMovementEnded: updatePosition()
spacing: 4
delegate: RowLayout {
2019-09-19 22:53:24 +03:00
anchors.leftMargin: avatarSize + 4
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: scrollbar.width
2019-09-18 21:34:30 +03:00
function isFullyVisible() {
return (y - chat.contentY - 1) + height < chat.height
}
function getIndex() {
return index;
}
Loader {
id: loader
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
height: item.height
source: switch(model.type) {
//case MtxEvent.Aliases: return "delegates/Aliases.qml"
//case MtxEvent.Avatar: return "delegates/Avatar.qml"
//case MtxEvent.CanonicalAlias: return "delegates/CanonicalAlias.qml"
//case MtxEvent.Create: return "delegates/Create.qml"
//case MtxEvent.GuestAccess: return "delegates/GuestAccess.qml"
//case MtxEvent.HistoryVisibility: return "delegates/HistoryVisibility.qml"
//case MtxEvent.JoinRules: return "delegates/JoinRules.qml"
//case MtxEvent.Member: return "delegates/Member.qml"
//case MtxEvent.Name: return "delegates/Name.qml"
//case MtxEvent.PowerLevels: return "delegates/PowerLevels.qml"
//case MtxEvent.Topic: return "delegates/Topic.qml"
case MtxEvent.NoticeMessage: return "delegates/NoticeMessage.qml"
case MtxEvent.TextMessage: return "delegates/TextMessage.qml"
2019-10-06 02:44:02 +03:00
case MtxEvent.EmoteMessage: return "delegates/TextMessage.qml"
case MtxEvent.ImageMessage: return "delegates/ImageMessage.qml"
2019-10-06 02:44:02 +03:00
case MtxEvent.Sticker: return "delegates/ImageMessage.qml"
2019-10-04 02:10:46 +03:00
case MtxEvent.FileMessage: return "delegates/FileMessage.qml"
case MtxEvent.VideoMessage: return "delegates/PlayableMediaMessage.qml"
case MtxEvent.AudioMessage: return "delegates/PlayableMediaMessage.qml"
2019-09-09 22:42:33 +03:00
case MtxEvent.Redacted: return "delegates/Redacted.qml"
default: return "delegates/placeholder.qml"
}
property variant eventData: model
}
2019-09-18 23:58:25 +03:00
StatusIndicator {
state: model.state
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Layout.preferredHeight: 16
}
2019-09-20 00:02:56 +03:00
EncryptionIndicator {
visible: model.isEncrypted
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Layout.preferredHeight: 16
}
Button {
Layout.alignment: Qt.AlignRight | Qt.AlignTop
id: replyButton
flat: true
2019-09-07 13:35:44 +03:00
Layout.preferredHeight: 16
ToolTip.visible: hovered
ToolTip.text: qsTr("Reply")
2019-09-07 02:33:46 +03:00
2019-09-07 13:35:44 +03:00
// disable background, because we don't want a border on hover
background: Item {
}
Image {
id: replyButtonImg
// Workaround, can't get icon.source working for now...
anchors.fill: parent
source: "qrc:/icons/icons/ui/mail-reply.png"
}
2019-09-07 02:33:46 +03:00
ColorOverlay {
anchors.fill: replyButtonImg
source: replyButtonImg
2019-09-07 13:35:44 +03:00
color: replyButton.hovered ? colors.highlight : colors.buttonText
2019-09-07 02:33:46 +03:00
}
2019-09-11 01:54:40 +03:00
onClicked: chat.model.replyAction(model.id)
}
Button {
Layout.alignment: Qt.AlignRight | Qt.AlignTop
id: optionsButton
flat: true
2019-09-07 13:35:44 +03:00
Layout.preferredHeight: 16
ToolTip.visible: hovered
ToolTip.text: qsTr("Options")
2019-09-07 13:35:44 +03:00
// disable background, because we don't want a border on hover
background: Item {
}
Image {
id: optionsButtonImg
// Workaround, can't get icon.source working for now...
anchors.fill: parent
source: "qrc:/icons/icons/ui/vertical-ellipsis.png"
}
2019-09-07 02:33:46 +03:00
ColorOverlay {
anchors.fill: optionsButtonImg
source: optionsButtonImg
2019-09-07 13:35:44 +03:00
color: optionsButton.hovered ? colors.highlight : colors.buttonText
2019-09-07 02:33:46 +03:00
}
onClicked: contextMenu.open()
Menu {
y: optionsButton.height
id: contextMenu
MenuItem {
2019-09-29 11:45:35 +03:00
text: qsTr("Read receipts")
onTriggered: chat.model.readReceiptsAction(model.id)
}
MenuItem {
2019-09-29 11:45:35 +03:00
text: qsTr("Mark as read")
}
MenuItem {
2019-09-29 11:45:35 +03:00
text: qsTr("View raw message")
2019-09-08 16:26:46 +03:00
onTriggered: chat.model.viewRawMessage(model.id)
}
MenuItem {
2019-09-29 11:45:35 +03:00
text: qsTr("Redact message")
2019-09-29 13:29:17 +03:00
onTriggered: chat.model.redactEvent(model.id)
2019-09-29 11:45:35 +03:00
}
MenuItem {
2019-10-06 02:44:02 +03:00
visible: model.type == MtxEvent.ImageMessage || model.type == MtxEvent.VideoMessage || model.type == MtxEvent.AudioMessage || model.type == MtxEvent.FileMessage || model.type == MtxEvent.Sticker
2019-09-29 11:45:35 +03:00
text: qsTr("Save as")
onTriggered: timelineManager.saveMedia(model.url, model.filename, model.mimetype, model.type)
}
}
}
Text {
Layout.alignment: Qt.AlignRight | Qt.AlignTop
text: model.timestamp.toLocaleTimeString("HH:mm")
2019-09-07 02:33:46 +03:00
color: inactiveColors.text
2019-09-07 13:35:44 +03:00
ToolTip.visible: ma.containsMouse
ToolTip.text: Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleLongDate)
MouseArea{
id: ma
anchors.fill: parent
hoverEnabled: true
}
}
}
section {
property: "section"
delegate: Column {
topPadding: 4
bottomPadding: 4
spacing: 8
width: parent.width
Label {
id: dateBubble
anchors.horizontalCenter: parent.horizontalCenter
visible: section.includes(" ")
text: chat.model.formatDateSeparator(new Date(Number(section.split(" ")[1])))
2019-09-07 02:33:46 +03:00
color: colors.windowText
height: contentHeight * 1.2
width: contentWidth * 1.2
horizontalAlignment: Text.AlignHCenter
background: Rectangle {
radius: parent.height / 2
2019-09-07 02:33:46 +03:00
color: colors.dark
}
}
Row {
height: userName.height
spacing: 4
2019-09-07 23:22:07 +03:00
Avatar {
2019-09-19 22:53:24 +03:00
width: avatarSize
height: avatarSize
2019-09-07 23:22:07 +03:00
url: chat.model.avatarUrl(section.split(" ")[0]).replace("mxc://", "image://MxcImage/")
displayName: chat.model.displayName(section.split(" ")[0])
}
Text {
id: userName
2019-09-07 03:01:44 +03:00
text: chat.model.escapeEmoji(chat.model.displayName(section.split(" ")[0]))
2019-09-07 02:33:46 +03:00
color: chat.model.userColor(section.split(" ")[0], colors.window)
2019-09-07 03:01:44 +03:00
textFormat: Text.RichText
}
}
}
2019-08-31 00:20:53 +03:00
}
2019-08-31 23:43:31 +03:00
}
2019-08-30 20:29:25 +03:00
}