mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Generate a date separator before local messages
This commit is contained in:
parent
da6b816228
commit
ddcc0f7f60
2 changed files with 21 additions and 11 deletions
|
@ -93,7 +93,7 @@ public:
|
|||
const QSharedPointer<QIODevice> data = QSharedPointer<QIODevice>(nullptr));
|
||||
void updatePendingMessage(int txn_id, QString event_id);
|
||||
void scrollDown();
|
||||
void addDateSeparator(QDateTime datetime, int position);
|
||||
QLabel *createDateSeparator(QDateTime datetime);
|
||||
|
||||
public slots:
|
||||
void sliderRangeChanged(int min, int max);
|
||||
|
@ -135,7 +135,8 @@ private:
|
|||
//! Decides whether or not to show or hide the scroll down button.
|
||||
void toggleScrollDownButton();
|
||||
void init();
|
||||
void addTimelineItem(TimelineItem *item, TimelineDirection direction);
|
||||
void addTimelineItem(TimelineItem *item,
|
||||
TimelineDirection direction = TimelineDirection::Bottom);
|
||||
void updateLastSender(const QString &user_id, TimelineDirection direction);
|
||||
void notifyForLastEvent();
|
||||
void notifyForLastEvent(const TimelineEvent &event);
|
||||
|
@ -245,7 +246,7 @@ TimelineView::addUserMessage(const QString &url,
|
|||
TimelineItem *view_item =
|
||||
new TimelineItem(widget, local_user_, with_sender, scroll_widget_);
|
||||
|
||||
pushTimelineItem(view_item);
|
||||
addTimelineItem(view_item);
|
||||
|
||||
lastMessageDirection_ = TimelineDirection::Bottom;
|
||||
|
||||
|
|
|
@ -450,8 +450,12 @@ TimelineView::addTimelineItem(TimelineItem *item, TimelineDirection direction)
|
|||
if (lastItem) {
|
||||
auto oldDate = lastItem->descriptionMessage().datetime;
|
||||
|
||||
if (oldDate.daysTo(newDate) != 0)
|
||||
addDateSeparator(newDate, lastItemPosition);
|
||||
if (oldDate.daysTo(newDate) != 0) {
|
||||
auto separator = createDateSeparator(newDate);
|
||||
|
||||
if (separator)
|
||||
scroll_layout_->addWidget(separator);
|
||||
}
|
||||
}
|
||||
|
||||
pushTimelineItem(item);
|
||||
|
@ -465,8 +469,12 @@ TimelineView::addTimelineItem(TimelineItem *item, TimelineDirection direction)
|
|||
if (firstItem) {
|
||||
auto oldDate = firstItem->descriptionMessage().datetime;
|
||||
|
||||
if (newDate.daysTo(oldDate) != 0)
|
||||
addDateSeparator(oldDate, 1);
|
||||
if (newDate.daysTo(oldDate) != 0) {
|
||||
auto separator = createDateSeparator(oldDate);
|
||||
|
||||
if (separator)
|
||||
scroll_layout_->insertWidget(1, separator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -501,7 +509,7 @@ TimelineView::addUserMessage(mtx::events::MessageType ty, const QString &body)
|
|||
TimelineItem *view_item =
|
||||
new TimelineItem(ty, local_user_, body, with_sender, scroll_widget_);
|
||||
|
||||
pushTimelineItem(view_item);
|
||||
addTimelineItem(view_item);
|
||||
|
||||
lastMessageDirection_ = TimelineDirection::Bottom;
|
||||
|
||||
|
@ -687,8 +695,8 @@ TimelineView::event(QEvent *event)
|
|||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void
|
||||
TimelineView::addDateSeparator(QDateTime datetime, int position)
|
||||
QLabel *
|
||||
TimelineView::createDateSeparator(QDateTime datetime)
|
||||
{
|
||||
auto now = QDateTime::currentDateTime();
|
||||
auto days = now.daysTo(datetime);
|
||||
|
@ -713,8 +721,9 @@ TimelineView::addDateSeparator(QDateTime datetime, int position)
|
|||
QString("font-size: %1px").arg(conf::timeline::fonts::dateSeparator));
|
||||
separator->setAlignment(Qt::AlignCenter);
|
||||
separator->setContentsMargins(0, 15, 0, 15);
|
||||
scroll_layout_->insertWidget(position, separator);
|
||||
}
|
||||
|
||||
return separator;
|
||||
}
|
||||
|
||||
QString
|
||||
|
|
Loading…
Reference in a new issue