UndoStack.cpp 2.84 KB
Newer Older
1 2 3
/*****************************************************************************
 * UndoStack.cpp: UndoStack For Undo/Redo Purposes
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6
 *
 * 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 24
 *
 * 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.
 *****************************************************************************/

#include "UndoStack.h"
25 26

#include "Commands.h"
27
#include "project/GuiProjectManager.h"
28
#include "SettingsManager.h"
29

30
#include <QEvent>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
31 32 33 34
#include <QUndoStack>
#include <QUndoCommand>

UndoStack::UndoStack( QWidget *parent ) : QUndoView( parent )
35
{
36
    setEmptyLabel( tr( "Nothing to undo" ) );
37

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

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
45 46
    connect( m_undoStack, SIGNAL( canRedoChanged( bool ) ), this, SIGNAL( canRedoChanged( bool ) ) );
    connect( m_undoStack, SIGNAL( canUndoChanged( bool ) ), this, SIGNAL( canUndoChanged( bool ) ) );
47

48
    connect( GUIProjectManager::getInstance(), SIGNAL( projectClosed() ), this, SLOT( clear() ) );
49 50
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
51 52
void
UndoStack::push( QUndoCommand *command )
53 54
{
    m_undoStack->push( command );
55
}
56

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
57 58
void
UndoStack::beginMacro( const QString& text )
59 60 61 62
{
    m_undoStack->beginMacro( text );
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
63 64
void
UndoStack::endMacro()
65 66 67 68
{
    m_undoStack->endMacro();
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
69 70
bool
UndoStack::canUndo()
71
{
72
    return m_undoStack->canUndo();
73 74
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
75 76
bool
UndoStack::canRedo()
77
{
78
    return m_undoStack->canRedo();
79 80
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
81 82
void
UndoStack::clear()
83
{
84
    m_undoStack->clear();
85
}
86

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
87 88
void
UndoStack::undo()
89 90 91 92
{
    m_undoStack->undo();
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
93 94
void
UndoStack::redo()
95 96 97
{
    m_undoStack->redo();
}
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

void
UndoStack::changeEvent( QEvent *event )
{
    switch ( event->type() )
    {
    case QEvent::LanguageChange:
        setEmptyLabel( tr( "Nothing to undo" ) );
        emit retranslateRequired();
        update( rootIndex() );
        break;
    default:
        break;
    }
}