make sure to attach to the document also when a resize event is received prior of...
[kdegraphics.git] / kolourpaint / commands / kpCommandHistory.h
blob199eed1e900ac070716dfa604ba7f15042a4375f
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 kpCommandHistory_H
30 #define kpCommandHistory_H
33 #include <kpCommandHistoryBase.h>
36 class kpToolSelectionCreateCommand;
40 // KolourPaint-specific command history functionality.
42 // Intercepts Undo/Redo requests:
44 // If the user is currently drawing a shape, it cancels it.
45 // Else it passes on the Undo/Redo request to kpCommandHistoryBase.
47 // TODO: This is wrong. It won't work if the Undo action is disabled,
48 // for instance. Later: What about kpToolText::viewEvent()'s use of
49 // QEvent::ShortcutOverride?
51 // Maybe the real solution is to call kpCommandHistoryBase::addCommand()
52 // as _soon_ as the shape starts - not after it ends. But the
53 // trouble with this solution is that if the user Undoes/cancels
54 // the shape s/he's currently drawing, it would replace a Redo
55 // slot in the history. Arguably you shouldn't be able to Redo
56 // something you never finished drawing.
58 // The solution is to add this functionality to kpCommandHistoryBase.
60 class kpCommandHistory : public kpCommandHistoryBase
62 Q_OBJECT
64 public:
65 kpCommandHistory (bool doReadConfig, kpMainWindow *mainWindow);
66 virtual ~kpCommandHistory ();
68 public:
69 // Same as addCommand(), except that this has a more desirable behavior
70 // when adding a selection border creation command: If the next undo command
71 // also creates a selection border, it overwrites that command
72 // with the given <cmd>, instead of adding to the undo history.
74 // This helps to reduce the number of consecutive selection border
75 // creation commands in the history. Exactly one border creation
76 // command before each "real" selection command is useful as it allows
77 // users to undo just that "real" operation and then do a different "real"
78 // operation with the same border (as sometimes, exact borders are difficult
79 // to recreate). However, multiple consecutive border creation
80 // commands get annoying since none of them mutate the document,
81 // so if the user has not done a "real" command with the last selection
82 // border (i.e. the next undo command), what this method is saying is
83 // that the user wanted to throw away that border drag anyway.
85 // This special behavior is perfectly safe since border creation commands
86 // do not mutate the document.
88 // If <cmd> creates a selection that is not just a border, this
89 // method has the same effect as addCommand().
91 // REFACTOR: Why not just override addCommand() and test if it was given a
92 // kpToolSelectionCreateCommand?
93 void addCreateSelectionCommand (kpToolSelectionCreateCommand *cmd,
94 bool execute = true);
96 public slots:
97 virtual void undo ();
98 virtual void redo ();
100 protected:
101 kpMainWindow *m_mainWindow;
105 #endif // kpCommandHistory_H