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-01-18 04:33:30 +01:00
|
|
|
explicit LazyLoadedImage(const QString &url, qreal scale = 1,
|
2017-01-26 17:26:20 +01:00
|
|
|
const QString &name = "",
|
|
|
|
const QString &tooltip = "",
|
|
|
|
const QMargins &margin = QMargins(),
|
|
|
|
bool isHat = false);
|
2017-02-06 17:42:28 +01:00
|
|
|
explicit LazyLoadedImage(QPixmap *currentPixmap, qreal scale = 1,
|
2017-01-26 17:26:20 +01:00
|
|
|
const QString &name = "",
|
|
|
|
const QString &tooltip = "",
|
|
|
|
const QMargins &margin = QMargins(),
|
|
|
|
bool isHat = false);
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
const QPixmap *
|
2017-01-18 04:33:30 +01:00
|
|
|
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-01-11 18:52:09 +01:00
|
|
|
qreal
|
2017-01-18 04:33:30 +01:00
|
|
|
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-01-11 18:52:09 +01:00
|
|
|
const QString &
|
2017-01-18 04:33:30 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
const QString &
|
2017-01-18 04:33:30 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
const QString &
|
2017-01-18 04:33:30 +01:00
|
|
|
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-01-11 18:52:09 +01:00
|
|
|
const QMargins &
|
2017-01-18 04:33:30 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-18 04:33:30 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-18 04:33:30 +01:00
|
|
|
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-01-13 18:59:11 +01:00
|
|
|
int
|
2017-01-18 04:33:30 +01:00
|
|
|
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-01-13 18:59:11 +01:00
|
|
|
int
|
2017-01-18 04:33:30 +01:00
|
|
|
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;
|
2017-02-06 18:31:25 +01:00
|
|
|
int duration;
|
2017-02-06 17:42:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
QPixmap *currentPixmap;
|
|
|
|
std::vector<FrameData> allFrames;
|
|
|
|
int currentFrame;
|
2017-02-06 18:31:25 +01:00
|
|
|
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
|