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

ClipHelpers are now used everywhere

parent db219732
......@@ -77,6 +77,7 @@ SET (VLMC_HDRS
Tools/VlmcDebug.h
Workflow/AudioClipWorkflow.h
Workflow/ClipWorkflow.h
Workflow/ClipHelper.h
Workflow/ImageClipWorkflow.h
Workflow/MainWorkflow.h
Workflow/TrackHandler.h
......
......@@ -42,15 +42,15 @@ void Commands::trigger( Commands::Generic* command )
Commands::MainWorkflow::AddClip::AddClip( Clip* clip,
Commands::MainWorkflow::AddClip::AddClip( ClipHelper* ch,
unsigned int trackNumber, qint64 pos,
::MainWorkflow::TrackType trackType,
bool undoRedoAction /*= false*/ ) :
m_clip( clip ),
m_trackNumber( trackNumber ),
m_pos( pos ),
m_trackType( trackType ),
m_undoRedoAction( undoRedoAction )
m_undoRedoAction( undoRedoAction ),
m_clipHelper( ch )
{
setText( QObject::tr( "Adding clip to track %1" ).arg( QString::number( trackNumber ) ) );
}
......@@ -61,7 +61,7 @@ Commands::MainWorkflow::AddClip::~AddClip()
void Commands::MainWorkflow::AddClip::redo()
{
m_clipHelper = ::MainWorkflow::getInstance()->addClip( m_clip, m_trackNumber, m_pos, m_trackType, m_undoRedoAction );
::MainWorkflow::getInstance()->addClip( m_clipHelper, m_trackNumber, m_pos, m_trackType, m_undoRedoAction );
m_undoRedoAction = false;
}
......@@ -70,12 +70,6 @@ void Commands::MainWorkflow::AddClip::undo()
::MainWorkflow::getInstance()->removeClip( m_clipHelper->uuid(), m_trackNumber, m_trackType );
}
ClipHelper*
Commands::MainWorkflow::AddClip::clipHelper()
{
return m_clipHelper;
}
Commands::MainWorkflow::MoveClip::MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
unsigned int oldTrack, unsigned int newTrack, qint64 newPos,
::MainWorkflow::TrackType trackType ) :
......@@ -105,31 +99,29 @@ void Commands::MainWorkflow::MoveClip::undo()
m_undoRedoAction = true;
}
Commands::MainWorkflow::RemoveClip::RemoveClip( Clip* clip, const QUuid& uuid, quint32 trackNumber,
Commands::MainWorkflow::RemoveClip::RemoveClip( ClipHelper* ch, quint32 trackNumber,
qint64 pos, ::MainWorkflow::TrackType trackType ) :
m_clip( clip ), m_trackNumber( trackNumber ),
m_pos( pos ), m_trackType( trackType ),
m_uuid( uuid )
m_clipHelper( ch ), m_trackNumber( trackNumber ),
m_pos( pos ), m_trackType( trackType )
{
setText( QObject::tr( "Remove clip" ) );
}
void Commands::MainWorkflow::RemoveClip::redo()
{
::MainWorkflow::getInstance()->removeClip( m_uuid, m_trackNumber, m_trackType );
::MainWorkflow::getInstance()->removeClip( m_clipHelper->uuid(), m_trackNumber, m_trackType );
}
void Commands::MainWorkflow::RemoveClip::undo()
{
m_uuid = (::MainWorkflow::getInstance()->addClip( m_clip, m_trackNumber, m_pos, m_trackType, true ))->uuid();
::MainWorkflow::getInstance()->addClip( m_clipHelper, m_trackNumber, m_pos, m_trackType, true );
}
Commands::MainWorkflow::ResizeClip::ResizeClip( const QUuid& uuid,
Commands::MainWorkflow::ResizeClip::ResizeClip( ClipHelper* clipHelper,
qint64 newBegin, qint64 newEnd,
qint64 oldBegin, qint64 oldEnd,
qint64 newPos, qint64 oldPos,
quint32 trackId,
::MainWorkflow::TrackType trackType ) :
m_uuid( uuid ),
m_newBegin( newBegin ),
m_newEnd( newEnd ),
m_oldBegin( oldBegin ),
......@@ -137,16 +129,16 @@ Commands::MainWorkflow::ResizeClip::ResizeClip( const QUuid& uuid,
m_newPos( newPos ),
m_oldPos( oldPos ),
m_trackId( trackId ),
m_clipHelper( clipHelper ),
m_trackType( trackType ),
m_undoRedoAction( false )
{
m_clip = ::MainWorkflow::getInstance()->getClip( uuid, trackId, m_trackType );
setText( QObject::tr( "Resizing clip" ) );
}
void Commands::MainWorkflow::ResizeClip::redo()
{
::MainWorkflow::getInstance()->resizeClip( m_clip, m_newBegin, m_newEnd, m_newPos, m_trackId, m_trackType, m_undoRedoAction );
::MainWorkflow::getInstance()->resizeClip( m_clipHelper, m_newBegin, m_newEnd, m_newPos, m_trackId, m_trackType, m_undoRedoAction );
m_undoRedoAction = true;
}
......@@ -157,16 +149,16 @@ void Commands::MainWorkflow::ResizeClip::undo()
//In the other cases, we need to move, then resize.
if ( m_oldBegin == m_newBegin )
{
::MainWorkflow::getInstance()->resizeClip( m_clip, m_oldBegin, m_oldEnd, m_oldPos, m_trackId, m_trackType, m_undoRedoAction );
::MainWorkflow::getInstance()->resizeClip( m_clipHelper, m_oldBegin, m_oldEnd, m_oldPos, m_trackId, m_trackType, m_undoRedoAction );
}
else
{
m_clip->setBoundaries( m_oldBegin, m_oldEnd );
::MainWorkflow::getInstance()->moveClip( m_clip->uuid(), m_trackId, m_trackId, m_oldPos, m_trackType, m_undoRedoAction );
m_clipHelper->setBoundaries( m_oldBegin, m_oldEnd );
::MainWorkflow::getInstance()->moveClip( m_clipHelper->uuid(), m_trackId, m_trackId, m_oldPos, m_trackType, m_undoRedoAction );
}
}
Commands::MainWorkflow::SplitClip::SplitClip( Clip* toSplit, quint32 trackId,
Commands::MainWorkflow::SplitClip::SplitClip( ClipHelper* toSplit, quint32 trackId,
qint64 newClipPos, qint64 newClipBegin, ::MainWorkflow::TrackType trackType ) :
m_toSplit( toSplit ),
m_newClip( NULL ),
......
......@@ -62,14 +62,12 @@ namespace Commands
NEW_COMMAND( AddClip )
{
public:
AddClip( Clip* clip, unsigned int trackNumber, qint64 pos,
AddClip( ClipHelper* ch, unsigned int trackNumber, qint64 pos,
::MainWorkflow::TrackType trackType, bool undoRedoAction = false );
virtual ~AddClip();
virtual void redo();
virtual void undo();
ClipHelper *clipHelper();
private:
Clip* m_clip;
unsigned int m_trackNumber;
qint64 m_pos;
::MainWorkflow::TrackType m_trackType;
......@@ -100,17 +98,16 @@ namespace Commands
NEW_COMMAND( RemoveClip )
{
public:
RemoveClip( Clip* clip, const QUuid& uuid, unsigned int trackNumber,
RemoveClip( ClipHelper* clip, unsigned int trackNumber,
qint64 pos, ::MainWorkflow::TrackType trackType );
virtual void redo();
virtual void undo();
private:
Clip* m_clip;
ClipHelper* m_clipHelper;
unsigned int m_trackNumber;
qint64 m_pos;
::MainWorkflow::TrackType m_trackType;
QUuid m_uuid;
};
/**
......@@ -127,14 +124,13 @@ namespace Commands
NEW_COMMAND( ResizeClip )
{
public:
ResizeClip( const QUuid& uuid,
ResizeClip( ClipHelper* clipHelper,
qint64 newBegin, qint64 newEnd, qint64 oldBegin,
qint64 oldEnd, qint64 newPos, qint64 oldPos,
quint32 trackId, ::MainWorkflow::TrackType trackType );
virtual void redo();
virtual void undo();
private:
QUuid m_uuid;
qint64 m_newBegin;
qint64 m_newEnd;
qint64 m_oldBegin;
......@@ -142,7 +138,7 @@ namespace Commands
qint64 m_newPos;
qint64 m_oldPos;
quint32 m_trackId;
Clip* m_clip;
ClipHelper* m_clipHelper;
::MainWorkflow::TrackType m_trackType;
bool m_undoRedoAction;
};
......@@ -150,14 +146,14 @@ namespace Commands
NEW_COMMAND( SplitClip )
{
public:
SplitClip( Clip* toSplit, quint32 trackId,
qint64 newClipPos, qint64 newClipBegin, ::MainWorkflow::TrackType trackType );
SplitClip( ClipHelper* toSplit, quint32 trackId, qint64 newClipPos,
qint64 newClipBegin, ::MainWorkflow::TrackType trackType );
~SplitClip();
virtual void redo();
virtual void undo();
private:
Clip* m_toSplit;
Clip* m_newClip;
ClipHelper* m_toSplit;
ClipHelper* m_newClip;
quint32 m_trackId;
qint64 m_newClipPos;
qint64 m_newClipBegin;
......
......@@ -33,10 +33,15 @@
#include "Media.h"
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
oldTrackNumber( -1 ), oldPosition( -1 ), m_clip( clip ), m_tracksView( NULL ),
oldTrackNumber( -1 ), oldPosition( -1 ), m_tracksView( NULL ),
m_group( NULL ), m_width( 0 ), m_height( 0 ), m_resizeExpected( false ),
m_muted( false )
{
m_clipHelper = new ClipHelper( clip );
// Adjust the width
setWidth( clip->length() );
// Automatically adjust future changes
connect( m_clipHelper, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
connect( clip, SIGNAL( unloaded( Clip* ) ),
this, SLOT( clipDestroyed( Clip* ) ), Qt::DirectConnection );
}
......@@ -225,58 +230,59 @@ qint64 AbstractGraphicsMediaItem::startPos()
void AbstractGraphicsMediaItem::resize( qint64 size, From from )
{
Q_ASSERT( clip() );
Q_ASSERT( clipHelper() );
if ( size < 1 )
return;
if ( clip()->getMedia()->fileType() != Media::Image )
if ( size > clip()->maxEnd() )
size = clip()->maxEnd();
if ( clipHelper()->clip()->getMedia()->fileType() != Media::Image )
if ( size > clipHelper()->clip()->end() )
size = clipHelper()->clip()->end();
if ( from == BEGINNING )
{
if ( clip()->getMedia()->fileType() != Media::Image )
if ( clip()->begin() + size > clip()->maxEnd() )
if ( clipHelper()->clip()->getMedia()->fileType() != Media::Image )
if ( clipHelper()->begin() + size > clipHelper()->end() )
return;
MainWorkflow::getInstance()->resizeClip( clip(), clip()->begin(),
clip()->begin() + size, 0,
MainWorkflow::getInstance()->resizeClip( m_clipHelper, m_clipHelper->begin(),
m_clipHelper->begin() + size, 0,
trackNumber(), mediaType() );
}
else
{
if ( clip()->getMedia()->fileType() != Media::Image )
if ( m_clipHelper->clip()->getMedia()->fileType() != Media::Image )
{
qint64 newBegin = qMax( clip()->end() - size, (qint64)0 );
if ( clip()->maxBegin() > newBegin )
qint64 newBegin = qMax( m_clipHelper->end() - size, (qint64)0 );
if ( m_clipHelper->clip()->begin() > newBegin )
return;
m_resizeExpected = true;
qint64 oldLength = clip()->length();
qint64 oldLength = m_clipHelper->length();
qint64 newStart = startPos() + ( oldLength - size );
if ( newStart < 0 )
return ;
MainWorkflow::getInstance()->resizeClip( clip(), qMax( clip()->end() - size, (qint64)0 ), clip()->end(),
MainWorkflow::getInstance()->resizeClip( m_clipHelper, qMax( m_clipHelper->end() - size,
(qint64)0 ), m_clipHelper->end(),
newStart, trackNumber(), mediaType() );
setStartPos( newStart );
}
else
{
m_resizeExpected = true;
qint64 oldLength = clip()->length();
qint64 oldLength = m_clipHelper->length();
// Commands::trigger( new Commands::MainWorkflow::ResizeClip( clip()->getUuid(),
// 0, size, startPos(),
// startPos() + oldLength,
// startPos() + ( oldLength - size ),
//
// ))
MainWorkflow::getInstance()->resizeClip( clip(), 0, size, startPos() + ( oldLength - size ),
MainWorkflow::getInstance()->resizeClip( m_clipHelper, 0, size, startPos() + ( oldLength - size ),
trackNumber(), mediaType() );
setStartPos( startPos() + ( oldLength - size ) );
}
}
setWidth( clip()->length() );
setWidth( m_clipHelper->length() );
}
void AbstractGraphicsMediaItem::adjustLength()
......@@ -286,8 +292,8 @@ void AbstractGraphicsMediaItem::adjustLength()
m_resizeExpected = false;
return ;
}
Q_ASSERT( clip() );
setWidth( clip()->length() );
Q_ASSERT( m_clipHelper );
setWidth( m_clipHelper->length() );
}
bool AbstractGraphicsMediaItem::resizeZone( const QPointF& position )
......@@ -316,3 +322,9 @@ AbstractGraphicsMediaItem::clipDestroyed( Clip* clip )
if ( m_tracksView != NULL )
m_tracksView->removeClip( clip->uuid() );
}
ClipHelper*
AbstractGraphicsMediaItem::clipHelper()
{
return m_clipHelper;
}
......@@ -74,9 +74,6 @@ public:
return m_clipHelper->uuid();
}
/// Clip contained in the item
virtual Clip* clip() const = 0;
/// Return a pointer to the TracksScene
TracksScene* scene();
......@@ -107,6 +104,8 @@ public:
/// Resize an item from its beginning or from its end.
void resize( qint64 size, From from = BEGINNING );
ClipHelper *clipHelper();
protected:
/**
* \details Returns a pointer to the tracksView which contains the item,
......@@ -123,10 +122,7 @@ protected:
*/
qint64 oldPosition;
/**
* \brief The Clip this AbstractGraphicsMediaItem is based upon.
*/
Clip* m_clip;
ClipHelper* m_clipHelper;
/**
* \brief Return a pointer to the linked item.
......@@ -181,8 +177,6 @@ private:
//FIXME: this is a nasty forest boolean
bool m_resizeExpected;
ClipHelper* m_clipHelper;
};
#endif // ABSTRACTGRAPHICSMEDIAITEM_H
......@@ -32,7 +32,8 @@
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneHoverEvent>
GraphicsAudioItem::GraphicsAudioItem( Clip* clip ) : AbstractGraphicsMediaItem( clip )
GraphicsAudioItem::GraphicsAudioItem( Clip* clip ) :
AbstractGraphicsMediaItem( clip )
{
setFlags( QGraphicsItem::ItemIsSelectable );
......@@ -43,11 +44,6 @@ GraphicsAudioItem::GraphicsAudioItem( Clip* clip ) : AbstractGraphicsMediaItem(
.arg( length.toString("hh:mm:ss.zzz") ) );
setToolTip( tooltip );
setAcceptHoverEvents( true );
// Adjust the width
setWidth( clip->length() );
// Automatically adjust future changes
connect( clip, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
}
GraphicsAudioItem::~GraphicsAudioItem()
......@@ -70,11 +66,6 @@ void GraphicsAudioItem::paint( QPainter* painter, const QStyleOptionGraphicsItem
painter->restore();
}
Clip* GraphicsAudioItem::clip() const
{
return m_clip;
}
void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphicsItem* option )
{
QRectF drawRect;
......@@ -160,7 +151,7 @@ void GraphicsAudioItem::paintTitle( QPainter* painter, const QStyleOptionGraphic
// Initiate the font metrics calculation
QFontMetrics fm( painter->font() );
QString text = m_clip->getMedia()->fileName();
QString text = m_clipHelper->clip()->getMedia()->fileName();
// Get the transformations required to map the text on the viewport
QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform();
......
......@@ -53,8 +53,6 @@ public:
virtual MainWorkflow::TrackType mediaType() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
virtual Clip* clip() const;
protected:
/**
* \brief Paint the item's rectangle.
......
......@@ -33,7 +33,8 @@
#include "TracksView.h"
#include "Timeline.h"
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : AbstractGraphicsMediaItem( clip )
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) :
AbstractGraphicsMediaItem( clip )
{
setFlags( QGraphicsItem::ItemIsSelectable );
......@@ -44,11 +45,6 @@ GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : AbstractGraphicsMediaItem(
.arg( length.toString("hh:mm:ss.zzz") ) );
setToolTip( tooltip );
setAcceptHoverEvents( true );
// Adjust the width
setWidth( clip->length() );
// Automatically adjust for future changes
connect( clip, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
}
GraphicsMovieItem::~GraphicsMovieItem()
......@@ -71,11 +67,6 @@ void GraphicsMovieItem::paint( QPainter* painter, const QStyleOptionGraphicsItem
painter->restore();
}
Clip* GraphicsMovieItem::clip() const
{
return m_clip;
}
void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphicsItem* option )
{
QRectF drawRect;
......@@ -160,7 +151,7 @@ void GraphicsMovieItem::paintTitle( QPainter* painter, const QStyleOptionGraphic
// Initiate the font metrics calculation
QFontMetrics fm( painter->font() );
QString text = m_clip->getMedia()->fileName();
QString text = m_clipHelper->clip()->getMedia()->fileName();
// Get the transformations required to map the text on the viewport
QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform();
......
......@@ -44,7 +44,7 @@ public:
* \brief See http://doc.trolltech.com/4.5/qgraphicsitem.html#type
*/
enum { Type = UserType + 1 };
GraphicsMovieItem( Clip* clip );
GraphicsMovieItem( Clip* clipHelper );
virtual ~GraphicsMovieItem();
virtual int type() const { return Type; }
......@@ -53,8 +53,6 @@ public:
virtual MainWorkflow::TrackType mediaType() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
virtual Clip* clip() const;
protected:
/**
* \brief Paint the item's rectangle.
......
......@@ -80,8 +80,8 @@ Timeline::Timeline( WorkflowRenderer* renderer, QWidget *parent ) :
connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
// Clip actions
connect( m_mainWorkflow, SIGNAL( clipAdded(Clip*,uint,qint64,MainWorkflow::TrackType ) ),
this, SLOT( actionAddClip(Clip*,uint,qint64,MainWorkflow::TrackType ) ) );
connect( m_mainWorkflow, SIGNAL( clipAdded(ClipHelper*,uint,qint64,MainWorkflow::TrackType ) ),
this, SLOT( actionAddClip(ClipHelper*,uint,qint64,MainWorkflow::TrackType ) ) );
connect( m_mainWorkflow, SIGNAL( clipMoved(QUuid, uint, qint64,MainWorkflow::TrackType ) ),
this, SLOT( actionMoveClip(QUuid,uint,qint64,MainWorkflow::TrackType ) ) );
connect( m_mainWorkflow, SIGNAL( clipRemoved(const QUuid&,uint,MainWorkflow::TrackType ) ),
......@@ -158,9 +158,9 @@ void Timeline::setTool( ToolButtons button )
tracksView()->setTool( button );
}
void Timeline::actionAddClip( Clip* clip, unsigned int track, qint64 start, MainWorkflow::TrackType trackType )
void Timeline::actionAddClip( ClipHelper* clipHelper, unsigned int track, qint64 start, MainWorkflow::TrackType trackType )
{
tracksView()->addMediaItem( clip, track, trackType, start );
tracksView()->addMediaItem( clipHelper, track, trackType, start );
}
void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, MainWorkflow::TrackType )
......
......@@ -78,7 +78,7 @@ public slots:
* \param start The position in frames.
* \param
*/
void actionAddClip( Clip* clip, unsigned int track, qint64 start, MainWorkflow::TrackType trackType );
void actionAddClip( ClipHelper* clip, unsigned int track, qint64 start, MainWorkflow::TrackType trackType );
/**
* \brief Move an item in the timeline.
* \param uuid The Universally Unique Identifier of the item.
......
......@@ -90,8 +90,7 @@ TracksScene::askRemoveSelectedItems()
AbstractGraphicsMediaItem* item = qgraphicsitem_cast<AbstractGraphicsMediaItem*>( items.at(i) );
if ( !item ) return;
Commands::trigger( new Commands::MainWorkflow::RemoveClip( item->clip(),
item->uuid(),
Commands::trigger( new Commands::MainWorkflow::RemoveClip( item->clipHelper(),
item->trackNumber(),
item->startPos(),
item->mediaType() ) );
......
......@@ -195,7 +195,8 @@ TracksView::removeClip( const QUuid& uuid )
// is the one we would like to remove.
foreach( item, items )
{
if ( item->clip()->uuid() == uuid || item->clip()->isChild( uuid ) == true )
if ( item->clipHelper()->uuid() == uuid ||
item->clipHelper()->clip()->isChild( uuid ) == true ) //This is probably useless now
{
// This item needs to be removed.
// Saving its values
......@@ -215,9 +216,9 @@ TracksView::removeClip( const QUuid& uuid )
}
void
TracksView::addMediaItem( Clip *clip, unsigned int track, MainWorkflow::TrackType trackType, qint64 start )
TracksView::addMediaItem( ClipHelper *ch, unsigned int track, MainWorkflow::TrackType trackType, qint64 start )
{
Q_ASSERT( clip );
Q_ASSERT( ch );
// If there is not enough tracks to insert
// the clip do it now.
......@@ -243,13 +244,13 @@ TracksView::addMediaItem( Clip *clip, unsigned int track, MainWorkflow::TrackTyp
AbstractGraphicsMediaItem *item = 0;
if ( trackType == MainWorkflow::VideoTrack )
{
item = new GraphicsMovieItem( clip );
item = new GraphicsMovieItem( ch->clip() );
connect( item, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
}
else if ( trackType == MainWorkflow::AudioTrack )
{
item = new GraphicsAudioItem( clip );
item = new GraphicsAudioItem( ch->clip() );
connect( item, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
}
......@@ -281,6 +282,7 @@ TracksView::dragEnterEvent( QDragEnterEvent *event )
{
if ( m_dragAudioItem ) delete m_dragAudioItem;
m_dragAudioItem = new GraphicsAudioItem( clip );
m_dragAudioItem->m_clipHelper = new ClipHelper( clip );
m_dragAudioItem->m_tracksView = this;
m_dragAudioItem->setHeight( tracksHeight() );
m_dragAudioItem->setTrack( getTrack( m_dragAudioItem->mediaType(), 0 ) );
......@@ -291,6 +293,7 @@ TracksView::dragEnterEvent( QDragEnterEvent *event )
{
if ( m_dragVideoItem ) delete m_dragVideoItem;
m_dragVideoItem = new GraphicsMovieItem( clip );
m_dragVideoItem->m_clipHelper = new ClipHelper( clip );
m_dragVideoItem->m_tracksView = this;
m_dragVideoItem->setHeight( tracksHeight() );
m_dragVideoItem->setTrack( getTrack( m_dragVideoItem->mediaType(), 0 ) );
......@@ -672,13 +675,10 @@ TracksView::dropEvent( QDropEvent *event )
m_dragAudioItem->oldTrackNumber = m_dragAudioItem->trackNumber();
m_dragAudioItem->oldPosition = (qint64)mappedXPos;
Commands::MainWorkflow::AddClip*
clip = new Commands::MainWorkflow::AddClip( m_dragAudioItem->clip(),
m_dragAudioItem->trackNumber(),
(qint64)mappedXPos,
MainWorkflow::AudioTrack );
Commands::trigger( clip );
m_dragAudioItem->m_clipHelper = clip->clipHelper();
Commands::trigger( new Commands::MainWorkflow::AddClip( m_dragAudioItem->clipHelper(),
m_dragAudioItem->trackNumber(),
(qint64)mappedXPos,
MainWorkflow::AudioTrack ) );
m_dragAudioItem = NULL;
}
......@@ -692,13 +692,10 @@ TracksView::dropEvent( QDropEvent *event )
m_dragVideoItem->oldTrackNumber = m_dragVideoItem->trackNumber();
m_dragVideoItem->oldPosition = (qint64)mappedXPos;
Commands::MainWorkflow::AddClip*
clip = new Commands::MainWorkflow::AddClip( m_dragVideoItem->clip(),
m_dragVideoItem->trackNumber(),
(qint64)mappedXPos,
MainWorkflow::VideoTrack );
Commands::trigger( clip );
m_dragVideoItem->m_clipHelper = clip->clipHelper();
Commands::trigger( new Commands::MainWorkflow::AddClip( m_dragVideoItem->clipHelper(),
m_dragVideoItem->trackNumber(),
(qint64)mappedXPos,
MainWorkflow::VideoTrack ) );
m_dragVideoItem = NULL;
}
......@@ -869,8 +866,8 @@ TracksView::mousePressEvent( QMouseEvent *event )
m_actionResizeType = AbstractGraphicsMediaItem::BEGINNING;
m_actionResize = true;
m_actionResizeStart = mapToScene( event->pos() ).x();
m_actionResizeBase = item->clip()->length();
m_actionResizeOldBegin = item->clip()->begin();
m_actionResizeBase = item->clipHelper()->length();
m_actionResizeOldBegin = item->clipHelper()->begin();
m_actionItem = item;
}
else if ( item->moveable() )
......@@ -964,12 +961,14 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
}
else if ( m_actionResize )
{
Clip *clip = m_actionItem->clip();
ClipHelper *ch = m_actionItem->clipHelper();
//This is a "pointless action". The resize already occured. However, by doing this
//we can have an undo action.
Commands::trigger( new Commands::MainWorkflow::ResizeClip( m_actionItem->uuid(), clip->begin(),
clip->end(), m_actionResizeOldBegin, m_actionResizeOldBegin + m_actionResizeBase,
m_actionItem->pos().x(), m_actionResizeStart, m_actionItem->trackNumber(), m_actionItem->mediaType() ) );
Commands::trigger( new Commands::MainWorkflow::ResizeClip( ch, ch->begin(),
ch->end(),
m_actionResizeOldBegin, m_actionResizeOldBegin + m_actionResizeBase,
m_actionItem->pos().x(), m_actionResizeStart,
m_actionItem->trackNumber(), m_actionItem->mediaType() ) );
updateDuration();
}
......@@ -1187,7 +1186,7 @@ TracksView::split( AbstractGraphicsMediaItem *item, qint64 frame )
//item->startPos() 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 startPos() + frame)
Commands::trigger( new Commands::MainWorkflow::SplitClip( item->clip(), item->trackNumber(),
item->startPos() + frame, frame + item->clip()->begin(),
Commands::trigger( new Commands::MainWorkflow::SplitClip( item->clipHelper(), item->trackNumber(),
item->startPos() + frame, frame + item->clipHelper()->begin(),
item->mediaType() ) );
}
......@@ -193,7 +193,8 @@ public slots:
* \param trackType The type of the track (Audio or Video)
* \param start The position in frames.
*/
void addMediaItem( Clip *clip, unsigned int track, MainWorkflow::TrackType trackType, qint64 start );
void addMediaItem( ClipHelper *clipHelper, unsigned int track,
MainWorkflow::TrackType trackType, qint64 start );
/**
* \brief Move an item in the timeline.
* \param uuid The Universally Unique Identifier of the item.
......
......@@ -38,15 +38,10 @@ Clip::Clip( Media *media, qint64 begin /*= 0*/, qint64 end /*= -1*/, const QStri
m_media( media ),
m_begin( begin ),
m_end( end ),
m_maxBegin( begin ),
m_maxEnd( end ),
m_parent( media->baseClip() )
{
if ( end == -1 )
{
m_end = media->nbFrames();
m_maxEnd = m_end;
}
if ( uuid.isEmpty() == true )
m_uuid = QUuid::createUuid();
else
......@@ -54,6 +49,8 @@ Clip::Clip( Media *media, qint64 begin /*= 0*/, qint64 end /*= -1*/, const QStri
m_childs = new MediaContainer( this );
m_rootClip = media->baseClip();
computeLength();
connect( media, SIGNAL( metaDataComputed( const Media* ) ),
this, SLOT( mediaMetadataUpdated( const Media* ) ) );
}
Clip::Clip( Clip *parent, qint64 begin /*= -1*/, qint64 end /*= -1*/,
......@@ -61,21 +58,13 @@ Clip::Clip( Clip *parent, qint64 begin /*= -1*/, qint64 end /*= -1*/,
m_parent( parent ),
m_begin( begin ),
m_end( end ),
m_maxBegin( begin ),
m_maxEnd( end ),
m_rootClip( parent->rootClip() ),
m_media( parent->getMedia() )
{
if ( begin < 0 )
{
m_begin = parent->m_begin;
m_maxBegin = m_begin;
}
if ( end < 0 )
{
m_end = parent->m_end;
m_maxEnd = m_end;
}
if ( uuid.isEmpty() == true )
m_uuid = QUuid::createUuid();
else
......@@ -92,18 +81,6 @@ Clip::~Clip()
delete m_media;
}
qint64
Clip::begin() const
{
return m_begin;
}