[vlmc-devel] commit: Improving resize behaviour. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sun Aug 29 15:51:48 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Fri Aug 27 01:46:49 2010 +0200| [599c83bc3d29b7358e60e0022aaff175251e117c] | committer: Hugo Beauzée-Luyssen 

Improving resize behaviour.

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

 src/Gui/timeline/AbstractGraphicsMediaItem.cpp |   51 +++++++++--------------
 src/Gui/timeline/AbstractGraphicsMediaItem.h   |    8 +++-
 src/Gui/timeline/TracksView.cpp                |   21 +++++-----
 src/Gui/timeline/TracksView.h                  |    4 +-
 4 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
index 585f1f5..beab8fd 100644
--- a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
+++ b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
@@ -35,6 +35,9 @@
 #include <QColorDialog>
 #include <QGraphicsSceneContextMenuEvent>
 
+#include <QCoreApplication>
+#include <QtDebug>
+
 AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
         m_oldTrack( NULL ),
         oldPosition( -1 ),
@@ -251,50 +254,36 @@ qint64 AbstractGraphicsMediaItem::startPos()
     return qRound64( QGraphicsItem::pos().x() );
 }
 
-void AbstractGraphicsMediaItem::resize( qint64 size, From from )
+bool  AbstractGraphicsMediaItem::resize( qint64 newSize, qint64 newBegin, From from )
 {
     Q_ASSERT( clipHelper() );
 
-    if ( size < 1 )
-        return;
+    if ( newSize < 1 )
+        return false;
 
     if ( clipHelper()->clip()->getMedia()->fileType() != Media::Image )
-        if ( size > clipHelper()->clip()->end() )
-            size = clipHelper()->clip()->end();
+        if ( newSize > clipHelper()->clip()->end() )
+            newSize = clipHelper()->clip()->end();
 
-    if ( from == BEGINNING ) //Inverted logic ?!
+    //The from actually stands for the clip bound that stays still.
+    if ( from == BEGINNING )
     {
         if ( clipHelper()->clip()->getMedia()->fileType() != Media::Image )
-            if ( clipHelper()->begin() + size > clipHelper()->clip()->end() )
-                return;
-        m_clipHelper->setEnd( m_clipHelper->begin() + size );
+        {
+            if ( clipHelper()->begin() + newSize > clipHelper()->clip()->end() )
+                return false;
+        }
+        setWidth( newSize );
     }
     else
     {
         if ( m_clipHelper->clip()->getMedia()->fileType() != Media::Image )
-        {
-            qint64 newBegin = qMax( m_clipHelper->end() - size, (qint64)0 );
-            if ( m_clipHelper->clip()->begin() > newBegin )
-                return;
-
-            qint64 oldLength = m_clipHelper->length();
-            qint64  newStart = startPos() + ( oldLength - size );
-            if ( newStart < 0 )
-                return ;
-            track()->trackWorkflow()->moveClip( m_clipHelper->uuid(), newStart );
-            m_clipHelper->setBegin( m_clipHelper->end() - size );
-            setStartPos( newStart );
-        }
-        else
-        {
-            qint64 oldLength = m_clipHelper->length();
-            track()->trackWorkflow()->moveClip( m_clipHelper->uuid(), startPos() + ( oldLength - size ) );
-            m_clipHelper->setBegin( startPos() + ( oldLength - size ) );
-            setStartPos( startPos() + ( oldLength - size ) );
-        }
+            if ( newBegin < 0 || m_clipHelper->clip()->begin() > newBegin )
+                return false;
+        setWidth( newSize );
+        setStartPos( newBegin );
     }
-
-    setWidth( m_clipHelper->length() );
+    return true;
 }
 
 void AbstractGraphicsMediaItem::adjustLength()
diff --git a/src/Gui/timeline/AbstractGraphicsMediaItem.h b/src/Gui/timeline/AbstractGraphicsMediaItem.h
index f26922d..c9150e9 100644
--- a/src/Gui/timeline/AbstractGraphicsMediaItem.h
+++ b/src/Gui/timeline/AbstractGraphicsMediaItem.h
@@ -102,8 +102,12 @@ public:
     /// Return the position of the item (in frames) for the x-axis.
     qint64 startPos();
 
-    /// Resize an item from its beginning or from its end.
-    void resize( qint64 size, From from = BEGINNING );
+    /**
+     * \brief    Resize an item from its beginning or from its end.
+     *
+     *  \returns    True if the element may be resized.
+     */
+    bool    resize( qint64 size, qint64 newBegin, From from = BEGINNING );
 
     ClipHelper  *clipHelper();
 
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index 1fe1388..19d14e4 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -818,13 +818,15 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
         {
             if ( m_actionResizeType == AbstractGraphicsMediaItem::END )
             {
-                qint64 distance = mapToScene( event->pos() ).x() - m_actionResizeStart;
-                qint64 newsize = qMax( m_actionResizeBase - distance, (qint64)0 );
-                m_actionItem->resize( newsize , AbstractGraphicsMediaItem::END );
+                m_actionResizeNewBegin = mapToScene( event->pos() ).x();
+                qint64 newSize = qMax( (qint64)(m_actionItem->clipHelper()->length() - mapToScene( event->pos() ).x()), (qint64)0 );
+                if ( m_actionItem->resize( newSize, mapToScene( event->pos() ).x(), AbstractGraphicsMediaItem::END ) == true )
+                    m_actionResizeSize = newSize;
             }
             else
             {
-                m_actionItem->resize( itemNewSize.x(), AbstractGraphicsMediaItem::BEGINNING );
+                if ( m_actionItem->resize( itemNewSize.x(), m_actionResizeNewBegin, AbstractGraphicsMediaItem::BEGINNING ) == true )
+                    m_actionResizeSize = itemNewSize.x();
             }
         }
     }
@@ -864,8 +866,7 @@ TracksView::mousePressEvent( QMouseEvent *event )
             else
                 m_actionResizeType = AbstractGraphicsMediaItem::BEGINNING;
             m_actionResize = true;
-            m_actionResizeStart = mapToScene( event->pos() ).x();
-            m_actionResizeBase = item->clipHelper()->length();
+            m_actionResizeNewBegin = item->pos().x();
             m_actionItem = item;
         }
         else if ( item->moveable() )
@@ -956,11 +957,11 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
     else if ( m_actionResize )
     {
         ClipHelper *ch = m_actionItem->clipHelper();
-        //This is a "pointless action". The resize already occurred. However, by doing this
-        //we can have an undo action.
+        qDebug() << "Putting clip in" << m_actionResizeNewBegin << "size:" << m_actionResizeSize;
         Commands::trigger( new Commands::MainWorkflow::ResizeClip( m_actionItem->track()->trackWorkflow(),
-                                                                   ch, ch->begin(), ch->end(),
-                                                                   m_actionItem->pos().x() ) );
+                                                                   ch, m_actionResizeNewBegin,
+                                                                   m_actionResizeNewBegin + m_actionResizeSize,
+                                                                   m_actionResizeNewBegin ) );
         updateDuration();
     }
 
diff --git a/src/Gui/timeline/TracksView.h b/src/Gui/timeline/TracksView.h
index da5e43c..8fbe18d 100644
--- a/src/Gui/timeline/TracksView.h
+++ b/src/Gui/timeline/TracksView.h
@@ -328,8 +328,8 @@ private:
     bool                    m_actionMove;
     bool                    m_actionMoveExecuted;
     bool                    m_actionResize;
-    qint64                  m_actionResizeStart;
-    qint64                  m_actionResizeBase;
+    qint64                  m_actionResizeNewBegin;
+    qint64                  m_actionResizeSize;
     int                     m_actionRelativeX;
     AbstractGraphicsMediaItem::From m_actionResizeType;
     AbstractGraphicsMediaItem       *m_actionItem;



More information about the Vlmc-devel mailing list