mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
76 lines
1.7 KiB
C++
76 lines
1.7 KiB
C++
#include "messages/lazyloadedimage.h"
|
|
|
|
#include "asyncexec.h"
|
|
#include "emotes.h"
|
|
#include "ircmanager.h"
|
|
#include "windows.h"
|
|
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkReply>
|
|
#include <QNetworkRequest>
|
|
#include <functional>
|
|
|
|
namespace chatterino {
|
|
namespace messages {
|
|
|
|
LazyLoadedImage::LazyLoadedImage(const QString &url, qreal scale,
|
|
const QString &name, const QString &tooltip,
|
|
const QMargins &margin, bool isHat)
|
|
: pixmap(NULL)
|
|
, url(url)
|
|
, name(name)
|
|
, tooltip(tooltip)
|
|
, animated(false)
|
|
, margin(margin)
|
|
, ishat(isHat)
|
|
, scale(scale)
|
|
, isLoading(false)
|
|
{
|
|
}
|
|
|
|
LazyLoadedImage::LazyLoadedImage(QPixmap *image, qreal scale,
|
|
const QString &name, const QString &tooltip,
|
|
const QMargins &margin, bool isHat)
|
|
: pixmap(image)
|
|
, url()
|
|
, name(name)
|
|
, tooltip(tooltip)
|
|
, animated(false)
|
|
, margin(margin)
|
|
, ishat(isHat)
|
|
, scale(scale)
|
|
, isLoading(true)
|
|
{
|
|
}
|
|
|
|
void
|
|
LazyLoadedImage::loadImage()
|
|
{
|
|
// QThreadPool::globalInstance()->start(new LambdaQRunnable([=] {
|
|
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
|
|
|
QUrl url(this->url);
|
|
QNetworkRequest request(url);
|
|
|
|
QNetworkReply *reply = manager->get(request);
|
|
|
|
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
|
QPixmap *pixmap = new QPixmap();
|
|
pixmap->loadFromData(reply->readAll());
|
|
|
|
if (pixmap->isNull()) {
|
|
return;
|
|
}
|
|
|
|
this->pixmap = pixmap;
|
|
Emotes::incGeneration();
|
|
Windows::layoutVisibleChatWidgets();
|
|
|
|
reply->deleteLater();
|
|
manager->deleteLater();
|
|
});
|
|
// }));
|
|
}
|
|
}
|
|
}
|