Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • structure
object.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17#ifndef OBJECT_H
18#define OBJECT_H
19
20#include <memory>
21#include <QCoreApplication>
22#include <QObject>
23#include <QList>
24#include <QColor>
25#include "layer.h"
26#include "colorref.h"
27#include "pencilerror.h"
28#include "pencildef.h"
29#include "objectdata.h"
30
31class QProgressDialog;
32class QFile;
33class LayerBitmap;
34class LayerVector;
35class LayerCamera;
36class LayerSound;
37class ObjectData;
38class ActiveFramePool;
39
40
41class Object final
42{
43 Q_DECLARE_TR_FUNCTIONS(Object)
44public:
45 explicit Object();
46 ~Object();
47
48 Object(Object const&) = delete;
49 Object(Object&&) = delete;
50 Object& operator=(Object const&) = delete;
51 Object& operator=(Object&&) = delete;
52
53 void init();
54 void createWorkingDir();
55 void deleteWorkingDir() const;
56 void setWorkingDir(const QString& path); // used by crash recovery
57
58 QString filePath() const { return mFilePath; }
59 void setFilePath(const QString& strFileName) { mFilePath = strFileName; }
60
61 QString workingDir() const { return mWorkingDirPath; }
62
63 QString dataDir() const { return mDataDirPath; }
64 void setDataDir(const QString& dirPath) { mDataDirPath = dirPath; }
65
66 QString mainXMLFile() const { return mMainXMLFile; }
67 void setMainXMLFile(const QString& file) { mMainXMLFile = file; }
68
69 QDomElement saveXML(QDomDocument& doc) const;
70 bool loadXML(const QDomElement& element, ProgressCallback progressForward);
71
72 void paintImage(QPainter& painter, int frameNumber, bool background, bool antialiasing) const;
73
74 QString copyFileToDataFolder(const QString& strFilePath);
75
76 // Color palette
77 ColorRef getColor(int index) const;
78 void setColor(int index, const QColor& newColor);
79 void setColorRef(int index, const ColorRef& newColorRef);
80 void movePaletteColor(int start, int end);
81 void moveVectorColor(int start, int end);
82
83 void addColor(const ColorRef& newColor) { mPalette.append(newColor); }
84 void addColorAtIndex(int index, const ColorRef& newColor);
85 void removeColor(int index);
86 bool isColorInUse(int index) const;
87 void renameColor(int i, const QString& text);
88 int getColorCount() { return mPalette.size(); }
89 bool importPalette(const QString& filePath);
90 void importPaletteGPL(QFile& file);
91 void importPalettePencil(QFile& file);
92 void openPalette(const QString& filePath);
93
94 bool exportPalette(const QString& filePath) const;
95 void exportPaletteGPL(QFile& file) const;
96 void exportPalettePencil(QFile& file) const;
97 QString savePalette(const QString& filePath) const;
98
99 void loadDefaultPalette();
100
101 LayerBitmap* addNewBitmapLayer();
102 LayerVector* addNewVectorLayer();
103 LayerSound* addNewSoundLayer();
104 LayerCamera* addNewCameraLayer();
105
106 int getLayerCount() const;
107 Layer* getLayer(int i) const;
108 Layer* getLayerBelow(int i, Layer::LAYER_TYPE type) const;
109 Layer* findLayerByName(const QString& strName, Layer::LAYER_TYPE type = Layer::UNDEFINED) const;
110 Layer* findLayerById(int layerId) const;
111 Layer* takeLayer(int layerId); // Note: transfer ownership of the layer
112
113 bool swapLayers(int i, int j);
114
122 bool canSwapLayers(int layerIndexLeft, int layerIndexRight) const;
123
130 bool canDeleteLayer(int index) const;
131
132 void deleteLayer(int i);
133 void deleteLayer(Layer*);
134 bool addLayer(Layer* layer);
135
136 template<typename T>
137 std::vector<T*> getLayersByType() const
138 {
139 std::vector<T*> result;
140 for (Layer* layer : mLayers)
141 {
142 T* t = dynamic_cast<T*>(layer);
143 if (t)
144 result.push_back(t);
145 }
146 return result;
147 }
148
149 // these functions need to be moved to somewhere...
150 bool exportFrames(int frameStart, int frameEnd, const LayerCamera* cameraLayer, QSize exportSize, QString filePath, QString format,
151 bool transparency, bool exportKeyframesOnly, const QString& layerName, bool antialiasing, QProgressDialog* progress, int progressMax) const;
152
153 bool exportIm(int frameStart, const QTransform& view, QSize cameraSize, QSize exportSize, const QString& filePath, const QString& format, bool antialiasing, bool transparency) const;
154
155 void modification() { modified = true; }
156 bool isModified() const { return modified; }
157 void setModified(bool b) { modified = b; }
158
159 int getUniqueLayerID();
160
161 ObjectData* data() { return &mData; }
162 const ObjectData* data() const { return &mData; }
163 void setData(const ObjectData&);
164
165 int totalKeyFrameCount() const;
166 void updateActiveFrames(int frame) const;
167 void setActiveFramePoolSize(int sizeInMB);
168
169private:
170 int getMaxLayerID();
171
172 QString mFilePath; //< where this object come from. (empty if new project)
173 QString mWorkingDirPath; //< the folder that pclx will uncompress to.
174 QString mDataDirPath; //< the folder which contains all bitmap & vector image & sound files.
175 QString mMainXMLFile; //< the location of main.xml
176
177 QList<Layer*> mLayers;
178 bool modified = false;
179
180 QList<ColorRef> mPalette;
181
182 ObjectData mData;
183 mutable std::unique_ptr<ActiveFramePool> mActiveFramePool;
184};
185
186
187#endif
ActiveFramePool
ActiveFramePool implemented a LRU cache to keep tracking the most recent accessed key frames A key fr...
Definition: activeframepool.h:34
ColorRef
Definition: colorref.h:26
LayerBitmap
Definition: layerbitmap.h:26
LayerCamera
Definition: layercamera.h:30
Layer
Definition: layer.h:33
LayerSound
Definition: layersound.h:26
LayerVector
Definition: layervector.h:26
ObjectData
Definition: objectdata.h:27
Object
Definition: object.h:42
Object::canDeleteLayer
bool canDeleteLayer(int index) const
Allows you to check whether the layer at the given index can be deleted.
Definition: object.cpp:341
Object::canSwapLayers
bool canSwapLayers(int layerIndexLeft, int layerIndexRight) const
Allows you to check whether two layers can be swappped, before doing the actual operation.
Definition: object.cpp:316
QColor
QDomDocument
QDomElement
QFile
QList
QList::append
void append(const T &value)
QList::size
int size() const const
QPainter
QProgressDialog
QSize
QString
QTransform
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39