mirror-chatterino2/src/messages/lazyloadedimage.hpp

120 lines
2.3 KiB
C++
Raw Normal View History

2017-06-06 21:18:05 +02:00
#pragma once
2017-01-04 15:12:31 +01:00
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 {
class EmoteManager;
class WindowManager;
2017-01-18 21:30:23 +01:00
namespace messages {
2017-02-06 17:42:28 +01:00
class LazyLoadedImage : QObject
2017-01-04 15:12:31 +01:00
{
public:
LazyLoadedImage() = delete;
explicit LazyLoadedImage(EmoteManager &_emoteManager, WindowManager &_windowManager,
const QString &_url, qreal _scale = 1, const QString &_name = "",
2017-04-14 14:52:31 +02:00
const QString &_tooltip = "", const QMargins &_margin = QMargins(),
2017-01-26 17:26:20 +01:00
bool isHat = false);
explicit LazyLoadedImage(EmoteManager &_emoteManager, WindowManager &_windowManager,
QPixmap *_currentPixmap, qreal _scale = 1, const QString &_name = "",
2017-04-14 14:52:31 +02:00
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
{
if (_currentPixmap == nullptr) {
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
{
if (_currentPixmap == nullptr) {
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:
EmoteManager &emoteManager;
WindowManager &windowManager;
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 = 0;
int _currentFrameOffset = 0;
2017-01-06 23:28:48 +01:00
2017-04-14 14:52:31 +02:00
QString _url;
QString _name;
QString _tooltip;
bool _animated = false;
2017-04-14 14:52:31 +02:00
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-06-06 21:18:05 +02:00
2017-04-14 17:52:22 +02:00
} // namespace messages
} // namespace chatterino