Commit 3ab2d164 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

TracksView: Factorization.

parent fbee7bf1
...@@ -101,14 +101,14 @@ TracksView::createLayout() ...@@ -101,14 +101,14 @@ TracksView::createLayout()
// - 1 video track // - 1 video track
// - a separator // - a separator
// - 1 audio track // - 1 audio track
addVideoTrack(); addTrack( Workflow::VideoTrack );
m_separator = new QGraphicsWidget(); m_separator = new QGraphicsWidget();
m_separator->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); m_separator->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
m_separator->setPreferredHeight( 20 ); m_separator->setPreferredHeight( 20 );
m_layout->insertItem( 1, m_separator ); m_layout->insertItem( 1, m_separator );
addAudioTrack(); addTrack( Workflow::AudioTrack );
m_scene->addItem( container ); m_scene->addItem( container );
...@@ -116,15 +116,15 @@ TracksView::createLayout() ...@@ -116,15 +116,15 @@ TracksView::createLayout()
} }
void void
TracksView::addVideoTrack() TracksView::addTrack( Workflow::TrackType type )
{ {
GraphicsTrack *track = new GraphicsTrack( Workflow::VideoTrack, m_numVideoTrack ); GraphicsTrack *track = new GraphicsTrack( type,
type == Workflow::VideoTrack ? m_numVideoTrack : m_numAudioTrack );
track->setHeight( m_tracksHeight ); track->setHeight( m_tracksHeight );
m_layout->insertItem( 0, track ); m_layout->insertItem( type == Workflow::VideoTrack ? 0 : 1000, track );
m_layout->activate(); m_layout->activate();
m_cursorLine->setHeight( m_layout->contentsRect().height() ); m_cursorLine->setHeight( m_layout->contentsRect().height() );
m_scene->invalidate(); // Redraw the background m_scene->invalidate(); // Redraw the background
m_numVideoTrack++;
connect( track->trackWorkflow(), SIGNAL( clipAdded( TrackWorkflow*, ClipHelper*, qint64 ) ), connect( track->trackWorkflow(), SIGNAL( clipAdded( TrackWorkflow*, ClipHelper*, qint64 ) ),
this, SLOT( addMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) ); this, SLOT( addMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) );
connect( track->trackWorkflow(), SIGNAL( clipRemoved( TrackWorkflow*, ClipHelper* ) ), connect( track->trackWorkflow(), SIGNAL( clipRemoved( TrackWorkflow*, ClipHelper* ) ),
...@@ -132,27 +132,17 @@ TracksView::addVideoTrack() ...@@ -132,27 +132,17 @@ TracksView::addVideoTrack()
connect( track->trackWorkflow(), SIGNAL( clipMoved( TrackWorkflow*, ClipHelper*, qint64 ) ), connect( track->trackWorkflow(), SIGNAL( clipMoved( TrackWorkflow*, ClipHelper*, qint64 ) ),
this, SLOT( moveMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) ); this, SLOT( moveMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) );
if ( type == Workflow::VideoTrack )
{
m_numVideoTrack++;
emit videoTrackAdded( track ); emit videoTrackAdded( track );
}
} else
{
void
TracksView::addAudioTrack()
{
GraphicsTrack *track = new GraphicsTrack( Workflow::AudioTrack, m_numAudioTrack );
track->setHeight( m_tracksHeight );
m_layout->insertItem( 1000, track );
m_layout->activate();
m_cursorLine->setHeight( m_layout->contentsRect().height() );
m_scene->invalidate(); // Redraw the background
m_numAudioTrack++; m_numAudioTrack++;
connect( track->trackWorkflow(), SIGNAL( clipAdded( TrackWorkflow*, ClipHelper*, qint64 ) ),
this, SLOT( addMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) );
connect( track->trackWorkflow(), SIGNAL( clipRemoved( TrackWorkflow*, ClipHelper* ) ),
this, SLOT( removeMediaItem( TrackWorkflow*, ClipHelper* ) ) );
connect( track->trackWorkflow(), SIGNAL( clipMoved( TrackWorkflow*, ClipHelper*, qint64 ) ),
this, SLOT( moveMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) );
emit audioTrackAdded( track ); emit audioTrackAdded( track );
}
} }
void void
...@@ -198,8 +188,8 @@ TracksView::clear() ...@@ -198,8 +188,8 @@ TracksView::clear()
m_numAudioTrack = 0; m_numAudioTrack = 0;
m_numVideoTrack = 0; m_numVideoTrack = 0;
addVideoTrack(); addTrack( Workflow::VideoTrack );
addAudioTrack(); addTrack( Workflow::AudioTrack );
updateDuration(); updateDuration();
} }
...@@ -255,7 +245,7 @@ TracksView::addMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 start ) ...@@ -255,7 +245,7 @@ TracksView::addMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 start )
{ {
int nbTrackToAdd = ( track + 2 ) - m_numVideoTrack; int nbTrackToAdd = ( track + 2 ) - m_numVideoTrack;
for ( int i = 0; i < nbTrackToAdd; ++i ) for ( int i = 0; i < nbTrackToAdd; ++i )
addVideoTrack(); addTrack( Workflow::VideoTrack );
} }
} }
else if ( trackType == Workflow::AudioTrack ) else if ( trackType == Workflow::AudioTrack )
...@@ -264,7 +254,7 @@ TracksView::addMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 start ) ...@@ -264,7 +254,7 @@ TracksView::addMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 start )
{ {
int nbTrackToAdd = ( track + 2 ) - m_numAudioTrack; int nbTrackToAdd = ( track + 2 ) - m_numAudioTrack;
for ( int i = 0; i < nbTrackToAdd; ++i ) for ( int i = 0; i < nbTrackToAdd; ++i )
addAudioTrack(); addTrack( Workflow::AudioTrack );
} }
} }
...@@ -403,12 +393,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, quint32 track, qint6 ...@@ -403,12 +393,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, quint32 track, qint6
if ( item->mediaType() == Workflow::AudioTrack ) if ( item->mediaType() == Workflow::AudioTrack )
{ {
while ( track >= m_numAudioTrack ) while ( track >= m_numAudioTrack )
addAudioTrack(); addTrack( Workflow::AudioTrack );
} }
else if ( item->mediaType() == Workflow::VideoTrack ) else if ( item->mediaType() == Workflow::VideoTrack )
{ {
while ( track >= m_numVideoTrack ) while ( track >= m_numVideoTrack )
addVideoTrack(); addTrack( Workflow::VideoTrack );
} }
ItemPosition p = findPosition( item, track, time ); ItemPosition p = findPosition( item, track, time );
...@@ -421,12 +411,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, quint32 track, qint6 ...@@ -421,12 +411,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, quint32 track, qint6
if ( item->groupItem()->mediaType() == Workflow::AudioTrack ) if ( item->groupItem()->mediaType() == Workflow::AudioTrack )
{ {
while ( p.track() >= m_numAudioTrack ) while ( p.track() >= m_numAudioTrack )
addAudioTrack(); addTrack( Workflow::AudioTrack );
} }
else if ( item->groupItem()->mediaType() == Workflow::VideoTrack ) else if ( item->groupItem()->mediaType() == Workflow::VideoTrack )
{ {
while ( p.track() >= m_numVideoTrack ) while ( p.track() >= m_numVideoTrack )
addVideoTrack(); addTrack( Workflow::VideoTrack );
} }
// Search a position for the linked item // Search a position for the linked item
...@@ -436,12 +426,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, quint32 track, qint6 ...@@ -436,12 +426,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, quint32 track, qint6
if ( item->mediaType() == Workflow::AudioTrack ) if ( item->mediaType() == Workflow::AudioTrack )
{ {
while ( p2.track() >= m_numAudioTrack ) while ( p2.track() >= m_numAudioTrack )
addAudioTrack(); addTrack( Workflow::AudioTrack );
} }
else if ( item->mediaType() == Workflow::VideoTrack ) else if ( item->mediaType() == Workflow::VideoTrack )
{ {
while ( p2.track() >= m_numVideoTrack ) while ( p2.track() >= m_numVideoTrack )
addVideoTrack(); addTrack( Workflow::VideoTrack );
} }
if ( p.time() == p2.time() && p.track() == p2.track() ) if ( p.time() == p2.time() && p.track() == p2.track() )
...@@ -680,7 +670,7 @@ TracksView::dropEvent( QDropEvent *event ) ...@@ -680,7 +670,7 @@ TracksView::dropEvent( QDropEvent *event )
{ {
updateDuration(); updateDuration();
if ( getTrack( Workflow::AudioTrack, m_numAudioTrack - 1 )->childItems().count() > 0 ) if ( getTrack( Workflow::AudioTrack, m_numAudioTrack - 1 )->childItems().count() > 0 )
addAudioTrack(); addTrack( Workflow::AudioTrack );
event->acceptProposedAction(); event->acceptProposedAction();
m_dragAudioItem->m_oldTrack = m_dragAudioItem->track()->trackWorkflow(); m_dragAudioItem->m_oldTrack = m_dragAudioItem->track()->trackWorkflow();
...@@ -696,7 +686,7 @@ TracksView::dropEvent( QDropEvent *event ) ...@@ -696,7 +686,7 @@ TracksView::dropEvent( QDropEvent *event )
{ {
updateDuration(); updateDuration();
if ( getTrack( Workflow::VideoTrack, m_numVideoTrack - 1 )->childItems().count() > 0 ) if ( getTrack( Workflow::VideoTrack, m_numVideoTrack - 1 )->childItems().count() > 0 )
addVideoTrack(); addTrack( Workflow::VideoTrack );
event->acceptProposedAction(); event->acceptProposedAction();
m_dragVideoItem->m_oldTrack = m_dragVideoItem->track()->trackWorkflow(); m_dragVideoItem->m_oldTrack = m_dragVideoItem->track()->trackWorkflow();
...@@ -932,9 +922,9 @@ TracksView::mouseReleaseEvent( QMouseEvent *event ) ...@@ -932,9 +922,9 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
updateDuration(); updateDuration();
if ( getTrack( Workflow::VideoTrack, m_numVideoTrack - 1 )->childItems().count() > 0 ) if ( getTrack( Workflow::VideoTrack, m_numVideoTrack - 1 )->childItems().count() > 0 )
addVideoTrack(); addTrack( Workflow::VideoTrack );
if ( getTrack( Workflow::AudioTrack, m_numAudioTrack - 1 )->childItems().count() > 0 ) if ( getTrack( Workflow::AudioTrack, m_numAudioTrack - 1 )->childItems().count() > 0 )
addAudioTrack(); addTrack( Workflow::VideoTrack );
UndoStack::getInstance()->beginMacro( "Move clip" ); UndoStack::getInstance()->beginMacro( "Move clip" );
......
...@@ -271,11 +271,7 @@ private: ...@@ -271,11 +271,7 @@ private:
/** /**
* \brief Insert an empty video track. * \brief Insert an empty video track.
*/ */
void addVideoTrack(); void addTrack( Workflow::TrackType type );
/**
* \brief Insert an empty audio track.
*/
void addAudioTrack();
/** /**
* \brief DOCUMENT ME * \brief DOCUMENT ME
*/ */
......
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