Commit 1d93be59 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

TracksView: Refactoring clip resizing.

This doesn't require a clipHelper anymore.
parent b4d32e07
......@@ -28,6 +28,8 @@
#include <QGraphicsSceneEvent>
#include <QtDebug>
AbstractGraphicsItem::AbstractGraphicsItem() :
m_tracksView( NULL ),
m_oldTrack( NULL ),
......@@ -112,37 +114,50 @@ AbstractGraphicsItem::startPos()
return qRound64( QGraphicsItem::pos().x() );
}
qint64
AbstractGraphicsItem::resize( qint64 newSize, qint64 newBegin, qint64 clipPos,
From from )
void
AbstractGraphicsItem::resize( qint64 newSize, qint64 newMovingBoundary,
qint64 currentStillBoundary, From from )
{
if ( newSize < 1 )
return 1;
if ( hasResizeBoundaries() == true )
newSize = qMin( newSize, maxEnd() );
{
// if ( from == END )
// setStartPos( currentStillBoundary - 1 );
// setWidth( 1 );
return ;
}
//The from actually stands for the clip bound that stays still.
qint64 maxSize = maxEnd() - maxBegin();
//The "from" actually stands for the clip bound that stays still.
if ( from == BEGINNING )
{
if ( hasResizeBoundaries() == true )
{
if ( newBegin + newSize > maxEnd() )
return newBegin + maxEnd();
qint64 beginOffset = begin() - maxBegin();
qint64 absoluteStartPos = currentStillBoundary - beginOffset;
if ( absoluteStartPos + maxSize < newMovingBoundary )
{
setWidth( maxSize - beginOffset );
return ;
}
}
setWidth( newSize );
return newSize;
}
else
{
if ( hasResizeBoundaries() )
if ( hasResizeBoundaries() == true )
{
qint64 endOffset = maxEnd() - end();
qint64 absoluteEnd = currentStillBoundary + endOffset;
if ( newMovingBoundary < absoluteEnd - maxSize )
{
if ( maxBegin() > newBegin )
return maxBegin();
// qint64 size = end() - begin();
// setWidth( size );
// setStartPos( currentStillBoundary - size );
return ;
}
}
setWidth( newSize );
setStartPos( clipPos );
return newBegin;
setStartPos( newMovingBoundary );
}
}
......@@ -242,3 +257,9 @@ AbstractGraphicsItem::ungroup()
m_group->m_group = NULL;
m_group = NULL;
}
qint64
AbstractGraphicsItem::width() const
{
return m_width;
}
......@@ -90,11 +90,9 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
/**
* \brief Resize an item from its beginning or from its end.
*
* \returns A contextual info (depending on "from") to compute
* the new length. (Either the new beginning of the new length)
*/
qint64 resize( qint64 size, qint64 newBegin, qint64 clipPos, From from = BEGINNING );
void resize( qint64 newSize, qint64 newMovingBoundary,
qint64 currentStillBoundary, From from = BEGINNING );
/**
* \brief Return a pointer to the linked item.
......@@ -108,6 +106,10 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
/// Ungroup two items
void ungroup();
virtual qint64 begin() const = 0;
virtual qint64 end() const = 0;
qint64 width() const;
protected:
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
......
......@@ -259,3 +259,16 @@ AbstractGraphicsMediaItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
else if ( tracksView()->tool() == TOOL_CUT )
emit split( this, qRound64( event->pos().x() ) );
}
qint64
AbstractGraphicsMediaItem::begin() const
{
return m_clipHelper->begin();
}
qint64
AbstractGraphicsMediaItem::end() const
{
return m_clipHelper->end();
}
......@@ -53,6 +53,8 @@ public:
const ClipHelper* clipHelper() const;
virtual void setEmphasized( bool value );
virtual qint64 begin() const;
virtual qint64 end() const;
protected:
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* event );
......
......@@ -185,3 +185,17 @@ GraphicsEffectItem::effect()
{
return m_effect;
}
qint64
GraphicsEffectItem::begin() const
{
return 0;
}
qint64
GraphicsEffectItem::end() const
{
return -1;
}
......@@ -42,6 +42,8 @@ class GraphicsEffectItem : public AbstractGraphicsItem
QWidget *widget );
virtual Workflow::TrackType trackType() const;
Effect* effect();
virtual qint64 begin() const;
virtual qint64 end() const;
protected:
virtual bool hasResizeBoundaries() const;
......
......@@ -870,8 +870,12 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
event->buttons() == Qt::LeftButton &&
m_action == TracksView::Resize )
{
QPointF itemPos = m_actionItem->mapToScene( 0, 0 );
QPointF itemNewSize = mapToScene( event->pos() ) - itemPos;
qint64 itemPos = m_actionItem->mapToScene( 0, 0 ).x();
qint64 itemNewSize;
if ( m_actionResizeType == AbstractGraphicsItem::BEGINNING )
itemNewSize = mapToScene( event->pos() ).x() - itemPos;
else
itemNewSize = itemPos + m_actionItem->width() - mapToScene( event->pos() ).x();
qint32 trackId = m_actionItem->trackNumber();
Q_ASSERT( trackId >= 0 );
......@@ -881,7 +885,7 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
Q_ASSERT( track );
QPointF collidePos = track->sceneBoundingRect().topRight();
collidePos.setX( itemPos.x() + itemNewSize.x() );
collidePos.setX( itemPos + itemNewSize );
QList<QGraphicsItem*> gi = scene()->items( collidePos );
......@@ -896,23 +900,17 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
}
}
// END UGLY
if ( !collide )
{
if ( m_actionResizeType == AbstractGraphicsMediaItem::END )
if ( m_actionResizeType == AbstractGraphicsItem::END )
{
qint64 newBegin = m_actionItem->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->clipHelper()->end() - ret;
m_actionResizeNewBegin = mapToScene( event->pos() ).x();
m_actionItem->resize( itemNewSize, mapToScene( event->pos() ).x(),
itemPos + itemNewSize, AbstractGraphicsItem::END );
}
else
{
m_actionResizeSize = m_actionItem->resize( itemNewSize.x(),
m_actionItem->clipHelper()->begin(), 0, //This parameters is unused in this case.
AbstractGraphicsMediaItem::BEGINNING );
m_actionItem->resize( itemNewSize, itemPos + itemNewSize,
itemPos, AbstractGraphicsItem::BEGINNING );
}
}
}
......@@ -952,8 +950,6 @@ TracksView::mousePressEvent( QMouseEvent *event )
else
m_actionResizeType = AbstractGraphicsMediaItem::BEGINNING;
m_action = TracksView::Resize;
m_actionResizeOldBegin = item->pos().x();
m_actionResizeNewBegin = m_actionResizeOldBegin;
m_actionItem = item;
}
else if ( item->moveable() )
......@@ -1051,12 +1047,12 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
if ( m_actionResizeType == AbstractGraphicsMediaItem::END )
{
newEnd = ch->end();
newBegin = newEnd - m_actionResizeSize;
newBegin = newEnd - m_actionItem->width();
}
else
{
newBegin = ch->begin();
newEnd = newBegin + m_actionResizeSize;
newEnd = newBegin + m_actionItem->width();
}
Commands::trigger( new Commands::MainWorkflow::ResizeClip( m_actionItem->track()->trackWorkflow(),
ch, newBegin, newEnd,
......
......@@ -340,9 +340,6 @@ private:
// Mouse actions on Medias
Action m_action;
qint64 m_actionResizeOldBegin;
qint64 m_actionResizeNewBegin;
qint64 m_actionResizeSize;
int m_actionRelativeX;
AbstractGraphicsMediaItem::From m_actionResizeType;
AbstractGraphicsMediaItem *m_actionItem;
......
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