Rename RoomEventList components
This commit is contained in:
9
src/qml/Chat/Timeline/Daybreak.qml
Normal file
9
src/qml/Chat/Timeline/Daybreak.qml
Normal file
@@ -0,0 +1,9 @@
|
||||
import QtQuick 2.7
|
||||
import "../../Base"
|
||||
|
||||
HNoticePage {
|
||||
text: model.date.toLocaleDateString()
|
||||
color: HStyle.chat.daybreak.foreground
|
||||
backgroundColor: HStyle.chat.daybreak.background
|
||||
radius: HStyle.chat.daybreak.radius
|
||||
}
|
120
src/qml/Chat/Timeline/EventContent.qml
Normal file
120
src/qml/Chat/Timeline/EventContent.qml
Normal file
@@ -0,0 +1,120 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Layouts 1.3
|
||||
import "../../Base"
|
||||
|
||||
Row {
|
||||
id: messageContent
|
||||
spacing: standardSpacing / 2
|
||||
layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight
|
||||
|
||||
function textHueForName(name) { // TODO: move
|
||||
return Qt.hsla(avatar.hueFromName(name),
|
||||
HStyle.displayName.saturation,
|
||||
HStyle.displayName.lightness,
|
||||
1)
|
||||
}
|
||||
|
||||
HAvatar {
|
||||
id: avatar
|
||||
hidden: combine
|
||||
name: senderInfo.displayName || stripUserId(model.senderId)
|
||||
dimension: model.showNameLine ? 48 : 28
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: HStyle.chat.message.background
|
||||
|
||||
//width: nameLabel.implicitWidth
|
||||
width: Math.min(
|
||||
roomEventListView.width - avatar.width - messageContent.spacing,
|
||||
HStyle.fontSize.normal * 0.5 * 75, // 600 with 16px font
|
||||
Math.max(
|
||||
nameLabel.visible ? nameLabel.implicitWidth : 0,
|
||||
contentLabel.implicitWidth
|
||||
)
|
||||
)
|
||||
height: nameLabel.height + contentLabel.implicitHeight
|
||||
|
||||
Column {
|
||||
spacing: 0
|
||||
anchors.fill: parent
|
||||
|
||||
HLabel {
|
||||
width: parent.width
|
||||
height: model.showNameLine && ! combine ? implicitHeight : 0
|
||||
visible: height > 0
|
||||
|
||||
id: nameLabel
|
||||
text: senderInfo.displayName || model.senderId
|
||||
color: textHueForName(avatar.name)
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
horizontalAlignment: isOwn ? Text.AlignRight : Text.AlignLeft
|
||||
|
||||
leftPadding: horizontalPadding
|
||||
rightPadding: horizontalPadding
|
||||
topPadding: verticalPadding
|
||||
}
|
||||
|
||||
HRichLabel {
|
||||
function escapeHtml(text) { // TODO: move this
|
||||
return text.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace('"', """)
|
||||
.replace("'", "'")
|
||||
}
|
||||
|
||||
function translate(text) {
|
||||
if (model.translatable == false) { return text }
|
||||
|
||||
text = text.replace(
|
||||
"%S",
|
||||
"<font color='" + nameLabel.color + "'>" +
|
||||
escapeHtml(senderInfo.displayName || model.senderId) +
|
||||
"</font>"
|
||||
)
|
||||
|
||||
var name = models.users.getUser(
|
||||
chatPage.userId, model.targetUserId
|
||||
).displayName
|
||||
var sid = avatar.stripUserId(model.targetUserId || "")
|
||||
|
||||
text = text.replace(
|
||||
"%T",
|
||||
"<font color='" + textHueForName(name || sid) + "'>" +
|
||||
escapeHtml(name || model.targetUserId) +
|
||||
"</font>"
|
||||
)
|
||||
|
||||
text = qsTr(text)
|
||||
if (model.translatable == true) { return text }
|
||||
|
||||
// Else, model.translatable should be an array of args
|
||||
for (var i = 0; model.translatable.length; i++) {
|
||||
text = text.arg(model.translatable[i])
|
||||
}
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
|
||||
id: contentLabel
|
||||
text: translate(model.content) +
|
||||
" <font size=" + HStyle.fontSize.small +
|
||||
"px color=" + HStyle.chat.message.date + ">" +
|
||||
Qt.formatDateTime(model.date, "hh:mm:ss") +
|
||||
"</font>" +
|
||||
(model.isLocalEcho ?
|
||||
" <font size=" + HStyle.fontSize.small +
|
||||
"px>⏳</font>" : "")
|
||||
color: HStyle.chat.message.body
|
||||
wrapMode: Text.Wrap
|
||||
|
||||
leftPadding: horizontalPadding
|
||||
rightPadding: horizontalPadding
|
||||
topPadding: nameLabel.visible ? 0 : verticalPadding
|
||||
bottomPadding: verticalPadding
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
src/qml/Chat/Timeline/EventDelegate.qml
Normal file
79
src/qml/Chat/Timeline/EventDelegate.qml
Normal file
@@ -0,0 +1,79 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Layouts 1.3
|
||||
import "../../Base"
|
||||
|
||||
Column {
|
||||
id: roomEventDelegate
|
||||
|
||||
function minsBetween(date1, date2) {
|
||||
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
|
||||
}
|
||||
|
||||
function getPreviousItem() {
|
||||
return index < roomEventListView.model.count - 1 ?
|
||||
roomEventListView.model.get(index + 1) : null
|
||||
}
|
||||
|
||||
property var previousItem: getPreviousItem()
|
||||
signal reloadPreviousItem()
|
||||
onReloadPreviousItem: previousItem = getPreviousItem()
|
||||
|
||||
property var senderInfo: null
|
||||
Component.onCompleted:
|
||||
senderInfo = models.users.getUser(chatPage.userId, senderId)
|
||||
|
||||
readonly property bool isOwn: chatPage.userId === senderId
|
||||
|
||||
readonly property bool isFirstEvent: model.event_type == "RoomCreateEvent"
|
||||
|
||||
readonly property bool combine:
|
||||
previousItem &&
|
||||
! talkBreak &&
|
||||
! dayBreak &&
|
||||
previousItem.senderId === senderId &&
|
||||
minsBetween(previousItem.date, model.date) <= 5
|
||||
|
||||
readonly property bool dayBreak:
|
||||
isFirstEvent ||
|
||||
previousItem &&
|
||||
model.date.getDate() != previousItem.date.getDate()
|
||||
|
||||
readonly property bool talkBreak:
|
||||
previousItem &&
|
||||
! dayBreak &&
|
||||
minsBetween(previousItem.date, model.date) >= 20
|
||||
|
||||
|
||||
property int standardSpacing: 16
|
||||
property int horizontalPadding: 6
|
||||
property int verticalPadding: 4
|
||||
|
||||
ListView.onAdd: {
|
||||
var nextDelegate = roomEventListView.contentItem.children[index]
|
||||
if (nextDelegate) { nextDelegate.reloadPreviousItem() }
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
|
||||
topPadding:
|
||||
isFirstEvent ? 0 :
|
||||
dayBreak ? standardSpacing * 2 :
|
||||
talkBreak ? standardSpacing * 3 :
|
||||
combine ? standardSpacing / 4 :
|
||||
standardSpacing
|
||||
|
||||
Loader {
|
||||
source: dayBreak ? "Daybreak.qml" : ""
|
||||
width: roomEventDelegate.width
|
||||
}
|
||||
|
||||
Item { // TODO: put this in Daybreak.qml?
|
||||
visible: dayBreak
|
||||
width: parent.width
|
||||
height: topPadding
|
||||
}
|
||||
|
||||
EventContent {
|
||||
anchors.right: isOwn ? parent.right : undefined
|
||||
}
|
||||
}
|
53
src/qml/Chat/Timeline/EventList.qml
Normal file
53
src/qml/Chat/Timeline/EventList.qml
Normal file
@@ -0,0 +1,53 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../../Base"
|
||||
|
||||
HRectangle {
|
||||
property int space: 8
|
||||
|
||||
color: HStyle.chat.roomEventList.background
|
||||
|
||||
HListView {
|
||||
id: roomEventListView
|
||||
clip: true
|
||||
|
||||
model: HListModel {
|
||||
sourceModel: models.timelines
|
||||
|
||||
filters: ValueFilter {
|
||||
roleName: "roomId"
|
||||
value: chatPage.roomId
|
||||
}
|
||||
}
|
||||
|
||||
delegate: EventDelegate {}
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: space
|
||||
anchors.rightMargin: space
|
||||
|
||||
topMargin: space
|
||||
bottomMargin: space
|
||||
verticalLayoutDirection: ListView.BottomToTop
|
||||
|
||||
// Keep x scroll pages cached, to limit images having to be
|
||||
// reloaded from network.
|
||||
cacheBuffer: height * 6
|
||||
|
||||
// Declaring this "alias" provides the on... signal
|
||||
property real yPos: visibleArea.yPosition
|
||||
|
||||
onYPosChanged: {
|
||||
if (chatPage.category != "Invites" && yPos <= 0.1) {
|
||||
//Backend.loadPastEvents(chatPage.roomId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HNoticePage {
|
||||
text: qsTr("Nothing to show here yet...")
|
||||
|
||||
visible: roomEventListView.model.count < 1
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user