on bionic help sign in
unity8/plugins/ImageCache/ImageCache.h
53 lines 1.8 kB history raw
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#pragma once
19#include <QFileInfo>
20#include <QImageReader>
21#include <QQuickImageProvider>
22#include <QSize>
24/**
25 * This class accepts an id formulated like a URL. So you'd use something like:
26 *
27 * Image {
28 * source: "image://unity8imagecache/file:///usr/share/..."
29 * }
30 *
31 * Right now, we only support file:/// URLs. We do accept some flags though:
32 *
33 * ?name=NAME
34 * - This will use NAME as the cache lookup key instead of the provided URL.
35 *
36 * We don't do any cleaning of old cached files yet. So you may want to always
37 * provide a name to avoid leaving lots of files around.
38 */
40class ImageCache: public QQuickImageProvider
42public:
43 ImageCache();
45 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
47private:
48 static QString imageCacheRoot();
49 static QFileInfo imagePath(const QUrl &image);
50 static bool needsUpdate(const QUrl &image, const QFileInfo &cachePath, const QSize &imageSize, const QSize &requestedSize, QSize &finalSize);
51 static QSize calculateSize(const QSize &imageSize, const QSize &requestedSize);
52 static QImage loadAndCacheImage(QImageReader &reader, const QFileInfo &cachePath, const QSize &finalSize);
53};