mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 09:43:24 +00:00
b450c155fd
The size of the to-be-created thumbnails was passed from DivePictureModel to Thumbnailer. This became more and more bothersome, because the size had to be stored with the request. Calling from Thumbnailer into DivePictureModel was not an option, since this is not linked to all tests. Therefore, move these functions to the Thumbnailer class. Since the maximum thumbnail size is now known to the thumbnailer, the dummy and failure images can be precalculated, which makes switching between dives faster. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef IMAGEDOWNLOADER_H
|
|
#define IMAGEDOWNLOADER_H
|
|
|
|
#include <QImage>
|
|
#include <QFuture>
|
|
#include <QNetworkReply>
|
|
#include <QThreadPool>
|
|
|
|
class ImageDownloader : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
ImageDownloader(const QString &filename);
|
|
void load(bool fromHash);
|
|
|
|
private:
|
|
bool loadFromUrl(const QUrl &); // return true on success
|
|
void saveImage(QNetworkReply *reply, bool &success);
|
|
QString filename;
|
|
};
|
|
|
|
class PictureEntry;
|
|
class Thumbnailer : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static Thumbnailer *instance();
|
|
|
|
// Schedule a thumbnail for fetching or calculation.
|
|
// Returns a placehlder thumbnail. The actual thumbnail will be sent
|
|
// via a signal later.
|
|
QImage fetchThumbnail(PictureEntry &entry);
|
|
|
|
// If we change dive, clear all unfinished thumbnail creations
|
|
void clearWorkQueue();
|
|
static int maxThumbnailSize();
|
|
static int defaultThumbnailSize();
|
|
static int thumbnailSize(double zoomLevel);
|
|
signals:
|
|
void thumbnailChanged(QString filename, QImage thumbnail);
|
|
private:
|
|
Thumbnailer();
|
|
void processItem(QString filename);
|
|
|
|
mutable QMutex lock;
|
|
QThreadPool pool;
|
|
QImage failImage; // Shown when image-fetching fails
|
|
QImage dummyImage; // Shown before thumbnail is fetched
|
|
|
|
QMap<QString,QFuture<void>> workingOn;
|
|
};
|
|
|
|
QImage getHashedImage(const QString &filename);
|
|
|
|
#endif // IMAGEDOWNLOADER_H
|