Improve time handling in NeoChat

This introduces a new NeoChatDateTime object that wraps a QDateTime. The intent is that it can be passed to QML and has a series of functions that format the QDateTime into the various string representations we need.

This means we only have to send the single object to QML and then the correct string can be grabbed from there, simplifying the backend. It is also easy to add a new representation if needed as a function with a QString output and Q_PROPERTY can be added and then it will be available.
This commit is contained in:
James Graham
2026-01-25 13:01:31 +00:00
parent c797ecea3d
commit 92c58b0ea0
17 changed files with 191 additions and 172 deletions

View File

@@ -27,14 +27,9 @@ RowLayout {
required property var author
/**
* @brief The timestamp of the message.
* @brief The timestamp of the event as a NeoChatDateTime.
*/
required property var time
/**
* @brief The timestamp of the message as a string.
*/
required property string timeString
required property NeoChatDateTime dateTime
Layout.fillWidth: true
Layout.maximumWidth: Message.maxContentWidth
@@ -83,11 +78,11 @@ RowLayout {
}
QQC2.Label {
id: timeLabel
text: root.timeString
text: root.dateTime.hourMinuteString
horizontalAlignment: Text.AlignRight
color: Kirigami.Theme.disabledTextColor
QQC2.ToolTip.visible: timeHoverHandler.hovered
QQC2.ToolTip.text: root.time.toLocaleString(Qt.locale(), Locale.ShortFormat)
QQC2.ToolTip.text: root.dateTime.shortDateTime
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
HoverHandler {