qmlFrontend/themeiconprovider.cpp
branchqmlfrontend
changeset 10436 084e046f6bd5
child 10440 b74a7bbe224e
equal deleted inserted replaced
10434:1614b13ad35e 10436:084e046f6bd5
       
     1 #include <QByteArray>
       
     2 #include <QDebug>
       
     3 
       
     4 #include "themeiconprovider.h"
       
     5 #include "flib.h"
       
     6 
       
     7 ThemeIconProvider::ThemeIconProvider()
       
     8     : QQuickImageProvider(QQuickImageProvider::Image)
       
     9 {
       
    10     getThemeIcon = 0;
       
    11 }
       
    12 
       
    13 void ThemeIconProvider::setFileContentsFunction(getThemeIcon_t *f)
       
    14 {
       
    15     getThemeIcon = f;
       
    16 }
       
    17 
       
    18 QImage ThemeIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
       
    19 {
       
    20     Q_UNUSED(requestedSize);
       
    21 
       
    22     if(!getThemeIcon)
       
    23         return QImage();
       
    24 
       
    25     QByteArray buf;
       
    26     buf.resize(65536);
       
    27 
       
    28     uint32_t fileSize = getThemeIcon(id.toUtf8().data(), buf.data(), buf.size());
       
    29     buf.truncate(fileSize);
       
    30     qDebug() << "ThemeIconProvider file size = " << fileSize;
       
    31 
       
    32     QImage img = QImage::fromData(buf);
       
    33 
       
    34     if (size)
       
    35         *size = img.size();
       
    36     return img;
       
    37 }