Commit 9f112ac5 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Fixing resize for good.

parent 599c83bc
......@@ -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()
......
......@@ -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();
......
......@@ -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();
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment