qmlFrontend/previewimageprovider.cpp
author unc0rr
Sat, 27 Sep 2014 12:49:08 +0400
branchqmlfrontend
changeset 10424 4be6cd55f1cf
parent 10420 02c573d19224
child 10426 727a154cf784
permissions -rw-r--r--
- Get rid of engine's PathPrefix and UserPathPrefix - Some refactoring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10420
unc0rr
parents:
diff changeset
     1
#include "previewimageprovider.h"
unc0rr
parents:
diff changeset
     2
unc0rr
parents:
diff changeset
     3
PreviewImageProvider::PreviewImageProvider()
unc0rr
parents:
diff changeset
     4
        : QQuickImageProvider(QQuickImageProvider::Pixmap)
unc0rr
parents:
diff changeset
     5
{
unc0rr
parents:
diff changeset
     6
}
unc0rr
parents:
diff changeset
     7
unc0rr
parents:
diff changeset
     8
QPixmap PreviewImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
unc0rr
parents:
diff changeset
     9
{
unc0rr
parents:
diff changeset
    10
    Q_UNUSED(id);
unc0rr
parents:
diff changeset
    11
    Q_UNUSED(requestedSize);
unc0rr
parents:
diff changeset
    12
unc0rr
parents:
diff changeset
    13
    if (size)
unc0rr
parents:
diff changeset
    14
        *size = m_px.size();
unc0rr
parents:
diff changeset
    15
unc0rr
parents:
diff changeset
    16
    return m_px;
unc0rr
parents:
diff changeset
    17
}
unc0rr
parents:
diff changeset
    18
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    19
void PreviewImageProvider::setPixmap(const QByteArray &px)
10420
unc0rr
parents:
diff changeset
    20
{
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    21
    if(px.size() == 128 * 256)
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    22
    {
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    23
        QVector<QRgb> colorTable;
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    24
        colorTable.resize(256);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    25
        for(int i = 0; i < 256; ++i)
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    26
            colorTable[i] = qRgba(255, 255, 0, i);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    27
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    28
        const quint8 *buf = (const quint8*) px.constData();
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    29
        QImage im(buf, 256, 128, QImage::Format_Indexed8);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    30
        im.setColorTable(colorTable);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    31
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    32
        m_px = QPixmap::fromImage(im, Qt::ColorOnly);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    33
        //QPixmap pxres(px.size());
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    34
        //QPainter p(&pxres);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    35
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    36
        //p.fillRect(pxres.rect(), linearGrad);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    37
        //p.drawPixmap(0, 0, px);
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    38
    }
10420
unc0rr
parents:
diff changeset
    39
}