decreased lag when opening the emote/emoji menu

This commit is contained in:
fourtf 2018-04-18 17:03:37 +02:00
parent 653e4c6adf
commit 4c99f2b5fd
2 changed files with 13 additions and 3 deletions

View file

@ -19,6 +19,8 @@
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
bool Image::loadedEventQueued = false;
Image::Image(const QString &url, qreal scale, const QString &name, const QString &tooltip, Image::Image(const QString &url, qreal scale, const QString &name, const QString &tooltip,
const QMargins &margin, bool isHat) const QMargins &margin, bool isHat)
: url(url) : url(url)
@ -63,7 +65,7 @@ void Image::loadImage()
util::NetworkRequest req(this->getUrl()); util::NetworkRequest req(this->getUrl());
req.setCaller(this); req.setCaller(this);
req.setUseQuickLoadCache(true); req.setUseQuickLoadCache(true);
req.get([lli = this](QByteArray bytes) -> bool { req.get([lli = this](QByteArray bytes)->bool {
QByteArray copy = QByteArray::fromRawData(bytes.constData(), bytes.length()); QByteArray copy = QByteArray::fromRawData(bytes.constData(), bytes.length());
QBuffer buffer(&copy); QBuffer buffer(&copy);
buffer.open(QIODevice::ReadOnly); buffer.open(QIODevice::ReadOnly);
@ -131,8 +133,14 @@ void Image::loadImage()
singletons::EmoteManager::getInstance().incGeneration(); singletons::EmoteManager::getInstance().incGeneration();
util::postToThread( if (!loadedEventQueued) {
[] { singletons::WindowManager::getInstance().layoutVisibleChatWidgets(); }); loadedEventQueued = true;
QTimer::singleShot(750, [] {
singletons::WindowManager::getInstance().layoutVisibleChatWidgets();
loadedEventQueued = false;
});
}
return true; return true;
}); });

View file

@ -40,6 +40,8 @@ private:
int duration; int duration;
}; };
static bool loadedEventQueued;
QPixmap *currentPixmap = nullptr; QPixmap *currentPixmap = nullptr;
QPixmap *loadedPixmap = nullptr; QPixmap *loadedPixmap = nullptr;
std::vector<FrameData> allFrames; std::vector<FrameData> allFrames;