mirror-chatterino2/src/messages/lazyloadedimage.h

110 lines
2.1 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-14 14:52:31 +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-14 14:52:31 +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-04-14 14:52:31 +02:00
if (!_isLoading) {
_isLoading = true;
2017-01-11 18:52:09 +01:00
loadImage();
}
2017-04-14 14:52:31 +02: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-04-14 14:52:31 +02: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-04-14 14:52:31 +02: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-04-14 14:52:31 +02: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-04-14 14:52:31 +02: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-04-14 14:52:31 +02: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-04-14 14:52:31 +02:00
return _animated;
2017-01-11 18:52:09 +01:00
}
2017-04-14 14:52:31 +02:00
bool isHat() const
2017-01-11 18:52:09 +01:00
{
2017-04-14 14:52:31 +02: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-04-14 14:52:31 +02:00
if (_currentPixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-04-14 14:52:31 +02: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-04-14 14:52:31 +02:00
if (_currentPixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-04-14 14:52:31 +02: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
};
2017-04-14 14:52:31 +02:00
QPixmap *_currentPixmap;
std::vector<FrameData> _allFrames;
int _currentFrame;
int _currentFrameOffset;
2017-01-06 23:28:48 +01:00
2017-04-14 14:52:31 +02:00
QString _url;
QString _name;
QString _tooltip;
bool _animated;
QMargins _margin;
bool _ishat;
qreal _scale;
2017-01-11 18:52:09 +01:00
2017-04-14 14:52:31 +02: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-04-14 17:52:22 +02:00
} // namespace messages
} // namespace chatterino
2017-01-04 15:12:31 +01:00
2017-01-11 18:52:09 +01:00
#endif // LAZYLOADEDIMAGE_H