17 #include "layerbitmap.h"
23 #include "bitmapimage.h"
30 setName(
tr(
"Bitmap Layer"));
33 LayerBitmap::~LayerBitmap()
37 BitmapImage* LayerBitmap::getBitmapImageAtFrame(
int frameNumber)
39 Q_ASSERT(frameNumber >= 1);
40 return static_cast<BitmapImage*
>(getKeyFrameAt(frameNumber));
43 BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(
int frameNumber,
int increment)
45 Q_ASSERT(frameNumber >= 1);
46 return static_cast<BitmapImage*
>(getLastKeyFrameAtPosition(frameNumber + increment));
49 void LayerBitmap::loadImageAtFrame(
QString path,
QPoint topLeft,
int frameNumber)
52 pKeyFrame->enableAutoCrop(
true);
53 pKeyFrame->setPos(frameNumber);
59 QString strFilePath = filePath(keyframe,
QDir(path));
63 bool needSave = needSaveFrame(keyframe, strFilePath);
69 bitmapImage->setFileName(strFilePath);
71 Status st = bitmapImage->writeFile(strFilePath);
74 bitmapImage->setFileName(
"");
77 dd <<
"LayerBitmap::saveKeyFrame";
78 dd <<
QString(
" KeyFrame.pos() = %1").
arg(keyframe->pos());
79 dd <<
QString(
" strFilePath = %1").
arg(strFilePath);
80 dd <<
QString(
"BitmapImage could not be saved");
81 dd.collect(st.details());
82 return Status(Status::FAIL, dd);
85 bitmapImage->setModified(
false);
93 b->enableAutoCrop(
true);
99 QDir dataFolder(sDataFolder);
101 std::vector<BitmapImage*> movedOnlyBitmaps;
102 foreachKeyFrame([&movedOnlyBitmaps,&dataFolder,
this](
KeyFrame* key)
106 if (!bitmap->fileName().isEmpty()
107 && !bitmap->isModified()
108 && bitmap->fileName() != filePath(bitmap, dataFolder))
110 movedOnlyBitmaps.push_back(bitmap);
119 if (
QFileInfo(b->fileName()).dir() != dataFolder) {
126 b->setFileName(tmpPath);
131 QString dest = filePath(b, dataFolder);
135 b->setFileName(dest);
143 return dataFolder.
filePath(fileName(key));
151 bool LayerBitmap::needSaveFrame(
KeyFrame* key,
const QString& savePath)
153 if (key->isModified())
166 foreachKeyFrame([&](
KeyFrame* pKeyFrame)
177 Q_ASSERT(
QFileInfo(pKeyFrame->fileName()).fileName() == fileName(pKeyFrame));
183 void LayerBitmap::loadDomElement(
const QDomElement& element,
QString dataDirPath, ProgressCallback progressStep)
185 this->loadBaseDomElement(element);
188 while (!imageTag.
isNull())
191 if (!imageElement.
isNull())
193 if (imageElement.
tagName() ==
"image")
197 if (!fi.exists()) path = imageElement.
attribute(
"src");
201 loadImageAtFrame(path,
QPoint(x, y), position);
QString asprintf(const char *cformat,...)
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const const
bool rename(const QString &newName)
QString filePath(const QString &fileName) const const
bool exists() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool copy(const QString &newName)
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 isEmpty() const const
bool isNull() const const
QDomNode firstChild() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString tagName() const const
QDomElement createElement(const QString &tagName)