14164
|
1 |
#include "previewimageprovider.h"
|
|
2 |
|
|
3 |
PreviewImageProvider::PreviewImageProvider()
|
|
4 |
: QQuickImageProvider(QQuickImageProvider::Pixmap) {}
|
|
5 |
|
|
6 |
QPixmap PreviewImageProvider::requestPixmap(const QString &id, QSize *size,
|
|
7 |
const QSize &requestedSize) {
|
|
8 |
Q_UNUSED(id);
|
|
9 |
Q_UNUSED(requestedSize);
|
|
10 |
|
|
11 |
if (size) *size = m_px.size();
|
|
12 |
|
|
13 |
return m_px;
|
|
14 |
}
|
|
15 |
|
|
16 |
void PreviewImageProvider::setPixmap(const QByteArray &px) {
|
|
17 |
QVector<QRgb> colorTable;
|
|
18 |
colorTable.resize(256);
|
|
19 |
for (int i = 0; i < 256; ++i) colorTable[i] = qRgba(255, 255, 0, i);
|
|
20 |
|
|
21 |
const quint8 *buf = (const quint8 *)px.constData();
|
|
22 |
QImage im(buf, 256, 128, QImage::Format_Indexed8);
|
|
23 |
im.setColorTable(colorTable);
|
|
24 |
|
|
25 |
m_px = QPixmap::fromImage(im, Qt::ColorOnly);
|
|
26 |
// QPixmap pxres(px.size());
|
|
27 |
// QPainter p(&pxres);
|
|
28 |
|
|
29 |
// p.fillRect(pxres.rect(), linearGrad);
|
|
30 |
// p.drawPixmap(0, 0, px);
|
|
31 |
}
|