18 #include "layermanager.h"
23 #include "layersound.h"
24 #include "layerbitmap.h"
25 #include "layervector.h"
26 #include "layercamera.h"
29 LayerManager::LayerManager( QObject* pParent ) :
BaseManager( pParent )
33 LayerManager::~LayerManager()
37 bool LayerManager::init()
45 connect( o, &Object::layerChanged,
this, &LayerManager::layerUpdated );
47 mCurrentLayerIndex = o->data()->getCurrentLayer();
50 emit layerCountChanged(o->getLayerCount());
57 o->data()->setCurrentLayer( mCurrentLayerIndex );
61 int LayerManager::getLastCameraLayer()
63 return lastCameraLayer;
66 Layer* LayerManager::currentLayer()
68 return currentLayer( 0 );
71 Layer* LayerManager::currentLayer(
int incr )
73 Q_ASSERT( editor()->
object() != NULL );
75 return editor()->object()->getLayer( mCurrentLayerIndex + incr );
78 Layer* LayerManager::getLayer(
int index )
80 Q_ASSERT( editor()->
object() != NULL );
82 return editor()->object()->getLayer( index );
85 int LayerManager::currentLayerIndex()
87 return mCurrentLayerIndex;
90 void LayerManager::setCurrentLayer(
int layerIndex )
92 Object* o = editor()->object();
94 if ( layerIndex >= o->getLayerCount() )
100 if ( mCurrentLayerIndex != layerIndex )
102 mCurrentLayerIndex = layerIndex;
103 Q_EMIT currentLayerChanged( mCurrentLayerIndex );
106 if ( editor()->
object() )
108 if ( editor()->
object()->getLayer( layerIndex )->type() == Layer::CAMERA )
110 lastCameraLayer = layerIndex;
115 void LayerManager::setCurrentLayer(
Layer* layer )
117 Object* o = editor()->object();
119 for (
int i = 0; i < o->getLayerCount(); ++i )
121 if ( layer == o->getLayer( i ) )
123 setCurrentLayer( i );
129 void LayerManager::gotoNextLayer()
131 if ( mCurrentLayerIndex < editor()->
object()->getLayerCount() - 1 )
133 mCurrentLayerIndex += 1;
134 Q_EMIT currentLayerChanged( mCurrentLayerIndex );
138 void LayerManager::gotoPreviouslayer()
140 if ( mCurrentLayerIndex > 0 )
142 mCurrentLayerIndex -= 1;
143 Q_EMIT currentLayerChanged( mCurrentLayerIndex );
147 LayerBitmap* LayerManager::createBitmapLayer(
const QString& strLayerName )
149 LayerBitmap* layer = editor()->object()->addNewBitmapLayer();
150 layer->setName( strLayerName );
152 Q_EMIT layerCountChanged( count() );
157 LayerVector* LayerManager::createVectorLayer(
const QString& strLayerName )
159 LayerVector* layer = editor()->object()->addNewVectorLayer();
160 layer->setName( strLayerName );
162 Q_EMIT layerCountChanged( count() );
167 LayerCamera* LayerManager::createCameraLayer(
const QString& strLayerName )
169 LayerCamera* layer = editor()->object()->addNewCameraLayer();
170 layer->setName( strLayerName );
172 Q_EMIT layerCountChanged( count() );
177 LayerSound* LayerManager::createSoundLayer(
const QString& strLayerName )
179 LayerSound* layer = editor()->object()->addNewSoundLayer();
180 layer->setName( strLayerName );
182 Q_EMIT layerCountChanged( count() );
187 int LayerManager::LastFrameAtFrame(
int frameIndex )
189 Object* pObj = editor()->object();
190 for (
int i = frameIndex; i >= 0; i -= 1 )
192 for (
int layerIndex = 0; layerIndex < pObj->getLayerCount(); ++layerIndex )
194 auto pLayer = pObj->getLayer( layerIndex );
195 if ( pLayer->keyExists( i ) )
204 int LayerManager::firstKeyFrameIndex()
206 int minPosition = INT_MAX;
208 Object* pObj = editor()->object();
209 for (
int i = 0; i < pObj->getLayerCount(); ++i )
211 Layer* pLayer = pObj->getLayer( i );
213 int position = pLayer->firstKeyFramePosition();
214 if ( position < minPosition )
216 minPosition = position;
222 int LayerManager::lastKeyFrameIndex()
226 for (
int i = 0; i < editor()->object()->getLayerCount(); ++i )
228 Layer* pLayer = editor()->object()->getLayer( i );
230 int position = pLayer->getMaxKeyFramePosition();
231 if ( position > maxPosition )
233 maxPosition = position;
239 int LayerManager::count()
241 return editor()->object()->getLayerCount();
244 bool LayerManager::deleteCurrentLayer()
247 if ( currentLayer()->type() == Layer::CAMERA )
252 editor()->object()->deleteLayer( currentLayerIndex() );
254 if ( currentLayerIndex() == editor()->
object()->getLayerCount() )
256 setCurrentLayer( currentLayerIndex() - 1 );
259 Q_EMIT layerCountChanged( count() );
264 int LayerManager::projectLength()
268 Object* pObject = editor()->object();
269 for (
int i = 0; i < pObject->getLayerCount(); i++ )
271 int frame = pObject->getLayer( i )->getMaxKeyFramePosition();
272 if ( frame > maxFrame )
280 void LayerManager::layerUpdated(
int layerId)
282 emit currentLayerChanged(layerId);