diff options
Diffstat (limited to 'src/MxcImageProvider.h')
-rw-r--r-- | src/MxcImageProvider.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/MxcImageProvider.h b/src/MxcImageProvider.h new file mode 100644 index 00000000..8710171c --- /dev/null +++ b/src/MxcImageProvider.h @@ -0,0 +1,48 @@ +#pragma once + +#include <QQuickAsyncImageProvider> +#include <QQuickImageResponse> + +#include <QImage> +#include <QThreadPool> + +class MxcImageResponse + : public QQuickImageResponse + , public QRunnable +{ +public: + MxcImageResponse(const QString &id, const QSize &requestedSize) + : m_id(id) + , m_requestedSize(requestedSize) + { + setAutoDelete(false); + } + + QQuickTextureFactory *textureFactory() const override + { + return QQuickTextureFactory::textureFactoryForImage(m_image); + } + QString errorString() const override { return m_error; } + + void run() override; + + QString m_id, m_error; + QSize m_requestedSize; + QImage m_image; +}; + +class MxcImageProvider : public QQuickAsyncImageProvider +{ +public: + QQuickImageResponse *requestImageResponse(const QString &id, + const QSize &requestedSize) override + { + MxcImageResponse *response = new MxcImageResponse(id, requestedSize); + pool.start(response); + return response; + } + +private: + QThreadPool pool; +}; + |