summary refs log tree commit diff
path: root/src/ColorImageProvider.cpp
blob: 92e4732b73c3fe79b92cecedb63375661ea10218 (plain) (blame)
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
#include "ColorImageProvider.h"

#include "Logging.h"
#include <QPainter>

QPixmap
ColorImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &)
{
        auto args = id.split('?');

        nhlog::ui()->info("Loading {}, source is {}", id.toStdString(), args[0].toStdString());

        QPixmap source(args[0]);

        if (size)
                *size = QSize(source.width(), source.height());

        if (args.size() < 2)
                return source;

        QColor color(args[1]);

        QPixmap colorized = source;
        QPainter painter(&colorized);
        painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        painter.fillRect(colorized.rect(), color);
        painter.end();

        return colorized;
}