2019-04-15 02:56:30 +10:00
|
|
|
import QtQuick 2.7
|
2019-04-29 05:45:42 +10:00
|
|
|
import QtQuick.Layouts 1.3
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../../Base"
|
2019-04-15 02:56:30 +10:00
|
|
|
|
|
|
|
Row {
|
2019-05-09 01:18:22 +10:00
|
|
|
id: messageContent
|
2019-04-30 13:58:17 +10:00
|
|
|
spacing: standardSpacing / 2
|
2019-04-15 02:56:30 +10:00
|
|
|
layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight
|
|
|
|
|
2019-07-03 12:22:29 +10:00
|
|
|
function textHueForName(name) { // TODO: move
|
|
|
|
return Qt.hsla(avatar.hueFromName(name),
|
|
|
|
HStyle.displayName.saturation,
|
|
|
|
HStyle.displayName.lightness,
|
|
|
|
1)
|
|
|
|
}
|
|
|
|
|
2019-05-09 01:18:22 +10:00
|
|
|
HAvatar {
|
|
|
|
id: avatar
|
|
|
|
hidden: combine
|
2019-07-03 03:59:52 +10:00
|
|
|
name: senderInfo.displayName || stripUserId(model.senderId)
|
2019-07-03 12:22:29 +10:00
|
|
|
dimension: model.showNameLine ? 48 : 28
|
2019-05-09 01:18:22 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
2019-07-03 13:48:36 +10:00
|
|
|
color: isMessage(model) ?
|
|
|
|
HStyle.chat.message.background : HStyle.chat.event.background
|
2019-04-15 02:56:30 +10:00
|
|
|
|
2019-05-09 01:18:22 +10:00
|
|
|
//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
|
2019-04-15 02:56:30 +10:00
|
|
|
)
|
2019-05-09 01:18:22 +10:00
|
|
|
)
|
|
|
|
height: nameLabel.height + contentLabel.implicitHeight
|
|
|
|
|
|
|
|
Column {
|
|
|
|
spacing: 0
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
width: parent.width
|
2019-07-03 12:22:29 +10:00
|
|
|
height: model.showNameLine && ! combine ? implicitHeight : 0
|
2019-05-09 01:18:22 +10:00
|
|
|
visible: height > 0
|
|
|
|
|
|
|
|
id: nameLabel
|
2019-07-03 03:59:52 +10:00
|
|
|
text: senderInfo.displayName || model.senderId
|
2019-07-03 12:22:29 +10:00
|
|
|
color: textHueForName(avatar.name)
|
2019-05-09 01:18:22 +10:00
|
|
|
elide: Text.ElideRight
|
|
|
|
maximumLineCount: 1
|
|
|
|
horizontalAlignment: isOwn ? Text.AlignRight : Text.AlignLeft
|
|
|
|
|
|
|
|
leftPadding: horizontalPadding
|
|
|
|
rightPadding: horizontalPadding
|
|
|
|
topPadding: verticalPadding
|
|
|
|
}
|
|
|
|
|
|
|
|
HRichLabel {
|
2019-07-03 12:22:29 +10:00
|
|
|
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])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 01:18:22 +10:00
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
id: contentLabel
|
2019-07-03 12:22:29 +10:00
|
|
|
text: translate(model.content) +
|
2019-05-09 01:18:22 +10:00
|
|
|
" <font size=" + HStyle.fontSize.small +
|
|
|
|
"px color=" + HStyle.chat.message.date + ">" +
|
2019-07-03 03:59:52 +10:00
|
|
|
Qt.formatDateTime(model.date, "hh:mm:ss") +
|
2019-05-09 01:18:22 +10:00
|
|
|
"</font>" +
|
2019-07-03 03:59:52 +10:00
|
|
|
(model.isLocalEcho ?
|
2019-05-09 01:18:22 +10:00
|
|
|
" <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
|
|
|
|
}
|
2019-04-15 02:56:30 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|