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 kpCommandHistory_H 0030 #define kpCommandHistory_H 0031 0032 0033 #include "kpCommandHistoryBase.h" 0034 0035 class kpMainWindow; 0036 class kpToolSelectionCreateCommand; 0037 0038 0039 // 0040 // KolourPaint-specific command history functionality. 0041 // 0042 // Intercepts Undo/Redo requests: 0043 // 0044 // If the user is currently drawing a shape, it cancels it. 0045 // Else it passes on the Undo/Redo request to kpCommandHistoryBase. 0046 // 0047 // TODO: This is wrong. It won't work if the Undo action is disabled, 0048 // for instance. Later: What about kpToolText::viewEvent()'s use of 0049 // QEvent::ShortcutOverride? 0050 // 0051 // Maybe the real solution is to call kpCommandHistoryBase::addCommand() 0052 // as _soon_ as the shape starts - not after it ends. But the 0053 // trouble with this solution is that if the user Undoes/cancels 0054 // the shape s/he's currently drawing, it would replace a Redo 0055 // slot in the history. Arguably you shouldn't be able to Redo 0056 // something you never finished drawing. 0057 // 0058 // The solution is to add this functionality to kpCommandHistoryBase. 0059 // 0060 class kpCommandHistory : public kpCommandHistoryBase 0061 { 0062 Q_OBJECT 0063 0064 public: 0065 kpCommandHistory (bool doReadConfig, kpMainWindow *mainWindow); 0066 ~kpCommandHistory () override; 0067 0068 public: 0069 // Same as addCommand(), except that this has a more desirable behavior 0070 // when adding a selection border creation command: If the next undo command 0071 // also creates a selection border, it overwrites that command 0072 // with the given <cmd>, instead of adding to the undo history. 0073 // 0074 // This helps to reduce the number of consecutive selection border 0075 // creation commands in the history. Exactly one border creation 0076 // command before each "real" selection command is useful as it allows 0077 // users to undo just that "real" operation and then do a different "real" 0078 // operation with the same border (as sometimes, exact borders are difficult 0079 // to recreate). However, multiple consecutive border creation 0080 // commands get annoying since none of them mutate the document, 0081 // so if the user has not done a "real" command with the last selection 0082 // border (i.e. the next undo command), what this method is saying is 0083 // that the user wanted to throw away that border drag anyway. 0084 // 0085 // This special behavior is perfectly safe since border creation commands 0086 // do not mutate the document. 0087 // 0088 // If <cmd> creates a selection that is not just a border, this 0089 // method has the same effect as addCommand(). 0090 // 0091 // REFACTOR: Why not just override addCommand() and test if it was given a 0092 // kpToolSelectionCreateCommand? 0093 void addCreateSelectionCommand (kpToolSelectionCreateCommand *cmd, 0094 bool execute = true); 0095 0096 public Q_SLOTS: 0097 void undo () override; 0098 void redo () override; 0099 0100 protected: 0101 kpMainWindow *m_mainWindow; 0102 }; 0103 0104 0105 #endif // kpCommandHistory_H