54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
#ifndef CBZIMAGEPROVIDER_H
|
|
#define CBZIMAGEPROVIDER_H
|
|
|
|
#include <QMutex>
|
|
#include <QRunnable>
|
|
#include <QString>
|
|
|
|
#include "backend/IImageLoader.h"
|
|
#include "backend/IImageProvider.h"
|
|
|
|
class CbzImageResponse : public QQuickImageResponse, public QRunnable {
|
|
// NO Q_OBJECT — already inherited from QQuickImageResponse
|
|
public:
|
|
CbzImageResponse(const QString &cbzPath, const QString &entryName,
|
|
int displayWidth, const QSize &requestedSize);
|
|
|
|
QQuickTextureFactory *textureFactory() const override;
|
|
void cancel() override;
|
|
void run() override;
|
|
|
|
private:
|
|
const QString m_cbzPath;
|
|
const QString m_entryName;
|
|
const int m_displayWidth;
|
|
const QSize m_requestedSize;
|
|
QAtomicInt m_cancelled{0};
|
|
QImage m_image;
|
|
};
|
|
|
|
class CbzImageProvider : public IImageProvider, public IImageLoader {
|
|
public:
|
|
QQuickImageResponse *requestImageResponse(const QString &id,
|
|
const QSize &requestedSize) override;
|
|
|
|
void setFilePath(const QString &filePath) override;
|
|
void setDisplayWidth(int width) override;
|
|
void clear() override;
|
|
QString coverImageUrl(const QString &coverPath) const override;
|
|
QString scheme() const override;
|
|
|
|
QImage load(const QUrl &url, int maxWidth) const override;
|
|
std::unique_ptr<IImageLoader> clone() const override;
|
|
|
|
static QImage loadImageFromCbz(const QString &cbzPath, const QString &entryName,
|
|
int displayWidth, const QSize &requestedSize);
|
|
|
|
private:
|
|
mutable QMutex m_mutex;
|
|
QString m_cbzPath;
|
|
int m_displayWidth = 0;
|
|
};
|
|
|
|
#endif // CBZIMAGEPROVIDER_H
|