| 1 | // SPDX-FileCopyrightText: Nheko Contributors |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "ColorImageProvider.h" |
| 6 | |
| 7 | #include <QIcon> |
| 8 | #include <QPainter> |
| 9 | |
| 10 | QPixmap |
| 11 | ColorImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &req) |
| 12 | { |
| 13 | auto args = id.split('?'); |
| 14 | |
| 15 | QPixmap source(args[0]); |
| 16 | |
| 17 | if (size) |
| 18 | *size = QSize(source.width(), source.height()); |
| 19 | |
| 20 | if (req.width() > 0 && req.height() > 0) |
| 21 | source = QIcon(args[0]).pixmap(req); |
| 22 | if (args.size() < 2) |
| 23 | return source; |
| 24 | |
| 25 | QColor color(args[1]); |
| 26 | |
| 27 | QPixmap colorized = source; |
| 28 | QPainter painter(&colorized); |
| 29 | painter.setCompositionMode(QPainter::CompositionMode_SourceIn); |
| 30 | painter.fillRect(colorized.rect(), color); |
| 31 | painter.end(); |
| 32 | |
| 33 | return colorized; |
| 34 | } |