17 #include "layervector.h"
19 #include "vectorimage.h"
27 setName(
tr(
"Vector Layer"));
30 LayerVector::~LayerVector()
34 bool 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);
47 void LayerVector::removeColor(
int colorIndex)
49 foreachKeyFrame([=](
KeyFrame* pKeyFrame)
51 auto pVecImage =
static_cast<VectorImage*
>(pKeyFrame);
56 void LayerVector::moveColor(
int start,
int end)
58 foreachKeyFrame( [=] (
KeyFrame* pKeyFrame)
60 auto pVecImage =
static_cast<VectorImage*
>(pKeyFrame);
61 pVecImage->moveColor(start, end);
65 void LayerVector::loadImageAtFrame(
QString path,
int frameNumber)
67 if (keyExists(frameNumber))
69 removeKeyFrame(frameNumber);
72 vecImg->setPos(frameNumber);
73 vecImg->setObject(
object());
75 addKeyFrame(frameNumber, vecImg);
80 QString theFileName = fileName(keyFrame);
85 if (needSaveFrame(keyFrame, strFilePath) ==
false)
93 vecImage->setFileName(
"");
97 dd <<
QString(
"KeyFrame.pos() = %1").
arg(keyFrame->pos());
99 dd <<
"- VectorImage failed to write";
100 dd.collect(st.details());
101 return Status(Status::FAIL, dd);
104 vecImage->setFileName(strFilePath);
105 vecImage->setModified(
false);
122 bool LayerVector::needSaveFrame(
KeyFrame* key,
const QString& strSavePath)
124 if (key->isModified())
128 if (strSavePath != key->fileName())
137 foreachKeyFrame([&](
KeyFrame* keyframe)
144 Q_ASSERT(
QFileInfo(keyframe->fileName()).fileName() == fileName(keyframe));
150 void LayerVector::loadDomElement(
const QDomElement& element,
QString dataDirPath, ProgressCallback progressStep)
152 this->loadBaseDomElement(element);
155 while (!imageTag.
isNull())
158 if (!imageElement.
isNull())
160 if (imageElement.
tagName() ==
"image")
166 if (!fi.exists()) path = imageElement.
attribute(
"src");
168 loadImageAtFrame(path, position);
173 addNewKeyFrameAt(frame);
183 VectorImage* LayerVector::getVectorImageAtFrame(
int frameNumber)
const
185 return static_cast<VectorImage*
>(getKeyFrameAt(frameNumber));
188 VectorImage* LayerVector::getLastVectorImageAtFrame(
int frameNumber,
int increment)
const
190 return static_cast<VectorImage*
>(getLastKeyFrameAtPosition(frameNumber + increment));
QString & append(QChar ch)
QString asprintf(const char *cformat,...)
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const const
bool read(QString filePath)
VectorImage::read.
void loadDomElement(QDomElement element)
VectorImage::loadDomElement.
QString filePath(const QString &fileName) const const
bool exists() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isNull() const const
QDomNode nextSibling() const const
QDomElement toElement() const const
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const const
bool usesColor(int index)
VectorImage::usesColor.
bool isNull() const const
Status write(QString filePath, QString format)
VectorImage::write.
QDomNode firstChild() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void removeColor(int index)
VectorImage::removeColor.
QString tagName() const const
QDomElement createElement(const QString &tagName)