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::repositionFrame(
QPoint point,
int frame)
51 image->moveTopLeft(point);
54QRect LayerBitmap::getFrameBounds(
int frame)
58 return image->bounds();
61void LayerBitmap::loadImageAtFrame(
QString path,
QPoint topLeft,
int frameNumber, qreal opacity)
64 pKeyFrame->enableAutoCrop(
true);
65 pKeyFrame->setPos(frameNumber);
66 pKeyFrame->setOpacity(opacity);
72 QString strFilePath = filePath(keyframe,
QDir(path));
76 bool needSave = needSaveFrame(keyframe, strFilePath);
82 bitmapImage->setFileName(strFilePath);
84 Status st = bitmapImage->writeFile(strFilePath);
87 bitmapImage->setFileName(
"");
90 dd <<
"LayerBitmap::saveKeyFrame";
91 dd <<
QString(
" KeyFrame.pos() = %1").
arg(keyframe->pos());
92 dd <<
QString(
" strFilePath = %1").
arg(strFilePath);
93 dd <<
QString(
"BitmapImage could not be saved");
94 dd.collect(st.details());
95 return Status(Status::FAIL, dd);
98 bitmapImage->setModified(
false);
102KeyFrame* LayerBitmap::createKeyFrame(
int position)
106 b->enableAutoCrop(
true);
112 QDir dataFolder(sDataFolder);
114 std::vector<BitmapImage*> movedOnlyBitmaps;
115 foreachKeyFrame([&movedOnlyBitmaps,&dataFolder,
this](
KeyFrame* key)
119 if (!bitmap->fileName().isEmpty()
120 && !bitmap->isModified()
121 && bitmap->fileName() != filePath(bitmap, dataFolder))
123 movedOnlyBitmaps.push_back(bitmap);
139 b->setFileName(tmpPath);
144 QString dest = filePath(b, dataFolder);
148 b->setFileName(dest);
156 return dataFolder.
filePath(fileName(key));
166 if (key->isModified())
179 foreachKeyFrame([&](
KeyFrame* pKeyFrame)
197void LayerBitmap::loadDomElement(
const QDomElement& element,
QString dataDirPath, ProgressCallback progressStep)
199 this->loadBaseDomElement(element);
202 while (!imageTag.
isNull())
205 if (!imageElement.
isNull())
207 if (imageElement.
tagName() ==
"image")
211 if (!fi.exists()) path = imageElement.
attribute(
"src");
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
bool hasAttribute(const QString &name) 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 copy(const QString &newName)
bool exists() const const
bool rename(const QString &newName)
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