summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/cutils.hpp
blob: 654c333bd91a3d21266675afe3d2abc02125dcfd (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
#pragma once

#include <QtQuick/QQuickItem>
#include <qobject.h>
#include <qqmlintegration.h>

namespace caelestia {

class CUtils : public QObject {
    Q_OBJECT
    QML_ELEMENT
    QML_SINGLETON

public:
    Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path);
    Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, const QRect& rect);
    Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, QJSValue onSaved);
    Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, QJSValue onSaved, QJSValue onFailed);
    Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, QJSValue onSaved);
    Q_INVOKABLE void saveItem(
        QQuickItem* target, const QUrl& path, const QRect& rect, QJSValue onSaved, QJSValue onFailed);

    Q_INVOKABLE bool copyFile(const QUrl& source, const QUrl& target) const;
    Q_INVOKABLE bool copyFile(const QUrl& source, const QUrl& target, bool overwrite) const;

    Q_INVOKABLE void getDominantColour(QQuickItem* item, QJSValue callback);
    Q_INVOKABLE void getDominantColour(QQuickItem* item, int rescaleSize, QJSValue callback);
    Q_INVOKABLE void getDominantColour(const QString& path, QJSValue callback);
    Q_INVOKABLE void getDominantColour(const QString& path, int rescaleSize, QJSValue callback);

    Q_INVOKABLE void getAverageLuminance(QQuickItem* item, QJSValue callback);
    Q_INVOKABLE void getAverageLuminance(QQuickItem* item, int rescaleSize, QJSValue callback);
    Q_INVOKABLE void getAverageLuminance(const QString& path, QJSValue callback);
    Q_INVOKABLE void getAverageLuminance(const QString& path, int rescaleSize, QJSValue callback);

    Q_INVOKABLE QString toLocalFile(const QUrl& url) const;

private:
    QColor findDominantColour(const QImage& image, int rescaleSize) const;
    qreal findAverageLuminance(const QImage& image, int rescaleSize) const;
};

} // namespace caelestia