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(
"Error: Failed to save BitmapImage");
 
   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);
 
  139            QFile::copy(b->fileName(), tmpPath);
 
  142            QFile::rename(b->fileName(), tmpPath);
 
  144        b->setFileName(tmpPath);
 
  149        QString dest = filePath(b, dataFolder);
 
  152        QFile::rename(b->fileName(), dest);
 
  153        b->setFileName(dest);
 
  161    return dataFolder.
filePath(fileName(key));
 
  171    if (key->isModified()) 
 
  173    if (QFile::exists(savePath) == 
false) 
 
  184    foreachKeyFrame([&](
KeyFrame* pKeyFrame)
 
  196        if (!pKeyFrame->fileName().
isEmpty()) {
 
  204void LayerBitmap::loadDomElement(
const QDomElement& element, 
QString dataDirPath, ProgressCallback progressStep)
 
  206    this->loadBaseDomElement(element);
 
  209    while (!imageTag.
isNull())
 
  212        if (!imageElement.
isNull() && imageElement.
tagName() == 
"image")
 
  214            QString path = validateDataPath(imageElement.
attribute(
"src"), dataDirPath);
 
  221                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