qmlFrontend/themeiconprovider.cpp
author unc0rr
Wed, 02 Dec 2015 22:30:13 +0300
branchqmlfrontend
changeset 11446 908aed8525f9
parent 11437 97e3e62ea5f9
permissions -rw-r--r--
Fix LEFT command handling
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
10440
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10436
diff changeset
    28
    char * bufptr = buf.data();
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10436
diff changeset
    29
    uint32_t fileSize = getThemeIcon(id.toUtf8().data(), bufptr, buf.size());
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    30
    buf.truncate(fileSize);
11437
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 10440
diff changeset
    31
    //qDebug() << "ThemeIconProvider file size = " << fileSize;
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    32
11437
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 10440
diff changeset
    33
    QImage img = fileSize ? QImage::fromData(buf) : QImage(16, 16, QImage::Format_ARGB32);
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    34
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    35
    if (size)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    36
        *size = img.size();
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    37
    return img;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents:
diff changeset
    38
}