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.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()

View file

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