cutter/src/common/SvgIconEngine.cpp

51 lines
1.2 KiB
C++
Raw Normal View History

2017-12-03 16:26:01 +00:00
#include "SvgIconEngine.h"
#include <QSvgRenderer>
#include <QPainter>
#include <QFile>
#include "Helpers.h"
SvgIconEngine::SvgIconEngine(const QString &filename)
{
QFile file(filename);
file.open(QFile::ReadOnly);
this->svgData = file.readAll();
}
2019-02-01 15:14:11 +00:00
SvgIconEngine::SvgIconEngine(const QString &filename, const QColor &tintColor) : SvgIconEngine(filename)
2017-12-03 16:26:01 +00:00
{
this->svgData = qhelpers::applyColorToSvg(svgData, tintColor);
}
2019-02-01 15:14:11 +00:00
SvgIconEngine::SvgIconEngine(const QString &filename, QPalette::ColorRole colorRole)
: SvgIconEngine(filename, QPalette().color(colorRole))
2017-12-03 16:26:01 +00:00
{
}
2018-03-21 20:32:32 +00:00
void SvgIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode /*mode*/,
QIcon::State /*state*/)
2017-12-03 16:26:01 +00:00
{
QSvgRenderer renderer(svgData);
renderer.render(painter, rect);
}
QIconEngine *SvgIconEngine::clone() const
{
return new SvgIconEngine(*this);
}
QPixmap SvgIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
QImage img(size, QImage::Format_ARGB32);
img.fill(qRgba(0, 0, 0, 0));
QPixmap pix = QPixmap::fromImage(img, Qt::NoFormatConversion);
{
QPainter painter(&pix);
2019-02-01 15:14:11 +00:00
QRect r(QPoint(0, 0), size);
2017-12-03 16:26:01 +00:00
this->paint(&painter, r, mode, state);
}
return pix;
}