[vlmc-devel] commit: More undo/redo fix. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Wed Sep 15 18:35:06 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Wed Sep 15 18:35:03 2010 +0200| [9c4f1e13994bf8a7a3305e68c76d88ac8f71b9d0] | committer: Hugo Beauzée-Luyssen 

More undo/redo fix.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=9c4f1e13994bf8a7a3305e68c76d88ac8f71b9d0
---

 src/Commands/Commands.cpp                      |    8 ++++++--
 src/Gui/timeline/AbstractGraphicsItem.h        |    2 +-
 src/Gui/timeline/AbstractGraphicsMediaItem.cpp |    4 ++--
 src/Gui/timeline/AbstractGraphicsMediaItem.h   |    2 +-
 src/Gui/timeline/GraphicsEffectItem.cpp        |    4 ++--
 src/Gui/timeline/GraphicsEffectItem.h          |    2 +-
 src/Gui/timeline/TracksView.cpp                |   23 ++++++++++++++++++-----
 7 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/Commands/Commands.cpp b/src/Commands/Commands.cpp
index 4a4dbff..51e6b4b 100644
--- a/src/Commands/Commands.cpp
+++ b/src/Commands/Commands.cpp
@@ -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 );
diff --git a/src/Gui/timeline/AbstractGraphicsItem.h b/src/Gui/timeline/AbstractGraphicsItem.h
index 264bd9a..c99e394 100644
--- a/src/Gui/timeline/AbstractGraphicsItem.h
+++ b/src/Gui/timeline/AbstractGraphicsItem.h
@@ -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;
diff --git a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
index 75e323e..6dd19fe 100644
--- a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
+++ b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
@@ -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*
diff --git a/src/Gui/timeline/AbstractGraphicsMediaItem.h b/src/Gui/timeline/AbstractGraphicsMediaItem.h
index 2c213fd..9b37dc3 100644
--- a/src/Gui/timeline/AbstractGraphicsMediaItem.h
+++ b/src/Gui/timeline/AbstractGraphicsMediaItem.h
@@ -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;
diff --git a/src/Gui/timeline/GraphicsEffectItem.cpp b/src/Gui/timeline/GraphicsEffectItem.cpp
index 555ba17..082de00 100644
--- a/src/Gui/timeline/GraphicsEffectItem.cpp
+++ b/src/Gui/timeline/GraphicsEffectItem.cpp
@@ -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
diff --git a/src/Gui/timeline/GraphicsEffectItem.h b/src/Gui/timeline/GraphicsEffectItem.h
index 22453bf..059cb79 100644
--- a/src/Gui/timeline/GraphicsEffectItem.h
+++ b/src/Gui/timeline/GraphicsEffectItem.h
@@ -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;
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index c442d47..11a6593 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -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 )
     {



More information about the Vlmc-devel mailing list