author | unc0rr |
Sat, 27 Sep 2014 12:49:08 +0400 | |
branch | qmlfrontend |
changeset 10424 | 4be6cd55f1cf |
parent 10420 | 02c573d19224 |
child 10426 | 727a154cf784 |
permissions | -rw-r--r-- |
10420 | 1 |
#include "previewimageprovider.h" |
2 |
||
3 |
PreviewImageProvider::PreviewImageProvider() |
|
4 |
: QQuickImageProvider(QQuickImageProvider::Pixmap) |
|
5 |
{ |
|
6 |
} |
|
7 |
||
8 |
QPixmap PreviewImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) |
|
9 |
{ |
|
10 |
Q_UNUSED(id); |
|
11 |
Q_UNUSED(requestedSize); |
|
12 |
||
13 |
if (size) |
|
14 |
*size = m_px.size(); |
|
15 |
||
16 |
return m_px; |
|
17 |
} |
|
18 |
||
10424
4be6cd55f1cf
- Get rid of engine's PathPrefix and UserPathPrefix
unc0rr
parents:
10420
diff
changeset
|
19 |
void PreviewImageProvider::setPixmap(const QByteArray &px) |
10420 | 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 | 39 |
} |