2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-03-05 02:35:15 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-11-08 16:39:45 +03:00
|
|
|
#include "ColorImageProvider.h"
|
|
|
|
|
2022-06-28 15:14:23 +03:00
|
|
|
#include <QIcon>
|
2019-11-08 16:39:45 +03:00
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
QPixmap
|
2022-06-28 15:14:23 +03:00
|
|
|
ColorImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &req)
|
2019-11-08 16:39:45 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
auto args = id.split('?');
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QPixmap source(args[0]);
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
if (size)
|
|
|
|
*size = QSize(source.width(), source.height());
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2022-06-28 15:14:23 +03:00
|
|
|
if (req.width() > 0 && req.height() > 0)
|
|
|
|
source = QIcon(args[0]).pixmap(req);
|
2021-09-18 01:22:33 +03:00
|
|
|
if (args.size() < 2)
|
|
|
|
return source;
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QColor color(args[1]);
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QPixmap colorized = source;
|
|
|
|
QPainter painter(&colorized);
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
|
|
|
painter.fillRect(colorized.rect(), color);
|
|
|
|
painter.end();
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
return colorized;
|
2019-11-08 16:39:45 +03:00
|
|
|
}
|