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

Fixing effect resize undo/redo

parent 9c4f1e13
......@@ -250,7 +250,8 @@ Commands::Effect::Move::undo()
m_new->moveEffect( m_helper, m_oldPos );
}
Commands::Effect::Resize::Resize( EffectHelper *helper, qint64 newBegin, qint64 newEnd ) :
Commands::Effect::Resize::Resize( EffectUser *target, EffectHelper *helper, qint64 newBegin, qint64 newEnd ) :
m_target( target ),
m_helper( helper ),
m_newBegin( newBegin ),
m_newEnd( newEnd )
......@@ -263,12 +264,16 @@ Commands::Effect::Resize::Resize( EffectHelper *helper, qint64 newBegin, qint64
void
Commands::Effect::Resize::redo()
{
if ( m_newBegin != m_oldBegin )
m_target->moveEffect( m_helper, m_newBegin );
m_helper->setBoundaries( m_newBegin, m_newEnd );
}
void
Commands::Effect::Resize::undo()
{
if ( m_oldBegin != m_newBegin )
m_target->moveEffect( m_helper, m_oldBegin );
m_helper->setBoundaries( m_oldBegin, m_oldEnd );
}
......
......@@ -177,10 +177,11 @@ namespace Commands
NEW_COMMAND( Resize )
{
public:
Resize( EffectHelper *helper, qint64 newBegin, qint64 newEnd );
Resize( EffectUser *target, EffectHelper *helper, qint64 newBegin, qint64 newEnd );
virtual void redo();
virtual void undo();
private:
EffectUser *m_target;
EffectHelper *m_helper;
qint64 m_newBegin;
qint64 m_newEnd;
......
......@@ -119,7 +119,7 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
qint64 width() const;
virtual void triggerMove( EffectUser *target, qint64 startPos ) = 0;
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
virtual void triggerResize( EffectUser *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos ) = 0;
virtual Workflow::Helper *helper() = 0;
virtual qint32 zSelected() const = 0;
......
......@@ -281,12 +281,15 @@ AbstractGraphicsMediaItem::helper()
}
void
AbstractGraphicsMediaItem::triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
AbstractGraphicsMediaItem::triggerResize( EffectUser *target, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos )
{
ClipHelper *clipHelper = qobject_cast<ClipHelper*>( helper );
if ( clipHelper == NULL )
return ;
TrackWorkflow *tw = qobject_cast<TrackWorkflow*>( target );
if ( tw == NULL )
return ;
Commands::trigger( new Commands::Clip::Resize( tw, clipHelper, newBegin,
newEnd, pos ) );
}
......
......@@ -58,7 +58,7 @@ public:
virtual Workflow::Helper *helper();
virtual void triggerMove( EffectUser *target, qint64 startPos );
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
virtual void triggerResize( EffectUser *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos );
virtual qint64 itemHeight() const;
virtual qint32 zSelected() const;
......
......@@ -255,13 +255,13 @@ GraphicsEffectItem::triggerMove( EffectUser *target, qint64 startPos )
}
void
GraphicsEffectItem::triggerResize( TrackWorkflow *, Workflow::Helper *helper,
GraphicsEffectItem::triggerResize( EffectUser *target, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 )
{
EffectHelper *eh = qobject_cast<EffectHelper*>( helper );
if ( eh == NULL )
return ;
Commands::trigger( new Commands::Effect::Resize( eh, newBegin, newEnd ) );
Commands::trigger( new Commands::Effect::Resize( target, eh, newBegin, newEnd ) );
}
qint32
......
......@@ -51,7 +51,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
virtual qint64 maxEnd() const;
virtual Workflow::Helper *helper();
virtual void triggerMove( EffectUser *target, qint64 startPos );
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
virtual void triggerResize( EffectUser *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos );
virtual qint64 itemHeight() const;
virtual qint32 zSelected() const;
......
......@@ -66,7 +66,7 @@ TracksView::TracksView( QGraphicsScene *scene, MainWorkflow *mainWorkflow,
m_dragVideoItem = NULL;
m_dragAudioItem = NULL;
m_lastKnownTrack = NULL;
m_effectMoveTarget = NULL;
m_effectTarget = NULL;
m_action = None;
m_actionRelativeX = -1;
m_actionItem = NULL;
......@@ -911,7 +911,7 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
AbstractGraphicsMediaItem *mediaItem = dynamic_cast<AbstractGraphicsMediaItem*>( collidingItem );
if ( mediaItem != NULL )
{
m_effectMoveTarget = mediaItem;
m_effectTarget = mediaItem;
break ;
}
}
......@@ -956,6 +956,20 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
// END UGLY
if ( !collide )
{
GraphicsEffectItem *effectItem = qgraphicsitem_cast<GraphicsEffectItem*>( m_actionItem );
if ( effectItem != NULL )
{
QList<QGraphicsItem*> list = m_actionItem->collidingItems();
foreach ( QGraphicsItem *collidingItem, list )
{
AbstractGraphicsMediaItem *mediaItem = dynamic_cast<AbstractGraphicsMediaItem*>( collidingItem );
if ( mediaItem != NULL )
{
m_effectTarget = mediaItem;
break ;
}
}
}
if ( m_actionResizeType == AbstractGraphicsItem::END )
{
m_actionItem->resize( itemNewSize, mapToScene( event->pos() ).x(),
......@@ -1010,7 +1024,7 @@ TracksView::mousePressEvent( QMouseEvent *event )
{
m_action = Move;
m_actionItem = item;
m_effectMoveTarget = NULL;
m_effectTarget = NULL;
}
scene()->clearSelection();
item->setSelected( true );
......@@ -1074,10 +1088,10 @@ 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 )
if ( effectItem != NULL && m_effectTarget != NULL )
{
target = m_effectMoveTarget->clipHelper()->clipWorkflow();
targetPos = m_actionItem->startPos() - m_effectMoveTarget->startPos();
target = m_effectTarget->clipHelper()->clipWorkflow();
targetPos = m_actionItem->startPos() - m_effectTarget->startPos();
}
m_actionItem->triggerMove( target, targetPos );
// Update the linked item too
......@@ -1094,7 +1108,7 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
m_actionRelativeX = -1;
m_actionItem = NULL;
m_lastKnownTrack = NULL;
m_effectMoveTarget = NULL;
m_effectTarget = NULL;
}
else if ( m_action == TracksView::Resize )
{
......@@ -1110,9 +1124,15 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
newBegin = m_actionItem->helper()->begin();
newEnd = newBegin + m_actionItem->width();
}
m_actionItem->triggerResize( m_actionItem->track()->trackWorkflow(), m_actionItem->helper(),
EffectUser *target = m_actionItem->track()->trackWorkflow();
GraphicsEffectItem *effectItem = qgraphicsitem_cast<GraphicsEffectItem*>( m_actionItem );
if ( effectItem != NULL && m_effectTarget != NULL )
target = m_effectTarget->clipHelper()->clipWorkflow();
m_actionItem->triggerResize( target, m_actionItem->helper(),
newBegin, newEnd, m_actionItem->pos().x() );
updateDuration();
m_effectTarget = NULL;
m_actionItem = NULL;
}
m_action = TracksView::None;
......
......@@ -343,7 +343,7 @@ private:
GraphicsMovieItem *m_dragVideoItem;
GraphicsAudioItem *m_dragAudioItem;
GraphicsEffectItem *m_dragEffectItem;
AbstractGraphicsMediaItem *m_effectMoveTarget;
AbstractGraphicsMediaItem *m_effectTarget;
QGraphicsWidget *m_separator;
ToolButtons m_tool;
......
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