matrixion/src/ColorImageProvider.cpp

35 lines
785 B
C++
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
2021-03-05 02:35:15 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "ColorImageProvider.h"
2022-06-28 15:14:23 +03:00
#include <QIcon>
#include <QPainter>
QPixmap
2022-06-28 15:14:23 +03:00
ColorImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &req)
{
2021-09-18 01:22:33 +03:00
auto args = id.split('?');
2021-09-18 01:22:33 +03:00
QPixmap source(args[0]);
2021-09-18 01:22:33 +03:00
if (size)
*size = QSize(source.width(), source.height());
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;
2021-09-18 01:22:33 +03:00
QColor color(args[1]);
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();
2021-09-18 01:22:33 +03:00
return colorized;
}