mirror of
https://github.com/QuasarApp/DocsSite.git
synced 2025-05-08 01:09:34 +00:00
fix background of pages
This commit is contained in:
parent
6305b2973f
commit
21da756fcc
Site
@ -23,15 +23,28 @@ CorrentHostImageProvider::~CorrentHostImageProvider() {
|
||||
QQuickImageResponse *CorrentHostImageProvider::requestImageResponse(
|
||||
const QString &id, const QSize &requestedSize) {
|
||||
|
||||
AsyncImageResponse *response = new AsyncImageResponse(id, requestedSize);
|
||||
AsyncImageResponse *response = new AsyncImageResponse(this, id, requestedSize);
|
||||
response->run();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
AsyncImageResponse::AsyncImageResponse(const QString &id, const QSize &requestedSize)
|
||||
const QImage *CorrentHostImageProvider::fromCache(const QString &id) {
|
||||
if (!_cache.contains(id)) {
|
||||
return nullptr;
|
||||
}
|
||||
return &_cache[id];
|
||||
}
|
||||
|
||||
void CorrentHostImageProvider::addToCache(const QString &id, const QImage &img) {
|
||||
_cache[id] = img;
|
||||
}
|
||||
|
||||
AsyncImageResponse::AsyncImageResponse(CorrentHostImageProvider * provider,
|
||||
const QString &id, const QSize &requestedSize)
|
||||
:
|
||||
m_fetch(new FetchAPI()),
|
||||
m_parentProvider(provider),
|
||||
m_id(id),
|
||||
m_requestedSize(requestedSize) {
|
||||
|
||||
@ -43,16 +56,19 @@ AsyncImageResponse::~AsyncImageResponse() {
|
||||
}
|
||||
|
||||
QQuickTextureFactory *AsyncImageResponse::textureFactory() const {
|
||||
|
||||
return QQuickTextureFactory::textureFactoryForImage(m_image);
|
||||
}
|
||||
|
||||
void AsyncImageResponse::run() {
|
||||
|
||||
m_fetch->Get(m_id);
|
||||
|
||||
auto handleSuccessful = [this](const QString&, const QByteArray& data) {
|
||||
auto handleSuccessful = [this](const QString& id, const QByteArray& data) {
|
||||
m_image = QImage::fromData(data);
|
||||
|
||||
if (m_parentProvider) {
|
||||
m_parentProvider->addToCache(id, m_image);
|
||||
}
|
||||
|
||||
emit finished();
|
||||
};
|
||||
|
||||
@ -63,6 +79,16 @@ void AsyncImageResponse::run() {
|
||||
connect(m_fetch, &FetchAPI::sigFinished, handleSuccessful);
|
||||
connect(m_fetch, &FetchAPI::sigError, handleFail);
|
||||
|
||||
if (m_parentProvider) {
|
||||
if (auto img = m_parentProvider->fromCache(m_id)) {
|
||||
m_image = *img;
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_fetch->Get(m_id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,17 +17,19 @@ class QNetworkAccessManager;
|
||||
|
||||
namespace BaseFront {
|
||||
class FetchAPI;
|
||||
class CorrentHostImageProvider;
|
||||
|
||||
class BASEFRONT_LIBRARYSHARED_EXPORT AsyncImageResponse : public QQuickImageResponse, public QRunnable
|
||||
{
|
||||
public:
|
||||
AsyncImageResponse(const QString &id, const QSize &requestedSize);
|
||||
AsyncImageResponse(CorrentHostImageProvider* provider, const QString &id, const QSize &requestedSize);
|
||||
~AsyncImageResponse() override;
|
||||
QQuickTextureFactory *textureFactory() const override;
|
||||
|
||||
void run() override;
|
||||
|
||||
FetchAPI *m_fetch = nullptr;
|
||||
CorrentHostImageProvider * m_parentProvider = nullptr;
|
||||
|
||||
QString m_id;
|
||||
QImage m_image;
|
||||
@ -42,6 +44,11 @@ public:
|
||||
|
||||
QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
|
||||
|
||||
const QImage *fromCache(const QString& id);
|
||||
void addToCache(const QString& id, const QImage& img);
|
||||
private:
|
||||
QHash<QString, QImage> _cache;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // CORRENTHOSTIMAGEPROVIDER_H
|
||||
|
@ -1,3 +1,10 @@
|
||||
//
|
||||
// Copyright (C) 2020-2020 QuasarApp.
|
||||
// Distributed under the lgplv3 software license, see the accompanying
|
||||
// Everyone is permitted to copy and distribute verbatim copies
|
||||
// of this license document, but changing it is not allowed.
|
||||
//
|
||||
|
||||
#include "fetchapi.h"
|
||||
#include <quasarapp.h>
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 55222dab0515858d0acef620cf9f08ae6f0e6321
|
||||
Subproject commit 2e1cbba4422ab3fe704b510d816560ca70857223
|
Loading…
x
Reference in New Issue
Block a user