UndoStack.cpp 2.41 KB
Newer Older
1 2 3 4 5 6
/*****************************************************************************
 * UndoStack.cpp: UndoStack For Undo/Redo Purposes
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Christophe Courtaut <christophe.courtaut@gmail.com>
7
 *          Hugo Beauzee-Luyssen <beauze.h@gmail.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 *****************************************************************************/

Ludovic Fauvet's avatar
Ludovic Fauvet committed
24 25 26
#include <QUndoStack>
#include <QUndoCommand>

27
#include "UndoStack.h"
28
#include "ProjectManager.h"
29 30
#include "SettingsManager.h"
#include "KeyboardShortcutHelper.h"
31

32
UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
33
{
34
    setEmptyLabel( tr( "Nothing to undo" ) );
35

36 37
    m_undoStack = new QUndoStack( this );
    setStack( m_undoStack );
38 39
    connect( m_undoStack, SIGNAL( cleanChanged( bool ) ),
             ProjectManager::getInstance(), SLOT( cleanChanged( bool ) ) );
40 41
    connect( ProjectManager::getInstance(), SIGNAL( projectSaved() ),
             m_undoStack, SLOT( setClean() ) );
42

43 44
    m_undoShortcut = new KeyboardShortcutHelper( "Undo", this );
    m_redoShortcut = new KeyboardShortcutHelper( "Redo", this );
45 46
    connect( m_undoShortcut, SIGNAL( activated() ), m_undoStack, SLOT( undo() ) );
    connect( m_redoShortcut, SIGNAL( activated() ), m_undoStack, SLOT( redo() ) );
47

48
    connect( ProjectManager::getInstance(), SIGNAL( projectClosed() ), this, SLOT( clear() ) );
49 50 51 52 53
}

void    UndoStack::push( QUndoCommand* command )
{
    m_undoStack->push( command );
54
}
55

56 57 58 59 60 61 62 63 64 65
void    UndoStack::beginMacro( const QString& text )
{
    m_undoStack->beginMacro( text );
}

void    UndoStack::endMacro()
{
    m_undoStack->endMacro();
}

66 67
void    UndoStack::clear()
{
68
    m_undoStack->clear();
69
}