[vlmc-devel] commit: GraphicsEffectItem: Follow the container clip when moved ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Thu Sep 16 21:05:52 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Thu Sep 16 21:06:04 2010 +0200| [69d182358c2fddf90febc8f05c365743304efcb5] | committer: Hugo Beauzée-Luyssen 

GraphicsEffectItem: Follow the container clip when moved

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

 src/CMakeLists.txt                      |    1 +
 src/Gui/timeline/AbstractGraphicsItem.h |    2 +-
 src/Gui/timeline/GraphicsEffectItem.cpp |   16 ++++++++++++-
 src/Gui/timeline/GraphicsEffectItem.h   |    5 ++++
 src/Gui/timeline/TracksView.cpp         |   39 ++++++++++++++++++++++++------
 5 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ccbbeb3..b5b2425 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -271,6 +271,7 @@ ELSE(NOT WITH_GUI)
         Gui/settings/StringWidget.h
         Gui/timeline/AbstractGraphicsItem.h
         Gui/timeline/AbstractGraphicsMediaItem.h
+        Gui/timeline/GraphicsEffectItem.h
         Gui/timeline/GraphicsCursorItem.h
         Gui/timeline/GraphicsTrack.h
         Gui/timeline/Timeline.h
diff --git a/src/Gui/timeline/AbstractGraphicsItem.h b/src/Gui/timeline/AbstractGraphicsItem.h
index 3fe0a61..3121f3b 100644
--- a/src/Gui/timeline/AbstractGraphicsItem.h
+++ b/src/Gui/timeline/AbstractGraphicsItem.h
@@ -88,7 +88,7 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
         GraphicsTrack* track();
 
         /// Set the position of the item (in frames) for the x-axis.
-        void setStartPos( qint64 position );
+        virtual void setStartPos( qint64 position );
 
         /// Return the position of the item (in frames) for the x-axis.
         qint64 startPos();
diff --git a/src/Gui/timeline/GraphicsEffectItem.cpp b/src/Gui/timeline/GraphicsEffectItem.cpp
index 391aa9f..0fd5bdf 100644
--- a/src/Gui/timeline/GraphicsEffectItem.cpp
+++ b/src/Gui/timeline/GraphicsEffectItem.cpp
@@ -22,6 +22,7 @@
 
 #include "GraphicsEffectItem.h"
 
+#include "AbstractGraphicsMediaItem.h"
 #include "Commands.h"
 #include "EffectHelper.h"
 #include "EffectInstance.h"
@@ -36,7 +37,8 @@
 
 GraphicsEffectItem::GraphicsEffectItem( Effect *effect ) :
         m_effect( effect ),
-        m_effectHelper( NULL )
+        m_effectHelper( NULL ),
+        m_container( NULL )
 {
     setOpacity( 0.8 );
     m_effectHelper = new EffectHelper( effect->createInstance() );
@@ -281,3 +283,15 @@ GraphicsEffectItem::containerMoved( qint64 pos )
 {
     setStartPos( m_effectHelper->begin() + pos );
 }
+
+void
+GraphicsEffectItem::setContainer( AbstractGraphicsMediaItem *item )
+{
+    if ( m_container != NULL )
+        m_container->disconnect( this );
+    m_container = item;
+    if ( item != NULL )
+    {
+        connect( item, SIGNAL( moved( qint64 ) ), this, SLOT( containerMoved( qint64 ) ) );
+    }
+}
diff --git a/src/Gui/timeline/GraphicsEffectItem.h b/src/Gui/timeline/GraphicsEffectItem.h
index 55aa4fc..62bba4f 100644
--- a/src/Gui/timeline/GraphicsEffectItem.h
+++ b/src/Gui/timeline/GraphicsEffectItem.h
@@ -27,11 +27,14 @@
 #include "EffectsEngine.h"
 
 class   EffectUser;
+class   AbstractGraphicsMediaItem;
 
 class   QUuid;
 
 class GraphicsEffectItem : public AbstractGraphicsItem
 {
+    Q_OBJECT
+
     public:
         enum { Type = UserType + 3 };
         GraphicsEffectItem( Effect *effect );
@@ -56,6 +59,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
         virtual qint64              itemHeight() const;
         virtual qint32              zSelected() const;
         virtual qint32              zNotSelected() const;
+        void                        setContainer( AbstractGraphicsMediaItem *item );
     protected:
         virtual bool                hasResizeBoundaries() const;
         /**
@@ -76,6 +80,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
     private:
         Effect                      *m_effect;
         EffectHelper                *m_effectHelper;
+        AbstractGraphicsMediaItem   *m_container;
 };
 
 #endif // GRAPHICSEFFECTITEM_H
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index 3280fa6..d9a0cc9 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -280,20 +280,39 @@ TracksView::addItem( TrackWorkflow *tw, Workflow::Helper *helper, qint64 start )
                      this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
         }
         item = mediaItem;
+        m_itemsLoaded.insert( helper->uuid() );
+        item->m_tracksView = this;
+        item->setHeight( item->itemHeight() );
+        item->setTrack( getTrack( trackType, track ) );
+        item->setStartPos( start );
+        item->m_oldTrack = tw;
+        moveItem( item, track, start );
     }
     else
     {
         EffectHelper    *effectHelper = qobject_cast<EffectHelper*>( helper );
         Q_ASSERT( effectHelper != NULL );
-        item = new GraphicsEffectItem( effectHelper );
+        GraphicsEffectItem *effectItem = new GraphicsEffectItem( effectHelper );
+        item = effectItem;
+        m_itemsLoaded.insert( helper->uuid() );
+        item->m_tracksView = this;
+        item->setHeight( item->itemHeight() );
+        item->setTrack( getTrack( trackType, track ) );
+        item->setStartPos( start );
+        item->m_oldTrack = tw;
+        moveItem( item, track, start );
+        QList<QGraphicsItem*>     collidingItems = item->collidingItems();
+        effectItem->setContainer( NULL );
+        foreach ( QGraphicsItem *collider, collidingItems )
+        {
+            AbstractGraphicsMediaItem   *mediaItem = dynamic_cast<AbstractGraphicsMediaItem*>( collider );
+            if ( mediaItem != NULL )
+            {
+                effectItem->setContainer( mediaItem );
+                break ;
+            }
+        }
     }
-    m_itemsLoaded.insert( helper->uuid() );
-    item->m_tracksView = this;
-    item->setHeight( item->itemHeight() );
-    item->setTrack( getTrack( trackType, track ) );
-    item->setStartPos( start );
-    item->m_oldTrack = tw;
-    moveItem( item, track, start );
     updateDuration();
 }
 
@@ -795,6 +814,7 @@ TracksView::dropEvent( QDropEvent *event )
                                                           item->clipHelper()->clipWorkflow() ) );
             m_dragEffectItem->m_oldTrack = item->track()->trackWorkflow();
             event->acceptProposedAction();
+            m_dragEffectItem->setContainer( item );
         }
         else
         {
@@ -813,6 +833,7 @@ TracksView::dropEvent( QDropEvent *event )
                                                                   track->trackWorkflow() ) );
 
                     event->acceptProposedAction();
+                    m_dragEffectItem->setContainer( NULL );
                     break ;
                 }
             }
@@ -1088,10 +1109,12 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
         qint64      targetPos = m_actionItem->startPos();
         if ( effectItem != NULL )
         {
+            effectItem->setContainer( NULL );
             if ( m_effectTarget != NULL )
             {
                 target = m_effectTarget->clipHelper()->clipWorkflow();
                 targetPos = m_actionItem->startPos() - m_effectTarget->startPos();
+                effectItem->setContainer( m_effectTarget );
             }
             UndoStack::getInstance()->beginMacro( "Move effect" );
         }



More information about the Vlmc-devel mailing list