Commit 5afc10e8 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Implemented Command patern, with undo redo

This works for adding/removing clip
parent 72a5bf84
......@@ -264,6 +264,15 @@ void MainWorkflow::clipMoved( QUuid clipUuid, int oldTrack, int newTra
computeLength();
}
Clip* MainWorkflow::removeClip( const QUuid& uuid, unsigned int trackId )
{
Q_ASSERT( trackId < m_trackCount );
Clip* clip = m_tracks[trackId]->removeClip( uuid );
emit clipRemoved( uuid, trackId );
return clip;
}
void MainWorkflow::activateOneFrameOnly()
{
for (unsigned int i = 0; i < m_trackCount; ++i)
......
......@@ -80,6 +80,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
static MainWorkflow* getInstance();
static void deleteInstance();
Clip* removeClip( const QUuid& uuid, unsigned int trackId );
private:
static MainWorkflow* m_instance;
......@@ -127,6 +128,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
void mainWorkflowEndReached();
void mainWorkflowPaused();
void clipRemoved( QUuid, unsigned int );
};
#endif // MAINWORKFLOW_H
/*****************************************************************************
* CommandManager.h: Manage the VLMC command pattern implementation
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef COMMANDMANAGER_H
#define COMMANDMANAGER_H
#include "Singleton.hpp"
#include "Command.h"
class CommandManager : public Singleton<CommandManager>
{
void triggerCommand( Command* command );
private:
ActionManager();
~ActionManager();
};
#endif // ACTIONMANAGER_H
/*****************************************************************************
* Commands.h: Contains all the implementation of VLMC commands.
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef COMMANDS_HPP
#define COMMANDS_HPP
#include <QUndoCommand>
#include "UndoStack.h"
#include "MainWorkflow.h"
#include "Clip.h"
#define NEW_COMMAND(x) class x : public QUndoCommand
namespace Commands
{
void trigger( QUndoCommand* command )
{
UndoStack::getInstance()->push( command );
}
namespace MainWorkflow
{
NEW_COMMAND( AddClip )
{
public:
AddClip( ::MainWorkflow* workflow, Clip* clip, unsigned int trackNumber, qint64 pos ) :
m_workflow( workflow ), m_clip( clip ), m_trackNumber( trackNumber ), m_pos( pos )
{
setText( "Adding clip to track" + QString::number( trackNumber ) );
}
virtual void redo()
{
m_workflow->addClip( m_clip, m_trackNumber, m_pos );
}
virtual void undo()
{
m_workflow->removeClip( m_clip->getUuid(), m_trackNumber );
}
private:
::MainWorkflow* m_workflow;
Clip* m_clip;
unsigned int m_trackNumber;
qint64 m_pos;
};
}
}
#endif // COMMANDS_HPP
......@@ -68,7 +68,6 @@ MainWindow::~MainWindow()
MetaDataManager::destroyInstance();
LibVLCpp::Instance::kill();
UndoStack::destroyInstance();
UndoStack::destroyInstance();
}
void MainWindow::changeEvent( QEvent *e )
......
......@@ -33,6 +33,7 @@
#include "Library.h"
#include "GraphicsMovieItem.h"
#include "GraphicsCursorItem.h"
#include "Commands.hpp"
TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidget* parent )
: QGraphicsView( scene, parent ), m_scene( scene ), m_mainWorkflow( mainWorkflow )
......@@ -249,9 +250,10 @@ void TracksView::dropEvent( QDropEvent* event )
qreal mappedXPos = ( mapToScene( event->pos() ).x() + 0.5 );
m_dragItem->oldTrackNumber = m_dragItem->trackNumber();
m_mainWorkflow->addClip( m_dragItem->clip(),
m_dragItem->trackNumber(),
(qint64)mappedXPos );
Commands::trigger( new Commands::MainWorkflow::AddClip( m_mainWorkflow,
m_dragItem->clip(),
m_dragItem->trackNumber(),
(qint64)mappedXPos ) );
m_dragItem = NULL;
}
}
......
......@@ -32,8 +32,8 @@
#include <QGraphicsSceneDragDropEvent>
#include "Media.h"
#include "GraphicsCursorItem.h"
#include "Workflow/MainWorkflow.h"
#include "Workflow/TrackWorkflow.h"
#include "MainWorkflow.h"
#include "TrackWorkflow.h"
class GraphicsMovieItem;
class AbstractGraphicsMediaItem;
......
......@@ -95,7 +95,8 @@ void* WorkflowRenderer::lock( void* datas )
}
if ( self->m_oneFrameOnly < 2 )
{
void* ret = self->m_mainWorkflow->getSynchroneOutput();
// void* ret = self->m_mainWorkflow->getSynchroneOutput();
void* ret = self->m_mainWorkflow->getOutput();
self->m_lastFrame = static_cast<unsigned char*>( ret );
qDebug() << "Returning new frame";
return ret;
......
......@@ -32,6 +32,8 @@
#ifndef SINGLETON_HPP
#define SINGLETON_HPP
#include <stdlib.h>
template <typename T>
class Singleton
{
......
......@@ -93,7 +93,8 @@ HEADERS += src/gui/MainWindow.h \
src/tools/Pool.hpp \
src/UndoStack.h \
src/tools/WaitCondition.hpp \
src/metadata/MetaDataManager.h
src/metadata/MetaDataManager.h \
src/commands/Commands.hpp
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui \
......@@ -113,6 +114,8 @@ INCLUDEPATH += src/LibVLCpp \
src/tools \
src/renderer \
src/metadata \
src/commands \
src/Workflow \
src
# QMAKE_CFLAGS+=-pg
......
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