update
[kdegraphics.git] / kolourpaint / commands / kpCommandHistoryBase.h
blob874813679fa990107a4128b99c1e3005f671aea2
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
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
33 #include <qobject.h>
34 #include <qstring.h>
35 #include <qlinkedlist.h>
37 #include <kpCommandSize.h>
39 class QAction;
41 class KActionCollection;
42 class KToolBarPopupAction;
44 class kpAbstractImageSelection;
45 class kpAbstractSelection;
46 class kpCommand;
47 class kpCommandEnvironment;
48 class kpDocument;
49 class kpMainWindow;
50 class kpTextSelection;
51 class kpViewManager;
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
64 Q_OBJECT
66 public:
67 kpCommandHistoryBase (bool doReadConfig, KActionCollection *ac);
68 virtual ~kpCommandHistoryBase ();
70 public:
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);
85 public:
86 // Read and write above config
87 void readConfig ();
88 void writeConfig ();
90 public:
91 void addCommand (kpCommand *command, bool execute = true);
92 void clear ();
94 protected slots:
95 // (same as undo() & redo() except they don't call
96 // trimCommandListsUpdateActions())
97 void undoInternal ();
98 void redoInternal ();
100 public slots:
101 virtual void undo ();
102 virtual void redo ();
104 virtual void undoUpToNumber (QAction *which);
105 virtual void redoUpToNumber (QAction *which);
107 protected:
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 ();
119 public:
120 kpCommand *nextUndoCommand () const;
121 kpCommand *nextRedoCommand () const;
123 void setNextUndoCommand (kpCommand *command);
125 public slots:
126 virtual void documentSaved ();
128 signals:
129 void documentRestored ();
131 protected:
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
143 // * 0: unmodified
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;
150 private:
151 struct kpCommandHistoryBasePrivate * const d;
155 #endif // kpCommandHistoryBase_H