Commit 21341f42 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen
Browse files

Solved problem when do/undo clip moving

parent 43b1a751
......@@ -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
......@@ -251,7 +251,8 @@ void MainWorkflow::deleteInstance()
}
}
void MainWorkflow::moveClip( const QUuid& clipUuid, unsigned int oldTrack, unsigned 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 );
......@@ -269,7 +270,11 @@ void MainWorkflow::moveClip( const QUuid& clipUuid, unsigned int oldTr
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 )
......
......@@ -82,7 +82,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
static void deleteInstance();
Clip* removeClip( const QUuid& uuid, unsigned int trackId );
void moveClip( const QUuid& uuid, unsigned int oldTrack,
unsigned int newTrack, qint64 pos );
unsigned int newTrack, qint64 pos, bool undoRedoCommand = false );
qint64 getClipPosition( const QUuid& uuid, unsigned int trackId ) const;
private:
......
......@@ -71,14 +71,20 @@ namespace Commands
{
setText( "Moving clip" );
m_oldPos = m_workflow->getClipPosition( uuid, oldTrack );
qDebug() << "Old pos == " << m_oldPos;
m_undoRedoAction = false;
}
virtual void redo()
{
m_workflow->moveClip( m_uuid, m_oldTrack, m_newTrack, m_pos );
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()
{
m_workflow->moveClip( m_uuid, m_newTrack, m_oldTrack, m_oldPos );
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:
......@@ -88,6 +94,7 @@ namespace Commands
unsigned int m_newTrack;
qint64 m_pos;
qint64 m_oldPos;
bool m_undoRedoAction;
};
}
}
......
......@@ -166,9 +166,7 @@ void MainWindow::initializeDockWidgets( void )
QDockWidget::AllDockWidgetFeatures,
Qt::TopDockWidgetArea );
QUndoView* undoView = new QUndoView( UndoStack::getInstance(), this);
undoView->setEmptyLabel( tr( "Nothing to undo" ) );
dockManager->addDockedWidget( undoView,
dockManager->addDockedWidget( UndoStack::getInstance( this ),
tr( "History" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures,
......
......@@ -381,6 +381,7 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event )
updateDuration();
if ( m_layout->itemAt( 0 )->graphicsItem()->childItems().count() > 0 )
addVideoTrack();
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() ) );
......
/*****************************************************************************
* 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
......@@ -94,7 +94,8 @@ HEADERS += src/gui/MainWindow.h \
src/UndoStack.h \
src/tools/WaitCondition.hpp \
src/metadata/MetaDataManager.h \
src/commands/Commands.hpp
src/commands/Commands.hpp \
src/tools/QSingleton.hpp
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.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