Add icons and images dependent on device resolution
[harbour-pedalo.git] / src / imageprovider.cpp
1 #include <sailfishapp.h>
2 #include <QQuickImageProvider>
3 #include <QPainter>
4 #include <QColor>
5 #include <QDebug>
6 #include "settings.h"
7
8 #include "imageprovider.h"
9
10 ImageProvider::ImageProvider(Settings const & settings) : QQuickImageProvider(QQuickImageProvider::Pixmap) {
11 imageDir = settings.getImageDir();
12 }
13
14 QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) {
15 QPixmap image;
16 QStringList parts = id.split('?');
17 QPixmap sourcePixmap(imageDir + parts.at(0) + ".png");
18
19 if (size) {
20 *size = sourcePixmap.size();
21 }
22 if (parts.length() > 1) {
23 if (QColor::isValidColor(parts.at(1))) {
24 QPainter painter(&sourcePixmap);
25 painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
26 painter.fillRect(sourcePixmap.rect(), parts.at(1));
27 painter.end();
28 }
29 }
30 if (requestedSize.width() > 0 && requestedSize.height() > 0) {
31 image = sourcePixmap.scaled(requestedSize.width(), requestedSize.height(), Qt::IgnoreAspectRatio);
32 }
33 else {
34 image = sourcePixmap;
35 }
36
37 return image;
38 }