00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 00021 #include "historymanager.h" 00022 00023 #include <QtCore/QVariant> 00024 #include <QtGui/QAction> 00025 #include <KUndoStack> 00026 00027 using namespace GluonCreator; 00028 00029 template<> GLUON_CREATOR_VISIBILITY HistoryManager* GluonCore::Singleton<HistoryManager>::m_instance = 0; 00030 00031 class HistoryManager::HistoryManagerPrivate 00032 { 00033 public: 00034 HistoryManagerPrivate() 00035 { 00036 stack = new KUndoStack(); 00037 } 00038 ~HistoryManagerPrivate() 00039 { 00040 delete stack; 00041 } 00042 00043 KUndoStack* stack; 00044 }; 00045 00046 void HistoryManager::addCommand( QUndoCommand* command ) 00047 { 00048 d->stack->push( command ); 00049 emit historyChanged( command ); 00050 } 00051 00052 void HistoryManager::redo() 00053 { 00054 d->stack->redo(); 00055 const QUndoCommand* command = d->stack->command( d->stack->index() - 1 ); 00056 emit historyChanged( command ); 00057 } 00058 00059 void HistoryManager::undo() 00060 { 00061 d->stack->undo(); 00062 const QUndoCommand* command = d->stack->command( d->stack->index() ); 00063 emit historyChanged( command ); 00064 } 00065 00066 void HistoryManager::clear() 00067 { 00068 d->stack->clear(); 00069 } 00070 00071 void HistoryManager::setClean() 00072 { 00073 d->stack->setClean(); 00074 } 00075 00076 HistoryManager::HistoryManager() : d( new HistoryManagerPrivate ) 00077 { 00078 connect( d->stack, SIGNAL( canRedoChanged( bool ) ), SIGNAL( canRedoChanged( bool ) ) ); 00079 connect( d->stack, SIGNAL( canUndoChanged( bool ) ), SIGNAL( canUndoChanged( bool ) ) ); 00080 connect( d->stack, SIGNAL( cleanChanged( bool ) ), SIGNAL( cleanChanged( bool ) ) ); 00081 } 00082 00083 HistoryManager::~HistoryManager() 00084 { 00085 delete d; 00086 } 00087 00088 //#include "historymanager.moc"