1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat: show date in chat log

This commit is contained in:
TriKriSta 2019-01-27 18:36:20 +02:00
parent 49507d76d8
commit d0e8ba8b9c
4 changed files with 25 additions and 0 deletions

View File

@ -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)

View File

@ -69,6 +69,7 @@ public:
signals:
void selectionChanged();
void workerTimeoutFinished();
void firstVisibleLineChanged(const ChatLine::Ptr&);
public slots:
void forceRelayout();

View File

@ -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("<b>%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();

View File

@ -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