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

Refactoring clip moving.

parent c83861e6
......@@ -48,8 +48,8 @@ Commands::MainWorkflow::AddClip::AddClip( ClipHelper* ch, TrackWorkflow* tw, qin
m_clipHelper( ch ),
m_trackWorkflow( tw ),
m_pos( pos )
{//Fixme !
setText( QObject::tr( "Adding clip to track %1" ).arg( -1 ) );
{
setText( QObject::tr( "Adding clip to track %1" ).arg( tw->trackId() ) );
}
Commands::MainWorkflow::AddClip::~AddClip()
......@@ -66,33 +66,44 @@ void Commands::MainWorkflow::AddClip::undo()
m_trackWorkflow->removeClip( m_clipHelper->uuid() );
}
Commands::MainWorkflow::MoveClip::MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
unsigned int oldTrack, unsigned int newTrack, qint64 newPos,
Workflow::TrackType trackType ) :
m_workflow( workflow ), m_uuid( uuid ), m_oldTrack( oldTrack ),
m_newTrack( newTrack ), m_pos( newPos ), m_trackType( trackType )
Commands::MainWorkflow::MoveClip::MoveClip( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
ClipHelper *clipHelper, qint64 newPos ) :
m_oldTrack( oldTrack ),
m_newTrack( newTrack ),
m_clipHelper( clipHelper ),
m_newPos( newPos )
{
Q_ASSERT( oldTrack->type() == newTrack->type() );
if ( oldTrack != newTrack )
setText( QObject::tr( "Moving clip from track %1 to %2" ).arg(
QString::number( oldTrack ), QString::number( newTrack ) ) );
QString::number( oldTrack->trackId() ), QString::number( newTrack->trackId() ) ) );
else
setText( QObject::tr( "Moving clip" ) );
m_undoRedoAction = false;
m_oldPos = m_workflow->getClipPosition( uuid, oldTrack, trackType );
m_oldPos = oldTrack->getClipPosition( clipHelper->uuid() );
}
void Commands::MainWorkflow::MoveClip::redo()
{
// qDebug() << "Moving clip from track" << m_oldTrack << "to" << m_newTrack << "at position:" << m_pos;
m_workflow->moveClip( m_uuid, m_oldTrack, m_newTrack, m_pos, m_trackType, m_undoRedoAction );
m_undoRedoAction = true;
if ( m_newTrack != m_oldTrack )
{
m_oldTrack->removeClip( m_clipHelper->uuid() );
m_newTrack->addClip( m_clipHelper, m_newPos );
}
else
m_oldTrack->moveClip( m_clipHelper->uuid(), m_newPos );
}
void Commands::MainWorkflow::MoveClip::undo()
{
// qDebug() << "Undo moving clip from track" << m_newTrack << "to" << m_oldTrack << "at position:" << m_oldPos;
m_workflow->moveClip( m_uuid, m_newTrack, m_oldTrack, m_oldPos, m_trackType, m_undoRedoAction );
m_undoRedoAction = true;
if ( m_newTrack != m_oldTrack )
{
m_oldTrack->removeClip( m_clipHelper->uuid() );
m_newTrack->addClip( m_clipHelper, m_oldPos );
}
else
m_newTrack->moveClip( m_clipHelper->uuid(), m_oldPos );
}
Commands::MainWorkflow::RemoveClip::RemoveClip( ClipHelper* ch, TrackWorkflow* tw ) :
......@@ -149,7 +160,7 @@ void Commands::MainWorkflow::ResizeClip::undo()
else
{
m_clipHelper->setBoundaries( m_oldBegin, m_oldEnd );
::MainWorkflow::getInstance()->moveClip( m_clipHelper->uuid(), m_trackId, m_trackId, m_oldPos, m_trackType, m_undoRedoAction );
// ::MainWorkflow::getInstance()->moveClip( m_clipHelper->uuid(), m_trackId, m_trackId, m_oldPos, m_trackType, m_undoRedoAction );
}
}
......
......@@ -76,21 +76,17 @@ namespace Commands
NEW_COMMAND( MoveClip )
{
public:
MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
unsigned int oldTrack, unsigned int newTrack,
qint64 newPos, Workflow::TrackType trackType );
MoveClip( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
ClipHelper *clipHelper, qint64 newPos );
virtual void redo();
virtual void undo();
private:
::MainWorkflow* m_workflow;
QUuid m_uuid;
unsigned int m_oldTrack;
unsigned int m_newTrack;
qint64 m_pos;
qint64 m_oldPos;
bool m_undoRedoAction;
Workflow::TrackType m_trackType;
TrackWorkflow *m_oldTrack;
TrackWorkflow *m_newTrack;
ClipHelper *m_clipHelper;
qint64 m_newPos;
qint64 m_oldPos;
};
NEW_COMMAND( RemoveClip )
......
......@@ -23,6 +23,7 @@
#include "AbstractGraphicsMediaItem.h"
#include "TracksView.h"
#include "TracksScene.h"
#include "TrackWorkflow.h"
#include "GraphicsTrack.h"
#include "Clip.h"
......@@ -35,7 +36,7 @@
#include <QGraphicsSceneContextMenuEvent>
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
oldTrackNumber( -1 ),
m_oldTrack( NULL ),
oldPosition( -1 ),
m_tracksView( NULL ),
m_group( NULL ),
......@@ -54,7 +55,7 @@ AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
}
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( ClipHelper* ch ) :
oldTrackNumber( -1 ),
m_oldTrack( NULL ),
oldPosition( -1 ),
m_clipHelper( ch ),
m_tracksView( NULL ),
......@@ -222,9 +223,7 @@ void AbstractGraphicsMediaItem::contextMenuEvent( QGraphicsSceneContextMenuEvent
{
item1->group( this );
tracksView()->moveMediaItem( item1, item1->trackNumber(), startPos() );
MainWorkflow::getInstance()->moveClip( item1->uuid(), item1->trackNumber(),
trackNumber(), startPos(),
item1->mediaType() );
track()->trackWorkflow()->moveClip( item1->clipHelper()->uuid(), startPos() );
}
}
else if ( selectedAction == unlinkAction )
......
......@@ -31,10 +31,11 @@ class ClipHelper;
#define RESIZE_ZONE 7
class TracksView;
class Clip;
class TracksScene;
class GraphicsTrack;
class Clip;
class TracksScene;
class TracksView;
class TrackWorkflow;
class GraphicsTrack;
/**
* \brief Base class for Audio/Video items.
......@@ -124,9 +125,9 @@ protected:
TracksView* tracksView();
/**
* \brief Contains the old trackNumber.
* \brief Contains the old track.
*/
unsigned int oldTrackNumber;
TrackWorkflow *m_oldTrack;
/**
* \brief Contains the old position.
*/
......
......@@ -159,13 +159,13 @@ void Timeline::setTool( ToolButtons button )
tracksView()->setTool( button );
}
void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, Workflow::TrackType )
{
tracksView()->moveMediaItem( uuid, track, time );
Q_ASSERT( tracksView()->setItemOldTrack( uuid, track ) == true );
tracksView()->updateDuration();
tracksRuler()->update();
}
//void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, Workflow::TrackType )
//{
// tracksView()->moveMediaItem( uuid, track, time );
// Q_ASSERT( tracksView()->setItemOldTrack( uuid, track ) == true );
// tracksView()->updateDuration();
// tracksRuler()->update();
//}
void
Timeline::save( QXmlStreamWriter &project ) const
......
......@@ -88,7 +88,7 @@ public slots:
* \param track The new track of the item.
* \param time The new position (in frames) of the item.
*/
void actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, Workflow::TrackType );
// void actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, Workflow::TrackType );
void dragEnterEvent( QDragEnterEvent *event );
void dropEvent( QDropEvent *event );
......
......@@ -276,7 +276,7 @@ TracksView::addMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 start )
item->setHeight( tracksHeight() );
item->setTrack( getTrack( trackType, track ) );
item->setStartPos( start );
item->oldTrackNumber = track;
item->m_oldTrack = tw;
item->oldPosition = start;
moveMediaItem( item, track, start );
updateDuration();
......@@ -339,22 +339,6 @@ TracksView::dragMoveEvent( QDragMoveEvent *event )
moveMediaItem( target, event->pos() );
}
bool
TracksView::setItemOldTrack( const QUuid &uuid, quint32 oldTrackNumber )
{
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() != uuid ) continue;
item->oldTrackNumber = oldTrackNumber;
return true;
}
return false;
}
void
TracksView::moveMediaItem( const QUuid &uuid, unsigned int track, qint64 time )
{
......@@ -687,7 +671,7 @@ TracksView::dropEvent( QDropEvent *event )
addAudioTrack();
event->acceptProposedAction();
m_dragAudioItem->oldTrackNumber = m_dragAudioItem->trackNumber();
m_dragAudioItem->m_oldTrack = m_dragAudioItem->track()->trackWorkflow();
m_dragAudioItem->oldPosition = (qint64)mappedXPos;
Commands::trigger( new Commands::MainWorkflow::AddClip( m_dragAudioItem->clipHelper(),
......@@ -703,7 +687,7 @@ TracksView::dropEvent( QDropEvent *event )
addVideoTrack();
event->acceptProposedAction();
m_dragVideoItem->oldTrackNumber = m_dragVideoItem->trackNumber();
m_dragVideoItem->m_oldTrack = m_dragVideoItem->track()->trackWorkflow();
m_dragVideoItem->oldPosition = (qint64)mappedXPos;
Commands::trigger( new Commands::MainWorkflow::AddClip( m_dragVideoItem->clipHelper(),
......@@ -943,30 +927,26 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
UndoStack::getInstance()->beginMacro( "Move clip" );
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_mainWorkflow,
m_actionItem->uuid(),
m_actionItem->oldTrackNumber,
m_actionItem->trackNumber(),
m_actionItem->startPos(),
m_actionItem->mediaType() ) );
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_actionItem->m_oldTrack,
m_actionItem->track()->trackWorkflow(),
m_actionItem->clipHelper(),
m_actionItem->startPos() ) );
// Update the linked item too
if ( m_actionItem->groupItem() )
{
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_mainWorkflow,
m_actionItem->groupItem()->uuid(),
m_actionItem->groupItem()->oldTrackNumber,
m_actionItem->groupItem()->trackNumber(),
m_actionItem->groupItem()->startPos(),
m_actionItem->groupItem()->mediaType() ) );
m_actionItem->groupItem()->oldTrackNumber = m_actionItem->groupItem()->trackNumber();
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_actionItem->m_oldTrack,
m_actionItem->track()->trackWorkflow(),
m_actionItem->clipHelper(),
m_actionItem->startPos() ) );
m_actionItem->groupItem()->m_oldTrack = m_actionItem->groupItem()->track()->trackWorkflow();
m_actionItem->groupItem()->oldPosition = m_actionItem->groupItem()->startPos();
}
UndoStack::getInstance()->endMacro();
m_actionItem->oldTrackNumber = m_actionItem->trackNumber();
m_actionItem->m_oldTrack = m_actionItem->track()->trackWorkflow();
m_actionItem->oldPosition = m_actionItem->startPos();
m_actionRelativeX = -1;
m_actionItem = NULL;
......
......@@ -173,11 +173,6 @@ public:
* \return A pointer to the current WorkflowRenderer.
*/
WorkflowRenderer *getRenderer() { return m_renderer; }
/**
* \brief Ugly hack to change the old track number of an item.
* \deprecated Do not use, will be removed soon.
*/
bool setItemOldTrack( const QUuid &uuid, quint32 oldTrackNumber );
/**
* \brief Remove a Clip from the timeline (and from the backend).
* \param uuid The unique identifier of the Media.
......
......@@ -190,21 +190,6 @@ MainWorkflow::stopFrameComputing()
m_tracks[type]->stopFrameComputing();
}
void
MainWorkflow::moveClip( const QUuid &clipUuid, unsigned int oldTrack,
unsigned int newTrack, qint64 startingFrame,
Workflow::TrackType trackType,
bool undoRedoCommand /*= false*/ )
{
m_tracks[trackType]->moveClip( clipUuid, oldTrack, newTrack, startingFrame );
computeLength();
if ( undoRedoCommand == true )
{
emit clipMoved( clipUuid, newTrack, startingFrame, trackType );
}
}
void
MainWorkflow::muteTrack( unsigned int trackId, Workflow::TrackType trackType )
{
......@@ -436,7 +421,7 @@ MainWorkflow::resizeClip( ClipHelper* clipHelper, qint64 newBegin, qint64 newEnd
if ( newBegin != clipHelper->begin() )
{
moveClip( clipHelper->uuid(), trackId, trackId, newPos, trackType, undoRedoAction );
// moveClip( clipHelper->uuid(), trackId, trackId, newPos, trackType, undoRedoAction );
}
clipHelper->setBoundaries( newBegin, newEnd );
}
......
......@@ -137,33 +137,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
*/
void previousFrame( Workflow::TrackType trackType );
/**
* \brief Move a clip in the workflow
*
* This will move a clip, potentially from a track to anoher, to a new
* starting position.
* if undoRedoCommand is true, the
* clipMoved( QUuid, unsigned int, qint64, Workflow::TrackType ) will be
* emitted.
* This (bad) behaviour is caused by the fact that this move is mostly required
* by the timeline, which has already move its graphic item.
* When caused by an undo redo command, the timeline isn't aware of the change,
* and needs to be.
* \param uuid The uuid of the clip to move
* \param oldTrack The origin track of the clip
* \param newTrack The destination track for the clip
* \param pos The new starting position for the clip
* \param trackType The type of the track containing the clip to move
* \param undoRedoCommand Must be true if the method is called from an
* undo/redo action. If any doubt, false seems like
* a good choice.
* \todo Fix the last parameter. Such a nasty hack shouldn't even exist.
* \sa clipMoved( QUuid, unsigned int, qint64, Workflow::TrackType )
*/
void moveClip( const QUuid& uuid, unsigned int oldTrack,
unsigned int newTrack, qint64 pos,
Workflow::TrackType trackType,
bool undoRedoCommand = false );
/**
* \brief Return the given clip position.
*
......@@ -378,7 +351,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
* Calling this method will cause every clip workflow to be deleted, along with
* the associated Clip.
* This method will emit cleared() signal once finished.
* \sa removeClip( const QUuid&, unsigned int, Workflow::TrackType )
* \sa reCip( const QUuid&, unsigned int, Workflow::TrackType )
* \sa cleared()
*/
void clear();
......@@ -404,20 +377,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
*/
void mainWorkflowEndReached();
/**
* \brief Emitted when a clip has been moved
*
* \param uuid The uuid of the moved clip
* \param trackid The destination track of the moved media
* \param pos The clip new position
* \param trackType The moved clip type.
* \sa moveClip( const QUuid&, unsigned int, unsigned int,
* qint64, Workflow::TrackType, bool );
* \warning This is not always emitted. Check removeClip for more
* details
*/
void clipMoved( const QUuid& uuid, unsigned int trackId,
qint64 pos, Workflow::TrackType trackType );
/**
* \brief Emitted when the workflow is cleared.
*
......
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