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