Only layout visible ChannelViews (#4811)

This commit is contained in:
nerix 2023-09-10 17:08:13 +02:00 committed by GitHub
parent 1b9ee939bb
commit 283ede86ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 28 deletions

View file

@ -13,6 +13,7 @@
- Dev: Do a pretty major refactor of the Settings classes. List settings (e.g. highlights) are most heavily modified, and should have an extra eye kept on them. (#4775) - Dev: Do a pretty major refactor of the Settings classes. List settings (e.g. highlights) are most heavily modified, and should have an extra eye kept on them. (#4775)
- Dev: Remove `boost::noncopyable` use & `boost_random` dependency. (#4776) - Dev: Remove `boost::noncopyable` use & `boost_random` dependency. (#4776)
- Dev: Fix clang-tidy `cppcoreguidelines-pro-type-member-init` warnings. (#4426) - Dev: Fix clang-tidy `cppcoreguidelines-pro-type-member-init` warnings. (#4426)
- Dev: Immediate layout for invisible `ChannelView`s is skipped. (#4811)
## 2.4.5 ## 2.4.5

View file

@ -228,8 +228,15 @@ void ChannelView::initializeLayout()
void ChannelView::initializeScrollbar() void ChannelView::initializeScrollbar()
{ {
this->scrollBar_->getCurrentValueChanged().connect([this] { this->scrollBar_->getCurrentValueChanged().connect([this] {
if (this->isVisible())
{
this->performLayout(true); this->performLayout(true);
this->queueUpdate(); this->queueUpdate();
}
else
{
this->layoutQueued_ = true;
}
}); });
} }
@ -413,33 +420,35 @@ void ChannelView::scaleChangedEvent(float scale)
void ChannelView::queueUpdate() void ChannelView::queueUpdate()
{ {
// if (this->updateTimer.isActive()) {
// this->updateQueued = true;
// return;
// }
// this->repaint();
this->update(); this->update();
// this->updateTimer.start();
} }
void ChannelView::queueLayout() void ChannelView::queueLayout()
{ {
// if (!this->layoutCooldown->isActive()) { if (this->isVisible())
{
this->performLayout(); this->performLayout();
}
// this->layoutCooldown->start(); else
// } else { {
// this->layoutQueued = true; this->layoutQueued_ = true;
// } }
} }
void ChannelView::performLayout(bool causedByScrollbar) void ChannelView::showEvent(QShowEvent * /*event*/)
{
if (this->layoutQueued_)
{
this->performLayout(false, true);
}
}
void ChannelView::performLayout(bool causedByScrollbar, bool causedByShow)
{ {
// BenchmarkGuard benchmark("layout"); // BenchmarkGuard benchmark("layout");
this->layoutQueued_ = false;
/// Get messages and check if there are at least 1 /// Get messages and check if there are at least 1
const auto &messages = this->getMessagesSnapshot(); const auto &messages = this->getMessagesSnapshot();
@ -451,7 +460,7 @@ void ChannelView::performLayout(bool causedByScrollbar)
this->layoutVisibleMessages(messages); this->layoutVisibleMessages(messages);
/// Update scrollbar /// Update scrollbar
this->updateScrollbar(messages, causedByScrollbar); this->updateScrollbar(messages, causedByScrollbar, causedByShow);
this->goToBottom_->setVisible(this->enableScrollingToBottom_ && this->goToBottom_->setVisible(this->enableScrollingToBottom_ &&
this->scrollBar_->isVisible() && this->scrollBar_->isVisible() &&
@ -490,7 +499,7 @@ void ChannelView::layoutVisibleMessages(
void ChannelView::updateScrollbar( void ChannelView::updateScrollbar(
const LimitedQueueSnapshot<MessageLayoutPtr> &messages, const LimitedQueueSnapshot<MessageLayoutPtr> &messages,
bool causedByScrollbar) bool causedByScrollbar, bool causedByShow)
{ {
if (messages.size() == 0) if (messages.size() == 0)
{ {
@ -539,6 +548,7 @@ void ChannelView::updateScrollbar(
showScrollbar && !causedByScrollbar) showScrollbar && !causedByScrollbar)
{ {
this->scrollBar_->scrollToBottom( this->scrollBar_->scrollToBottom(
!causedByShow &&
getSettings()->enableSmoothScrollingNewMessages.getValue()); getSettings()->enableSmoothScrollingNewMessages.getValue());
} }
} }
@ -799,7 +809,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
this->underlyingChannel_ = underlyingChannel; this->underlyingChannel_ = underlyingChannel;
this->queueLayout(); this->performLayout();
this->queueUpdate(); this->queueUpdate();
// Notifications // Notifications
@ -903,6 +913,10 @@ void ChannelView::messageAppended(MessagePtr &message,
else else
{ {
this->scrollBar_->offsetMinimum(1); this->scrollBar_->offsetMinimum(1);
if (this->showingLatestMessages_ && !this->isVisible())
{
this->scrollBar_->scrollToBottom(false);
}
this->selection_.shiftMessageIndex(1); this->selection_.shiftMessageIndex(1);
} }
} }

View file

@ -181,6 +181,7 @@ protected:
void mouseDoubleClickEvent(QMouseEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override;
void hideEvent(QHideEvent *) override; void hideEvent(QHideEvent *) override;
void showEvent(QShowEvent *event) override;
void handleLinkClick(QMouseEvent *event, const Link &link, void handleLinkClick(QMouseEvent *event, const Link &link,
MessageLayout *layout); MessageLayout *layout);
@ -200,11 +201,12 @@ private:
void messageReplaced(size_t index, MessagePtr &replacement); void messageReplaced(size_t index, MessagePtr &replacement);
void messagesUpdated(); void messagesUpdated();
void performLayout(bool causedByScrollbar = false); void performLayout(bool causedByScrollbar = false,
bool causedByShow = false);
void layoutVisibleMessages( void layoutVisibleMessages(
const LimitedQueueSnapshot<MessageLayoutPtr> &messages); const LimitedQueueSnapshot<MessageLayoutPtr> &messages);
void updateScrollbar(const LimitedQueueSnapshot<MessageLayoutPtr> &messages, void updateScrollbar(const LimitedQueueSnapshot<MessageLayoutPtr> &messages,
bool causedByScrollbar); bool causedByScrollbar, bool causedByShow);
void drawMessages(QPainter &painter); void drawMessages(QPainter &painter);
void setSelection(const SelectionItem &start, const SelectionItem &end); void setSelection(const SelectionItem &start, const SelectionItem &end);
@ -256,11 +258,8 @@ private:
void showReplyThreadPopup(const MessagePtr &message); void showReplyThreadPopup(const MessagePtr &message);
bool canReplyToMessages() const; bool canReplyToMessages() const;
QTimer *layoutCooldown_{}; bool layoutQueued_ = false;
bool layoutQueued_{};
QTimer updateTimer_;
bool updateQueued_ = false;
bool lastMessageHasAlternateBackground_ = false; bool lastMessageHasAlternateBackground_ = false;
bool lastMessageHasAlternateBackgroundReverse_ = true; bool lastMessageHasAlternateBackgroundReverse_ = true;