matrixion/src/ColorImageProvider.cpp

32 lines
680 B
C++
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "ColorImageProvider.h"
#include <QPainter>
QPixmap
ColorImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &)
{
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());
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;
}