Commit 57f680e8 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Timeline: Code refactoring for x-axis placement

parent bb701f5d
...@@ -64,3 +64,13 @@ AbstractGraphicsMediaItem* AbstractGraphicsMediaItem::groupItem() ...@@ -64,3 +64,13 @@ AbstractGraphicsMediaItem* AbstractGraphicsMediaItem::groupItem()
{ {
return m_group; return m_group;
} }
void AbstractGraphicsMediaItem::setStartPos( qint64 position )
{
QGraphicsItem::setPos( (qreal)position, 0 );
}
qint64 AbstractGraphicsMediaItem::startPos()
{
return qRound64( QGraphicsItem::pos().x() );
}
...@@ -65,6 +65,12 @@ public: ...@@ -65,6 +65,12 @@ public:
/// Return the current track of the item /// Return the current track of the item
quint32 trackNumber(); quint32 trackNumber();
/// Set the position of the item (in frames) for the x-axis.
void setStartPos( qint64 position );
/// Return the position of the item (in frames) for the x-axis.
qint64 startPos();
protected: protected:
/** /**
* Returns the current tracksView for the item, * Returns the current tracksView for the item,
......
...@@ -68,7 +68,7 @@ void TracksScene::keyPressEvent( QKeyEvent* keyEvent ) ...@@ -68,7 +68,7 @@ void TracksScene::keyPressEvent( QKeyEvent* keyEvent )
Commands::MainWorkflow::ClipActionInfo ai; Commands::MainWorkflow::ClipActionInfo ai;
ai.clip = item->clip(); ai.clip = item->clip();
ai.trackNumber = item->trackNumber(); ai.trackNumber = item->trackNumber();
ai.pos = item->pos().x(); ai.pos = item->startPos();
ai.trackType = MainWorkflow::VideoTrack; ai.trackType = MainWorkflow::VideoTrack;
clipsinfos.append( ai ); clipsinfos.append( ai );
} }
......
...@@ -169,7 +169,7 @@ void TracksView::addMediaItem( Clip* clip, unsigned int track, qint64 start ) ...@@ -169,7 +169,7 @@ void TracksView::addMediaItem( Clip* clip, unsigned int track, qint64 start )
GraphicsMovieItem* item = new GraphicsMovieItem( clip ); GraphicsMovieItem* item = new GraphicsMovieItem( clip );
item->setHeight( tracksHeight() ); item->setHeight( tracksHeight() );
item->setParentItem( getTrack( MainWorkflow::VideoTrack, track ) ); item->setParentItem( getTrack( MainWorkflow::VideoTrack, track ) );
item->setPos( start, 0 ); item->setStartPos( start );
item->oldTrackNumber = track; item->oldTrackNumber = track;
item->oldPosition = start; item->oldPosition = start;
connect( item, SIGNAL( split(GraphicsMovieItem*,qint64) ), connect( item, SIGNAL( split(GraphicsMovieItem*,qint64) ),
...@@ -251,7 +251,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track, ...@@ -251,7 +251,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track,
if ( track > m_numVideoTrack - 1) if ( track > m_numVideoTrack - 1)
track = m_numVideoTrack - 1; track = m_numVideoTrack - 1;
QPointF oldPos = item->pos(); qint64 oldPos = item->startPos();
QGraphicsItem* oldParent = item->parentItem(); QGraphicsItem* oldParent = item->parentItem();
// Check for vertical collisions // Check for vertical collisions
item->setParentItem( getTrack( MainWorkflow::VideoTrack, track ) ); item->setParentItem( getTrack( MainWorkflow::VideoTrack, track ) );
...@@ -298,7 +298,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track, ...@@ -298,7 +298,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track,
} }
// Check for horizontal collisions // Check for horizontal collisions
qint64 mappedXPos = qMax( time, (qint64)0 ); qint64 mappedXPos = qMax( time, (qint64)0 );
item->setPos( mappedXPos, 0 ); item->setStartPos( mappedXPos );
AbstractGraphicsMediaItem* hItem = NULL; AbstractGraphicsMediaItem* hItem = NULL;
QList<QGraphicsItem*> collide = item->collidingItems(); QList<QGraphicsItem*> collide = item->collidingItems();
...@@ -318,11 +318,11 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track, ...@@ -318,11 +318,11 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track,
newpos = hItem->pos().x() - item->boundingRect().width(); newpos = hItem->pos().x() - item->boundingRect().width();
if ( newpos < 0 || newpos == hItem->pos().x() ) if ( newpos < 0 || newpos == hItem->pos().x() )
item->setPos( oldPos ); // Fail item->setStartPos( oldPos ); // Fail
else else
{ {
// A solution may be found // A solution may be found
item->setPos( newpos, 0 ); item->setStartPos( qRound64( newpos ) );
QList<QGraphicsItem*> collideAgain = item->collidingItems(); QList<QGraphicsItem*> collideAgain = item->collidingItems();
for ( int i = 0; i < collideAgain.count(); ++i ) for ( int i = 0; i < collideAgain.count(); ++i )
{ {
...@@ -330,7 +330,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track, ...@@ -330,7 +330,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, quint32 track,
dynamic_cast<AbstractGraphicsMediaItem*>( collideAgain.at( i ) ); dynamic_cast<AbstractGraphicsMediaItem*>( collideAgain.at( i ) );
if ( currentItem ) if ( currentItem )
{ {
item->setPos( oldPos ); // Fail item->setStartPos( oldPos ); // Fail
break; break;
} }
} }
...@@ -556,10 +556,10 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event ) ...@@ -556,10 +556,10 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event )
movieItem->oldTrackNumber, movieItem->oldTrackNumber,
movieItem->oldPosition, movieItem->oldPosition,
movieItem->trackNumber(), movieItem->trackNumber(),
(qint64)movieItem->pos().x(), movieItem->startPos(),
MainWorkflow::VideoTrack ) ); MainWorkflow::VideoTrack ) );
movieItem->oldTrackNumber = movieItem->trackNumber(); movieItem->oldTrackNumber = movieItem->trackNumber();
movieItem->oldPosition = movieItem->pos().x(); movieItem->oldPosition = movieItem->startPos();
m_actionRelativeX = -1; m_actionRelativeX = -1;
m_actionItem = NULL; m_actionItem = NULL;
} }
...@@ -655,8 +655,8 @@ void TracksView::updateDuration() ...@@ -655,8 +655,8 @@ void TracksView::updateDuration()
AbstractGraphicsMediaItem* item = AbstractGraphicsMediaItem* item =
dynamic_cast<AbstractGraphicsMediaItem*>( sceneItems.at( i ) ); dynamic_cast<AbstractGraphicsMediaItem*>( sceneItems.at( i ) );
if ( !item ) continue; if ( !item ) continue;
if ( item->pos().x() + item->boundingRect().width() > projectDuration ) if ( ( item->startPos() + item->boundingRect().width() ) > projectDuration )
projectDuration = ( int ) ( item->pos().x() + item->boundingRect().width() ); projectDuration = ( int ) ( item->startPos() + item->boundingRect().width() );
} }
m_projectDuration = projectDuration; m_projectDuration = projectDuration;
...@@ -693,18 +693,18 @@ void TracksView::split( GraphicsMovieItem* item, qint64 frame ) ...@@ -693,18 +693,18 @@ void TracksView::split( GraphicsMovieItem* item, qint64 frame )
// Clip* newclip = item->clip()->split( frame ); // Clip* newclip = item->clip()->split( frame );
// Q_ASSERT( newclip ); // Q_ASSERT( newclip );
// //
// addMediaItem( newclip, item->trackNumber(), item->pos().x() + frame ); // addMediaItem( newclip, item->trackNumber(), item->startPos() + frame );
// Commands::trigger( new Commands::MainWorkflow::AddClip( m_renderer, // Commands::trigger( new Commands::MainWorkflow::AddClip( m_renderer,
// newclip, // newclip,
// item->trackNumber(), // item->trackNumber(),
// item->pos().x() + frame, // item->startPos() + frame,
// MainWorkflow::VideoTrack ) ); // MainWorkflow::VideoTrack ) );
//frame is the number of frame from the beginning of the clip //frame is the number of frame from the beginning of the clip
//item->pos().x() is the position of the splitted clip (in frame) //item->pos().x() is the position of the splitted clip (in frame)
//therefore, the position of the newly created clip is //therefore, the position of the newly created clip is
//the splitted clip pos + the splitting point (ie pos().x() + frame) //the splitted clip pos + the splitting point (ie startPos() + frame)
// m_renderer->split( item->clip(), item->trackNumber(), item->pos().x() + frame, frame, MainWorkflow::VideoTrack ); // m_renderer->split( item->clip(), item->trackNumber(), item->startPos() + frame, frame, MainWorkflow::VideoTrack );
Commands::trigger( new Commands::MainWorkflow::SplitClip( m_renderer, item->clip(), item->trackNumber(), Commands::trigger( new Commands::MainWorkflow::SplitClip( m_renderer, item->clip(), item->trackNumber(),
item->pos().x() + frame, frame, MainWorkflow::VideoTrack ) ); item->startPos() + frame, frame, MainWorkflow::VideoTrack ) );
} }
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