diff --git a/app/src/importlayersdialog.cpp b/app/src/importlayersdialog.cpp index f303072f0..35ae3f71b 100644 --- a/app/src/importlayersdialog.cpp +++ b/app/src/importlayersdialog.cpp @@ -27,6 +27,7 @@ GNU General Public License for more details. #include "soundmanager.h" #include "layer.h" #include "layersound.h" +#include "layervector.h" #include "soundclip.h" @@ -83,29 +84,43 @@ void ImportLayersDialog::importLayers() int currentFrame = mEditor->currentFrame(); Q_ASSERT(ui->lwLayers->count() == mImportObject->getLayerCount()); - for (int i = 0; i < ui->lwLayers->count(); i++ ) + QMap importedColors; + + for (const QListWidgetItem* item : ui->lwLayers->selectedItems()) { - QListWidgetItem* item = ui->lwLayers->item(i); - if (item->isSelected()) - { - int layerId = item->data(Qt::UserRole).toInt(); + mImportLayer = mImportObject->takeLayer(item->data(Qt::UserRole).toInt()); + mImportLayer->setName(mEditor->layers()->nameSuggestLayer(item->text())); + loadKeyFrames(mImportLayer); // all keyframes of this layer must be in memory - mImportLayer = mImportObject->takeLayer(layerId); - mImportLayer->setName(mEditor->layers()->nameSuggestLayer(item->text())); - loadKeyFrames(mImportLayer); // all keyframes of this layer must be in memory + object->addLayer(mImportLayer); - object->addLayer(mImportLayer); + if (mImportLayer->type() == Layer::VECTOR) + { + LayerVector* layerVector = static_cast(mImportLayer); + for (int i = 0; i < mImportObject->getColorCount(); i++) { + if (!layerVector->usesColor(i)) { + continue; + } + + if (!importedColors.contains(i)) { + const ColorRef color = mImportObject->getColor(i); + object->addColor(color); + importedColors[i] = object->getColorCount() - 1; + } + + layerVector->moveColor(i, importedColors[i]); + } + } - if (mImportLayer->type() == Layer::SOUND) + if (mImportLayer->type() == Layer::SOUND) + { + LayerSound* layerSound = static_cast(mImportLayer); + layerSound->foreachKeyFrame([this](KeyFrame* key) { - LayerSound* layerSound = static_cast(mImportLayer); - layerSound->foreachKeyFrame([this](KeyFrame* key) - { - SoundClip* clip = dynamic_cast(key); - Status st = mEditor->sound()->loadSound(clip, clip->fileName()); - Q_ASSERT(st.ok()); - }); - } + SoundClip* clip = dynamic_cast(key); + Status st = mEditor->sound()->loadSound(clip, clip->fileName()); + Q_ASSERT(st.ok()); + }); } } mEditor->object()->modification(); diff --git a/core_lib/src/canvaspainter.cpp b/core_lib/src/canvaspainter.cpp index f03ae616f..24529ec38 100644 --- a/core_lib/src/canvaspainter.cpp +++ b/core_lib/src/canvaspainter.cpp @@ -251,7 +251,7 @@ void CanvasPainter::paintVectorOnionSkinFrame(QPainter& painter, const QRect& bl QPainter onionSkinPainter; initializePainter(onionSkinPainter, mOnionSkinPixmap, blitRect); - vectorImage->paintImage(onionSkinPainter, mOptions.bOutlines, mOptions.bThinLines, mOptions.bAntiAlias); + vectorImage->paintImage(onionSkinPainter, *mObject, mOptions.bOutlines, mOptions.bThinLines, mOptions.bAntiAlias); paintOnionSkinFrame(painter, onionSkinPainter, nFrame, colorize, vectorImage->getOpacity()); } @@ -344,7 +344,7 @@ void CanvasPainter::paintCurrentVectorFrame(QPainter& painter, const QRect& blit const bool isDrawing = mTiledBuffer->isValid(); // Paint existing vector image to the painter - vectorImage->paintImage(currentVectorPainter, mOptions.bOutlines, mOptions.bThinLines, mOptions.bAntiAlias); + vectorImage->paintImage(currentVectorPainter, *mObject, mOptions.bOutlines, mOptions.bThinLines, mOptions.bAntiAlias); if (isCurrentLayer) { if (isDrawing) { diff --git a/core_lib/src/graphics/vector/beziercurve.cpp b/core_lib/src/graphics/vector/beziercurve.cpp index 97c2a79d6..ebfe27eea 100644 --- a/core_lib/src/graphics/vector/beziercurve.cpp +++ b/core_lib/src/graphics/vector/beziercurve.cpp @@ -34,7 +34,7 @@ BezierCurve::BezierCurve() BezierCurve::BezierCurve(const QList& pointList, bool smooth) { QList pressureList; - for (int i = 0; i < pointList.size(); i++) + for (int i = 0; i < pointList.size(); i++) { pressureList << 0.5; // default pressure } @@ -297,13 +297,13 @@ BezierCurve BezierCurve::transformed(QTransform transformation) const if (isSelected(-1)) { newOrigin = transformation.map(newOrigin); } transformedCurve.setOrigin( newOrigin ); for(int i=0; i< vertex.size(); i++) { - QPointF newC1 = c1.at(i); - QPointF newC2 = c2.at(i); - QPointF newVertex = vertex.at(i); - if (isSelected(i-1)) { newC1 = transformation.map(newC1); } - if (isSelected(i)) { newC2 = transformation.map(newC2); newVertex = transformation.map(newVertex); } - transformedCurve.appendCubic( newC1, newC2, newVertex, pressure.at(i) ); - if (isSelected(i)) { transformedCurve.setSelected(i, true); } + QPointF newC1 = c1.at(i); + QPointF newC2 = c2.at(i); + QPointF newVertex = vertex.at(i); + if (isSelected(i-1)) { newC1 = transformation.map(newC1); } + if (isSelected(i)) { newC2 = transformation.map(newC2); newVertex = transformation.map(newVertex); } + transformedCurve.appendCubic( newC1, newC2, newVertex, pressure.at(i) ); + if (isSelected(i)) { transformedCurve.setSelected(i, true); } } transformedCurve.setWidth( width); transformedCurve.setVariableWidth( variableWidth ); @@ -429,9 +429,9 @@ void BezierCurve::removeVertex(int i) } } -void BezierCurve::drawPath(QPainter& painter, Object* object, QTransform transformation, bool simplified, bool showThinLines ) +void BezierCurve::drawPath(QPainter& painter, const Object& object, QTransform transformation, bool simplified, bool showThinLines ) { - QColor color = object->getColor(colorNumber).color; + QColor color = object.getColor(colorNumber).color; BezierCurve myCurve; if (isPartlySelected()) { myCurve = (transformed(transformation)); } @@ -869,7 +869,7 @@ bool BezierCurve::findIntersection(BezierCurve curve1, int i1, BezierCurve curve //if (L2.intersect(L1, intersection) == QLineF::BoundedIntersection) { //qDebug() << " FOUND rectangle intersection "; //if (intersectionPoint != curve1.getVertex(i1-1) && intersectionPoint != curve1.getVertex(i1)) { - // qDebug() << " it's not one of the points "; + // qDebug() << " it's not one of the points "; // find the cubic intersection int nSteps = 24; P1 = curve1.getVertex(i1-1); diff --git a/core_lib/src/graphics/vector/beziercurve.h b/core_lib/src/graphics/vector/beziercurve.h index 0f1b67f30..47297f57f 100644 --- a/core_lib/src/graphics/vector/beziercurve.h +++ b/core_lib/src/graphics/vector/beziercurve.h @@ -89,7 +89,7 @@ class BezierCurve QPainterPath getStrokedPath(qreal width, bool pressure); QRectF getBoundingRect(); - void drawPath(QPainter& painter, Object* object, QTransform transformation, bool simplified, bool showThinLines ); + void drawPath(QPainter& painter, const Object& object, QTransform transformation, bool simplified, bool showThinLines ); void createCurve(const QList& pointList, const QList& pressureList , bool smooth); void smoothCurve(); diff --git a/core_lib/src/graphics/vector/vectorimage.cpp b/core_lib/src/graphics/vector/vectorimage.cpp index 9dfe0980c..061b36c2b 100644 --- a/core_lib/src/graphics/vector/vectorimage.cpp +++ b/core_lib/src/graphics/vector/vectorimage.cpp @@ -33,7 +33,6 @@ VectorImage::VectorImage() VectorImage::VectorImage(const VectorImage& v2) : KeyFrame(v2) { deselectAll(); - mObject = v2.mObject; mCurves = v2.mCurves; mArea = v2.mArea; mOpacity = v2.mOpacity; @@ -52,7 +51,6 @@ VectorImage& VectorImage::operator=(const VectorImage& a) { deselectAll(); KeyFrame::operator=(a); - mObject = a.mObject; mCurves = a.mCurves; mArea = a.mArea; mOpacity = a.mOpacity; @@ -1090,16 +1088,6 @@ void VectorImage::paste(VectorImage& vectorImage) modification(); } -/** - * @brief VectorImage::getColor - * @param colorNumber: the color number which is referred to in the palette - * @return QColor - */ -QColor VectorImage::getColor(int colorNumber) -{ - return mObject->getColor(colorNumber).color; -} - /** * @brief VectorImage::getColorNumber * @param point: The QPoint of the BezierArea @@ -1194,11 +1182,13 @@ void VectorImage::moveColor(int start, int end) /** * @brief VectorImage::paintImage * @param painter: QPainter& + * @param object: const Object& * @param simplified: bool * @param showThinCurves: bool * @param antialiasing: bool */ void VectorImage::paintImage(QPainter& painter, + const Object& object, bool simplified, bool showThinCurves, bool antialiasing) @@ -1220,7 +1210,7 @@ void VectorImage::paintImage(QPainter& painter, updateArea(mArea[i]); // to do: if selected // --- fill areas ---- // - QColor color = getColor(mArea[i].mColorNumber); + QColor color = object.getColor(mArea[i].mColorNumber).color; painter.save(); painter.setWorldMatrixEnabled(false); @@ -1246,7 +1236,7 @@ void VectorImage::paintImage(QPainter& painter, // ---- draw curves ---- for (BezierCurve curve : mCurves) { - curve.drawPath(painter, mObject, mSelectionTransformation, simplified, showThinCurves); + curve.drawPath(painter, object, mSelectionTransformation, simplified, showThinCurves); painter.setClipping(false); } painter.restore(); diff --git a/core_lib/src/graphics/vector/vectorimage.h b/core_lib/src/graphics/vector/vectorimage.h index ec97458a5..8f9769deb 100644 --- a/core_lib/src/graphics/vector/vectorimage.h +++ b/core_lib/src/graphics/vector/vectorimage.h @@ -38,8 +38,6 @@ class VectorImage : public KeyFrame VectorImage* clone() const override; - void setObject(Object* pObj) { mObject = pObj; } - bool read(QString filePath); Status write(QString filePath, QString format); @@ -85,7 +83,6 @@ class VectorImage : public KeyFrame void paste(VectorImage&); - QColor getColor(int i); int getColorNumber(QPointF point); bool usesColor(int index); void removeColor(int index); @@ -93,7 +90,7 @@ class VectorImage : public KeyFrame bool isCurveVisible(int curve); void moveColor(int start, int end); - void paintImage(QPainter& painter, bool simplified, bool showThinCurves, bool antialiasing); + void paintImage(QPainter& painter, const Object& object, bool simplified, bool showThinCurves, bool antialiasing); void clear(); void clean(); @@ -165,7 +162,6 @@ class VectorImage : public KeyFrame private: QList mCurves; - Object* mObject = nullptr; QRectF mSelectionRect; QTransform mSelectionTransformation; QSize mSize; diff --git a/core_lib/src/managers/soundmanager.cpp b/core_lib/src/managers/soundmanager.cpp index 655d51307..8bcc3843c 100644 --- a/core_lib/src/managers/soundmanager.cpp +++ b/core_lib/src/managers/soundmanager.cpp @@ -68,57 +68,6 @@ Status SoundManager::save(Object*) return Status::OK; } -Status SoundManager::loadSound(Layer* soundLayer, int frameNumber, QString soundFilePath) -{ - Q_ASSERT(soundLayer); - if (soundLayer->type() != Layer::SOUND) - { - return Status::ERROR_INVALID_LAYER_TYPE; - } - - if (frameNumber < 0) - { - return Status::ERROR_INVALID_FRAME_NUMBER; - } - - if (!QFile::exists(soundFilePath)) - { - return Status::FILE_NOT_FOUND; - } - - KeyFrame* key = soundLayer->getKeyFrameAt(frameNumber); - if (key == nullptr) - { - key = new SoundClip; - soundLayer->addKeyFrame(frameNumber, key); - } - - if (!key->fileName().isEmpty()) - { - // file path should be empty. - // we can only load a audio clip to an empty key! - return Status::FAIL; - } - - QString strCopyFile = soundLayer->object()->copyFileToDataFolder(soundFilePath); - Q_ASSERT(!strCopyFile.isEmpty()); - - QString sOriginalName = QFileInfo(soundFilePath).fileName(); - - SoundClip* soundClip = dynamic_cast(key); - soundClip->init(strCopyFile); - soundClip->setSoundClipName(sOriginalName); - - Status st = createMediaPlayer(soundClip); - if (!st.ok()) - { - delete soundClip; - return st; - } - - return Status::OK; -} - Status SoundManager::loadSound(SoundClip* soundClip, QString strSoundFile) { Q_ASSERT(soundClip); diff --git a/core_lib/src/managers/soundmanager.h b/core_lib/src/managers/soundmanager.h index 31abc12d5..4085ad3b5 100644 --- a/core_lib/src/managers/soundmanager.h +++ b/core_lib/src/managers/soundmanager.h @@ -38,7 +38,6 @@ class SoundManager : public BaseManager Status load(Object*) override; Status save(Object*) override; - Status loadSound(Layer* soundLayer, int frameNumber, QString strSoundFile); Status loadSound(SoundClip* soundClip, QString strSoundFile); Status processSound(SoundClip* soundClip); diff --git a/core_lib/src/structure/layer.cpp b/core_lib/src/structure/layer.cpp index 1e5f43553..f272e5912 100644 --- a/core_lib/src/structure/layer.cpp +++ b/core_lib/src/structure/layer.cpp @@ -22,7 +22,6 @@ GNU General Public License for more details. #include #include #include "keyframe.h" -#include "object.h" // Used to sort the selected frames list bool sortAsc(int left, int right) @@ -30,15 +29,14 @@ bool sortAsc(int left, int right) return left < right; } -Layer::Layer(Object* object, LAYER_TYPE eType) +Layer::Layer(int id, LAYER_TYPE eType) { Q_ASSERT(eType != UNDEFINED); - mObject = object; meType = eType; mName = QString(tr("Undefined Layer")); - mId = object->getUniqueLayerID(); + mId = id; } Layer::~Layer() @@ -51,13 +49,6 @@ Layer::~Layer() mKeyFrames.clear(); } -void Layer::setObject(Object* obj) -{ - Q_ASSERT(obj); - mObject = obj; - mId = mObject->getUniqueLayerID(); -} - void Layer::foreachKeyFrame(std::function action) const { for (auto pair : mKeyFrames) @@ -180,7 +171,7 @@ bool Layer::addNewKeyFrameAt(int position) { if (position <= 0) return false; - KeyFrame* key = createKeyFrame(position, mObject); + KeyFrame* key = createKeyFrame(position); return addKeyFrame(position, key); } diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index bbb857cf8..0e82e2b1d 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -28,11 +28,10 @@ class QMouseEvent; class QPainter; class KeyFrame; -class Object; class TimeLineCells; class Status; -#define ProgressCallback std::function +typedef std::function ProgressCallback; class Layer : public QObject { @@ -49,15 +48,13 @@ class Layer : public QObject CAMERA = 5, }; - explicit Layer(Object*, LAYER_TYPE); + explicit Layer(int id, LAYER_TYPE eType); ~Layer() override; int id() const { return mId; } + void setId(int layerId) { mId = layerId; } LAYER_TYPE type() const { return meType; } - Object* object() const { return mObject; } - void setObject(Object* obj); - void setName(QString name) { mName = name; } QString name() const { return mName; } @@ -168,15 +165,13 @@ class Layer : public QObject void clearDirtyFrames() { mDirtyFrames.clear(); } protected: - void setId(int LayerId) { mId = LayerId; } - virtual KeyFrame* createKeyFrame(int position, Object*) = 0; + virtual KeyFrame* createKeyFrame(int position) = 0; bool loadKey(KeyFrame*); private: void removeFromSelectionList(int position); LAYER_TYPE meType = UNDEFINED; - Object* mObject = nullptr; int mId = 0; bool mVisible = true; QString mName; diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 119464046..d5eb0cc62 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -23,7 +23,7 @@ GNU General Public License for more details. #include "bitmapimage.h" -LayerBitmap::LayerBitmap(Object* object) : Layer(object, Layer::BITMAP) +LayerBitmap::LayerBitmap(int id) : Layer(id, Layer::BITMAP) { setName(tr("Bitmap Layer")); } @@ -99,7 +99,7 @@ Status LayerBitmap::saveKeyFrameFile(KeyFrame* keyframe, QString path) return Status::OK; } -KeyFrame* LayerBitmap::createKeyFrame(int position, Object*) +KeyFrame* LayerBitmap::createKeyFrame(int position) { BitmapImage* b = new BitmapImage; b->setPos(position); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 4865dd64a..8ae10fe1a 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -27,7 +27,7 @@ class LayerBitmap : public Layer Q_OBJECT public: - LayerBitmap(Object* object); + explicit LayerBitmap(int id); ~LayerBitmap() override; QDomElement createDomElement(QDomDocument& doc) const override; @@ -42,7 +42,7 @@ class LayerBitmap : public Layer protected: Status saveKeyFrameFile(KeyFrame*, QString strPath) override; - KeyFrame* createKeyFrame(int position, Object*) override; + KeyFrame* createKeyFrame(int position) override; private: void loadImageAtFrame(QString strFilePath, QPoint topLeft, int frameNumber, qreal opacity); diff --git a/core_lib/src/structure/layercamera.cpp b/core_lib/src/structure/layercamera.cpp index c41507f5b..b072954e0 100644 --- a/core_lib/src/structure/layercamera.cpp +++ b/core_lib/src/structure/layercamera.cpp @@ -22,7 +22,7 @@ GNU General Public License for more details. #include "camera.h" #include "pencildef.h" -LayerCamera::LayerCamera(Object* object) : Layer(object, Layer::CAMERA) +LayerCamera::LayerCamera(int id) : Layer(id, Layer::CAMERA) { setName(tr("Camera Layer")); @@ -539,7 +539,7 @@ Status LayerCamera::saveKeyFrameFile(KeyFrame*, QString) return Status::OK; } -KeyFrame* LayerCamera::createKeyFrame(int position, Object*) +KeyFrame* LayerCamera::createKeyFrame(int position) { Camera* c = new Camera; c->setPos(position); diff --git a/core_lib/src/structure/layercamera.h b/core_lib/src/structure/layercamera.h index 0ef4cc151..54773ecb6 100644 --- a/core_lib/src/structure/layercamera.h +++ b/core_lib/src/structure/layercamera.h @@ -29,7 +29,7 @@ class Camera; class LayerCamera : public Layer { public: - explicit LayerCamera(Object* object); + explicit LayerCamera(int id); ~LayerCamera() override; void loadImageAtFrame(int frame, qreal dx, qreal dy, qreal rotate, qreal scale, CameraEasingType easing, const QPointF& pathPoint, bool pathMoved); @@ -70,7 +70,7 @@ class LayerCamera : public Layer protected: Status saveKeyFrameFile(KeyFrame*, QString path) override; - KeyFrame* createKeyFrame(int position, Object*) override; + KeyFrame* createKeyFrame(int position) override; private: void linearInterpolateTransform(Camera*); diff --git a/core_lib/src/structure/layersound.cpp b/core_lib/src/structure/layersound.cpp index 83b46bc50..c3c88751d 100644 --- a/core_lib/src/structure/layersound.cpp +++ b/core_lib/src/structure/layersound.cpp @@ -20,11 +20,10 @@ GNU General Public License for more details. #include #include #include -#include "object.h" #include "soundclip.h" -LayerSound::LayerSound(Object* object) : Layer(object, Layer::SOUND) +LayerSound::LayerSound(int id) : Layer(id, Layer::SOUND) { setName(tr("Sound Layer")); } @@ -155,7 +154,7 @@ Status LayerSound::saveKeyFrameFile(KeyFrame* key, QString path) return Status::OK; } -KeyFrame* LayerSound::createKeyFrame(int position, Object*) +KeyFrame* LayerSound::createKeyFrame(int position) { SoundClip* s = new SoundClip; s->setPos(position); diff --git a/core_lib/src/structure/layersound.h b/core_lib/src/structure/layersound.h index 718c6fc38..ddcf8c6fa 100644 --- a/core_lib/src/structure/layersound.h +++ b/core_lib/src/structure/layersound.h @@ -27,7 +27,7 @@ class LayerSound : public Layer Q_OBJECT public: - LayerSound( Object* object ); + explicit LayerSound(int id); ~LayerSound(); QDomElement createDomElement(QDomDocument& doc) const override; void loadDomElement(const QDomElement& element, QString dataDirPath, ProgressCallback progressStep) override; @@ -39,7 +39,7 @@ class LayerSound : public Layer protected: Status saveKeyFrameFile(KeyFrame*, QString path) override; - KeyFrame* createKeyFrame(int position, Object*) override; + KeyFrame* createKeyFrame(int position) override; }; #endif diff --git a/core_lib/src/structure/layervector.cpp b/core_lib/src/structure/layervector.cpp index 57ea14443..3efd51e9f 100644 --- a/core_lib/src/structure/layervector.cpp +++ b/core_lib/src/structure/layervector.cpp @@ -22,7 +22,7 @@ GNU General Public License for more details. #include -LayerVector::LayerVector(Object* object) : Layer(object, Layer::VECTOR) +LayerVector::LayerVector(int id) : Layer(id, Layer::VECTOR) { setName(tr("Vector Layer")); } @@ -70,7 +70,6 @@ void LayerVector::loadImageAtFrame(QString path, int frameNumber) } VectorImage* vecImg = new VectorImage; vecImg->setPos(frameNumber); - vecImg->setObject(object()); vecImg->read(path); addKeyFrame(frameNumber, vecImg); } @@ -106,11 +105,10 @@ Status LayerVector::saveKeyFrameFile(KeyFrame* keyFrame, QString path) return Status::OK; } -KeyFrame* LayerVector::createKeyFrame(int position, Object* obj) +KeyFrame* LayerVector::createKeyFrame(int position) { VectorImage* v = new VectorImage; v->setPos(position); - v->setObject(obj); return v; } diff --git a/core_lib/src/structure/layervector.h b/core_lib/src/structure/layervector.h index 563a1800b..163cdc0a4 100644 --- a/core_lib/src/structure/layervector.h +++ b/core_lib/src/structure/layervector.h @@ -27,7 +27,7 @@ class LayerVector : public Layer Q_OBJECT public: - LayerVector(Object* object); + explicit LayerVector(int id); ~LayerVector(); // method from layerImage @@ -45,7 +45,7 @@ class LayerVector : public Layer protected: Status saveKeyFrameFile(KeyFrame*, QString path) override; - KeyFrame* createKeyFrame(int position, Object*) override; + KeyFrame* createKeyFrame(int position) override; private: QString fileName(KeyFrame* key) const; diff --git a/core_lib/src/structure/object.cpp b/core_lib/src/structure/object.cpp index 30391fed5..17834e6f7 100644 --- a/core_lib/src/structure/object.cpp +++ b/core_lib/src/structure/object.cpp @@ -97,16 +97,16 @@ bool Object::loadXML(const QDomElement& docElem, ProgressCallback progressForwar switch (element.attribute("type").toInt()) { case Layer::BITMAP: - newLayer = new LayerBitmap(this); + newLayer = new LayerBitmap(getUniqueLayerID()); break; case Layer::VECTOR: - newLayer = new LayerVector(this); + newLayer = new LayerVector(getUniqueLayerID()); break; case Layer::SOUND: - newLayer = new LayerSound(this); + newLayer = new LayerSound(getUniqueLayerID()); break; case Layer::CAMERA: - newLayer = new LayerCamera(this); + newLayer = new LayerCamera(getUniqueLayerID()); break; default: Q_UNREACHABLE(); @@ -119,7 +119,7 @@ bool Object::loadXML(const QDomElement& docElem, ProgressCallback progressForwar LayerBitmap* Object::addNewBitmapLayer() { - LayerBitmap* layerBitmap = new LayerBitmap(this); + LayerBitmap* layerBitmap = new LayerBitmap(getUniqueLayerID()); mLayers.append(layerBitmap); layerBitmap->addNewKeyFrameAt(1); @@ -129,7 +129,7 @@ LayerBitmap* Object::addNewBitmapLayer() LayerVector* Object::addNewVectorLayer() { - LayerVector* layerVector = new LayerVector(this); + LayerVector* layerVector = new LayerVector(getUniqueLayerID()); mLayers.append(layerVector); layerVector->addNewKeyFrameAt(1); @@ -139,7 +139,7 @@ LayerVector* Object::addNewVectorLayer() LayerSound* Object::addNewSoundLayer() { - LayerSound* layerSound = new LayerSound(this); + LayerSound* layerSound = new LayerSound(getUniqueLayerID()); mLayers.append(layerSound); // No default keyFrame at position 1 for Sound layer. @@ -149,7 +149,7 @@ LayerSound* Object::addNewSoundLayer() LayerCamera* Object::addNewCameraLayer() { - LayerCamera* layerCamera = new LayerCamera(this); + LayerCamera* layerCamera = new LayerCamera(getUniqueLayerID()); mLayers.append(layerCamera); layerCamera->addNewKeyFrameAt(1); @@ -378,7 +378,7 @@ bool Object::addLayer(Layer* layer) { return false; } - layer->setObject(this); + layer->setId(getUniqueLayerID()); mLayers.append(layer); return true; } @@ -456,7 +456,7 @@ void Object::removeColor(int index) mPalette.removeAt(index); - // update the vector pictures using that color ! + // update the vector pictures using that color! } void Object::renameColor(int i, const QString& text) @@ -507,8 +507,8 @@ void Object::exportPalettePencil(QFile& file) const tag.setAttribute("alpha", ref.color.alpha()); root.appendChild(tag); } - int IndentSize = 2; - doc.save(out, IndentSize); + int indentSize = 2; + doc.save(out, indentSize); } bool Object::exportPalette(const QString& filePath) const @@ -542,7 +542,7 @@ void Object::importPaletteGPL(QFile& file) QTextStream in(&file); QString line; - // First line must start with "GIMP Palette" + // The first line must start with "GIMP Palette" // Displaying an error here would be nice in.readLineInto(&line); if (!line.startsWith("GIMP Palette")) return; @@ -553,16 +553,16 @@ void Object::importPaletteGPL(QFile& file) if (line.startsWith("Name: ")) { in.readLineInto(&line); - // The new format contains an optional thrid line starting with "Columns: " + // The new format contains an optional third line starting with "Columns: " if (line.startsWith("Columns: ")) { - // Skip to next line + // Skip to the next line in.readLineInto(&line); } } // Colors inherit the value from the previous color for missing channels - // Some palettes may rely on this behavior so we should try to replicate it + // Some palettes may rely on this behavior, so we should try to replicate it QColor prevColor(Qt::black); do @@ -606,7 +606,7 @@ void Object::importPaletteGPL(QFile& file) if (countInLine < 2) green = prevColor.green(); if (countInLine < 3) blue = prevColor.blue(); - // GIMP assigns colors the name "Untitled" by default now + // GIMP assigns colors the name "Untitled" by default now, // so in addition to missing names, we also use automatic // naming for this if (name.isEmpty() || name == "Untitled") name = QString(); @@ -755,7 +755,7 @@ void Object::paintImage(QPainter& painter,int frameNumber, if (vec) { painter.setOpacity(vec->getOpacity()); - vec->paintImage(painter, false, false, antialiasing); + vec->paintImage(painter, *this, false, false, antialiasing); } } } @@ -815,7 +815,7 @@ bool Object::exportFrames(int frameStart, int frameEnd, { format = "JPG"; extension = ".jpg"; - transparency = false; // JPG doesn't support transparency so we have to include the background + transparency = false; // JPG doesn't support transparency, so we have to include the background } if (formatStr == "TIFF" || formatStr == "tiff" || formatStr == "TIF" || formatStr == "tif") { diff --git a/core_lib/src/structure/object.h b/core_lib/src/structure/object.h index 6ed45a318..c7701d06b 100644 --- a/core_lib/src/structure/object.h +++ b/core_lib/src/structure/object.h @@ -45,10 +45,10 @@ class Object final explicit Object(); ~Object(); - Object(Object const&) = delete; - Object(Object&&) = delete; - Object& operator=(Object const&) = delete; - Object& operator=(Object&&) = delete; + Object(Object const&) = delete; + Object(Object&&) = delete; + Object& operator=(Object const&) = delete; + Object& operator=(Object&&) = delete; void init(); void createWorkingDir(); diff --git a/tests/src/test_layer.cpp b/tests/src/test_layer.cpp index 39eb0be60..73478d105 100644 --- a/tests/src/test_layer.cpp +++ b/tests/src/test_layer.cpp @@ -26,43 +26,37 @@ GNU General Public License for more details. TEST_CASE("LayerType") { - Object* object = new Object; - SECTION("Bitmap Layer") { - Layer* bitmapLayer = new LayerBitmap(object); + Layer* bitmapLayer = new LayerBitmap(1); REQUIRE(bitmapLayer->type() == Layer::BITMAP); delete bitmapLayer; } SECTION("Vector Layer") { - Layer* vecLayer = new LayerVector(object); + Layer* vecLayer = new LayerVector(2); REQUIRE(vecLayer->type() == Layer::VECTOR); delete vecLayer; } SECTION("Camera Layer") { - Layer* cameraLayer = new LayerCamera(object); + Layer* cameraLayer = new LayerCamera(3); REQUIRE(cameraLayer->type() == Layer::CAMERA); delete cameraLayer; } SECTION("Sound Layer") { - Layer* soundLayer = new LayerSound(object); + Layer* soundLayer = new LayerSound(4); REQUIRE(soundLayer->type() == Layer::SOUND); delete soundLayer; } - - delete object; } SCENARIO("Add key frames into a Layer", "[Layer]") { - Object* object = new Object; - GIVEN("A Bitmap Layer") { - Layer* layer = new LayerBitmap(object); + Layer* layer = new LayerBitmap(1); REQUIRE(layer->addNewKeyFrameAt(0) == false); // first key position is 1. REQUIRE(layer->keyFrameCount() == 0); @@ -96,7 +90,7 @@ SCENARIO("Add key frames into a Layer", "[Layer]") GIVEN("A Vector Layer") { - Layer* layer = new LayerVector(object); + Layer* layer = new LayerVector(2); REQUIRE(layer->addNewKeyFrameAt(0) == false); // first key position is 1. REQUIRE(layer->keyFrameCount() == 0); @@ -117,7 +111,7 @@ SCENARIO("Add key frames into a Layer", "[Layer]") GIVEN("A Camera Layer") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(3); REQUIRE(layer->addNewKeyFrameAt(0) == false); // first key position is 1. REQUIRE(layer->keyFrameCount() == 0); @@ -135,7 +129,6 @@ SCENARIO("Add key frames into a Layer", "[Layer]") } delete layer; } - delete object; } TEST_CASE("Test Layer::keyExists()", "[Layer]") diff --git a/tests/src/test_layercamera.cpp b/tests/src/test_layercamera.cpp index c37afdc26..f6899d73f 100644 --- a/tests/src/test_layercamera.cpp +++ b/tests/src/test_layercamera.cpp @@ -26,11 +26,9 @@ GNU General Public License for more details. SCENARIO("Create camera keyframe with linear easing") { - Object* object = new Object; - GIVEN("A Camera Layer with one keyframe") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(1); LayerCamera* camLayer = static_cast(layer); WHEN("Adding a keyframe") @@ -46,17 +44,13 @@ SCENARIO("Create camera keyframe with linear easing") } } } - - delete object; } SCENARIO("Add a second keyframe and see that the path point of the first keyframe is updated") { - Object* object = new Object; - GIVEN("A Camera layer with multiple keyframes") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(1); LayerCamera* camLayer = static_cast(layer); layer->addNewKeyFrameAt(1); @@ -75,17 +69,13 @@ SCENARIO("Add a second keyframe and see that the path point of the first keyfram } } } - - delete object; } SCENARIO("Add keyframe after having interpolated the previous keyframe and see that the translation is kept") { - Object* object = new Object; - GIVEN("A Camera layer with multiple keyframes") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(1); LayerCamera* camLayer = static_cast(layer); layer->addNewKeyFrameAt(1); @@ -102,17 +92,13 @@ SCENARIO("Add keyframe after having interpolated the previous keyframe and see t } } } - - delete object; } SCENARIO("Remove a camera keyframe and see that the path is properly reset") { - Object* object = new Object; - GIVEN("A Camera layer with multiple keyframes") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(1); LayerCamera* camLayer = static_cast(layer); layer->addNewKeyFrameAt(1); @@ -132,17 +118,13 @@ SCENARIO("Remove a camera keyframe and see that the path is properly reset") } } } - - delete object; } SCENARIO("When deleting an in between keyframe, the previous keyframe will try to recover its initial control point, if possible") { - Object* object = new Object; - GIVEN("A Camera layer with multiple keyframes where the keys are added sequentially") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(1); LayerCamera* camLayer = static_cast(layer); layer->addNewKeyFrameAt(1); @@ -169,7 +151,7 @@ SCENARIO("When deleting an in between keyframe, the previous keyframe will try t GIVEN("A Camera layer with multiple keyframes where the third frame is added in-between") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(2); LayerCamera* camLayer = static_cast(layer); layer->addNewKeyFrameAt(1); @@ -196,17 +178,13 @@ SCENARIO("When deleting an in between keyframe, the previous keyframe will try t } } } - - delete object; } SCENARIO("When adding a keyframe in-between two othes where the control points has been modified, the curve will be preserved") { - Object* object = new Object; - GIVEN("A Camera layer with multiple keyframes where the third frame is added in-between") { - Layer* layer = new LayerCamera(object); + Layer* layer = new LayerCamera(1); LayerCamera* camLayer = static_cast(layer); layer->addNewKeyFrameAt(1); @@ -233,8 +211,6 @@ SCENARIO("When adding a keyframe in-between two othes where the control points h } } } - - delete object; } SCENARIO("Loading a project and see that all camera properties are set, if applicable")