17#include "layerbitmap.h"
23#include "bitmapimage.h"
26LayerBitmap::LayerBitmap(
int id) :
Layer(id,
Layer::BITMAP)
28 setName(tr(
"Bitmap Layer"));
31LayerBitmap::~LayerBitmap()
35BitmapImage* LayerBitmap::getBitmapImageAtFrame(
int frameNumber)
37 Q_ASSERT(frameNumber >= 1);
38 return static_cast<BitmapImage*
>(getKeyFrameAt(frameNumber));
41BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(
int frameNumber,
int increment)
43 Q_ASSERT(frameNumber >= 1);
44 return static_cast<BitmapImage*
>(getLastKeyFrameAtPosition(frameNumber + increment));
47void LayerBitmap::replaceKeyFrame(
const KeyFrame* bitmapImage)
49 *getBitmapImageAtFrame(bitmapImage->pos()) = *
static_cast<const BitmapImage*
>(bitmapImage);
52void LayerBitmap::repositionFrame(
QPoint point,
int frame)
56 image->moveTopLeft(point);
59QRect LayerBitmap::getFrameBounds(
int frame)
63 return image->bounds();
66void LayerBitmap::loadImageAtFrame(
QString path,
QPoint topLeft,
int frameNumber, qreal opacity)
69 pKeyFrame->enableAutoCrop(
true);
70 pKeyFrame->setPos(frameNumber);
71 pKeyFrame->setOpacity(opacity);
77 QString strFilePath = filePath(keyframe,
QDir(path));
81 bool needSave = needSaveFrame(keyframe, strFilePath);
87 bitmapImage->setFileName(strFilePath);
89 Status st = bitmapImage->writeFile(strFilePath);
92 bitmapImage->setFileName(
"");
95 dd <<
"LayerBitmap::saveKeyFrame";
96 dd <<
QString(
" KeyFrame.pos() = %1").
arg(keyframe->pos());
97 dd.collect(st.details());
98 return Status(Status::FAIL, dd);
101 bitmapImage->setModified(
false);
105KeyFrame* LayerBitmap::createKeyFrame(
int position)
109 b->enableAutoCrop(
true);
115 QDir dataFolder(sDataFolder);
117 std::vector<BitmapImage*> movedOnlyBitmaps;
118 foreachKeyFrame([&movedOnlyBitmaps,&dataFolder,
this](
KeyFrame* key)
122 if (!bitmap->fileName().isEmpty()
123 && !bitmap->isModified()
124 && bitmap->fileName() != filePath(bitmap, dataFolder))
126 movedOnlyBitmaps.push_back(bitmap);
137 QFile::copy(b->fileName(), tmpPath);
140 QFile::rename(b->fileName(), tmpPath);
142 b->setFileName(tmpPath);
147 QString dest = filePath(b, dataFolder);
150 QFile::rename(b->fileName(), dest);
151 b->setFileName(dest);
159 return dataFolder.
filePath(fileName(key));
169 if (key->isModified())
171 if (QFile::exists(savePath) ==
false)
182 foreachKeyFrame([&](
KeyFrame* pKeyFrame)
194 if (!pKeyFrame->fileName().
isEmpty()) {
202void LayerBitmap::loadDomElement(
const QDomElement& element,
QString dataDirPath, ProgressCallback progressStep)
204 this->loadBaseDomElement(element);
207 while (!imageTag.
isNull())
210 if (!imageElement.
isNull() && imageElement.
tagName() ==
"image")
212 QString path = validateDataPath(imageElement.
attribute(
"src"), dataDirPath);
219 loadImageAtFrame(path,
QPoint(x, y), position, opacity);
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
QString fileName() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString asprintf(const char *cformat,...)
bool isEmpty() const const
double toDouble(bool *ok) const const
int toInt(bool *ok, int base) const const