Browse Source

feat: show date in chat log

reviewable/pr5532/r2
TriKriSta 7 years ago
parent
commit
d0e8ba8b9c
  1. 4
      src/chatlog/chatlog.cpp
  2. 1
      src/chatlog/chatlog.h
  3. 18
      src/widget/form/genericchatform.cpp
  4. 2
      src/widget/form/genericchatform.h

4
src/chatlog/chatlog.cpp

@ -700,6 +700,10 @@ void ChatLog::checkVisibility() @@ -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)

1
src/chatlog/chatlog.h

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

18
src/widget/form/genericchatform.cpp

@ -137,9 +137,12 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent) @@ -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) @@ -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) @@ -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() @@ -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();

2
src/widget/form/genericchatform.h

@ -114,6 +114,7 @@ protected slots: @@ -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: @@ -173,6 +174,7 @@ protected:
ChatFormHeader* headWidget;
SearchForm *searchForm;
QLabel *dateInfo;
ChatLog* chatWidget;
ChatTextEdit* msgEdit;
#ifdef SPELL_CHECKING

Loading…
Cancel
Save