1 #include <sailfishapp.h>
2 #include <QQuickImageProvider>
8 #include "imageprovider.h"
10 ImageProvider::ImageProvider(Settings
const & settings
) : QQuickImageProvider(QQuickImageProvider::Pixmap
) {
11 imageDir
= settings
.getImageDir();
14 QPixmap
ImageProvider::requestPixmap(const QString
&id
, QSize
*size
, const QSize
&requestedSize
) {
16 QStringList parts
= id
.split('?');
17 QPixmap
sourcePixmap(imageDir
+ parts
.at(0) + ".png");
18 QPixmap
alphaMask(sourcePixmap
);
21 *size
= sourcePixmap
.size();
23 if (parts
.length() > 1) {
24 if (QColor::isValidColor(parts
.at(1))) {
25 QPainter
painter(&sourcePixmap
);
26 painter
.setCompositionMode(QPainter::CompositionMode_SoftLight
);
27 painter
.fillRect(sourcePixmap
.rect(), parts
.at(1));
29 painter
.setCompositionMode(QPainter::CompositionMode_DestinationIn
);
30 painter
.drawPixmap(sourcePixmap
.rect(), alphaMask
);
34 if (requestedSize
.width() > 0 && requestedSize
.height() > 0) {
35 image
= sourcePixmap
.scaled(requestedSize
.width(), requestedSize
.height(), Qt::IgnoreAspectRatio
);