qmlFrontend/themeiconprovider.cpp
author unc0rr
Wed, 01 Oct 2014 01:20:05 +0400
branchqmlfrontend
changeset 10436 084e046f6bd5
child 10440 b74a7bbe224e
permissions -rw-r--r--
flib provides theme icons, qmlFrontend shows them
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     1
#include <QByteArray>
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     2
#include <QDebug>
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     3
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     4
#include "themeiconprovider.h"
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     5
#include "flib.h"
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     6
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     7
ThemeIconProvider::ThemeIconProvider()
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     8
    : QQuickImageProvider(QQuickImageProvider::Image)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
     9
{
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    10
    getThemeIcon = 0;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    11
}
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    12
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    13
void ThemeIconProvider::setFileContentsFunction(getThemeIcon_t *f)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    14
{
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    15
    getThemeIcon = f;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    16
}
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    17
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    18
QImage ThemeIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    19
{
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    20
    Q_UNUSED(requestedSize);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    21
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    22
    if(!getThemeIcon)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    23
        return QImage();
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    24
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    25
    QByteArray buf;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    26
    buf.resize(65536);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    27
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    28
    uint32_t fileSize = getThemeIcon(id.toUtf8().data(), buf.data(), buf.size());
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    29
    buf.truncate(fileSize);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    30
    qDebug() << "ThemeIconProvider file size = " << fileSize;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    31
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    32
    QImage img = QImage::fromData(buf);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    33
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    34
    if (size)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    35
        *size = img.size();
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    36
    return img;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    37
}