Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • graphics
  • vector
bezierarea.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18
19#include "bezierarea.h"
20#include "pencilerror.h"
21
22#include <QXmlStreamWriter>
23#include <QDomElement>
24
25BezierArea::BezierArea()
26{
27}
28
29BezierArea::BezierArea(QList<VertexRef> vertexList, int color)
30{
31 mVertex = vertexList;
32 mColorNumber = color;
33 mSelected = false;
34}
35
36VertexRef BezierArea::getVertexRef(int i)
37{
38 while (i >= mVertex.size() )
39 {
40 i = i - mVertex.size();
41 }
42 while (i < 0 )
43 {
44 i = i + mVertex.size();
45 }
46 return mVertex[i];
47}
48
49void BezierArea::setSelected(bool YesOrNo)
50{
51 mSelected = YesOrNo;
52}
53
54Status BezierArea::createDomElement( QXmlStreamWriter& xmlStream )
55{
56 xmlStream.writeStartElement( "area" );
57 xmlStream.writeAttribute( "colourNumber", QString::number( mColorNumber ) );
58 xmlStream.writeAttribute("filled", QString::number( mIsFilled ) );
59
60 int errorLocation = -1;
61 for ( int i = 0; i < mVertex.size(); i++ )
62 {
63 xmlStream.writeEmptyElement( "vertex" );
64 xmlStream.writeAttribute( "curve", QString::number( mVertex.at( i ).curveNumber ) );
65 xmlStream.writeAttribute( "vertex", QString::number( mVertex.at( i ).vertexNumber ) );
66
67 if ( errorLocation < 0 && xmlStream.hasError() )
68 {
69 errorLocation = i;
70 }
71 }
72
73 xmlStream.writeEndElement(); // Close area element
74
75 if ( xmlStream.hasError() && errorLocation >= 0 )
76 {
77 DebugDetails debugInfo;
78 debugInfo << "BezierArea::createDomElement";
79 debugInfo << QString("colorNumber = %1").arg(mColorNumber);
80 debugInfo << QString("- mVertex[%1] has failed to write").arg(errorLocation);
81 debugInfo << QString("&nbsp;&nbsp;curve = %1").arg(mVertex.at(errorLocation).curveNumber);
82 debugInfo << QString("&nbsp;&nbsp;vertex = %1 ").arg(mVertex.at(errorLocation).vertexNumber);
83
84 return Status( Status::FAIL, debugInfo );
85 }
86
87 return Status::OK;
88}
89
90void BezierArea::loadDomElement(const QDomElement& element)
91{
92 mColorNumber = element.attribute("colourNumber").toInt();
93
94 QDomNode vertexTag = element.firstChild();
95 while (!vertexTag.isNull())
96 {
97 QDomElement vertexElement = vertexTag.toElement();
98 if (!vertexElement.isNull())
99 {
100 if (vertexElement.tagName() == "vertex")
101 {
102 mVertex.append( VertexRef(vertexElement.attribute("curve").toInt() , vertexElement.attribute("vertex").toInt() ) );
103 }
104 }
105 vertexTag = vertexTag.nextSibling();
106 }
107}
DebugDetails
Definition: pencilerror.h:25
Status
Definition: pencilerror.h:40
VertexRef
Definition: vertexref.h:22
QDomElement
QDomElement::attribute
QString attribute(const QString &name, const QString &defValue) const const
QDomElement::tagName
QString tagName() const const
QDomNode
QDomNode::firstChild
QDomNode firstChild() const const
QDomNode::isNull
bool isNull() const const
QDomNode::nextSibling
QDomNode nextSibling() const const
QDomNode::toElement
QDomElement toElement() const const
QList
QList::append
void append(const T &value)
QList::at
const T & at(int i) const const
QList::size
int size() const const
QString
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString::number
QString number(int n, int base)
QString::toInt
int toInt(bool *ok, int base) const const
QXmlStreamWriter
QXmlStreamWriter::hasError
bool hasError() const const
QXmlStreamWriter::writeAttribute
void writeAttribute(const QString &qualifiedName, const QString &value)
QXmlStreamWriter::writeEmptyElement
void writeEmptyElement(const QString &qualifiedName)
QXmlStreamWriter::writeEndElement
void writeEndElement()
QXmlStreamWriter::writeStartElement
void writeStartElement(const QString &qualifiedName)
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39