qmlFrontend/themeiconprovider.cpp
author sheepluva
Sun, 01 May 2016 21:09:45 +0200
branchqmlfrontend
changeset 11787 bcba7938ccb5
parent 11432 97e3e62ea5f9
permissions -rw-r--r--
qmlfrontend/map-preview: add hog count display thingy (only displays "?" for now)

#include <QByteArray>
#include <QDebug>

#include "themeiconprovider.h"
#include "flib.h"

ThemeIconProvider::ThemeIconProvider()
    : QQuickImageProvider(QQuickImageProvider::Image)
{
    getThemeIcon = 0;
}

void ThemeIconProvider::setFileContentsFunction(getThemeIcon_t *f)
{
    getThemeIcon = f;
}

QImage ThemeIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
    Q_UNUSED(requestedSize);

    if(!getThemeIcon)
        return QImage();

    QByteArray buf;
    buf.resize(65536);

    char * bufptr = buf.data();
    uint32_t fileSize = getThemeIcon(id.toUtf8().data(), bufptr, buf.size());
    buf.truncate(fileSize);
    //qDebug() << "ThemeIconProvider file size = " << fileSize;

    QImage img = fileSize ? QImage::fromData(buf) : QImage(16, 16, QImage::Format_ARGB32);

    if (size)
        *size = img.size();
    return img;
}