~attente/unity8/1634508

« back to all changes in this revision

Viewing changes to plugins/ImageCache/ImageCache.h

  • Committer: Bileto Bot
  • Author(s): Michael Terry
  • Date: 2016-09-22 07:40:11 UTC
  • mfrom: (2552.8.8 default-wallpaper)
  • Revision ID: ci-train-bot@canonical.com-20160922074011-b4t82zo3k7ipgtx0
Use the default system wallpaper instead of our custom one.

Additionally, crop the default wallpaper instead of rotating it, only darken the wallpaper if it's not the default one, and avoid reloading the wallpaper when the device is rotated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
16
 
 
17
#pragma once
 
18
 
 
19
#include <QFileInfo>
 
20
#include <QImageReader>
 
21
#include <QQuickImageProvider>
 
22
#include <QSize>
 
23
 
 
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
 */
 
39
 
 
40
class ImageCache: public QQuickImageProvider
 
41
{
 
42
public:
 
43
    ImageCache();
 
44
 
 
45
    QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
 
46
 
 
47
private:
 
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
};