thumbnail.h 2.22 KB
Newer Older
Malte Starostik's avatar
Malte Starostik committed
1
/*  This file is part of the KDE libraries
2
3
4
    SPDX-FileCopyrightText: 2000 Malte Starostik <malte@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
Malte Starostik's avatar
Malte Starostik committed
5
6
7
*/

#ifndef _THUMBNAIL_H_
Frans Englich's avatar
   
Frans Englich committed
8
#define _THUMBNAIL_H_
Malte Starostik's avatar
Malte Starostik committed
9

David Faure's avatar
David Faure committed
10
11
12
#include <QHash>
#include <QPainter>
#include <QSet>
13
#include <QRandomGenerator>
Malte Starostik's avatar
Malte Starostik committed
14
15
16
17
18
19

#include <kio/slavebase.h>

class ThumbCreator;
class QImage;

20
21
22
23
24
25
struct ThumbCreatorWithMetadata {
    ThumbCreator *creator = nullptr;
    bool cacheThumbnail = true;
    bool handleSequences = false;
};

Malte Starostik's avatar
Malte Starostik committed
26
27
28
class ThumbnailProtocol : public KIO::SlaveBase
{
public:
Laurent Montel's avatar
Laurent Montel committed
29
    ThumbnailProtocol(const QByteArray &pool, const QByteArray &app);
Kevin Funk's avatar
Kevin Funk committed
30
    ~ThumbnailProtocol() override;
Malte Starostik's avatar
Malte Starostik committed
31

Kevin Funk's avatar
Kevin Funk committed
32
    void get(const QUrl &url) override;
Malte Starostik's avatar
Malte Starostik committed
33
34

protected:
35
    ThumbCreatorWithMetadata* getThumbCreator(const QString& plugin);
36
    bool isOpaque(const QImage &image) const;
37
    void drawPictureFrame(QPainter *painter, const QPoint &pos, const QImage &image,
38
                          int frameWidth, QSize imageTargetSize, int rotationAngle) const;
39
    QImage thumbForDirectory(const QString& directory);
40
    QString pluginForMimeType(const QString& mimeType);
41

42
    float sequenceIndex() const;
43

44
45
46
47
48
49
50
51
52
53
private:
    /**
     * Creates a sub thumbnail for the directory thumbnail. If a cached
     * version of the sub thumbnail is available, the cached version will be used.
     * If no cached version is available, the created sub thumbnail will be
     * added to the cache for later use.
     */
    bool createSubThumbnail(QImage& thumbnail, const QString& filePath,
                            int segmentWidth, int segmentHeight);

54
    /**
55
     * Draw the SubThumbnail
56
     **/
57
    void drawSubThumbnail(QPainter& p, QImage subThumbnail, int width, int height,
58
                          int xPos, int yPos, int frameWidth);
Malte Starostik's avatar
Malte Starostik committed
59
private:
60
    void ensureDirsCreated();
61
62
    bool createThumbnail(ThumbCreatorWithMetadata* subCreator, const QString& filePath, int width, int height, QImage& thumbnail);

Malte Starostik's avatar
Malte Starostik committed
63
    QString m_mimeType;
64
65
    int m_width;
    int m_height;
Malte Starostik's avatar
Malte Starostik committed
66
    // Thumbnail creators
67
    QHash<QString, ThumbCreatorWithMetadata*> m_creators;
68
    QStringList m_enabledPlugins;
69
    QSet<QString> m_propagationDirectories;
70
    QString m_thumbBasePath;
71
    qint64 m_maxFileSize;
72
    QRandomGenerator m_randomGenerator;
Malte Starostik's avatar
Malte Starostik committed
73
74
75
};

#endif