Commit eae68aa7 authored by Blackbeard (alberto flores)'s avatar Blackbeard (alberto flores) 🚢

Add KisVectorHelperPipe Class

parent 351aaa52
/*
* Copyright (c) 2019 Alberto Eleuterio Flores Guerrero <barbanegra+bugs@posteo.mx>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KisVectorShapeObject.h"
#include <SvgParser.h>
#include <KoDocumentResourceManager.h>
#include <KoXmlReader.h>
#include <KoShapePainter.h>
KisVectorShapeObject::KisVectorShapeObject(KoShape* shape)
{
m_shape = shape;
renderImage(1000, 1000);
}
void KisVectorShapeObject::setShape(KoShape* shape)
{
m_shape = shape;
}
void KisVectorShapeObject::renderImage(int width, int height)
{
KoShape* shape = m_shape;
QList<KoShape*> list_shape;
list_shape.append(shape);
KoShapePainter painter;
painter.setShapes(list_shape);
QImage theImage(width, height, QImage::Format_ARGB32); //fix size
{
QPainter p(&theImage);
p.fillRect(0, 0, theImage.width(), theImage.height(), Qt::white);
}
painter.paint(theImage);
QVector<QRgb> table;
for (int i = 0; i < 256; ++i) table.push_back(qRgb(i, i, i));
theImage = theImage.convertToFormat(QImage::Format_Indexed8, table);
m_image = theImage;
}
QImage KisVectorShapeObject::image()
{
return m_image;
}
KoShape* KisVectorShapeObject::shape()
{
return m_shape;
}
/*
* Copyright (c) 2019 Alberto Eleuterio Flores Guerrero <barbanegra+bugs@posteo.mx>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISVECTORSHAPEOBJECT_H
#define KISVECTORSHAPEOBJECT_H
#include <KoShape.h>
#include <qimage.h>
class KisVectorShapeObject
{
public:
KisVectorShapeObject(KoShape* shape);
void setShape(KoShape* shape);
QImage image();
KoShape* shape();
void renderImage(int width, int weight);
private:
private:
KoShape* m_shape;
QImage m_image;
};
#endif // KISVECTORSHAPEOBJECT_H
...@@ -34,6 +34,39 @@ ...@@ -34,6 +34,39 @@
#include <QDebug> #include <QDebug>
class KisVectorHelperPipe : public KisBrushesPipe<KisVectorShapeObject>
{
public:
KisVectorHelperPipe()
: m_currentIndex(0)
{
m_parasite.setIndex(0);
}
public:
int currentBrushIndex() override {
return m_currentIndex;
}
int chooseNextBrush(const KisPaintInformation& info) override {
Q_UNUSED(info)
return 0;
}
void updateBrushIndexes(const KisPaintInformation& info, int seqNo) override {
Q_UNUSED(info)
Q_UNUSED(seqNo)
m_parasite.nextIndex();
m_currentIndex = m_parasite.index();
}
private:
int m_currentIndex;
KisVectorBrushParasite m_parasite;
};
KisVectorAnimatedBrush::KisVectorAnimatedBrush(const QString& filename) KisVectorAnimatedBrush::KisVectorAnimatedBrush(const QString& filename)
: KisScalingSizeBrush(filename) : KisScalingSizeBrush(filename)
{ {
...@@ -88,6 +121,9 @@ bool KisVectorAnimatedBrush::loadFromDevice(QIODevice *dev) ...@@ -88,6 +121,9 @@ bool KisVectorAnimatedBrush::loadFromDevice(QIODevice *dev)
// set Index to 0 // set Index to 0
m_parasite.setIndex(0); m_parasite.setIndex(0);
// clean de brush
m_vectorObjects.clear();
// convert the shapes to KisVectorShapeObjects // convert the shapes to KisVectorShapeObjects
for(int i = 0; i<m_shapes.count(); i++) for(int i = 0; i<m_shapes.count(); i++)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment