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