Commit 11c5b117 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

Timeline: Support undo/redo when adding a new clip

Please note, this is only partially working. A bug in the backend
prevents the use of this functionnality.
parent 44dde9ff
......@@ -59,6 +59,7 @@ Timeline::Timeline( QWidget *parent ) :
setDuration( 0 );
connect( m_tracksView->horizontalScrollBar(), SIGNAL( valueChanged( int ) ), m_tracksRuler, SLOT( moveRuler( int ) ) );
connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
connect( m_mainWorkflow, SIGNAL( clipAdded(Clip*,uint,qint64) ), this, SLOT( actionAddClip(Clip*,uint,qint64) ) );
connect( m_mainWorkflow, SIGNAL( clipMoved(QUuid, uint, qint64 ) ), this, SLOT( actionMoveClip(QUuid,uint,qint64) ) );
connect( m_mainWorkflow, SIGNAL( clipRemoved(QUuid,uint) ), this, SLOT( actionRemoveClip(QUuid,uint)) );
}
......@@ -93,6 +94,11 @@ void Timeline::setDuration( int duration )
m_tracksRuler->setDuration( duration );
}
void Timeline::actionAddClip( Clip* clip, unsigned int track, qint64 start )
{
tracksView()->addMediaItem( clip, track, start );
}
void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time )
{
tracksView()->moveMediaItem( uuid, track, time );
......
......@@ -46,6 +46,7 @@ public:
public slots:
void changeZoom( int factor );
void setDuration( int duration );
void actionAddClip( Clip* clip, unsigned int track, qint64 start );
void actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time );
void actionRemoveClip( const QUuid& uuid, unsigned int track );
......
......@@ -127,6 +127,29 @@ void TracksView::addAudioTrack()
m_cursorLine->setHeight( m_layout->contentsRect().height() );
}
void TracksView::addMediaItem( Clip* clip, unsigned int track, qint64 start )
{
Q_ASSERT( clip );
// Is the clip already existing in the timeline ?
//TODO: please optimize me!
QList<QGraphicsItem*> sceneItems = m_scene->items();
for ( int i = 0; i < sceneItems.size(); ++i )
{
AbstractGraphicsMediaItem* item =
dynamic_cast<AbstractGraphicsMediaItem*>( sceneItems.at( i ) );
if ( !item || item->uuid() != clip->getUuid() ) continue;
// Item already exist: goodbye!
return;
}
GraphicsMovieItem* item = new GraphicsMovieItem( clip );
item->setWidth( clip->getLength() );
item->setHeight( tracksHeight() );
item->setParentItem( getTrack( track ) );
moveMediaItem( item, track, start );
}
void TracksView::dragEnterEvent( QDragEnterEvent* event )
{
if ( event->mimeData()->hasFormat( "vlmc/uuid" ) )
......
......@@ -59,6 +59,7 @@ public:
void removeMediaItem( const QList<AbstractGraphicsMediaItem*>& items, bool notifyBackend = true );
public slots:
void addMediaItem( Clip* clip, unsigned int track, qint64 start );
void moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
void removeMediaItem( const QUuid& uuid, unsigned int track, bool notifyBackend = true );
......
......@@ -82,6 +82,8 @@ void MainWorkflow::addClip( Clip* clip, unsigned int trackId, qint64 start )
m_tracks[trackId]->addClip( clip, start );
if ( m_tracks[trackId]->getLength() > m_length )
m_length = m_tracks[trackId]->getLength();
emit clipAdded( clip, trackId, start );
}
void MainWorkflow::computeLength()
......
......@@ -156,6 +156,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
void mainWorkflowEndReached();
void mainWorkflowPaused();
void mainWorkflowUnpaused();
void clipAdded( Clip*, unsigned int, qint64 );
void clipRemoved( QUuid, unsigned int );
void clipMoved( QUuid, unsigned int, qint64 );
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment