Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

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

Load Vector Animated Brush

parent cd5450a8
......@@ -19,6 +19,7 @@ set(kritalibbrush_LIB_SRCS
kis_pipebrush_parasite.cpp
kis_png_brush.cpp
kis_svg_brush.cpp
kis_vectoranimated_brush.cpp
kis_qimage_pyramid.cpp
KisSharedQImagePyramid.cpp
kis_text_brush.cpp
......
......@@ -44,7 +44,7 @@ class BrushResourceServer : public KisBrushResourceServer
public:
BrushResourceServer()
: KisBrushResourceServer("kis_brushes", "*.gbr:*.gih:*.abr:*.png:*.svg")
: KisBrushResourceServer("kis_brushes", "*.gbr:*.gih:*.abr:*.png:*.svg:*.avb")
{
}
......@@ -115,6 +115,10 @@ private:
else if (fileExtension == "svg") {
brush = new KisSvgBrush(filename);
}
else if (fileExtension == "avb") {
brush = new KisSvgBrush(filename);
}
return brush;
}
};
......
/*
* Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
*
* 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 2 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 "kis_vectoranimated_brush.h"
#include <QDomElement>
#include <QFileInfo>
#include <QPainter>
#include <QImageReader>
#include <QSvgRenderer>
KisVectorAnimatedBrush::KisVectorAnimatedBrush(const QString& filename)
: KisScalingSizeBrush(filename)
{
setBrushType(INVALID);
setSpacing(0.25);
setHasColor(false);
}
KisVectorAnimatedBrush::KisVectorAnimatedBrush(const KisVectorAnimatedBrush& rhs)
: KisScalingSizeBrush(rhs)
, m_svg(rhs.m_svg)
{
}
KisBrush* KisVectorAnimatedBrush::clone() const
{
return new KisVectorAnimatedBrush(*this);
}
bool KisVectorAnimatedBrush::load()
{
QFile f(filename());
if (f.size() == 0) return false;
if (!f.exists()) return false;
if (!f.open(QIODevice::ReadOnly)) {
warnKrita << "Can't open file " << filename();
return false;
}
bool res = loadFromDevice(&f);
f.close();
return res;
}
bool KisVectorAnimatedBrush::loadFromDevice(QIODevice *dev)
{
m_svg = dev->readAll();
QSvgRenderer renderer(m_svg);
QRect box = renderer.viewBox();
if (box.isEmpty()) return false;
QImage image_(1000, (1000 * box.height()) / box.width(), QImage::Format_ARGB32);
{
QPainter p(&image_);
p.fillRect(0, 0, image_.width(), image_.height(), Qt::white);
renderer.render(&p);
}
QVector<QRgb> table;
for (int i = 0; i < 256; ++i) table.push_back(qRgb(i, i, i));
image_ = image_.convertToFormat(QImage::Format_Indexed8, table);
setBrushTipImage(image_);
setValid(true);
// Well for now, always true
if (brushTipImage().isGrayscale()) {
setBrushType(MASK);
setHasColor(false);
}
else {
setBrushType(IMAGE);
setHasColor(true);
}
setWidth(brushTipImage().width());
setHeight(brushTipImage().height());
QFileInfo fi(filename());
setName(fi.baseName());
return !brushTipImage().isNull() && valid();
}
bool KisVectorAnimatedBrush::save()
{
QFile f(filename());
if (!f.open(QFile::WriteOnly)) return false;
bool res = saveToDevice(&f);
f.close();
return res;
}
bool KisVectorAnimatedBrush::saveToDevice(QIODevice *dev) const
{
if((dev->write(m_svg.constData(), m_svg.size()) == m_svg.size())) {
KoResource::saveToDevice(dev);
return true;
}
return false;
}
QString KisVectorAnimatedBrush::defaultFileExtension() const
{
return QString(".avb");
}
void KisVectorAnimatedBrush::toXML(QDomDocument& d, QDomElement& e) const
{
predefinedBrushToXML("svg_brush", e);
KisBrush::toXML(d, e);
}
/*
* Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
*
* 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 2 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 KIS_VECTORANIMATED_BRUSH_
#define KIS_VECTORANIMATED_BRUSH_
#include "kis_scaling_size_brush.h"
class BRUSH_EXPORT KisVectorAnimatedBrush : public KisScalingSizeBrush
{
public:
/// Construct brush to load filename later as brush
KisVectorAnimatedBrush(const QString& filename);
KisVectorAnimatedBrush(const KisVectorAnimatedBrush& rhs);
KisBrush* clone() const override;
bool load() override;
bool loadFromDevice(QIODevice *dev) override;
bool save() override;
bool saveToDevice(QIODevice *dev) const override;
QString defaultFileExtension() const override;
void toXML(QDomDocument& d, QDomElement& e) const override;
private:
QByteArray m_svg;
};
#endif
......@@ -157,6 +157,11 @@ void KisMimeDatabase::fillMimeData()
KisMimeType mimeType;
mimeType.mimeType = "image/svg";
mimeType.description = i18nc("description of a file type", "Animated Vector Brush");
mimeType.suffixes = QStringList() << "avb";
s_mimeDatabase << mimeType;
mimeType.mimeType = "image/x-gimp-brush";
mimeType.description = i18nc("description of a file type", "Gimp Brush");
mimeType.suffixes = QStringList() << "gbr" << "vbr";
......
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