Commit f27ec19b authored by Ludovic Fauvet's avatar Ludovic Fauvet

Add support for Clip/region deletion

An issue still remains in the undo/redo code and will be fixed asap.
parent 32ad1cf9
......@@ -56,7 +56,7 @@ namespace Commands
m_workflow->removeClip( m_clip->getUuid(), m_trackNumber );
}
private:
::MainWorkflow* m_workflow;
::MainWorkflow* m_workflow;
Clip* m_clip;
unsigned int m_trackNumber;
qint64 m_pos;
......@@ -95,6 +95,30 @@ namespace Commands
qint64 m_oldPos;
bool m_undoRedoAction;
};
NEW_COMMAND( RemoveClip )
{
public:
RemoveClip( ::MainWorkflow* workflow, Clip* clip, unsigned int trackNumber, qint64 pos ) :
m_workflow( workflow ), m_clip( clip ), m_trackNumber( trackNumber ), m_pos( pos )
{
setText( "Remove clip from track" + QString::number( trackNumber ) );
}
virtual void redo()
{
m_workflow->removeClip( m_clip->getUuid(), m_trackNumber );
}
virtual void undo()
{
m_workflow->addClip( m_clip, m_trackNumber, m_pos );
}
private:
::MainWorkflow* m_workflow;
Clip* m_clip;
unsigned int m_trackNumber;
qint64 m_pos;
};
}
}
......
......@@ -47,7 +47,7 @@ int AbstractGraphicsMediaItem::trackNumber()
{
if ( parentItem() )
{
GraphicsTrack* graphicsTrack = dynamic_cast<GraphicsTrack*>( parentItem() );
GraphicsTrack* graphicsTrack = qgraphicsitem_cast<GraphicsTrack*>( parentItem() );
if ( graphicsTrack )
return graphicsTrack->trackNumber();
}
......
......@@ -25,7 +25,10 @@
#include <QGraphicsItem>
#include <QUuid>
#include "TracksView.h"
#include <QCursor>
#include "GraphicsTrack.hpp"
class TracksView;
class AbstractGraphicsMediaItem : public QObject, public QGraphicsItem
{
......
......@@ -53,7 +53,13 @@ void TracksScene::keyPressEvent( QKeyEvent* keyEvent )
// Skip the deletion process
if ( b == QMessageBox::No ) return;
//TODO delete the item(s)
QList<QGraphicsItem*> items = selectedItems();
for (int i = 0; i < items.size(); ++i )
{
AbstractGraphicsMediaItem* item = qgraphicsitem_cast<AbstractGraphicsMediaItem*>( items.at(i) );
if ( !item ) return;
tv->removeMediaItem( item );
}
}
QGraphicsScene::keyPressEvent( keyEvent );
......
......@@ -34,6 +34,7 @@
#include "GraphicsMovieItem.h"
#include "GraphicsCursorItem.h"
#include "Commands.hpp"
#include "GraphicsTrack.hpp"
TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidget* parent )
: QGraphicsView( scene, parent ), m_scene( scene ), m_mainWorkflow( mainWorkflow )
......@@ -267,6 +268,23 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, qint
}
}
void TracksView::removeMediaItem( AbstractGraphicsMediaItem* item )
{
GraphicsMovieItem* movieItem = qgraphicsitem_cast<GraphicsMovieItem*>( item );
if ( !movieItem )
{
//TODO add support for audio tracks
qWarning( tr( "Action not supported." ).toAscii() );
return;
}
Commands::trigger( new Commands::MainWorkflow::RemoveClip( m_mainWorkflow,
movieItem->clip(),
movieItem->trackNumber(),
movieItem->pos().x() ) );
delete movieItem;
}
void TracksView::dragLeaveEvent( QDragLeaveEvent* event )
{
Q_UNUSED( event )
......
......@@ -34,47 +34,10 @@
#include "GraphicsCursorItem.h"
#include "MainWorkflow.h"
#include "TrackWorkflow.h"
#include "AbstractGraphicsMediaItem.h"
class GraphicsMovieItem;
class AbstractGraphicsMediaItem;
class GraphicsTrack : public QGraphicsWidget
{
Q_OBJECT
public:
enum { Type = UserType + 2 };
enum MediaType
{
Video,
Audio
};
GraphicsTrack( MediaType type, int trackNumber, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
{
m_type = type;
m_trackNumber = trackNumber;
}
int trackNumber()
{
return m_trackNumber;
}
virtual int type() const { return Type; }
protected:
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* = 0 )
{
if ( m_type == Video )
painter->setBrush( Qt::green );
else
painter->setBrush( Qt::blue );
painter->setPen( Qt::transparent );
painter->drawRect( rect() );
}
private:
MediaType m_type;
int m_trackNumber;
};
//class AbstractGraphicsMediaItem;
class TracksView : public QGraphicsView
{
......@@ -91,6 +54,7 @@ public:
GraphicsCursorItem* tracksCursor() const { return m_cursorLine; }
void setScale( double scaleFactor );
QList<AbstractGraphicsMediaItem*> mediaItems( const QPoint& pos );
void removeMediaItem( AbstractGraphicsMediaItem* item );
public slots:
void moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
......
......@@ -104,7 +104,8 @@ HEADERS += src/GUI/MainWindow.h \
src/GUI/ClipProperty.h \
src/GUI/WorkflowFileRendererDialog.h \
src/GUI/Settings.h \
src/GUI/Panel.h
src/GUI/Panel.h \
src/GUI/GraphicsTrack.hpp
FORMS += src/GUI/ui/MainWindow.ui \
src/GUI/ui/PreviewWidget.ui \
src/GUI/ui/LanguagePreferences.ui \
......
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