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 <<
QString(
" strFilePath = %1").
arg(strFilePath);
98 dd <<
QString(
"BitmapImage could not be saved");
99 dd.collect(st.details());
100 return Status(Status::FAIL, dd);
103 bitmapImage->setModified(
false);
107KeyFrame* LayerBitmap::createKeyFrame(
int position)
111 b->enableAutoCrop(
true);
117 QDir dataFolder(sDataFolder);
119 std::vector<BitmapImage*> movedOnlyBitmaps;
120 foreachKeyFrame([&movedOnlyBitmaps,&dataFolder,
this](
KeyFrame* key)
124 if (!bitmap->fileName().isEmpty()
125 && !bitmap->isModified()
126 && bitmap->fileName() != filePath(bitmap, dataFolder))
128 movedOnlyBitmaps.push_back(bitmap);
144 b->setFileName(tmpPath);
149 QString dest = filePath(b, dataFolder);
153 b->setFileName(dest);
161 return dataFolder.
filePath(fileName(key));
171 if (key->isModified())
184 foreachKeyFrame([&](
KeyFrame* pKeyFrame)
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
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