3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef kpCommandHistoryBase_H
30 #define kpCommandHistoryBase_H
35 #include <qlinkedlist.h>
37 #include <kpCommandSize.h>
41 class KActionCollection
;
42 class KToolBarPopupAction
;
44 class kpAbstractImageSelection
;
45 class kpAbstractSelection
;
47 class kpCommandEnvironment
;
50 class kpTextSelection
;
54 // Clone of KCommandHistory with features required by KolourPaint but which
55 // could also be useful for other apps:
56 // - nextUndoCommand()/nextRedoCommand()
57 // - undo/redo history limited by both number and size
59 // Features not required by KolourPaint (e.g. commandExecuted()) are not
60 // implemented and undo limit == redo limit. So compared to
61 // KCommandHistory, this is only "almost source compatible".
62 class kpCommandHistoryBase
: public QObject
67 kpCommandHistoryBase (bool doReadConfig
, KActionCollection
*ac
);
68 virtual ~kpCommandHistoryBase ();
71 // (provided for compatibility with KCommandHistory)
72 int undoLimit () const;
73 void setUndoLimit (int limit
);
76 int undoMinLimit () const;
77 void setUndoMinLimit (int limit
);
79 int undoMaxLimit () const;
80 void setUndoMaxLimit (int limit
);
82 kpCommandSize::SizeType
undoMaxLimitSizeLimit () const;
83 void setUndoMaxLimitSizeLimit (kpCommandSize::SizeType sizeLimit
);
86 // Read and write above config
91 void addCommand (kpCommand
*command
, bool execute
= true);
95 // (same as undo() & redo() except they don't call
96 // trimCommandListsUpdateActions())
101 virtual void undo ();
102 virtual void redo ();
104 virtual void undoUpToNumber (QAction
*which
);
105 virtual void redoUpToNumber (QAction
*which
);
108 QString
undoActionText () const;
109 QString
redoActionText () const;
111 QString
undoActionToolTip () const;
112 QString
redoActionToolTip () const;
114 void trimCommandListsUpdateActions ();
115 void trimCommandList (QLinkedList
<kpCommand
*> *commandList
);
116 void trimCommandLists ();
117 void updateActions ();
120 kpCommand
*nextUndoCommand () const;
121 kpCommand
*nextRedoCommand () const;
123 void setNextUndoCommand (kpCommand
*command
);
126 virtual void documentSaved ();
129 void documentRestored ();
132 KToolBarPopupAction
*m_actionUndo
, *m_actionRedo
;
134 // (Front element is the next one)
135 QLinkedList
<kpCommand
*> m_undoCommandList
;
136 QLinkedList
<kpCommand
*> m_redoCommandList
;
138 int m_undoMinLimit
, m_undoMaxLimit
;
139 kpCommandSize::SizeType m_undoMaxLimitSizeLimit
;
141 // What you have to do to get back to the document's unmodified state:
142 // * -x: must Undo x times
144 // * +x: must Redo x times
145 // * INT_MAX: can never become unmodified again
147 // ASSUMPTION: will never have INT_MAX commands in any list.
148 int m_documentRestoredPosition
;
151 struct kpCommandHistoryBasePrivate
* const d
;
155 #endif // kpCommandHistoryBase_H