summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/webkit/imageanalyzer/imageanalyzer.h
blob: ef30a5772eec088aa5c73f761f2e66e6b64f70b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef IMAGEANALYZER_H
#define IMAGEANALYZER_H

#include <QFutureWatcher>
#include <QtWidgets>

QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
class QNetworkReply;
class QNetworkDiskCache;
QT_END_NAMESPACE

//! [ ImageAnalyzer - public interface ]
class ImageAnalyzer : public QObject
{
    Q_OBJECT
public:
    ImageAnalyzer(QNetworkDiskCache * netcache, QObject * parent=0);

    QRgb lastResults();
    float lastRed();
    float lastGreen();
    float lastBlue();
    bool isBusy();
    Q_PROPERTY(bool busy READ isBusy);
    Q_PROPERTY(float red READ lastRed);
    Q_PROPERTY(float green READ lastGreen);
    Q_PROPERTY(float blue READ lastBlue);
    ~ImageAnalyzer();

public slots:
    /*! initiates analysis of all the urls in the list */
    void startAnalysis(const QStringList & urls);

signals:
    void finishedAnalysis();
    void updateProgress(int completed, int total);
    //! [ ImageAnalyzer - public interface ]

private slots:
    void handleReply(QNetworkReply*);
    void doneProcessing();
    void progressStatus(int);

private:
    QRgb processImages();
    void fetchURLs();
    void queueImage(QImage img);

    //! [ ImageAnalyzer - private members ]
private:
    QNetworkAccessManager* m_network;
    QNetworkDiskCache* m_cache;
    QStringList m_URLQueue;
    QList<QImage> m_imageQueue;
    int m_outstandingFetches;
    QFutureWatcher<QRgb> * m_watcher;
    //! [ ImageAnalyzer - private members ]
};

QRgb averageRGB(const QImage &img);

#endif