Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
object.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #ifndef OBJECT_H
18 #define OBJECT_H
19 
20 #include <memory>
21 #include <QObject>
22 #include <QList>
23 #include <QColor>
24 #include "layer.h"
25 #include "colourref.h"
26 #include "pencilerror.h"
27 #include "pencildef.h"
28 #include "objectdata.h"
29 
30 class QProgressDialog;
31 class LayerBitmap;
32 class LayerVector;
33 class LayerCamera;
34 class LayerSound;
35 class ObjectData;
36 
37 #define ProgressCallback std::function<void(float)>
38 
39 
41 {
42  int startFrame;
43  int endFrame;
44  QTransform view;
45  Layer* currentLayer;
46  QSize exportSize;
47  QString filePath;
48  int fps;
49  int exportFps;
50  QString exportFormat;
51 };
52 
54 {
55  int frameStart;
56  int frameEnd;
57  QTransform view;
58  Layer* currentLayer;
59  QSize exportSize;
60  QString filePath;
61  const char* format;
62  int quality;
63  bool background;
64  bool antialiasing;
65  QProgressDialog* progress;
66  int progressMax;
67  int fps;
68  int exportFps;
69 };
70 
71 class Object : public QObject
72 {
73  Q_OBJECT
74 
75 public:
76  Object( QObject* parent = nullptr );
77  virtual ~Object();
78 
79  void init();
80  void createWorkingDir();
81  void deleteWorkingDir() const;
82 
83  QString filePath() const { return mFilePath; }
84  void setFilePath( QString strFileName ) { mFilePath = strFileName; }
85 
86  QString workingDir() const { return mWorkingDirPath; }
87  //void setWorkingDir( QString dirPath ) { mWorkingDirPath = dirPath; }
88 
89  QString dataDir() const { return mDataDirPath; }
90  void setDataDir( QString dirPath ) { mDataDirPath = dirPath; }
91 
92  QString mainXMLFile() const { return mMainXMLFile; }
93  void setMainXMLFile( QString file ){ mMainXMLFile = file; }
94 
95  QDomElement saveXML( QDomDocument& doc );
96  bool loadXML( QDomElement element, ProgressCallback progress = [] (float){} );
97 
98  void paintImage( QPainter& painter, int frameNumber, bool background, bool antialiasing ) const;
99 
100  QString copyFileToDataFolder( QString strFilePath );
101 
102  // Color palette
103  ColourRef getColour( int i );
104  void setColour( int index, QColor newColour )
105  {
106  Q_ASSERT( index >= 0 );
107  mPalette[ index ].colour = newColour;
108  }
109  void addColour( QColor );
110  void addColour( ColourRef newColour ) { mPalette.append( newColour ); }
111  bool removeColour( int index );
112  void renameColour( int i, QString text );
113  int getColourCount() { return mPalette.size(); }
114  bool importPalette( QString filePath );
115  bool exportPalette( QString filePath );
116  bool savePalette( QString filePath );
117 
118  void loadDefaultPalette();
119 
120  LayerBitmap* addNewBitmapLayer();
121  LayerVector* addNewVectorLayer();
122  LayerSound* addNewSoundLayer();
123  LayerCamera* addNewCameraLayer();
124 
125  int getLayerCount() const ;
126 
127  Layer* getLayer( int i ) const;
128  Layer* findLayerByName( QString strName, Layer::LAYER_TYPE type = Layer::UNDEFINED ) const;
129 
130  bool moveLayer( int i, int j );
131  void deleteLayer( int i );
132  void deleteLayer( Layer* );
133 
134  template< typename T >
135  std::vector< T* > getLayersByType() const
136  {
137  std::vector< T* > result;
138  for ( Layer* layer : mLayers )
139  {
140  T* t = dynamic_cast<T*>( layer );
141  if ( t )
142  {
143  result.push_back( t );
144  }
145  }
146  return result;
147  }
148 
149  // these functions need to be moved to somewhere...
150  bool exportFrames( int frameStart, int frameEnd, Layer* currentLayer, QSize exportSize, QString filePath, const char* format, int quality, bool transparency, bool antialiasing, QProgressDialog* progress, int progressMax );
151  bool exportX( int frameStart, int frameEnd, QTransform view, QSize exportSize, QString filePath, bool antialiasing );
152  bool exportIm(int frameStart, int frameEnd, QTransform view, QSize exportSize, QString filePath, QString format, bool antialiasing , bool transparency);
153 
154  void modification() { modified = true; }
155  bool isModified() { return modified; }
156  void setModified( bool b ) { modified = b; }
157 
158  int getUniqueLayerID();
159 
160  ObjectData* data();
161  void setData( ObjectData* );
162 
163  void setLayerUpdated(int layerId);
164 
165 Q_SIGNALS:
166  void layerChanged( int layerId );
167 
168 private:
169  int getMaxLayerID();
170 
171  QString mFilePath; //< where this object come from. (empty if new project)
172  QString mWorkingDirPath; //< the folder that pclx will uncompress to.
173  QString mDataDirPath; //< the folder which contains all bitmap & vector image & sound files.
174  QString mMainXMLFile; //< the location of main.xml
175 
176  QList< Layer* > mLayers;
177  bool modified = false;
178 
179  QList< ColourRef > mPalette;
180 
181  std::unique_ptr< ObjectData > mEditorState;
182 };
183 
184 
185 #endif
Definition: layer.h:32
Definition: object.h:71