moment/src/gui/Pages/Chat/Timeline/EventContent.qml

200 lines
6.3 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-18 19:53:08 +11:00
import "../../../Base"
import "../../.."
2019-04-15 02:56:30 +10:00
HRowLayout {
2019-07-18 21:22:41 +10:00
id: eventContent
spacing: theme.spacing / 1.25
layoutDirection: onRight ? Qt.RightToLeft: Qt.LeftToRight
readonly property string senderText:
hideNameLine ? "" : (
"<div class='sender'>" +
utils.coloredNameHtml(model.sender_name, model.sender_id) +
"</div>"
)
readonly property string contentText: utils.processedEventText(model)
readonly property string timeText: utils.formatTime(model.date, false)
readonly property string localEchoText:
model.is_local_echo ?
2019-11-18 18:57:13 +11:00
`&nbsp;<font size=${theme.fontSize.small}px></font>` :
""
readonly property bool pureMedia: ! contentText && linksRepeater.count
2019-04-15 02:56:30 +10:00
readonly property string hoveredLink: contentLabel.hoveredLink
readonly property bool hoveredSelectable: contentHover.hovered
2019-09-20 09:28:28 +10:00
readonly property int xOffset:
onRight ?
Math.min(
contentColumn.width - contentLabel.paintedWidth -
contentLabel.leftPadding - contentLabel.rightPadding,
contentColumn.width - linksRepeater.widestChild -
(
pureMedia ?
0 : contentLabel.leftPadding + contentLabel.rightPadding
),
) :
2019-09-20 09:28:28 +10:00
0
// ~600px max with a 16px font
readonly property int maxMessageWidth: theme.fontSize.normal * 0.5 * 75
readonly property alias debugConsoleLoader: debugConsoleLoader
DebugConsoleLoader {
id: debugConsoleLoader
active: false
onLoaded: item.runJS("json()")
2019-09-20 09:28:28 +10:00
}
Item {
id: avatarWrapper
opacity: collapseAvatar ? 0 : 1
visible: ! hideAvatar
2019-12-05 00:08:38 +11:00
Layout.minimumWidth: theme.chat.message.avatarSize
Layout.minimumHeight:
collapseAvatar ? 1 :
smallAvatar ? theme.chat.message.collapsedAvatarSize :
Layout.minimumWidth
Layout.maximumWidth: Layout.minimumWidth
Layout.maximumHeight: Layout.minimumHeight
Layout.alignment: Qt.AlignTop
HUserAvatar {
id: avatar
Big performance refactoring & various improvements Instead of passing all sorts of events for the JS to handle and manually add to different data models, we now handle everything we can in Python. For any change, the python models send a sync event with their contents (no more than 4 times per second) to JS, and the QSyncable library's JsonListModel takes care of converting it to a QML ListModel and sending the appropriate signals. The SortFilterProxyModel library is not used anymore, the only case where we need to filter/sort something now is when the user interacts with the "Filter rooms" or "Filter members" fields. These cases are handled by a simple JS function. We now keep separated room and timeline models for different accounts, the previous approach of sharing all the data we could between accounts created a lot of complications (local echoes, decrypted messages replacing others, etc). The users's own account profile changes are now hidden in the timeline. On startup, if all events for a room were only own profile changes, more events will be loaded. Any kind of image format supported by Qt is now handled by the pyotherside image provider, instead of just PNG/JPG. SVGs which previously caused errors are supported as well. The typing members bar paddings/margins are fixed. The behavior of the avatar/"upload a profile picture" overlay is fixed. Config files read from disk are now cached (TODO: make them reloadable again). Pylint is not used anymore because of all its annoying false warnings and lack of understanding for dataclasses, it is replaced by flake8 with a custom config and various plugins. Debug mode is now considered on if the program was compiled with the right option, instead of taking an argument from CLI. When on, C++ will set a flag in the Window QML component. The loading screen is now unloaded after the UI is ready, where previously it just stayed in the background invisible and wasted CPU. The overall refactoring and improvements make us now able to handle rooms with thousand of members and no lazy-loading, where previously everything would freeze and simply scrolling up to load past events in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
userId: model.sender_id
displayName: model.sender_name
mxc: model.sender_avatar
width: parent.width
2019-12-05 00:08:38 +11:00
height: collapseAvatar ? 1 : theme.chat.message.avatarSize
}
}
HColumnLayout {
id: contentColumn
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
HSelectableLabel {
id: contentLabel
container: selectableLabelContainer
index: model.index
visible: ! pureMedia
topPadding: theme.spacing / 1.75
bottomPadding: topPadding
leftPadding: eventContent.spacing
rightPadding: leftPadding
2019-11-30 22:10:48 +11:00
color: model.event_type === "RoomMessageNotice" ?
theme.chat.message.noticeBody :
theme.chat.message.body
font.italic: model.event_type === "RoomMessageEmote"
wrapMode: TextEdit.Wrap
textFormat: Text.RichText
text:
// CSS
theme.chat.message.styleInclude +
// Sender name
eventContent.senderText +
// Message body
eventContent.contentText +
// Time
// For some reason, if there's only one space,
// times will be on their own lines most of the time.
" " +
2019-11-18 18:57:13 +11:00
`<font size=${theme.fontSize.small}px ` +
`color=${theme.chat.message.date}>` +
timeText +
"</font>" +
// Local echo icon
(model.is_local_echo ?
2019-11-18 18:57:13 +11:00
`&nbsp;<font size=${theme.fontSize.small}px></font>` : "")
2019-09-20 09:28:28 +10:00
transform: Translate { x: xOffset }
Layout.maximumWidth: eventContent.maxMessageWidth
Layout.fillWidth: true
function selectAllText() {
// Select the message body without the date or name
container.clearSelection()
contentLabel.select(
0,
contentLabel.length -
timeText.length - 1 // - 1: separating space
)
contentLabel.updateContainerSelectedTexts()
}
HoverHandler { id: contentHover }
Rectangle {
width: Math.max(
parent.paintedWidth +
parent.leftPadding + parent.rightPadding,
2019-12-20 06:56:07 +11:00
linksRepeater.summedWidth +
(pureMedia ? 0 : parent.leftPadding + parent.rightPadding),
)
height: contentColumn.height
2020-03-13 16:09:04 +11:00
z: -100
color: isOwn?
theme.chat.message.ownBackground :
theme.chat.message.background
2019-11-30 22:10:48 +11:00
Rectangle {
visible: model.event_type === "RoomMessageNotice"
width: theme.chat.message.noticeLineWidth
height: parent.height
color: utils.nameColor(
2019-11-30 22:10:48 +11:00
model.sender_name || model.sender_id.substring(1),
)
}
}
}
HRepeater {
2019-09-20 09:28:28 +10:00
id: linksRepeater
model: [
eventDelegate.currentModel.media_url,
...JSON.parse(eventDelegate.currentModel.links),
]
EventMediaLoader {
singleMediaInfo: eventDelegate.currentModel
mediaUrl: modelData
showSender: pureMedia ? senderText : ""
showDate: pureMedia ? timeText : ""
showLocalEcho: pureMedia ? localEchoText : ""
2019-09-20 09:28:28 +10:00
transform: Translate { x: xOffset }
2019-10-28 04:26:00 +11:00
Layout.bottomMargin: pureMedia ? 0 : contentLabel.bottomPadding
Layout.leftMargin: pureMedia ? 0 : eventContent.spacing
Layout.rightMargin: pureMedia ? 0 : eventContent.spacing
2019-11-06 00:19:48 +11:00
Layout.preferredWidth: item ? item.width : -1
Layout.preferredHeight: item ? item.height : -1
}
2019-04-15 02:56:30 +10:00
}
}
HSpacer {}
2019-04-15 02:56:30 +10:00
}