cutter/src/common/SvgIconEngine.cpp

56 lines
1.3 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();
}
SvgIconEngine::SvgIconEngine(const QByteArray &svgData)
{
this->svgData = svgData;
}
SvgIconEngine::SvgIconEngine(const QString &filename, QColor tintColor) : SvgIconEngine(filename)
{
this->svgData = qhelpers::applyColorToSvg(svgData, tintColor);
}
SvgIconEngine::SvgIconEngine(const QByteArray &svgData, QColor tintColor)
{
this->svgData = qhelpers::applyColorToSvg(svgData, tintColor);
}
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);
QRect r(QPoint(0.0, 0.0), size);
this->paint(&painter, r, mode, state);
}
return pix;
}