Commit 52f58b90 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Merge branch 'chouquette_commands'

Conflicts:
	src/renderer/WorkflowRenderer.cpp
	vlmc.pro
parents c9afff06 da4c0663
......@@ -22,7 +22,20 @@
#include "UndoStack.h"
UndoStack::UndoStack()
UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
{
setEmptyLabel( tr( "Nothing to undo" ) );
m_undoStack = new QUndoStack( this );
setStack( m_undoStack );
m_undoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+z", "Undo" ) ), this );
m_redoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+z", "Redo" ) ), this );
connect( m_undoShortcut, SIGNAL( activated() ), m_undoStack, SLOT( undo() ) );
connect( m_redoShortcut, SIGNAL( activated() ), m_undoStack, SLOT( redo() ) );
}
void UndoStack::push( QUndoCommand* command )
{
m_undoStack->push( command );
}
......@@ -24,16 +24,26 @@
#define UNDOSTACK_H
#include <QUndoStack>
#include "Singleton.hpp"
#include <QUndoView>
#include <QShortcut>
#include <QUndoCommand>
#include "QSingleton.hpp"
class UndoStack : public QUndoStack, public Singleton<UndoStack>
class UndoStack : public QUndoView, public QSingleton<UndoStack>
{
Q_OBJECT
Q_DISABLE_COPY( UndoStack );
public:
void push( QUndoCommand* command );
private:
UndoStack();
friend class Singleton<UndoStack>;
UndoStack( QWidget* parent );
QUndoStack* m_undoStack;
QShortcut* m_undoShortcut;
QShortcut* m_redoShortcut;
friend class QSingleton<UndoStack>;
};
#endif // UNDOSTACK_H
......@@ -193,6 +193,13 @@ qint64 MainWorkflow::getLength() const
return m_length;
}
qint64 MainWorkflow::getClipPosition( const QUuid& uuid, unsigned int trackId ) const
{
Q_ASSERT( trackId < m_trackCount );
return m_tracks[trackId]->getClipPosition( uuid );
}
void MainWorkflow::trackEndReached( unsigned int trackId )
{
m_tracks[trackId].deactivate();
......@@ -242,9 +249,10 @@ void MainWorkflow::deleteInstance()
}
}
void MainWorkflow::clipMoved( QUuid clipUuid, int oldTrack, int newTrack, qint64 startingFrame )
void MainWorkflow::moveClip( const QUuid& clipUuid, unsigned int oldTrack,
unsigned int newTrack, qint64 startingFrame, bool undoRedoCommand /*= false*/ )
{
Q_ASSERT( newTrack < m_trackCount && oldTrack < m_trackCount && oldTrack >= 0 && newTrack >= 0 );
Q_ASSERT( newTrack < m_trackCount && oldTrack < m_trackCount );
if ( oldTrack == newTrack )
{
......@@ -260,6 +268,20 @@ void MainWorkflow::clipMoved( QUuid clipUuid, int oldTrack, int newTra
m_tracks[newTrack].activate();
}
computeLength();
if ( undoRedoCommand == true )
{
qDebug() << "Emitted Clip moved: to track" << newTrack << "at pos" << startingFrame;
emit clipMoved( clipUuid, newTrack, startingFrame );
}
}
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()
......
......@@ -80,6 +80,10 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
static MainWorkflow* getInstance();
static void deleteInstance();
Clip* removeClip( const QUuid& uuid, unsigned int trackId );
void moveClip( const QUuid& uuid, unsigned int oldTrack,
unsigned int newTrack, qint64 pos, bool undoRedoCommand = false );
qint64 getClipPosition( const QUuid& uuid, unsigned int trackId ) const;
private:
static MainWorkflow* m_instance;
......@@ -107,9 +111,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
QWaitCondition* m_synchroneRenderWaitCondition;
QMutex* m_synchroneRenderWaitConditionMutex;
public slots:
void clipMoved( QUuid, int, int, qint64 );
private slots:
void trackEndReached( unsigned int trackId );
void trackPaused();
......@@ -127,6 +128,8 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
void mainWorkflowEndReached();
void mainWorkflowPaused();
void clipRemoved( QUuid, unsigned int );
void clipMoved( QUuid, unsigned int, qint64 );
};
#endif // MAINWORKFLOW_H
......@@ -82,6 +82,20 @@ qint64 TrackWorkflow::getLength() const
return m_length;
}
qint64 TrackWorkflow::getClipPosition( const QUuid& uuid ) const
{
QMap<qint64, ClipWorkflow*>::const_iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::const_iterator end = m_clips.end();
while ( it != end )
{
if ( it.value()->getClip()->getUuid() == uuid )
return it.key();
++it;
}
return -1;
}
unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
qint64 start , bool needRepositioning,
bool pauseAfterRender )
......
......@@ -58,6 +58,7 @@ class TrackWorkflow : public QObject
void addClip( Clip*, qint64 start );
void addClip( ClipWorkflow*, qint64 start );
void activateOneFrameOnly();
qint64 getClipPosition( const QUuid& uuid ) const;
/**
* Returns the output that has been computed in synchrone mode.
*/
......
/*****************************************************************************
* 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;
};
NEW_COMMAND( MoveClip )
{
public:
MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
unsigned int oldTrack, unsigned int newTrack, qint64 newPos ) :
m_workflow( workflow ), m_uuid( uuid ), m_oldTrack( oldTrack ), m_newTrack( newTrack ), m_pos( newPos )
{
setText( "Moving clip" );
m_oldPos = m_workflow->getClipPosition( uuid, oldTrack );
qDebug() << "Old pos == " << m_oldPos;
m_undoRedoAction = false;
}
virtual void redo()
{
qDebug() << "Moving from track" << m_oldTrack << "to" << m_newTrack << "at pos" << m_pos;
m_workflow->moveClip( m_uuid, m_oldTrack, m_newTrack, m_pos, m_undoRedoAction );
m_undoRedoAction = true;
}
virtual void undo()
{
qDebug() << "Moving from track" << m_newTrack << "to" << m_oldTrack << "at pos" << m_oldPos;
m_workflow->moveClip( m_uuid, m_newTrack, m_oldTrack, m_oldPos, m_undoRedoAction );
m_undoRedoAction = true;
}
private:
::MainWorkflow* m_workflow;
QUuid m_uuid;
unsigned int m_oldTrack;
unsigned int m_newTrack;
qint64 m_pos;
qint64 m_oldPos;
bool m_undoRedoAction;
};
}
}
#endif // COMMANDS_HPP
......@@ -2,13 +2,13 @@
#include "GraphicsCursorItem.h"
GraphicsCursorItem::GraphicsCursorItem( int height, const QPen& pen )
: m_height( height ), m_pen( pen )
: m_pen( pen )
{
setFlags( QGraphicsItem::ItemIgnoresTransformations | QGraphicsItem::ItemIsMovable );
setCursor( QCursor( Qt::SizeHorCursor ) );
setZValue( 100 );
m_boundingRect = QRectF( -2, 0, 3, m_height );
m_boundingRect = QRectF( -2, 0, 3, height );
}
QRectF GraphicsCursorItem::boundingRect() const
......@@ -19,7 +19,7 @@ QRectF GraphicsCursorItem::boundingRect() const
void GraphicsCursorItem::paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* )
{
painter->setPen( m_pen );
painter->drawLine( 0, 0, 0, m_height );
painter->drawLine( 0, 0, 0, m_boundingRect.height() );
}
QVariant GraphicsCursorItem::itemChange( GraphicsItemChange change, const QVariant& value )
......@@ -46,3 +46,9 @@ void GraphicsCursorItem::updateCursorPos( qint64 position )
{
setCursorPos( (qint64) position );
}
void GraphicsCursorItem::setHeight( int height )
{
m_boundingRect.setHeight( height );
update();
}
......@@ -17,13 +17,13 @@ public:
int cursorPos() const { return ( int )pos().x(); }
void setCursorPos( int position );
virtual QRectF boundingRect() const;
void setHeight( int height );
protected:
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
virtual QVariant itemChange( GraphicsItemChange change, const QVariant& value );
private:
int m_height;
QPen m_pen;
QRectF m_boundingRect;
......
......@@ -68,8 +68,6 @@ MainWindow::~MainWindow()
delete m_renderer;
MetaDataManager::destroyInstance();
LibVLCpp::Instance::kill();
UndoStack::destroyInstance();
UndoStack::destroyInstance();
}
void MainWindow::changeEvent( QEvent *e )
......@@ -170,7 +168,7 @@ void MainWindow::initializeDockWidgets( void )
QDockWidget::AllDockWidgetFeatures,
Qt::TopDockWidgetArea );
dockManager->addDockedWidget( new QUndoView( UndoStack::getInstance(), this),
dockManager->addDockedWidget( UndoStack::getInstance( this ),
tr( "History" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures,
......
......@@ -59,8 +59,7 @@ Timeline::Timeline( QWidget *parent ) :
setDuration( 0 );
connect( m_tracksView->horizontalScrollBar(), SIGNAL( valueChanged( int ) ), m_tracksRuler, SLOT( moveRuler( int ) ) );
connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
connect( m_tracksView, SIGNAL( clipMoved( QUuid, int, int, qint64) ),
MainWorkflow::getInstance(), SLOT( clipMoved( QUuid, int, int, qint64 ) ) );
connect( m_mainWorkflow, SIGNAL( clipMoved(QUuid, uint, qint64 ) ), m_tracksView, SLOT( moveMediaItem(QUuid, uint, qint64 ) ) );
}
Timeline::~Timeline()
......
......@@ -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 )
......@@ -45,7 +46,6 @@ TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidg
m_numAudioTrack = 0;
m_numVideoTrack = 0;
m_videoTracksCounter = MAX_TRACKS - 1;
m_dragItem = NULL;
m_actionMove = false;
m_actionRelativeX = -1;
......@@ -102,16 +102,17 @@ void TracksView::createLayout()
void TracksView::addVideoTrack()
{
GraphicsTrack* track = new GraphicsTrack( GraphicsTrack::Video, m_videoTracksCounter );
GraphicsTrack* track = new GraphicsTrack( GraphicsTrack::Video, m_numVideoTrack );
track->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
track->setPreferredHeight( m_tracksHeight );
track->setContentsMargins( 0, 0, 0, 0 );
m_layout->insertItem( 0, track );
QApplication::processEvents(); //FIXME This is a bit hackish
m_numVideoTrack++;
m_videoTracksCounter--;
m_scene->invalidate();
//FIXME this should maybe go elsewhere
setSceneRect( m_layout->contentsRect().adjusted( 0, 0, 100, 100 ) );
m_cursorLine->setHeight( m_layout->contentsRect().height() );
}
void TracksView::addAudioTrack()
......@@ -121,10 +122,12 @@ void TracksView::addAudioTrack()
track->setPreferredHeight( m_tracksHeight );
track->setContentsMargins( 0, 0, 0, 0 );
m_layout->insertItem( 1000, track );
QApplication::processEvents(); //FIXME This is a bit hackish
m_numAudioTrack++;
m_scene->invalidate();
//FIXME this should maybe go elsewhere
setSceneRect( m_layout->contentsRect().adjusted( 0, 0, 100, 100 ) );
m_cursorLine->setHeight( m_layout->contentsRect().height() );
}
void TracksView::dragEnterEvent( QDragEnterEvent* event )
......@@ -153,20 +156,48 @@ void TracksView::dragMoveEvent( QDragMoveEvent* event )
moveMediaItem( m_dragItem, event->pos() );
}
void TracksView::moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time )
{
QList<QGraphicsItem*> sceneItems = m_scene->items();
for ( int i = 0; i < sceneItems.size(); ++i )
{
AbstractGraphicsMediaItem* item =
dynamic_cast<AbstractGraphicsMediaItem*>( sceneItems.at( i ) );
if ( !item || item->uuid() != uuid ) continue;
moveMediaItem( item, track, time );
}
}
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position )
{
int track = (unsigned int)( mapToScene( position ).y() / m_tracksHeight );
GraphicsTrack* track = NULL;
QList<QGraphicsItem*> list = items( position );
for ( int i = 0; i < list.size(); ++i )
{
track = qgraphicsitem_cast<GraphicsTrack*>( list.at(i) );
if (track) break;
}
if (!track) return;
qreal time = ( mapToScene( position ).x() + 0.5 );
moveMediaItem( item, track->trackNumber(), (int)time);
}
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time )
{
if ( track < 0 )
track = 0;
else if ( track > m_numVideoTrack - 1)
track = m_numVideoTrack - 1;
qreal mappedXPos = ( mapToScene( position ).x() + 0.5 );
//qDebug() << ">>>>>> Move track number" << track;
QPointF oldPos = item->pos();
QGraphicsItem* oldParent = item->parentItem();
// Check for vertical collisions
item->setParentItem( m_layout->itemAt( track )->graphicsItem() );
item->setParentItem( m_layout->itemAt( m_numVideoTrack - track - 1 )->graphicsItem() );
bool continueSearch = true;
while ( continueSearch )
{
......@@ -179,7 +210,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position
{
// Collision with an item of the same type
itemCollision = true;
if ( currentItem->pos().y() < position.y() )
if ( currentItem->trackNumber() > track )
{
if ( track < 1 )
{
......@@ -191,7 +222,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position
Q_ASSERT( m_layout->itemAt( track )->graphicsItem() != NULL );
item->setParentItem( m_layout->itemAt( track )->graphicsItem() );
}
else if ( currentItem->pos().y() > position.y() )
else if ( currentItem->trackNumber() < track )
{
if ( track >= m_numVideoTrack - 1 )
{
......@@ -209,7 +240,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position
continueSearch = false;
}
// Check for horizontal collisions
mappedXPos = qMax( mappedXPos, (qreal)0 );
int mappedXPos = qMax( time, 0 );
item->setPos( mappedXPos, 0 );
QList<QGraphicsItem*> colliding = item->collidingItems( Qt::IntersectsItemShape );
for ( int i = 0; i < colliding.size(); ++i )
......@@ -248,9 +279,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;
}
}
......@@ -361,10 +393,10 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event )
updateDuration();
if ( m_layout->itemAt( 0 )->graphicsItem()->childItems().count() > 0 )
addVideoTrack();
emit clipMoved( movieItem->clip()->getUuid(),
movieItem->oldTrackNumber,
movieItem->trackNumber(),
(qint64)movieItem->pos().x() );
qDebug() << "Trigerring move command. track" << movieItem->oldTrackNumber << "->" << movieItem->trackNumber();
Commands::trigger( new Commands::MainWorkflow::MoveClip( m_mainWorkflow, movieItem->clip()->getUuid(),
movieItem->oldTrackNumber, movieItem->trackNumber(),
(qint64)movieItem->pos().x() ) );
movieItem->oldTrackNumber = movieItem->trackNumber();
m_actionMove = false;
m_actionRelativeX = -1;
......
......@@ -30,10 +30,11 @@
#include <QGraphicsWidget>
#include <QWheelEvent>
#include <QGraphicsSceneDragDropEvent>
#include <QApplication>
#include "Media.h"
#include "GraphicsCursorItem.h"
#include "Workflow/MainWorkflow.h"
#include "Workflow/TrackWorkflow.h"
#include "MainWorkflow.h"
#include "TrackWorkflow.h"
class GraphicsMovieItem;
class AbstractGraphicsMediaItem;
......@@ -43,12 +44,13 @@ class GraphicsTrack : public QGraphicsWidget
Q_OBJECT
public:
enum Type
enum { Type = UserType + 2 };
enum MediaType
{
Video,
Audio
};
GraphicsTrack( Type type, int trackNumber, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
GraphicsTrack( MediaType type, int trackNumber, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
{
m_type = type;
m_trackNumber = trackNumber;
......@@ -57,6 +59,7 @@ public:
{
return m_trackNumber;
}
virtual int type() const { return Type; }
protected:
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* = 0 )
......@@ -70,7 +73,7 @@ protected:
}
private:
Type m_type;
MediaType m_type;
int m_trackNumber;
};
......@@ -90,6 +93,9 @@ public:
void setScale( double scaleFactor );
QList<AbstractGraphicsMediaItem*> mediaItems( const QPoint& pos );
public slots:
void moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void drawBackground( QPainter* painter, const QRectF& rect );
......@@ -111,6 +117,7 @@ private:
void addVideoTrack();
void addAudioTrack();
void moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position );
void moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time );
QGraphicsScene* m_scene;
int m_tracksHeight;
unsigned int m_tracksCount;
......@@ -120,7 +127,6 @@ private:
QGraphicsLinearLayout* m_layout;
int m_numVideoTrack;
int m_numAudioTrack;
int m_videoTracksCounter;
MainWorkflow* m_mainWorkflow;
GraphicsMovieItem* m_dragItem;
QGraphicsWidget* m_separator;
......@@ -134,7 +140,6 @@ signals:
void zoomIn();
void zoomOut();
void durationChanged( int duration );
void clipMoved( const QUuid& uuid, int oldTrack, int newTrack, qint64 start );
};
#endif // TRACKSVIEW_H
/*****************************************************************************
* QSingleton.hpp : Generic singleton pattern implementation with Qt parent's
* parameter that can be passed to the ctor
*****************************************************************************
* 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.
*****************************************************************************/
/** \file
* This file contain the templated singleton.
* Class/struct to be singletonized just have to
* iherit from this classe with the class/struct type in template
* parameter.You have to do few other things, but you know your job,
* don't you :) ?
*/
#ifndef QSINGLETON_HPP
#define QSINGLETON_HPP
#include <stdlib.h>
#include <QWidget>
template <typename T>
class QSingleton
{
public:
static T* getInstance( QWidget* parent = NULL )
{
if ( m_instance == NULL )
m_instance = new T( parent );
return m_instance;
}
static void destroyInstance()
{
if ( m_instance != NULL )
{
delete m_instance;
m_instance = NULL;
}
}
protected:
QSingleton(){}
virtual ~QSingleton(){}
//Not implemented since these methods should *NEVER* been called. If they do, it probably won't compile :)
QSingleton(const QSingleton<T>&);
QSingleton<T>& operator=(const QSingleton<T>&);
private:
static T* m_instance;
};
template <typename T>
T* QSingleton<T>::m_instance = NULL;
#endif // QSINGLETON_HPP
......@@ -32,6 +32,8 @@
#ifndef SINGLETON_HPP
#define SINGLETON_HPP
#include <stdlib.h>
template <typename T>
class Singleton
{
......
......@@ -95,7 +95,9 @@ HEADERS += src/gui/MainWindow.h \
src/UndoStack.h \
src/tools/WaitCondition.hpp \
src/metadata/MetaDataManager.h \
src/gui/MediaProperty.h
src/gui/MediaProperty.h \
src/commands/Commands.hpp \
src/tools/QSingleton.hpp
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui \
......@@ -116,6 +118,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