-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicons.cpp
More file actions
65 lines (53 loc) · 1.42 KB
/
Copy pathicons.cpp
File metadata and controls
65 lines (53 loc) · 1.42 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "icons.h"
#include <QApplication>
#include <QIconEngine>
#include <QPainter>
#include <QPalette>
#include <QPixmap>
#include <QSvgRenderer>
#include <oclero/qlementine/icons/QlementineIcons.hpp>
namespace {
class PaletteIconEngine : public QIconEngine
{
public:
explicit PaletteIconEngine(const char* path) : m_path(path) {}
void paint(QPainter* painter, const QRect& rect, QIcon::Mode, QIcon::State) override
{
painter->drawPixmap(rect, tinted(rect.size()));
}
QPixmap pixmap(const QSize& size, QIcon::Mode, QIcon::State) override
{
return tinted(size);
}
QIconEngine* clone() const override
{
return new PaletteIconEngine(m_path);
}
private:
QPixmap tinted(const QSize& size) const
{
QSvgRenderer renderer{QString(m_path)};
QSize target = size.isEmpty() ? renderer.defaultSize() : size;
QPixmap px(target);
px.fill(Qt::transparent);
QPainter p(&px);
renderer.render(&p);
p.setCompositionMode(QPainter::CompositionMode_SourceIn);
p.fillRect(px.rect(), qApp->palette().windowText().color());
return px;
}
const char* m_path;
};
} // namespace
void initIcons()
{
initializeIconTheme();
}
QIcon themedIcon(Icons16 id)
{
return QIcon(new PaletteIconEngine(iconPath(id)));
}
QIcon qrCodeIcon()
{
return QIcon(new PaletteIconEngine(":/icons/icons/qrcode-scan.svg"));
}