-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageProvider.cpp
35 lines (28 loc) · 1013 Bytes
/
ImageProvider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "ImageProvider.h"
#include <qmessagebox.h>
ImageProvider::ImageProvider(QDeclarativeImageProvider::ImageType type) :
QDeclarativeImageProvider(type) {}
ImageProvider::~ImageProvider() {
}
QImage ImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
{
double coef = double(requestedSize.width()) / double(svg.defaultSize().width());
QImage img(svg.defaultSize().width() * coef, svg.defaultSize().height() * coef,
QImage::Format_ARGB32_Premultiplied);
img.fill(QColor(0,0,0,0).rgba());
QPainter paint(&img);
svg.render(&paint);
*size = requestedSize;
return img;
}
QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize)
{
QPixmap image = pImg;
QPixmap result;
if (requestedSize.isValid() )
result = image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
else
result = image;
*size = result.size();
return result;
}