File indexing completed on 2024-04-28 04:20:11
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 All rights reserved. 0005 0006 Redistribution and use in source and binary forms, with or without 0007 modification, are permitted provided that the following conditions 0008 are met: 0009 0010 1. Redistributions of source code must retain the above copyright 0011 notice, this list of conditions and the following disclaimer. 0012 2. Redistributions in binary form must reproduce the above copyright 0013 notice, this list of conditions and the following disclaimer in the 0014 documentation and/or other materials provided with the distribution. 0015 0016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 0029 #ifndef kpCommandHistoryBase_H 0030 #define kpCommandHistoryBase_H 0031 0032 0033 #include <QObject> 0034 #include <QString> 0035 #include <QList> 0036 0037 0038 #include "commands/kpCommandSize.h" 0039 0040 class QAction; 0041 0042 class KActionCollection; 0043 class KToolBarPopupAction; 0044 0045 class kpCommand; 0046 0047 0048 // Clone of KCommandHistory with features required by KolourPaint but which 0049 // could also be useful for other apps: 0050 // - nextUndoCommand()/nextRedoCommand() 0051 // - undo/redo history limited by both number and size 0052 // 0053 // Features not required by KolourPaint (e.g. commandExecuted()) are not 0054 // implemented and undo limit == redo limit. So compared to 0055 // KCommandHistory, this is only "almost source compatible". 0056 class kpCommandHistoryBase : public QObject 0057 { 0058 Q_OBJECT 0059 0060 public: 0061 kpCommandHistoryBase (bool doReadConfig, KActionCollection *ac); 0062 ~kpCommandHistoryBase () override; 0063 0064 public: 0065 // (provided for compatibility with KCommandHistory) 0066 int undoLimit () const; 0067 void setUndoLimit (int limit); 0068 0069 0070 int undoMinLimit () const; 0071 void setUndoMinLimit (int limit); 0072 0073 int undoMaxLimit () const; 0074 void setUndoMaxLimit (int limit); 0075 0076 kpCommandSize::SizeType undoMaxLimitSizeLimit () const; 0077 void setUndoMaxLimitSizeLimit (kpCommandSize::SizeType sizeLimit); 0078 0079 public: 0080 // Read and write above config 0081 void readConfig (); 0082 void writeConfig (); 0083 0084 public: 0085 void addCommand (kpCommand *command, bool execute = true); 0086 void clear (); 0087 0088 protected Q_SLOTS: 0089 // (same as undo() & redo() except they don't call 0090 // trimCommandListsUpdateActions()) 0091 void undoInternal (); 0092 void redoInternal (); 0093 0094 public Q_SLOTS: 0095 virtual void undo (); 0096 virtual void redo (); 0097 0098 virtual void undoUpToNumber (QAction *which); 0099 virtual void redoUpToNumber (QAction *which); 0100 0101 protected: 0102 QString undoActionText () const; 0103 QString redoActionText () const; 0104 0105 QString undoActionToolTip () const; 0106 QString redoActionToolTip () const; 0107 0108 void trimCommandListsUpdateActions (); 0109 void trimCommandList(QList<kpCommand *> &commandList); 0110 void trimCommandLists (); 0111 void updateActions (); 0112 0113 public: 0114 kpCommand *nextUndoCommand () const; 0115 kpCommand *nextRedoCommand () const; 0116 0117 void setNextUndoCommand (kpCommand *command); 0118 0119 public Q_SLOTS: 0120 virtual void documentSaved (); 0121 0122 Q_SIGNALS: 0123 void documentRestored (); 0124 0125 protected: 0126 KToolBarPopupAction *m_actionUndo, *m_actionRedo; 0127 0128 // (Front element is the next one) 0129 QList <kpCommand *> m_undoCommandList; 0130 QList <kpCommand *> m_redoCommandList; 0131 0132 int m_undoMinLimit, m_undoMaxLimit; 0133 kpCommandSize::SizeType m_undoMaxLimitSizeLimit; 0134 0135 // What you have to do to get back to the document's unmodified state: 0136 // * -x: must Undo x times 0137 // * 0: unmodified 0138 // * +x: must Redo x times 0139 // * INT_MAX: can never become unmodified again 0140 // 0141 // ASSUMPTION: will never have INT_MAX commands in any list. 0142 int m_documentRestoredPosition; 0143 }; 0144 0145 0146 #endif // kpCommandHistoryBase_H