1 2 /* 3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions 8 are met: 9 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. 15 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. 26 */ 27 28 29 #ifndef kpCommandHistoryBase_H 30 #define kpCommandHistoryBase_H 31 32 33 #include <QObject> 34 #include <QString> 35 #include <QList> 36 37 38 #include "commands/kpCommandSize.h" 39 40 class QAction; 41 42 class KActionCollection; 43 class KToolBarPopupAction; 44 45 class kpCommand; 46 47 48 // Clone of KCommandHistory with features required by KolourPaint but which 49 // could also be useful for other apps: 50 // - nextUndoCommand()/nextRedoCommand() 51 // - undo/redo history limited by both number and size 52 // 53 // Features not required by KolourPaint (e.g. commandExecuted()) are not 54 // implemented and undo limit == redo limit. So compared to 55 // KCommandHistory, this is only "almost source compatible". 56 class kpCommandHistoryBase : public QObject 57 { 58 Q_OBJECT 59 60 public: 61 kpCommandHistoryBase (bool doReadConfig, KActionCollection *ac); 62 ~kpCommandHistoryBase () override; 63 64 public: 65 // (provided for compatibility with KCommandHistory) 66 int undoLimit () const; 67 void setUndoLimit (int limit); 68 69 70 int undoMinLimit () const; 71 void setUndoMinLimit (int limit); 72 73 int undoMaxLimit () const; 74 void setUndoMaxLimit (int limit); 75 76 kpCommandSize::SizeType undoMaxLimitSizeLimit () const; 77 void setUndoMaxLimitSizeLimit (kpCommandSize::SizeType sizeLimit); 78 79 public: 80 // Read and write above config 81 void readConfig (); 82 void writeConfig (); 83 84 public: 85 void addCommand (kpCommand *command, bool execute = true); 86 void clear (); 87 88 protected slots: 89 // (same as undo() & redo() except they don't call 90 // trimCommandListsUpdateActions()) 91 void undoInternal (); 92 void redoInternal (); 93 94 public slots: 95 virtual void undo (); 96 virtual void redo (); 97 98 virtual void undoUpToNumber (QAction *which); 99 virtual void redoUpToNumber (QAction *which); 100 101 protected: 102 QString undoActionText () const; 103 QString redoActionText () const; 104 105 QString undoActionToolTip () const; 106 QString redoActionToolTip () const; 107 108 void trimCommandListsUpdateActions (); 109 void trimCommandList(QList<kpCommand *> &commandList); 110 void trimCommandLists (); 111 void updateActions (); 112 113 public: 114 kpCommand *nextUndoCommand () const; 115 kpCommand *nextRedoCommand () const; 116 117 void setNextUndoCommand (kpCommand *command); 118 119 public slots: 120 virtual void documentSaved (); 121 122 signals: 123 void documentRestored (); 124 125 protected: 126 KToolBarPopupAction *m_actionUndo, *m_actionRedo; 127 128 // (Front element is the next one) 129 QList <kpCommand *> m_undoCommandList; 130 QList <kpCommand *> m_redoCommandList; 131 132 int m_undoMinLimit, m_undoMaxLimit; 133 kpCommandSize::SizeType m_undoMaxLimitSizeLimit; 134 135 // What you have to do to get back to the document's unmodified state: 136 // * -x: must Undo x times 137 // * 0: unmodified 138 // * +x: must Redo x times 139 // * INT_MAX: can never become unmodified again 140 // 141 // ASSUMPTION: will never have INT_MAX commands in any list. 142 int m_documentRestoredPosition; 143 }; 144 145 146 #endif // kpCommandHistoryBase_H 147