[vlmc-devel] commit: Fixing resize for good. ( 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> | Sun Aug 29 15:45:59 2010 +0200| [9f112ac514f94a44a33dc48b5aaa076ac50e1eec] | committer: Hugo Beauzée-Luyssen 

Fixing resize for good.

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

 src/Gui/timeline/AbstractGraphicsMediaItem.cpp |   22 +++++++++------
 src/Gui/timeline/AbstractGraphicsMediaItem.h   |    5 ++-
 src/Gui/timeline/TracksView.cpp                |   33 ++++++++++++++++-------
 src/Gui/timeline/TracksView.h                  |    1 +
 4 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
index beab8fd..cf9ba6a 100644
--- a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
+++ b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
@@ -254,12 +254,13 @@ qint64 AbstractGraphicsMediaItem::startPos()
     return qRound64( QGraphicsItem::pos().x() );
 }
 
-bool  AbstractGraphicsMediaItem::resize( qint64 newSize, qint64 newBegin, From from )
+qint64  AbstractGraphicsMediaItem::resize( qint64 newSize, qint64 newBegin, qint64 clipPos,
+                                           From from )
 {
     Q_ASSERT( clipHelper() );
 
     if ( newSize < 1 )
-        return false;
+        return 1;
 
     if ( clipHelper()->clip()->getMedia()->fileType() != Media::Image )
         if ( newSize > clipHelper()->clip()->end() )
@@ -268,22 +269,25 @@ bool  AbstractGraphicsMediaItem::resize( qint64 newSize, qint64 newBegin, From f
     //The from actually stands for the clip bound that stays still.
     if ( from == BEGINNING )
     {
-        if ( clipHelper()->clip()->getMedia()->fileType() != Media::Image )
+        if ( m_clipHelper->clip()->getMedia()->fileType() != Media::Image )
         {
-            if ( clipHelper()->begin() + newSize > clipHelper()->clip()->end() )
-                return false;
+            if ( m_clipHelper->begin() + newSize > m_clipHelper->clip()->end() )
+                return m_clipHelper->length();
         }
         setWidth( newSize );
+        return newSize;
     }
     else
     {
         if ( m_clipHelper->clip()->getMedia()->fileType() != Media::Image )
-            if ( newBegin < 0 || m_clipHelper->clip()->begin() > newBegin )
-                return false;
+        {
+            if ( m_clipHelper->clip()->begin() > newBegin )
+                return m_clipHelper->clip()->begin();
+        }
         setWidth( newSize );
-        setStartPos( newBegin );
+        setStartPos( clipPos );
+        return newBegin;
     }
-    return true;
 }
 
 void AbstractGraphicsMediaItem::adjustLength()
diff --git a/src/Gui/timeline/AbstractGraphicsMediaItem.h b/src/Gui/timeline/AbstractGraphicsMediaItem.h
index c9150e9..e1f1863 100644
--- a/src/Gui/timeline/AbstractGraphicsMediaItem.h
+++ b/src/Gui/timeline/AbstractGraphicsMediaItem.h
@@ -105,9 +105,10 @@ public:
     /**
      * \brief    Resize an item from its beginning or from its end.
      *
-     *  \returns    True if the element may be resized.
+     *  \returns    A contextual info (depending on "from") to compute
+     *              the new length. (Either the new beginning of the new length)
      */
-    bool    resize( qint64 size, qint64 newBegin, From from = BEGINNING );
+    qint64      resize( qint64 size, qint64 newBegin, qint64 clipPos, From from = BEGINNING );
 
     ClipHelper  *clipHelper();
 
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index 19d14e4..76277b1 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -818,15 +818,17 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
         {
             if ( m_actionResizeType == AbstractGraphicsMediaItem::END )
             {
+                qint64  newBegin = m_actionItem->m_clipHelper->begin() + ( mapToScene( event->pos() ).x() - m_actionResizeOldBegin );
+                qint64  newSize = qMax( m_actionItem->clipHelper()->end() - newBegin, (qint64)0 );
+                qint64  ret = m_actionItem->resize( newSize, newBegin, m_actionResizeNewBegin,
+                                                    AbstractGraphicsMediaItem::END );
+                m_actionResizeSize = m_actionItem->m_clipHelper->end() - ret;
                 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
             {
-                if ( m_actionItem->resize( itemNewSize.x(), m_actionResizeNewBegin, AbstractGraphicsMediaItem::BEGINNING ) == true )
-                    m_actionResizeSize = itemNewSize.x();
+                m_actionResizeSize = m_actionItem->resize( itemNewSize.x(), 0, 0, //These parameters are unused in this case.
+                                                           AbstractGraphicsMediaItem::BEGINNING );
             }
         }
     }
@@ -866,7 +868,8 @@ TracksView::mousePressEvent( QMouseEvent *event )
             else
                 m_actionResizeType = AbstractGraphicsMediaItem::BEGINNING;
             m_actionResize = true;
-            m_actionResizeNewBegin = item->pos().x();
+            m_actionResizeOldBegin = item->pos().x();
+            m_actionResizeNewBegin = m_actionResizeOldBegin;
             m_actionItem = item;
         }
         else if ( item->moveable() )
@@ -957,11 +960,21 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
     else if ( m_actionResize )
     {
         ClipHelper *ch = m_actionItem->clipHelper();
-        qDebug() << "Putting clip in" << m_actionResizeNewBegin << "size:" << m_actionResizeSize;
+        qint64  newBegin;
+        qint64  newEnd;
+        if ( m_actionResizeType == AbstractGraphicsMediaItem::END )
+        {
+            newEnd = ch->end();
+            newBegin = newEnd - m_actionResizeSize;
+        }
+        else
+        {
+            newBegin = ch->begin();
+            newEnd = newBegin + m_actionResizeSize;
+        }
         Commands::trigger( new Commands::MainWorkflow::ResizeClip( m_actionItem->track()->trackWorkflow(),
-                                                                   ch, m_actionResizeNewBegin,
-                                                                   m_actionResizeNewBegin + m_actionResizeSize,
-                                                                   m_actionResizeNewBegin ) );
+                                                                   ch, newBegin, newEnd,
+                                                                   m_actionItem->pos().x() ) );
         updateDuration();
     }
 
diff --git a/src/Gui/timeline/TracksView.h b/src/Gui/timeline/TracksView.h
index 8fbe18d..968f84e 100644
--- a/src/Gui/timeline/TracksView.h
+++ b/src/Gui/timeline/TracksView.h
@@ -328,6 +328,7 @@ private:
     bool                    m_actionMove;
     bool                    m_actionMoveExecuted;
     bool                    m_actionResize;
+    qint64                  m_actionResizeOldBegin;
     qint64                  m_actionResizeNewBegin;
     qint64                  m_actionResizeSize;
     int                     m_actionRelativeX;



More information about the Vlmc-devel mailing list