From 4ec2c0d8b3d091be0d3c27d47402f674fb85d712 Mon Sep 17 00:00:00 2001 From: fourtf Date: Fri, 6 Apr 2018 18:27:49 +0200 Subject: [PATCH] added cooldown to layouting to reduce lag when opening the emojis tab --- src/widgets/helper/channelview.cpp | 38 +++++++++++++++++++++--------- src/widgets/helper/channelview.hpp | 3 +++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index a732bc1fd..177ecc882 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -83,15 +83,15 @@ ChannelView::ChannelView(BaseWidget *parent) }); }); - this->updateTimer.setInterval(1000 / 60); - this->updateTimer.setSingleShot(true); - connect(&this->updateTimer, &QTimer::timeout, this, [this] { - if (this->updateQueued) { - this->updateQueued = false; - this->repaint(); - this->updateTimer.start(); - } - }); + // this->updateTimer.setInterval(1000 / 60); + // this->updateTimer.setSingleShot(true); + // connect(&this->updateTimer, &QTimer::timeout, this, [this] { + // if (this->updateQueued) { + // this->updateQueued = false; + // this->repaint(); + // this->updateTimer.start(); + // } + // }); this->pauseTimeout.setSingleShot(true); @@ -99,10 +99,20 @@ ChannelView::ChannelView(BaseWidget *parent) // this->resizeEvent(e); // delete e; - this->scrollBar.resize(this->scrollBar.width(), height()); + this->scrollBar.resize(this->scrollBar.width(), height() + 1); singletons::SettingManager::getInstance().showLastMessageIndicator.connect( [this](auto, auto) { this->update(); }, this->managedConnections); + + this->layoutCooldown = new QTimer(this); + this->layoutCooldown->setSingleShot(true); + this->layoutCooldown->setInterval(66); + + QObject::connect(this->layoutCooldown, &QTimer::timeout, [this] { + if (this->layoutQueued) { + this->layoutMessages(); + } + }); } ChannelView::~ChannelView() @@ -140,7 +150,13 @@ void ChannelView::queueUpdate() void ChannelView::layoutMessages() { - this->actuallyLayoutMessages(); + if (!this->layoutCooldown->isActive()) { + this->actuallyLayoutMessages(); + + this->layoutCooldown->start(); + } else { + this->layoutQueued = true; + } } void ChannelView::actuallyLayoutMessages() diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index bc62fb875..0db184ac9 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -77,6 +77,9 @@ protected: QPoint &relativePos, int &index); private: + QTimer *layoutCooldown; + bool layoutQueued; + QTimer updateTimer; bool updateQueued = false; bool messageWasAdded = false;