mirror-chatterino2/lazyloadedimage.h

109 lines
1.9 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
class LazyLoadedImage
{
public:
2017-01-18 04:33:30 +01:00
explicit LazyLoadedImage(const QString &url, qreal scale = 1,
const QString &getName = "",
const QString &getTooltip = "",
const QMargins &getMargin = QMargins(),
bool getIsHat = false);
explicit LazyLoadedImage(QPixmap *pixmap, qreal scale = 1,
const QString &getName = "",
const QString &getTooltip = "",
const QMargins &getMargin = QMargins(),
bool getIsHat = 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-01-18 04:33:30 +01:00
return pixmap;
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-01-18 04:33:30 +01:00
if (pixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-01-18 04:33:30 +01:00
return pixmap->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-01-18 04:33:30 +01:00
if (pixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-01-18 04:33:30 +01:00
return pixmap->height();
2017-01-11 01:08:20 +01:00
}
2017-01-05 16:07:20 +01:00
private:
2017-01-18 04:33:30 +01:00
QPixmap *pixmap;
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-01-04 15:12:31 +01:00
};
2017-01-11 18:52:09 +01:00
#endif // LAZYLOADEDIMAGE_H