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

More undo/redo fix.

parent b62b8949
......@@ -103,8 +103,8 @@ void Commands::Clip::Move::undo()
{
if ( m_newTrack != m_oldTrack )
{
m_oldTrack->removeClip( m_clipHelper->uuid() );
m_newTrack->addClip( m_clipHelper, m_oldPos );
m_newTrack->removeClip( m_clipHelper->uuid() );
m_oldTrack->addClip( m_clipHelper, m_oldPos );
}
else
m_newTrack->moveClip( m_clipHelper->uuid(), m_oldPos );
......@@ -229,6 +229,8 @@ Commands::Effect::Move::redo()
{
m_old->removeEffect( m_helper );
m_new->addEffect( m_helper );
qint64 offset = m_helper->begin() - m_newPos;
m_helper->setBoundaries( m_newPos, m_helper->end() - offset );
}
else
m_new->moveEffect( m_helper, m_newPos );
......@@ -241,6 +243,8 @@ Commands::Effect::Move::undo()
{
m_new->removeEffect( m_helper );
m_old->addEffect( m_helper );
qint64 offset = m_helper->begin() - m_oldPos;
m_helper->setBoundaries( m_oldPos, m_helper->end() - offset );
}
else
m_new->moveEffect( m_helper, m_oldPos );
......
......@@ -118,7 +118,7 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
virtual qint64 end() const = 0;
qint64 width() const;
virtual void triggerMove( EffectUser *target ) = 0;
virtual void triggerMove( EffectUser *target, qint64 startPos ) = 0;
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos ) = 0;
virtual Workflow::Helper *helper() = 0;
......
......@@ -266,12 +266,12 @@ AbstractGraphicsMediaItem::end() const
}
void
AbstractGraphicsMediaItem::triggerMove( EffectUser *target )
AbstractGraphicsMediaItem::triggerMove( EffectUser *target, qint64 startPos )
{
TrackWorkflow *tw = qobject_cast<TrackWorkflow*>( target );
if ( tw == NULL )
return ;
Commands::trigger( new Commands::Clip::Move( m_oldTrack, tw, m_clipHelper, startPos() ) );
Commands::trigger( new Commands::Clip::Move( m_oldTrack, tw, m_clipHelper, startPos ) );
}
Workflow::Helper*
......
......@@ -57,7 +57,7 @@ public:
virtual qint64 end() const;
virtual Workflow::Helper *helper();
virtual void triggerMove( EffectUser *target );
virtual void triggerMove( EffectUser *target, qint64 startPos );
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos );
virtual qint64 itemHeight() const;
......
......@@ -248,10 +248,10 @@ GraphicsEffectItem::helper()
}
void
GraphicsEffectItem::triggerMove( EffectUser *target )
GraphicsEffectItem::triggerMove( EffectUser *target, qint64 startPos )
{
Commands::trigger( new Commands::Effect::Move( m_effectHelper, m_effectHelper->target(),
target, startPos() ) );
target, startPos ) );
}
void
......
......@@ -50,7 +50,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
virtual qint64 maxBegin() const;
virtual qint64 maxEnd() const;
virtual Workflow::Helper *helper();
virtual void triggerMove( EffectUser *target );
virtual void triggerMove( EffectUser *target, qint64 startPos );
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos );
virtual qint64 itemHeight() const;
......
......@@ -905,9 +905,16 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
GraphicsEffectItem *effectItem = qgraphicsitem_cast<GraphicsEffectItem*>( m_actionItem );
if ( effectItem != NULL )
{
QList<AbstractGraphicsMediaItem*> list = mediaItems<AbstractGraphicsMediaItem>( pos );
if ( list.size() >= 1 )
m_effectMoveTarget = list.at( 0 );
QList<QGraphicsItem*> list = m_actionItem->collidingItems();
foreach ( QGraphicsItem *collidingItem, list )
{
AbstractGraphicsMediaItem *mediaItem = dynamic_cast<AbstractGraphicsMediaItem*>( collidingItem );
if ( mediaItem != NULL )
{
m_effectMoveTarget = mediaItem;
break ;
}
}
}
}
else if ( event->modifiers() == Qt::NoModifier &&
......@@ -1066,13 +1073,18 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
EffectUser *target = m_actionItem->track()->trackWorkflow();
GraphicsEffectItem *effectItem = qgraphicsitem_cast<GraphicsEffectItem*>( m_actionItem );
qint64 targetPos = m_actionItem->startPos();
if ( effectItem != NULL && m_effectMoveTarget != NULL )
{
target = m_effectMoveTarget->clipHelper()->clipWorkflow();
m_actionItem->triggerMove( target );
targetPos = m_actionItem->startPos() - m_effectMoveTarget->startPos();
}
m_actionItem->triggerMove( target, targetPos );
// Update the linked item too
if ( m_actionItem->groupItem() )
{
m_actionItem->groupItem()->triggerMove( m_actionItem->groupItem()->track()->trackWorkflow() );
m_actionItem->groupItem()->triggerMove( m_actionItem->groupItem()->track()->trackWorkflow(),
m_actionItem->groupItem()->startPos() );
m_actionItem->groupItem()->m_oldTrack = m_actionItem->groupItem()->track()->trackWorkflow();
}
......@@ -1082,6 +1094,7 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
m_actionRelativeX = -1;
m_actionItem = NULL;
m_lastKnownTrack = NULL;
m_effectMoveTarget = NULL;
}
else if ( m_action == TracksView::Resize )
{
......
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