Web image support
This commit is contained in:
22 files changed
+370
-48
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAtomicInt>
|
||||
#include <QMutex>
|
||||
#include <QRunnable>
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
|
||||
#include "backend/IImageLoader.h"
|
||||
#include "backend/IImageProvider.h"
|
||||
|
||||
class WebImageResponse : public QQuickImageResponse, public QRunnable {
|
||||
// NO Q_OBJECT — already inherited from QQuickImageResponse
|
||||
public:
|
||||
WebImageResponse(const QString &url, int displayWidth, const QSize &requestedSize);
|
||||
|
||||
QQuickTextureFactory *textureFactory() const override;
|
||||
void cancel() override;
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
const QString m_url;
|
||||
const int m_displayWidth;
|
||||
const QSize m_requestedSize;
|
||||
QAtomicInt m_cancelled{0};
|
||||
QImage m_image;
|
||||
};
|
||||
|
||||
class WebImageProvider : public IImageProvider, public IImageLoader {
|
||||
public:
|
||||
QQuickImageResponse *requestImageResponse(const QString &id,
|
||||
const QSize &requestedSize) override;
|
||||
|
||||
void setFilePath(const QString &) override {}
|
||||
void setDisplayWidth(int width) override;
|
||||
void clear() override {}
|
||||
QString coverImageUrl(const QString &) const override { return {}; }
|
||||
QString scheme() const override;
|
||||
|
||||
QImage load(const QUrl &url, int maxWidth) const override;
|
||||
std::unique_ptr<IImageLoader> clone() const override;
|
||||
|
||||
// Download (or load from disk cache) a web image. Thread-safe, may block.
|
||||
static QImage loadWebImage(const QString &urlString, int displayWidth,
|
||||
const QSize &requestedSize);
|
||||
|
||||
static QString cacheDir();
|
||||
static QString cacheFilePath(const QString &urlString);
|
||||
|
||||
private:
|
||||
mutable QMutex m_mutex;
|
||||
int m_displayWidth = 0;
|
||||
};
|
||||
Reference in new issue
Block a user