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

Merge pull request #5875

Mick Sayson (1):
      fix(chatform): Prevent date line oscillations maxing CPU
This commit is contained in:
Anthony Bilinski 2019-11-23 17:27:36 -08:00
commit af19c0d73b
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
4 changed files with 15 additions and 6 deletions

View File

@ -782,6 +782,10 @@ void ChatLog::checkVisibility(bool causedWheelEvent)
auto upperBound = std::lower_bound(lowerBound, lines.cend(), getVisibleRect().bottom(),
ChatLine::lessThanBSRectTop);
const ChatLine::Ptr lastLineBeforeVisible = lowerBound == lines.cbegin()
? ChatLine::Ptr()
: *std::prev(lowerBound);
// set visibilty
QList<ChatLine::Ptr> newVisibleLines;
for (auto itr = lowerBound; itr != upperBound; ++itr) {
@ -807,7 +811,7 @@ void ChatLog::checkVisibility(bool causedWheelEvent)
// visibleLines.last()->getRow() << " total " << visibleLines.size();
if (!visibleLines.isEmpty()) {
emit firstVisibleLineChanged(visibleLines.at(0));
emit firstVisibleLineChanged(lastLineBeforeVisible, visibleLines.at(0));
}
if (causedWheelEvent) {

View File

@ -78,7 +78,7 @@ public:
signals:
void selectionChanged();
void workerTimeoutFinished();
void firstVisibleLineChanged(const ChatLine::Ptr&);
void firstVisibleLineChanged(const ChatLine::Ptr& prevLine, const ChatLine::Ptr& firstLine);
void loadHistoryLower();
void loadHistoryUpper();

View File

@ -644,7 +644,7 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const
if (timestamp) {
return timestamp->getTime();
} else {
return QDateTime::currentDateTime();
return QDateTime();
}
}
@ -1192,9 +1192,14 @@ void GenericChatForm::loadHistoryUpper()
}
}
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& prevLine, const ChatLine::Ptr& topLine)
{
const auto date = getTime(line);
// If the dateInfo is visible we need to pretend the top line is the one
// covered by the date to prevent oscillations
const auto effectiveTopLine = (dateInfo->isVisible() && prevLine)
? prevLine : topLine;
const auto date = getTime(effectiveTopLine);
if (date.isValid() && date.date() != QDate::currentDate()) {
const auto dateText = QStringLiteral("<b>%1<\b>").arg(date.toString(Settings::getInstance().getDateFormat()));

View File

@ -117,7 +117,7 @@ protected slots:
void onExportChat();
void searchFormShow();
void onSearchTriggered();
void updateShowDateInfo(const ChatLine::Ptr& line);
void updateShowDateInfo(const ChatLine::Ptr& prevLine, const ChatLine::Ptr& topLine);
void searchInBegin(const QString& phrase, const ParameterSearch& parameter);
void onSearchUp(const QString& phrase, const ParameterSearch& parameter);