qmlFrontend/previewimageprovider.cpp
author unc0rr
Mon, 16 Nov 2015 22:57:24 +0300
branchqmlfrontend
changeset 11408 b894922d58cc
parent 10426 727a154cf784
permissions -rw-r--r--
Merge default (add a bunch of FIXMEs)
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
{
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    21
    QVector<QRgb> colorTable;
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    22
    colorTable.resize(256);
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    23
    for(int i = 0; i < 256; ++i)
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    24
        colorTable[i] = qRgba(255, 255, 0, i);
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    25
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    26
    const quint8 *buf = (const quint8*) px.constData();
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    27
    QImage im(buf, 256, 128, QImage::Format_Indexed8);
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    28
    im.setColorTable(colorTable);
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    29
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    30
    m_px = QPixmap::fromImage(im, Qt::ColorOnly);
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    31
    //QPixmap pxres(px.size());
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    32
    //QPainter p(&pxres);
10424
4be6cd55f1cf - Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents: 10420
diff changeset
    33
10426
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    34
    //p.fillRect(pxres.rect(), linearGrad);
727a154cf784 Some refactoring
unc0rr
parents: 10424
diff changeset
    35
    //p.drawPixmap(0, 0, px);
10420
unc0rr
parents:
diff changeset
    36
}