2017-06-06 21:18:05 +02:00
|
|
|
#pragma once
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "common/Common.hpp"
|
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
#include <QPixmap>
|
2017-01-11 18:52:09 +01:00
|
|
|
#include <QString>
|
2018-08-09 18:39:46 +02:00
|
|
|
#include <QThread>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <atomic>
|
2018-01-11 20:16:25 +01:00
|
|
|
#include <boost/noncopyable.hpp>
|
2018-08-06 20:00:04 +02:00
|
|
|
#include <boost/variant.hpp>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "common/NullablePtr.hpp"
|
2018-01-19 22:45:33 +01:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
2018-08-06 18:25:47 +02:00
|
|
|
namespace {
|
2018-08-06 20:00:04 +02:00
|
|
|
using Pixmap = boost::variant<const QPixmap *, std::unique_ptr<QPixmap>>;
|
|
|
|
struct Frame {
|
|
|
|
Pixmap pixmap;
|
|
|
|
int duration;
|
2018-08-06 18:25:47 +02:00
|
|
|
};
|
2018-08-09 18:39:46 +02:00
|
|
|
struct ParseFrame {
|
|
|
|
QImage image;
|
|
|
|
int duration;
|
|
|
|
};
|
2018-08-06 18:25:47 +02:00
|
|
|
class Frames
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Frames();
|
|
|
|
Frames(std::vector<Frame> &&frames);
|
|
|
|
~Frames();
|
|
|
|
Frames(Frames &&other) = default;
|
|
|
|
Frames &operator=(Frames &&other) = default;
|
|
|
|
|
|
|
|
bool animated() const;
|
|
|
|
void advance();
|
|
|
|
const QPixmap *current() const;
|
|
|
|
const QPixmap *first() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Frame> items_;
|
|
|
|
int index_{0};
|
2018-08-06 20:00:04 +02:00
|
|
|
int durationOffset_{0};
|
2018-08-06 18:25:47 +02:00
|
|
|
};
|
|
|
|
} // namespace
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
class Image;
|
|
|
|
using ImagePtr = std::shared_ptr<Image>;
|
|
|
|
|
|
|
|
class Image : public std::enable_shared_from_this<Image>, boost::noncopyable
|
2017-01-04 15:12:31 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-08-02 14:23:27 +02:00
|
|
|
static ImagePtr fromUrl(const Url &url, qreal scale = 1);
|
2018-08-06 21:17:03 +02:00
|
|
|
static ImagePtr fromOwningPixmap(std::unique_ptr<QPixmap> pixmap,
|
|
|
|
qreal scale = 1);
|
2018-08-02 14:23:27 +02:00
|
|
|
static ImagePtr fromNonOwningPixmap(QPixmap *pixmap, qreal scale = 1);
|
|
|
|
static ImagePtr getEmpty();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-08-06 18:25:47 +02:00
|
|
|
const Url &url() const;
|
|
|
|
const QPixmap *pixmap() const;
|
|
|
|
qreal scale() const;
|
|
|
|
bool empty() const;
|
|
|
|
int width() const;
|
|
|
|
int height() const;
|
|
|
|
bool animated() const;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
bool operator==(const Image &image) const;
|
|
|
|
bool operator!=(const Image &image) const;
|
2018-06-24 18:29:30 +02:00
|
|
|
|
2017-01-05 16:07:20 +01:00
|
|
|
private:
|
2018-08-02 14:23:27 +02:00
|
|
|
Image();
|
|
|
|
Image(const Url &url, qreal scale);
|
|
|
|
Image(std::unique_ptr<QPixmap> owning, qreal scale);
|
|
|
|
Image(QPixmap *nonOwning, qreal scale);
|
2018-04-18 17:03:37 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void load();
|
2018-08-06 18:25:47 +02:00
|
|
|
|
|
|
|
Url url_{};
|
|
|
|
qreal scale_{1};
|
|
|
|
bool empty_{false};
|
|
|
|
bool shouldLoad_{false};
|
|
|
|
Frames frames_{};
|
|
|
|
QObject object_{};
|
2017-01-04 15:12:31 +01:00
|
|
|
};
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|