Time and date support in messageeventmodel && local echo support.

This commit is contained in:
Black Hat
2018-07-30 00:00:41 +08:00
parent a105f344f4
commit 93a303799a
7 changed files with 279 additions and 216 deletions

View File

@@ -1,5 +1,6 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2
AvatarContainer {
@@ -10,24 +11,46 @@ AvatarContainer {
Rectangle {
id: messageRect
width: Math.min(messageText.implicitWidth + 24, messageListView.width - (!sentByMe ? 40 + messageRow.spacing : 0))
height: messageText.implicitHeight + 24
width: Math.min(Math.max(messageText.implicitWidth, (timeText.visible ? timeText.implicitWidth : 0)) + 24, messageListView.width - (!sentByMe ? 40 + messageRow.spacing : 0))
height: messageText.implicitHeight + (timeText.visible ? timeText.implicitHeight : 0) + 24
color: isNotice ? "transparent" : !sentByMe ? Material.accent : background
border.color: Material.accent
border.width: isNotice ? 2 : 0
Label {
id: messageText
text: display
color: isNotice || sentByMe ? Material.foreground : "white"
ColumnLayout {
id: messageColumn
anchors.fill: parent
anchors.margins: 12
wrapMode: Label.Wrap
linkColor: isNotice || sentByMe ? Material.accent : "white"
// textFormat: contentType === "text/html" ? Text.RichText : Text.StyledText
textFormat: Text.StyledText
onLinkActivated: Qt.openUrlExternally(link)
spacing: 0
Label {
id: messageText
Layout.maximumWidth: parent.width
text: display
color: isNotice || sentByMe ? Material.foreground : "white"
wrapMode: Label.Wrap
linkColor: isNotice || sentByMe ? Material.accent : "white"
// textFormat: contentType === "text/html" ? Text.RichText : Text.StyledText
textFormat: Text.StyledText
onLinkActivated: Qt.openUrlExternally(link)
}
Label {
id: timeText
visible: Math.abs(time - aboveTime) > 600000 || index == 0
Layout.alignment: Qt.AlignRight
text: Qt.formatDateTime(time, "d MMM hh:mm")
color: isNotice || sentByMe ? "grey" : "white"
font.pointSize: 8
// Component.onCompleted: {
// console.log("Difference: " + Math.abs(time - aboveTime))
// console.log("Index: " + index)
// }
}
}
}
}

View File

@@ -16,14 +16,6 @@ Item {
anchors.right: !(eventType === "state" || eventType === "emote") && sentByMe ? parent.right : undefined
anchors.horizontalCenter: (eventType === "state" || eventType === "emote") ? parent.horizontalCenter : undefined
MouseArea {
anchors.fill: parent
ToolTip.visible: pressed
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: time
}
Loader {
id: delegateLoader

View File

@@ -96,6 +96,21 @@ Item {
delegate: MessageDelegate {}
section.property: "section"
section.criteria: ViewSection.FullString
section.delegate: Label {
text: section
color: "grey"
padding: 16
verticalAlignment: Text.AlignVCenter
anchors.horizontalCenter: parent.horizontalCenter
background: Rectangle {
anchors.fill: parent
anchors.margins: 4
color: Material.theme == Material.Light ? "#dbdbdb" : "#363636"
}
}
onAtYBeginningChanged: atYBeginning && currentRoom ? currentRoom.getPreviousContent(50) : {}
onAtYEndChanged: atYEnd && currentRoom ? currentRoom.markAllMessagesAsRead() : {}
@@ -180,6 +195,13 @@ Item {
bottomPadding: 0
selectByMouse: true
Keys.onReturnPressed: {
if (inputField.text) {
inputField.postMessage(inputField.text)
inputField.text = ""
}
}
background: Item {
Rectangle {
z: 5
@@ -191,16 +213,6 @@ Item {
Rectangle { anchors.fill: parent; color: Material.theme == Material.Light ? "#eaeaea" : "#242424" }
}
Shortcut {
sequence: "Ctrl+Return"
onActivated: {
if (inputField.text) {
inputField.postMessage(inputField.text)
inputField.text = ""
}
}
}
function postMessage(text) {
if (text.trim().length === 0) { return }
if(!currentRoom) { return }