17#include "layervector.h"
19#include "vectorimage.h"
25LayerVector::LayerVector(
int id) :
Layer(id,
Layer::VECTOR)
27 setName(tr(
"Vector Layer"));
30LayerVector::~LayerVector()
34bool LayerVector::usesColor(
int colorIndex)
36 bool bUseColor =
false;
37 foreachKeyFrame([&](
KeyFrame* pKeyFrame)
39 auto pVecImage =
static_cast<VectorImage*
>(pKeyFrame);
41 bUseColor = bUseColor || pVecImage->
usesColor(colorIndex);
47void LayerVector::removeColor(
int colorIndex)
49 foreachKeyFrame([=](
KeyFrame* pKeyFrame)
51 auto pVecImage =
static_cast<VectorImage*
>(pKeyFrame);
56void LayerVector::moveColor(
int start,
int end)
58 foreachKeyFrame( [=] (
KeyFrame* pKeyFrame)
60 auto pVecImage =
static_cast<VectorImage*
>(pKeyFrame);
61 pVecImage->moveColor(start, end);
65void LayerVector::loadImageAtFrame(
QString path,
int frameNumber)
67 if (keyExists(frameNumber))
69 removeKeyFrame(frameNumber);
72 vecImg->setPos(frameNumber);
79 QString theFileName = fileName(keyFrame);
84 if (needSaveFrame(keyFrame, strFilePath) ==
false)
92 vecImage->setFileName(
"");
96 dd <<
QString(
"KeyFrame.pos() = %1").
arg(keyFrame->pos());
98 dd <<
"- VectorImage failed to write";
99 dd.collect(st.details());
100 return Status(Status::FAIL, dd);
103 vecImage->setFileName(strFilePath);
104 vecImage->setModified(
false);
108KeyFrame* LayerVector::createKeyFrame(
int position)
120bool LayerVector::needSaveFrame(
KeyFrame* key,
const QString& strSavePath)
122 if (key->isModified())
126 if (strSavePath != key->fileName())
135 foreachKeyFrame([&](
KeyFrame* keyframe)
140 VectorImage* image = getVectorImageAtFrame(keyframe->pos());
150void LayerVector::loadDomElement(
const QDomElement& element,
QString dataDirPath, ProgressCallback progressStep)
152 this->loadBaseDomElement(element);
155 while (!imageTag.
isNull())
158 if (!imageElement.
isNull() && imageElement.
tagName() ==
"image")
164 QString path = validateDataPath(rawPath, dataDirPath);
168 loadImageAtFrame(path, position);
169 getVectorImageAtFrame(position)->setOpacity(imageElement.
attribute(
"opacity",
"1.0").
toDouble());
177 getVectorImageAtFrame(position)->setOpacity(imageElement.
attribute(
"opacity",
"1.0").
toDouble());
188VectorImage* LayerVector::getVectorImageAtFrame(
int frameNumber)
const
190 return static_cast<VectorImage*
>(getKeyFrameAt(frameNumber));
193VectorImage* LayerVector::getLastVectorImageAtFrame(
int frameNumber,
int increment)
const
195 return static_cast<VectorImage*
>(getLastKeyFrameAtPosition(frameNumber + increment));
198void LayerVector::replaceKeyFrame(
const KeyFrame* vectorImage)
200 *getVectorImageAtFrame(vectorImage->pos()) = *
static_cast<const VectorImage*
>(vectorImage);
bool addNewKeyFrameAt(int position)
Creates a new keyframe at the given position, unless one already exists.
virtual bool addKeyFrame(int position, KeyFrame *pKeyFrame)
Adds a keyframe at the given position, unless one already exists.
void loadDomElement(QDomElement element)
VectorImage::loadDomElement.
bool usesColor(int index)
VectorImage::usesColor.
void removeColor(int index)
VectorImage::removeColor.
bool read(QString filePath)
VectorImage::read.
Status write(QString filePath, QString format)
VectorImage::write.
QString filePath(const QString &fileName) const const
QDomElement createElement(const QString &tagName)
QString attribute(const QString &name, const QString &defValue) const const
void setAttribute(const QString &name, const QString &value)
QString tagName() const const
QDomNode appendChild(const QDomNode &newChild)
QDomNode firstChild() const const
bool isNull() const const
QDomNode nextSibling() const const
QDomElement toElement() const const
bool exists() const const
QString fileName() const const
QString & append(QChar ch)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString asprintf(const char *cformat,...)
bool isEmpty() const const
bool isNull() const const
double toDouble(bool *ok) const const
int toInt(bool *ok, int base) const const