Commit 06727771 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Solved moving undo/redo problems

parent 9105f792
......@@ -62,7 +62,7 @@ namespace Commands
}
virtual void undo()
{
m_workflow->removeClip( m_clip->getUuid(), m_trackNumber );
m_workflow->removeClip( m_clip->getTimelineUuid(), m_trackNumber );
}
private:
::MainWorkflow* m_workflow;
......@@ -116,7 +116,7 @@ namespace Commands
virtual void redo()
{
for (int i = 0; i < m_clips.size(); ++i )
m_workflow->removeClip( m_clips.at( i ).clip->getUuid(), m_clips.at( i ).trackNumber );
m_workflow->removeClip( m_clips.at( i ).clip->getTimelineUuid(), m_clips.at( i ).trackNumber );
}
virtual void undo()
{
......
......@@ -148,3 +148,8 @@ void GraphicsMovieItem::updateTitle()
//FIXME there is a small visual refresh bug here
m_movieTitle->setPlainText( fm.elidedText( text, Qt::ElideRight, width ) );
}
void GraphicsMovieItem::setClip( Clip* clip )
{
m_clip = clip;
}
......@@ -39,13 +39,14 @@ public:
virtual int type() const { return Type; }
virtual bool expandable() const { return false; }
virtual bool moveable() const { return true; }
virtual const QUuid& uuid() const { return m_clip->getUuid(); }
virtual const QUuid& uuid() const { return m_clip->getTimelineUuid(); }
virtual QRectF boundingRect() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
void setWidth( int width );
void setHeight( int height );
Clip* clip() const;
void setClip( Clip* clip );
//void setAudioSpectrum( QVector<float*> spectrum );
void paintAudioSpectrum( QPainter* painter );
......
......@@ -144,6 +144,7 @@ void TracksView::dragEnterEvent( QDragEnterEvent* event )
m_dragItem->setHeight( tracksHeight() );
m_dragItem->setPos( mappedXPos, 0 );
m_dragItem->setParentItem( m_layout->itemAt( 0 )->graphicsItem() );
m_dragItem->oldPosition = mappedXPos;
moveMediaItem( m_dragItem, event->pos() );
}
......@@ -343,8 +344,10 @@ void TracksView::dropEvent( QDropEvent* event )
qreal mappedXPos = ( mapToScene( event->pos() ).x() + 0.5 );
m_dragItem->oldTrackNumber = m_dragItem->trackNumber();
Clip* clip = new Clip( m_dragItem->clip() );
m_dragItem->setClip( clip );
Commands::trigger( new Commands::MainWorkflow::AddClip( m_mainWorkflow,
m_dragItem->clip(),
clip,
m_dragItem->trackNumber(),
(qint64)mappedXPos ) );
m_dragItem = NULL;
......@@ -463,8 +466,9 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event )
updateDuration();
if ( m_layout->itemAt( 0 )->graphicsItem()->childItems().count() > 0 )
addVideoTrack();
qDebug() << "Moving from mouse event. New pos:" << (qint64)movieItem->pos().x() << movieItem->oldPosition;
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_mainWorkflow,
movieItem->clip()->getUuid(),
movieItem->clip()->getTimelineUuid(),
movieItem->oldTrackNumber,
movieItem->oldPosition,
movieItem->trackNumber(),
......
......@@ -44,6 +44,18 @@ Clip::Clip( Media* parent, float begin, float end ) : m_parent( parent ), m_begi
init();
}
Clip::Clip( Clip* clip ) :
m_parent( clip->m_parent ),
m_begin( clip->m_begin ),
m_end( clip->m_end ),
m_length( clip->m_length ),
m_lengthSeconds( clip->m_lengthSeconds ),
m_uuid( clip->m_uuid ),
m_metaTags( clip->m_metaTags ),
m_notes( clip->m_notes )
{
}
Clip::~Clip()
{
}
......@@ -52,7 +64,6 @@ void Clip::init()
{
m_uuid = QUuid::createUuid();
computeLength();
m_metaTags << "Toto" << "titi" << "tutu";
}
float Clip::getBegin() const
......@@ -136,3 +147,15 @@ void Clip::setNotes( const QString& notes )
{
m_notes = notes;
}
const QUuid& Clip::getTimelineUuid() const
{
Q_ASSERT( m_timelineUuid.isNull() == false );
return m_timelineUuid;
}
void Clip::setTimelineUuid( const QUuid& uuid )
{
m_timelineUuid = uuid;
qDebug() << "Setting timeline UUID to" << uuid;
}
......@@ -46,6 +46,7 @@ class Clip : public QObject
Clip( Media* parent );
Clip( Media* parent, float begin, float end );
Clip( Clip* creator, float begin, float end );
Clip( Clip* clip );
virtual ~Clip();
/**
......@@ -87,6 +88,7 @@ class Clip : public QObject
\return The Clip's Uuid as a QUuid
*/
const QUuid& getUuid() const;
const QUuid& getTimelineUuid() const;
const QStringList& getMetaTags() const;
void setMetaTags( const QStringList& tags );
......@@ -95,6 +97,7 @@ class Clip : public QObject
const QString& getNotes() const;
void setNotes( const QString& notes );
void setTimelineUuid( const QUuid& uuid );
private:
void computeLength();
......@@ -105,10 +108,20 @@ class Clip : public QObject
float m_end;
qint64 m_length;
qint64 m_lengthSeconds;
/**
* The Clip's UUID. It's used to identify the clip in the library.
*/
QUuid m_uuid;
/**
* The Clip's timeline UUID. Used to identify the Clip in the
* timeline, as a unique object, even if this clip is present more than
* once.
*/
QUuid m_timelineUuid;
QStringList m_metaTags;
QString m_notes;
};
#endif //CLIP_H__
......@@ -82,6 +82,7 @@ void MainWorkflow::addClip( Clip* clip, unsigned int trackId, qint64 start )
m_tracks[trackId]->addClip( clip, start );
if ( m_tracks[trackId]->getLength() > m_length )
m_length = m_tracks[trackId]->getLength();
clip->setTimelineUuid( QUuid::createUuid() );
}
void MainWorkflow::computeLength()
......
......@@ -91,7 +91,7 @@ qint64 TrackWorkflow::getClipPosition( const QUuid& uuid ) const
while ( it != end )
{
if ( it.value()->getClip()->getUuid() == uuid )
if ( it.value()->getClip()->getTimelineUuid() == uuid )
return it.key();
++it;
}
......@@ -374,7 +374,7 @@ void TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
while ( it != end )
{
if ( it.value()->getClip()->getUuid() == id )
if ( it.value()->getClip()->getTimelineUuid() == id )
{
ClipWorkflow* cw = it.value();
m_clips.erase( it );
......@@ -399,7 +399,7 @@ Clip* TrackWorkflow::removeClip( const QUuid& id )
while ( it != end )
{
if ( it.value()->getClip()->getUuid() == id )
if ( it.value()->getClip()->getTimelineUuid() == id )
{
ClipWorkflow* cw = it.value();
Clip* clip = cw->getClip();
......
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