diff --git a/src/libneochat/neochatdatetime.cpp b/src/libneochat/neochatdatetime.cpp index 3bc114f0b..6b58c8b1d 100644 --- a/src/libneochat/neochatdatetime.cpp +++ b/src/libneochat/neochatdatetime.cpp @@ -27,6 +27,11 @@ QString NeoChatDateTime::shortDateTime() const return QLocale().toString(m_dateTime.toLocalTime(), QLocale::ShortFormat); } +QString NeoChatDateTime::longDateTime() const +{ + return QLocale().toString(m_dateTime.toLocalTime(), QLocale::LongFormat); +} + QString NeoChatDateTime::relativeDate() const { KFormat formatter; @@ -39,6 +44,14 @@ QString NeoChatDateTime::relativeDateTime() const return formatter.formatRelativeDateTime(m_dateTime.toLocalTime(), QLocale::ShortFormat); } +QString NeoChatDateTime::shortRelativeDateTime() const +{ + if (m_dateTime > QDate::currentDate().startOfDay()) { + return hourMinuteString(); + } + return relativeDate() + u", "_s + hourMinuteString(); +} + bool NeoChatDateTime::isValid() const { return m_dateTime.isValid(); diff --git a/src/libneochat/neochatdatetime.h b/src/libneochat/neochatdatetime.h index 30ae257b0..b38b35d6b 100644 --- a/src/libneochat/neochatdatetime.h +++ b/src/libneochat/neochatdatetime.h @@ -35,16 +35,21 @@ class NeoChatDateTime */ Q_PROPERTY(QString shortDateTime READ shortDateTime CONSTANT) + /** + * @brief The date and time formatted as per QLocale::LongFormat for your locale. + */ + Q_PROPERTY(QString longDateTime READ longDateTime CONSTANT) + /** * @brief The date formatted as relative to now. * - * If the date falls within one week before or after the current date + * If the date falls within 2 days or after the current date * then a relative date string will be returned, such as: * - Yesterday * - Today * - Tomorrow - * - Last Tuesday - * - Next Wednesday + * - Two days ago + * - In Two Days * * If the date falls outside this period then the format QLocale::ShortFormat * for your locale is used. @@ -54,21 +59,37 @@ class NeoChatDateTime /** * @brief The time and date formatted as relative to now. * - * The format is "RelativeDate, hh::mm" + * The format is "RelativeDate at hh::mm" * - * If the date falls within one week before or after the current date + * If the date falls within 2 days before or after the current date * then a relative date string will be returned, such as: * - Yesterday * - Today * - Tomorrow - * - Last Tuesday - * - Next Wednesday + * - Two days ago + * - In Two Days * * If the date falls outside this period then the format QLocale::ShortFormat * for your locale is used. */ Q_PROPERTY(QString relativeDateTime READ relativeDateTime CONSTANT) + /** + * @brief The time and date formatted as relative to now. + * + * The format is "RelativeDate, hh::mm" + * + * If the date falls on the same day as current date, the date is skipped. + * If the date falls within 2 days before current date + * then a relative date string will be returned, such as: + * - Yesterday + * - Tomorrow + * + * If the date falls outside this period then the format QLocale::ShortFormat + * for your locale is used. + */ + Q_PROPERTY(QString shortRelativeDateTime READ shortRelativeDateTime CONSTANT) + /** * @brief Whether this object has a valid date time. */ @@ -81,8 +102,10 @@ public: QString hourMinuteString() const; QString shortDateTime() const; + QString longDateTime() const; QString relativeDate() const; QString relativeDateTime() const; + QString shortRelativeDateTime() const; bool isValid() const; diff --git a/src/messagecontent/AuthorComponent.qml b/src/messagecontent/AuthorComponent.qml index 3577cb61d..0de091289 100644 --- a/src/messagecontent/AuthorComponent.qml +++ b/src/messagecontent/AuthorComponent.qml @@ -35,6 +35,7 @@ RowLayout { Layout.maximumWidth: Message.maxContentWidth implicitHeight: Math.max(nameButton.implicitHeight, timeLabel.implicitHeight) + spacing: Kirigami.Units.mediumSpacing QQC2.Label { id: nameButton @@ -45,11 +46,15 @@ RowLayout { font.weight: Font.Bold elide: Text.ElideRight clip: true // Intentional to limit insane Unicode in display names + + Layout.fillWidth: true + Layout.maximumWidth: nameButton.implicitWidth + Kirigami.Units.smallSpacing + function openUserMenu(): void { const menu = Qt.createComponent("org.kde.neochat", "UserMenu").createObject(root, { window: QQC2.ApplicationWindow.window as Kirigami.ApplicationWindow, - author: root.author, + author: root.author }); menu.popup(root.QQC2.Overlay.overlay); } @@ -73,20 +78,24 @@ RowLayout { onTapped: nameButton.openUserMenu() } } - Item { - Layout.fillWidth: true - } QQC2.Label { id: timeLabel - text: root.dateTime.hourMinuteString + + text: root.dateTime.shortRelativeDateTime horizontalAlignment: Text.AlignRight color: Kirigami.Theme.disabledTextColor + QQC2.ToolTip.visible: timeHoverHandler.hovered - QQC2.ToolTip.text: root.dateTime.shortDateTime + QQC2.ToolTip.text: root.dateTime.longDateTime QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay HoverHandler { id: timeHoverHandler } } + + Item { + Layout.fillWidth: true + } + }