nheko/src/MxcImageProvider.h

65 lines
1.7 KiB
C
Raw Normal View History

2021-03-05 00:35:15 +01:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
2019-09-07 22:22:07 +02:00
#pragma once
#include <QQuickAsyncImageProvider>
#include <QQuickImageResponse>
#include <QImage>
#include <QThreadPool>
#include <functional>
#include <mtx/common.hpp>
2019-09-07 22:22:07 +02:00
class MxcImageResponse
: public QQuickImageResponse
, public QRunnable
{
public:
2021-08-14 17:17:50 +02:00
MxcImageResponse(const QString &id, bool crop, double radius, const QSize &requestedSize)
2019-09-07 22:22:07 +02:00
: m_id(id)
, m_requestedSize(requestedSize)
2021-08-06 01:45:47 +02:00
, m_crop(crop)
2021-08-14 17:17:50 +02:00
, m_radius(radius)
2019-09-07 22:22:07 +02:00
{
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;
2021-08-06 01:45:47 +02:00
bool m_crop;
2021-08-14 17:17:50 +02:00
double m_radius;
2019-09-07 22:22:07 +02:00
};
class MxcImageProvider
: public QObject
, public QQuickAsyncImageProvider
2019-09-07 22:22:07 +02:00
{
Q_OBJECT
public slots:
2019-09-07 22:22:07 +02:00
QQuickImageResponse *requestImageResponse(const QString &id,
const QSize &requestedSize) override;
static void addEncryptionInfo(mtx::crypto::EncryptedFile info);
static void download(const QString &id,
const QSize &requestedSize,
2021-08-06 01:45:47 +02:00
std::function<void(QString, QSize, QImage, QString)> then,
2021-08-14 17:17:50 +02:00
bool crop = true,
double radius = 0);
2019-09-07 22:22:07 +02:00
private:
QThreadPool pool;
};