matrixion/src/MxcImageProvider.h
Nicolas Werner 86f4119a05 Implement basic ImageMessages in qml timeline
I suck at sizing so the images in the message are currently hardcoded to
300 pixels in width...
2019-11-23 20:06:14 +01:00

47 lines
1.2 KiB
C++

#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;
};