From 47d455dd55be855e4cc691c32f687f723d9247ee Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kcoloredit/editablestreamhistory.h | 107 +++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 kcoloredit/editablestreamhistory.h (limited to 'kcoloredit/editablestreamhistory.h') diff --git a/kcoloredit/editablestreamhistory.h b/kcoloredit/editablestreamhistory.h new file mode 100644 index 00000000..9fe59d99 --- /dev/null +++ b/kcoloredit/editablestreamhistory.h @@ -0,0 +1,107 @@ +/*************************************************************************** + editablestreamhistory.h - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : art@zeus.polsl.gliwice.pl + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef EDITABLESTREAMHISTORY_H +#define EDITABLESTREAMHISTORY_H + +/** A template class adding undo/redo history for EDITABLE_STREAM paste and cut + * methods + * @author Artur Rataj + */ +template class EditableStreamHistory { +public: + /** Constructs the class with stream as an EDITABLE_STREAM and + * a given number of undo levels + */ + EditableStreamHistory(EDITABLE_STREAM* stream, const int undoLevels); + ~EditableStreamHistory(); + /** Cuts a stream at index, of length length. + * Uses undo/redo history. + * @return A stream that has been cut out + */ + EDITABLE_STREAM cut(const int index, const int length); + /** Pastes a stream at index. Uses undo/redo history */ + void paste(const int index, EDITABLE_STREAM& pasteStream); + /** Replaces a stream at index. Uses undo/redo history */ + void replace(const int index, EDITABLE_STREAM& replaceStream); + /** @return Whether undo possible */ + bool undoPossible(); + /** @return Whether redo possible */ + bool redoPossible(); + /** Undoes if possible */ + void undo(); + /** Redoes if possible */ + void redo(); + /** @return A pointer to editableStream */ + EDITABLE_STREAM* editableStream(); + +protected: + /** An editable stream */ + EDITABLE_STREAM* m_editableStream; + /** A number of undo levels */ + int m_undoLevels; +}; + +template EditableStreamHistory:: + EditableStreamHistory(EDITABLE_STREAM* stream, const int undoLevels) { + m_editableStream = stream; + m_undoLevels = undoLevels; +} +template EditableStreamHistory::~EditableStreamHistory() { +} + +template EDITABLE_STREAM + EditableStreamHistory::cut(const int index, const int length) { + EDITABLE_STREAM cut_stream = m_editableStream->cut(index, length); + return cut_stream; +} + +template void + EditableStreamHistory::paste(const int index, EDITABLE_STREAM& pasteStream) { + m_editableStream->paste(index, pasteStream); +} + +template void + EditableStreamHistory::replace(const int index, EDITABLE_STREAM& replaceStream) { + m_editableStream->cut(index, replaceStream.length()); + m_editableStream->paste(index, replaceStream); +} + +template bool + EditableStreamHistory::undoPossible() { + return false; +} + +template bool + EditableStreamHistory::redoPossible() { + return false; +} + +template void + EditableStreamHistory::undo() { +} + +template void + EditableStreamHistory::redo() { +} + +template EDITABLE_STREAM* + EditableStreamHistory::editableStream() { + return m_editableStream; +} + +#endif -- cgit v1.2.1