added cooldown to layouting to reduce lag when opening the emojis tab

This commit is contained in:
fourtf 2018-04-06 18:27:49 +02:00
parent fffe9c93c4
commit 2ab571fe54
2 changed files with 30 additions and 11 deletions

View file

@ -83,15 +83,15 @@ ChannelView::ChannelView(BaseWidget *parent)
}); });
}); });
this->updateTimer.setInterval(1000 / 60); // this->updateTimer.setInterval(1000 / 60);
this->updateTimer.setSingleShot(true); // this->updateTimer.setSingleShot(true);
connect(&this->updateTimer, &QTimer::timeout, this, [this] { // connect(&this->updateTimer, &QTimer::timeout, this, [this] {
if (this->updateQueued) { // if (this->updateQueued) {
this->updateQueued = false; // this->updateQueued = false;
this->repaint(); // this->repaint();
this->updateTimer.start(); // this->updateTimer.start();
} // }
}); // });
this->pauseTimeout.setSingleShot(true); this->pauseTimeout.setSingleShot(true);
@ -99,10 +99,20 @@ ChannelView::ChannelView(BaseWidget *parent)
// this->resizeEvent(e); // this->resizeEvent(e);
// delete e; // delete e;
this->scrollBar.resize(this->scrollBar.width(), height()); this->scrollBar.resize(this->scrollBar.width(), height() + 1);
singletons::SettingManager::getInstance().showLastMessageIndicator.connect( singletons::SettingManager::getInstance().showLastMessageIndicator.connect(
[this](auto, auto) { this->update(); }, this->managedConnections); [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() ChannelView::~ChannelView()
@ -140,7 +150,13 @@ void ChannelView::queueUpdate()
void ChannelView::layoutMessages() void ChannelView::layoutMessages()
{ {
if (!this->layoutCooldown->isActive()) {
this->actuallyLayoutMessages(); this->actuallyLayoutMessages();
this->layoutCooldown->start();
} else {
this->layoutQueued = true;
}
} }
void ChannelView::actuallyLayoutMessages() void ChannelView::actuallyLayoutMessages()

View file

@ -77,6 +77,9 @@ protected:
QPoint &relativePos, int &index); QPoint &relativePos, int &index);
private: private:
QTimer *layoutCooldown;
bool layoutQueued;
QTimer updateTimer; QTimer updateTimer;
bool updateQueued = false; bool updateQueued = false;
bool messageWasAdded = false; bool messageWasAdded = false;