mirror-chatterino2/messages/lazyloadedimage.h

110 lines
2 KiB
C
Raw Normal View History

2017-01-04 15:12:31 +01:00
#ifndef LAZYLOADEDIMAGE_H
#define LAZYLOADEDIMAGE_H
2017-01-13 18:59:11 +01:00
#include <QPixmap>
2017-01-11 18:52:09 +01:00
#include <QString>
2017-01-04 15:12:31 +01:00
2017-01-18 21:30:23 +01:00
namespace chatterino {
namespace messages {
2017-02-06 17:42:28 +01:00
class LazyLoadedImage : QObject
2017-01-04 15:12:31 +01:00
{
public:
2017-04-12 17:46:44 +02:00
explicit LazyLoadedImage(const QString &url, qreal scale = 1, const QString &name = "",
const QString &tooltip = "", const QMargins &margin = QMargins(),
2017-01-26 17:26:20 +01:00
bool isHat = false);
2017-04-12 17:46:44 +02:00
explicit LazyLoadedImage(QPixmap *currentPixmap, qreal scale = 1, const QString &name = "",
const QString &tooltip = "", const QMargins &margin = QMargins(),
2017-01-26 17:26:20 +01:00
bool isHat = false);
2017-01-05 16:07:20 +01:00
2017-04-12 17:46:44 +02:00
const QPixmap *getPixmap()
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
if (!isLoading) {
isLoading = true;
2017-01-11 18:52:09 +01:00
loadImage();
}
2017-02-06 17:42:28 +01:00
return currentPixmap;
2017-01-05 16:07:20 +01:00
}
2017-04-12 17:46:44 +02:00
qreal getScale() const
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
return scale;
2017-01-06 23:28:48 +01:00
}
2017-04-12 17:46:44 +02:00
const QString &getUrl() const
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
return url;
2017-01-11 18:52:09 +01:00
}
2017-04-12 17:46:44 +02:00
const QString &getName() const
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
return name;
2017-01-11 18:52:09 +01:00
}
2017-04-12 17:46:44 +02:00
const QString &getTooltip() const
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
return tooltip;
2017-01-11 18:52:09 +01:00
}
2017-01-06 23:28:48 +01:00
2017-04-12 17:46:44 +02:00
const QMargins &getMargin() const
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
return margin;
2017-01-11 18:52:09 +01:00
}
2017-04-12 17:46:44 +02:00
bool getAnimated() const
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
return animated;
2017-01-11 18:52:09 +01:00
}
2017-04-12 17:46:44 +02:00
bool getIsHat() const
2017-01-11 18:52:09 +01:00
{
2017-01-18 04:33:30 +01:00
return ishat;
2017-01-11 18:52:09 +01:00
}
2017-04-12 17:46:44 +02:00
int getWidth() const
2017-01-11 18:52:09 +01:00
{
2017-02-06 17:42:28 +01:00
if (currentPixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-02-06 17:42:28 +01:00
return currentPixmap->width();
2017-01-11 01:08:20 +01:00
}
2017-04-12 17:46:44 +02:00
int getHeight() const
2017-01-11 18:52:09 +01:00
{
2017-02-06 17:42:28 +01:00
if (currentPixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-02-06 17:42:28 +01:00
return currentPixmap->height();
2017-01-11 01:08:20 +01:00
}
2017-01-05 16:07:20 +01:00
private:
2017-02-06 17:42:28 +01:00
struct FrameData {
QPixmap *image;
int duration;
2017-02-06 17:42:28 +01:00
};
QPixmap *currentPixmap;
std::vector<FrameData> allFrames;
int currentFrame;
int currentFrameOffset;
2017-01-06 23:28:48 +01:00
2017-01-18 04:33:30 +01:00
QString url;
QString name;
QString tooltip;
bool animated;
QMargins margin;
bool ishat;
qreal scale;
2017-01-11 18:52:09 +01:00
2017-01-18 04:33:30 +01:00
bool isLoading;
2017-01-11 18:52:09 +01:00
void loadImage();
2017-02-06 17:42:28 +01:00
void gifUpdateTimout();
2017-01-04 15:12:31 +01:00
};
2017-01-18 21:30:23 +01:00
}
}
2017-01-04 15:12:31 +01:00
2017-01-11 18:52:09 +01:00
#endif // LAZYLOADEDIMAGE_H