1
/* ============================================================
2
* File : undomanager.cpp
3
* Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
4
* J�rn Ahrens <joern.ahrens@kdemail.net>
8
* Copyright 2005 by Renchi Raju, J�rn Ahrens
10
* This program is free software; you can redistribute it
11
* and/or modify it under the terms of the GNU General
12
* Public License as published by the Free Software Foundation;
13
* either version 2, or (at your option)
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* ============================================================ */
25
#include <qstringlist.h>
27
#include "imlibinterface.h"
28
#include "undoaction.h"
29
#include "undocache.h"
30
#include "undomanager.h"
34
UndoManager::UndoManager(Digikam::ImlibInterface* iface)
37
m_cache = new UndoCache;
40
UndoManager::~UndoManager()
46
void UndoManager::addAction(UndoAction* action)
51
// All redo actions are invalid now
54
m_undoActions.push_back(action);
56
if (typeid(*action) == typeid(UndoActionIrreversible))
58
int w = m_iface->origWidth();
59
int h = m_iface->origHeight();
60
uint* data = m_iface->getData();
62
m_cache->putData(m_undoActions.size(), w, h, data);
66
void UndoManager::undo()
68
if (m_undoActions.isEmpty())
71
UndoAction* action = m_undoActions.back();
73
if (typeid(*action) == typeid(UndoActionIrreversible))
75
int w = m_iface->origWidth();
76
int h = m_iface->origHeight();
77
uint* data = m_iface->getData();
79
// save the current state for the redo operation
80
m_cache->putData(m_undoActions.size() + 1, w, h, data);
82
// and now, undo the action
83
m_cache->getData(m_undoActions.size(), w, h, data, false);
84
m_iface->putData(data, w, h);
93
m_undoActions.pop_back();
94
m_redoActions.push_back(action);
97
void UndoManager::redo()
99
if(m_redoActions.isEmpty())
102
UndoAction *action = m_redoActions.back();
104
if(typeid(*action) == typeid(UndoActionIrreversible))
109
m_cache->getData(m_undoActions.size() + 2, w, h, data, false);
110
m_iface->putData(data, w, h);
119
m_redoActions.pop_back();
120
m_undoActions.push_back(action);
123
void UndoManager::clear(bool clearCache)
132
void UndoManager::clearUndoActions()
135
QValueList<UndoAction*>::iterator it;
137
for(it = m_undoActions.begin(); it != m_undoActions.end(); ++it)
142
m_undoActions.clear();
145
void UndoManager::clearRedoActions()
151
QValueList<UndoAction*>::iterator it;
153
// get the level of the first redo action
154
int level = m_undoActions.size() + 1;
155
for(it = m_redoActions.begin(); it != m_redoActions.end(); ++it)
158
m_cache->erase(level);
162
m_cache->erase(level);
163
m_redoActions.clear();
166
bool UndoManager::anyMoreUndo()
168
return !m_undoActions.isEmpty();
171
bool UndoManager::anyMoreRedo()
173
return !m_redoActions.isEmpty();
176
void UndoManager::getUndoHistory(QStringList &titles)
178
QValueList<UndoAction*>::iterator it;
180
for(it = m_undoActions.begin(); it != m_undoActions.end(); ++it)
182
titles.push_front((*it)->getTitle());
186
void UndoManager::getRedoHistory(QStringList &titles)
188
QValueList<UndoAction*>::iterator it;
190
for(it = m_redoActions.begin(); it != m_redoActions.end(); ++it)
192
titles.push_front((*it)->getTitle());