mirror-chatterino2/lazyloadedimage.h

105 lines
1.7 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-11 18:52:09 +01:00
LazyLoadedImage(const QString &url, qreal scale = 1,
const QString &name = "", const QString &tooltip = "",
const QMargins &margin = QMargins(), bool isHat = false);
2017-01-13 18:59:11 +01:00
LazyLoadedImage(QPixmap *pixmap, qreal scale = 1, const QString &name = "",
2017-01-11 18:52:09 +01:00
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 *
pixmap()
2017-01-11 18:52:09 +01:00
{
if (!m_isLoading) {
m_isLoading = true;
loadImage();
}
2017-01-13 18:59:11 +01:00
return m_pixmap;
2017-01-05 16:07:20 +01:00
}
2017-01-11 18:52:09 +01:00
qreal
scale() const
{
2017-01-06 23:28:48 +01:00
return m_scale;
}
2017-01-11 18:52:09 +01:00
const QString &
url() const
{
return m_url;
}
const QString &
name() const
{
return m_name;
}
const QString &
tooltip() const
{
return m_tooltip;
}
2017-01-06 23:28:48 +01:00
2017-01-11 18:52:09 +01:00
const QMargins &
margin() const
{
return m_margin;
}
bool
animated() const
{
return m_animated;
}
bool
isHat() const
{
return m_ishat;
}
2017-01-13 18:59:11 +01:00
int
2017-01-11 18:52:09 +01:00
width() const
{
2017-01-13 18:59:11 +01:00
if (m_pixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-01-13 18:59:11 +01:00
return m_pixmap->width();
2017-01-11 01:08:20 +01:00
}
2017-01-13 18:59:11 +01:00
int
2017-01-11 18:52:09 +01:00
height() const
{
2017-01-13 18:59:11 +01:00
if (m_pixmap == NULL) {
2017-01-11 01:08:20 +01:00
return 16;
}
2017-01-13 18:59:11 +01:00
return m_pixmap->height();
2017-01-11 01:08:20 +01:00
}
2017-01-05 16:07:20 +01:00
private:
2017-01-13 18:59:11 +01:00
QPixmap *m_pixmap;
2017-01-06 23:28:48 +01:00
QString m_url;
QString m_name;
QString m_tooltip;
bool m_animated;
QMargins m_margin;
bool m_ishat;
2017-01-13 18:59:11 +01:00
qreal m_scale;
2017-01-11 18:52:09 +01:00
bool m_isLoading;
void loadImage();
2017-01-04 15:12:31 +01:00
};
2017-01-11 18:52:09 +01:00
#endif // LAZYLOADEDIMAGE_H