From d0e8ba8b9ca0de2ca9f5a847ea0c86cacd13833a Mon Sep 17 00:00:00 2001 From: TriKriSta Date: Sun, 27 Jan 2019 18:36:20 +0200 Subject: [PATCH] feat: show date in chat log --- src/chatlog/chatlog.cpp | 4 ++++ src/chatlog/chatlog.h | 1 + src/widget/form/genericchatform.cpp | 18 ++++++++++++++++++ src/widget/form/genericchatform.h | 2 ++ 4 files changed, 25 insertions(+) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index f21eecc8f..75b108233 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -700,6 +700,10 @@ void ChatLog::checkVisibility() // if (!visibleLines.empty()) // qDebug() << "visible from " << visibleLines.first()->getRow() << "to " << // visibleLines.last()->getRow() << " total " << visibleLines.size(); + + if (!visibleLines.isEmpty()) { + emit firstVisibleLineChanged(visibleLines.at(0)); + } } void ChatLog::scrollContentsBy(int dx, int dy) diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 9ac12806f..22f2df674 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -69,6 +69,7 @@ public: signals: void selectionChanged(); void workerTimeoutFinished(); + void firstVisibleLineChanged(const ChatLine::Ptr&); public slots: void forceRelayout(); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index bc2616d61..e8a9247a8 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -137,9 +137,12 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent) curRow = 0; headWidget = new ChatFormHeader(); searchForm = new SearchForm(); + dateInfo = new QLabel(this); chatWidget = new ChatLog(this); chatWidget->setBusyNotification(ChatMessage::createBusyNotification()); searchForm->hide(); + dateInfo->setAlignment(Qt::AlignHCenter); + dateInfo->setVisible(false); // settings const Settings& s = Settings::getInstance(); @@ -199,6 +202,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent) QVBoxLayout* contentLayout = new QVBoxLayout(contentWidget); contentLayout->addWidget(searchForm); + contentLayout->addWidget(dateInfo); contentLayout->addWidget(chatWidget); contentLayout->addLayout(mainFootLayout); @@ -228,6 +232,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent) connect(chatWidget, &ChatLog::customContextMenuRequested, this, &GenericChatForm::onChatContextMenuRequested); + connect(chatWidget, &ChatLog::firstVisibleLineChanged, this, &GenericChatForm::updateShowDateInfo); connect(searchForm, &SearchForm::searchInBegin, this, &GenericChatForm::searchInBegin); connect(searchForm, &SearchForm::searchUp, this, &GenericChatForm::onSearchUp); @@ -977,6 +982,19 @@ void GenericChatForm::onSearchTriggered() } } +void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line) +{ + const auto date = getDate(line); + + if (date.isValid() && date != QDate::currentDate()) { + const auto dateText = QStringLiteral("%1<\b>").arg(date.toString(Settings::getInstance().getDateFormat())); + dateInfo->setText(dateText); + dateInfo->setVisible(true); + } else { + dateInfo->setVisible(false); + } +} + void GenericChatForm::onContinueSearch() { const QString phrase = searchForm->getSearchPhrase(); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index ff04bb0d3..fbfd00dfc 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -114,6 +114,7 @@ protected slots: void copyLink(); void searchFormShow(); void onSearchTriggered(); + void updateShowDateInfo(const ChatLine::Ptr& line); virtual void searchInBegin(const QString& phrase, const ParameterSearch& parameter) = 0; virtual void onSearchUp(const QString& phrase, const ParameterSearch& parameter) = 0; @@ -173,6 +174,7 @@ protected: ChatFormHeader* headWidget; SearchForm *searchForm; + QLabel *dateInfo; ChatLog* chatWidget; ChatTextEdit* msgEdit; #ifdef SPELL_CHECKING