Commit 086f02aa authored by Ludovic Fauvet's avatar Ludovic Fauvet

Fix the undo/redo that was partially working

parent 52f33707
......@@ -66,8 +66,9 @@ namespace Commands
{
public:
MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
unsigned int oldTrack, unsigned int newTrack, qint64 newPos ) :
m_workflow( workflow ), m_uuid( uuid ), m_oldTrack( oldTrack ), m_newTrack( newTrack ), m_pos( newPos )
unsigned int oldTrack, qint64 oldPos, unsigned int newTrack, qint64 newPos ) :
m_workflow( workflow ), m_uuid( uuid ), m_oldTrack( oldTrack ),
m_newTrack( newTrack ), m_pos( newPos ), m_oldPos( oldPos )
{
setText( "Moving clip" );
m_undoRedoAction = false;
......
......@@ -23,7 +23,7 @@
#include "AbstractGraphicsMediaItem.h"
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem() :
oldTrackNumber( -1 ), m_tracksView( NULL )
oldTrackNumber( -1 ), oldPosition( -1 ), m_tracksView( NULL )
{
setCursor( Qt::OpenHandCursor );
}
......
......@@ -47,6 +47,7 @@ public:
/// Should return the unique uid of the contained media.
virtual const QUuid& uuid() const = 0;
/// Return the current track of the item
int trackNumber();
protected:
......@@ -60,6 +61,10 @@ protected:
* Contains the old trackNumber
*/
int oldTrackNumber;
/**
* Contains the old position
*/
qint64 oldPosition;
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
......
......@@ -161,6 +161,7 @@ void TracksView::moveMediaItem( const QUuid& uuid, unsigned int track, qint64 ti
AbstractGraphicsMediaItem* item =
dynamic_cast<AbstractGraphicsMediaItem*>( sceneItems.at( i ) );
if ( !item || item->uuid() != uuid ) continue;
qDebug() << uuid.toString() << track << time;
moveMediaItem( item, track, time );
}
}
......@@ -189,10 +190,10 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position
lastKnownTrack = track;
qreal time = ( mapToScene( position ).x() + 0.5 );
moveMediaItem( item, track->trackNumber(), (int)time);
moveMediaItem( item, track->trackNumber(), (qint64)time);
}
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time )
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, qint64 time )
{
if ( track < 0 )
track = 0;
......@@ -245,7 +246,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, int
continueSearch = false;
}
// Check for horizontal collisions
int mappedXPos = qMax( time, 0 );
qint64 mappedXPos = qMax( time, (qint64)0 );
item->setPos( mappedXPos, 0 );
QList<QGraphicsItem*> colliding = item->collidingItems( Qt::IntersectsItemShape );
for ( int i = 0; i < colliding.size(); ++i )
......@@ -402,10 +403,14 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event )
updateDuration();
if ( m_layout->itemAt( 0 )->graphicsItem()->childItems().count() > 0 )
addVideoTrack();
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_mainWorkflow, movieItem->clip()->getUuid(),
movieItem->oldTrackNumber, movieItem->trackNumber(),
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_mainWorkflow,
movieItem->clip()->getUuid(),
movieItem->oldTrackNumber,
movieItem->oldPosition,
movieItem->trackNumber(),
(qint64)movieItem->pos().x() ) );
movieItem->oldTrackNumber = movieItem->trackNumber();
movieItem->oldPosition = movieItem->pos().x();
m_actionMove = false;
m_actionRelativeX = -1;
m_actionItem = NULL;
......
......@@ -116,7 +116,7 @@ private:
void addVideoTrack();
void addAudioTrack();
void moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position );
void moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time );
void moveMediaItem( AbstractGraphicsMediaItem* item, int track, qint64 time );
QGraphicsScene* m_scene;
int m_tracksHeight;
unsigned int m_tracksCount;
......
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