[vlmc-devel] commit: Adding an undo/redo command for adding clip ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Wed Sep 8 22:09:25 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Wed Sep  8 22:09:26 2010 +0200| [e209ee90d02959f36ce8d24f5e05ae524ac4c365] | committer: Hugo Beauzée-Luyssen 

Adding an undo/redo command for adding clip

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

 src/Commands/Commands.cpp       |   20 ++++++++++++++++++++
 src/Commands/Commands.h         |   11 +++++++++++
 src/Gui/timeline/TracksView.cpp |    6 ++++--
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/Commands/Commands.cpp b/src/Commands/Commands.cpp
index b4fcbdc..adc4904 100644
--- a/src/Commands/Commands.cpp
+++ b/src/Commands/Commands.cpp
@@ -192,6 +192,25 @@ void    Commands::Clip::Split::undo()
     m_toSplit->setEnd( m_oldEnd );
 }
 
+Commands::Effect::Add::Add( EffectHelper *helper, EffectUser *target ) :
+        m_helper( helper ),
+        m_target( target )
+{
+    setText( QObject::tr( "Adding effect %1" ).arg( m_helper->effectInstance()->effect()->name() ) );
+}
+
+void
+Commands::Effect::Add::redo()
+{
+    m_target->addEffect( m_helper );
+}
+
+void
+Commands::Effect::Add::undo()
+{
+    m_target->removeEffect( m_helper );
+}
+
 Commands::Effect::Move::Move( EffectHelper *helper, EffectUser *old, EffectUser *newUser,
                               qint64 pos) :
     m_helper( helper ),
@@ -200,6 +219,7 @@ Commands::Effect::Move::Move( EffectHelper *helper, EffectUser *old, EffectUser
     m_newPos( pos )
 {
     m_oldPos = helper->begin();
+    setText( QObject::tr( "Moving effect %1" ).arg( m_helper->effectInstance()->effect()->name() ) );
 }
 
 void
diff --git a/src/Commands/Commands.h b/src/Commands/Commands.h
index e3c56d1..4c6bd6c 100644
--- a/src/Commands/Commands.h
+++ b/src/Commands/Commands.h
@@ -147,6 +147,17 @@ namespace Commands
     }
     namespace   Effect
     {
+        NEW_COMMAND( Add )
+        {
+            public:
+                Add( EffectHelper *helper, EffectUser *target );
+                virtual void    redo();
+                virtual void    undo();
+            private:
+                EffectHelper    *m_helper;
+                EffectUser      *m_target;
+        };
+
         NEW_COMMAND( Move )
         {
             public:
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index 148309e..8f97888 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -741,7 +741,8 @@ TracksView::dropEvent( QDropEvent *event )
         if ( clips.size() > 0 )
         {
             AbstractGraphicsMediaItem   *item = clips.first();
-            item->clipHelper()->clipWorkflow()->addEffect( m_dragEffectItem->effectHelper() );
+            Commands::trigger( new Commands::Effect::Add( m_dragEffectItem->effectHelper(),
+                                                          item->clipHelper()->clipWorkflow() ) );
             m_dragEffectItem->m_oldTrack = item->track()->trackWorkflow();
             event->acceptProposedAction();
         }
@@ -753,7 +754,8 @@ TracksView::dropEvent( QDropEvent *event )
                 GraphicsTrack   *track = qgraphicsitem_cast<GraphicsTrack*>( item );
                 if ( track != NULL )
                 {
-                    track->trackWorkflow()->addEffect( m_dragEffectItem->effectHelper() );
+                    Commands::trigger( new Commands::Effect::Add( m_dragEffectItem->effectHelper(),
+                                                                  track->trackWorkflow() ) );
                     m_dragEffectItem->m_oldTrack = track->trackWorkflow();
                     event->acceptProposedAction();
                     break ;



More information about the Vlmc-devel mailing list