-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathIconProvider.h
42 lines (33 loc) · 1.17 KB
/
IconProvider.h
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
36
37
38
39
40
41
#ifndef ICONPROVIDER_H
#define ICONPROVIDER_H
#include <sailfishapp.h>
#include <QQuickImageProvider>
#include <QPainter>
#include <QColor>
class IconProvider : public QQuickImageProvider
{
public:
IconProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap)
{
}
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
QStringList parts = id.split('?');
QPixmap sourcePixmap(SailfishApp::pathTo("qml/icons/" + parts.at(0) + ".png").toString(QUrl::RemoveScheme));
if (size)
*size = sourcePixmap.size();
if (parts.length() > 1)
if (QColor::isValidColor(parts.at(1)))
{
QPainter painter(&sourcePixmap);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.fillRect(sourcePixmap.rect(), parts.at(1));
painter.end();
}
if (requestedSize.width() > 0 && requestedSize.height() > 0)
return sourcePixmap.scaled(requestedSize.width(), requestedSize.height(), Qt::IgnoreAspectRatio);
else
return sourcePixmap;
}
};
#endif // ICONPROVIDER_H