Commit 188de93c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Refactoring clip resizing.

parent 54c2f9ef
......@@ -122,46 +122,38 @@ void Commands::MainWorkflow::RemoveClip::undo()
m_trackWorkflow->addClip( m_clipHelper, m_pos );
}
Commands::MainWorkflow::ResizeClip::ResizeClip( ClipHelper* clipHelper,
Commands::MainWorkflow::ResizeClip::ResizeClip( TrackWorkflow* tw,
ClipHelper* ch,
qint64 newBegin, qint64 newEnd,
qint64 oldBegin, qint64 oldEnd,
qint64 newPos, qint64 oldPos,
quint32 trackId,
Workflow::TrackType trackType ) :
qint64 newPos ) :
m_trackWorkflow( tw ),
m_clipHelper( ch ),
m_newBegin( newBegin ),
m_newEnd( newEnd ),
m_oldBegin( oldBegin ),
m_oldEnd( oldEnd ),
m_newPos( newPos ),
m_oldPos( oldPos ),
m_trackId( trackId ),
m_clipHelper( clipHelper ),
m_trackType( trackType ),
m_undoRedoAction( false )
m_newPos( newPos )
{
m_oldBegin = ch->begin();
m_oldEnd = ch->end();
m_oldPos = tw->getClipPosition( ch->uuid() );
setText( QObject::tr( "Resizing clip" ) );
}
void Commands::MainWorkflow::ResizeClip::redo()
{
::MainWorkflow::getInstance()->resizeClip( m_clipHelper, m_newBegin, m_newEnd, m_newPos, m_trackId, m_trackType, m_undoRedoAction );
m_undoRedoAction = true;
if ( m_newBegin != m_newEnd )
{
m_trackWorkflow->moveClip( m_clipHelper->uuid(), m_newPos );
}
m_clipHelper->setBoundaries( m_newBegin, m_newEnd );
}
void Commands::MainWorkflow::ResizeClip::undo()
{
//This code is complete crap.
// We need to case, because when we redo a "begin-resize", we need to first resize, then move.
//In the other cases, we need to move, then resize.
if ( m_oldBegin == m_newBegin )
{
::MainWorkflow::getInstance()->resizeClip( m_clipHelper, m_oldBegin, m_oldEnd, m_oldPos, m_trackId, m_trackType, m_undoRedoAction );
}
else
if ( m_oldBegin != m_newBegin )
{
m_clipHelper->setBoundaries( m_oldBegin, m_oldEnd );
// ::MainWorkflow::getInstance()->moveClip( m_clipHelper->uuid(), m_trackId, m_trackId, m_oldPos, m_trackType, m_undoRedoAction );
m_trackWorkflow->moveClip( m_clipHelper->uuid(), m_oldPos );
}
m_clipHelper->setBoundaries( m_oldBegin, m_oldEnd );
}
Commands::MainWorkflow::SplitClip::SplitClip( ClipHelper* toSplit, quint32 trackId,
......
......@@ -104,35 +104,27 @@ namespace Commands
/**
* \brief This command is used to resize a clip.
* \param uuid: The clip's uuid
* \param newBegin: The clip's new beginning
* \param newEnd: The clip's new end
* \param newPos: if the clip was resized from the beginning, it is moved
* so we have to know its new position
* \param trackId:The track in which the modification occurs. This is only
* used when the clip is resized from the beginning.
* \param trackType: The track's type (Audio or Video)
*/
NEW_COMMAND( ResizeClip )
{
public:
ResizeClip( ClipHelper* clipHelper,
qint64 newBegin, qint64 newEnd, qint64 oldBegin,
qint64 oldEnd, qint64 newPos, qint64 oldPos,
quint32 trackId, Workflow::TrackType trackType );
ResizeClip( TrackWorkflow* tw, ClipHelper* clipHelper,
qint64 newBegin, qint64 newEnd, qint64 newPos );
virtual void redo();
virtual void undo();
private:
TrackWorkflow* m_trackWorkflow;
ClipHelper* m_clipHelper;
qint64 m_newBegin;
qint64 m_newEnd;
qint64 m_oldBegin;
qint64 m_oldEnd;
qint64 m_newPos;
qint64 m_oldPos;
quint32 m_trackId;
ClipHelper* m_clipHelper;
Workflow::TrackType m_trackType;
bool m_undoRedoAction;
};
NEW_COMMAND( SplitClip )
......
......@@ -264,14 +264,12 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
if ( size > clipHelper()->clip()->end() )
size = clipHelper()->clip()->end();
if ( from == BEGINNING )
if ( from == BEGINNING ) //Inverted logic ?!
{
if ( clipHelper()->clip()->getMedia()->fileType() != Media::Image )
if ( clipHelper()->begin() + size > clipHelper()->clip()->end() )
return;
MainWorkflow::getInstance()->resizeClip( m_clipHelper, m_clipHelper->begin(),
m_clipHelper->begin() + size, 0,
trackNumber(), mediaType() );
m_clipHelper->setEnd( m_clipHelper->begin() + size );
}
else
{
......@@ -286,9 +284,8 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
qint64 newStart = startPos() + ( oldLength - size );
if ( newStart < 0 )
return ;
MainWorkflow::getInstance()->resizeClip( m_clipHelper, qMax( m_clipHelper->end() - size,
(qint64)0 ), m_clipHelper->end(),
newStart, trackNumber(), mediaType() );
track()->trackWorkflow()->moveClip( m_clipHelper->uuid(), newStart );
m_clipHelper->setBegin( m_clipHelper->end() - size );
setStartPos( newStart );
}
else
......@@ -301,8 +298,8 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
// startPos() + ( oldLength - size ),
//
// ))
MainWorkflow::getInstance()->resizeClip( m_clipHelper, 0, size, startPos() + ( oldLength - size ),
trackNumber(), mediaType() );
track()->trackWorkflow()->moveClip( m_clipHelper->uuid(), startPos() + ( oldLength - size ) );
m_clipHelper->setBegin( startPos() + ( oldLength - size ) );
setStartPos( startPos() + ( oldLength - size ) );
}
}
......
......@@ -155,14 +155,6 @@ void Timeline::setTool( ToolButtons button )
tracksView()->setTool( button );
}
//void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, Workflow::TrackType )
//{
// tracksView()->moveMediaItem( uuid, track, time );
// Q_ASSERT( tracksView()->setItemOldTrack( uuid, track ) == true );
// tracksView()->updateDuration();
// tracksRuler()->update();
//}
void
Timeline::save( QXmlStreamWriter &project ) const
{
......
......@@ -876,7 +876,6 @@ TracksView::mousePressEvent( QMouseEvent *event )
m_actionResize = true;
m_actionResizeStart = mapToScene( event->pos() ).x();
m_actionResizeBase = item->clipHelper()->length();
m_actionResizeOldBegin = item->clipHelper()->begin();
m_actionItem = item;
}
else if ( item->moveable() )
......@@ -969,11 +968,9 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
ClipHelper *ch = m_actionItem->clipHelper();
//This is a "pointless action". The resize already occurred. However, by doing this
//we can have an undo action.
Commands::trigger( new Commands::MainWorkflow::ResizeClip( ch, ch->begin(),
ch->end(),
m_actionResizeOldBegin, m_actionResizeOldBegin + m_actionResizeBase,
m_actionItem->pos().x(), m_actionResizeStart,
m_actionItem->trackNumber(), m_actionItem->mediaType() ) );
Commands::trigger( new Commands::MainWorkflow::ResizeClip( m_actionItem->track()->trackWorkflow(),
ch, ch->begin(), ch->end(),
m_actionItem->pos().x() ) );
updateDuration();
}
......
......@@ -334,7 +334,6 @@ private:
bool m_actionResize;
qint64 m_actionResizeStart;
qint64 m_actionResizeBase;
qint64 m_actionResizeOldBegin;
int m_actionRelativeX;
AbstractGraphicsMediaItem::From m_actionResizeType;
AbstractGraphicsMediaItem *m_actionItem;
......
......@@ -412,20 +412,6 @@ MainWorkflow::setFullSpeedRender( bool val )
// return newClip;
//}
void
MainWorkflow::resizeClip( ClipHelper* clipHelper, qint64 newBegin, qint64 newEnd, qint64 newPos,
quint32 trackId, Workflow::TrackType trackType,
bool undoRedoAction /*= false*/ )
{
QMutexLocker lock( m_renderStartedMutex );
if ( newBegin != clipHelper->begin() )
{
// moveClip( clipHelper->uuid(), trackId, trackId, newPos, trackType, undoRedoAction );
}
clipHelper->setBoundaries( newBegin, newEnd );
}
void
MainWorkflow::unsplit( ClipHelper* origin, ClipHelper* splitted, quint32 trackId,
Workflow::TrackType trackType )
......
......@@ -240,11 +240,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
// qint64 newClipPos, qint64 newClipBegin,
// Workflow::TrackType trackType );
void resizeClip( ClipHelper* clipHelper, qint64 newBegin, qint64 newEnd,
qint64 newPos, quint32 trackId,
Workflow::TrackType trackType,
bool undoRedoAction = false );
void unsplit( ClipHelper* origin, ClipHelper* splitted, quint32 trackId,
Workflow::TrackType trackType );
......
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