15
15
You should have received a copy of the GNU Library General Public License
16
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
21
#ifndef __VCOMMAND_H__
37
* The base class for all karbon commands.
39
* It basically defines the common interface that all commands should implement.
36
41
class VCommand : public VVisitor
45
* Constructs a new command.
47
* @param doc the document the command should work on
48
* @param name the name of the command (appears in command history)
49
* @param icon the icon of the command (appears in command history)
39
51
VCommand( VDocument* doc, const QString& name, const QString& icon = "14_action" )
40
52
: m_document( doc ), m_name( name ), m_icon( icon )
59
/** Destroys the command */
47
60
virtual ~VCommand() {}
63
* Executes the command.
65
* All the changes to the document are done here.
66
* All commands have to implement this function.
49
68
virtual void execute() = 0;
71
* Unexecutes the command.
73
* All changes to the document have to be undone here.
50
75
virtual void unexecute() {}
78
* Returns if the command changes the actual document selection.
80
* This flag is checked to determine if the document has to be redrawn.
82
* @return true if the selection is changed, else false
52
84
virtual bool changesSelection() const { return false; }
87
* Returns the name of the command.
89
* @return the command name
54
91
QString name() const
97
* Sets the name of the command.
99
* @param name the new command name
59
101
void setName( const QString& name )
107
* Returns the icon of the command.
109
* @return the command icon
65
111
QString icon() const
117
* Returns the document the command works on.
119
* @return the command's document
70
121
VDocument* document() const
72
123
return m_document;
134
* Manages a set of commands.
136
* It keeps the commands in a list, commands higher in the list are older
137
* than lower commands.
138
* All commands in the list can be undone, beginning from the latest command
139
* at the end of the list. Undone commands can be redone, beginning at the
140
* oldest undone command. That makes it possible to go back and forth to a
141
* specific document state.
83
143
class VCommandHistory : public QObject
149
* Constructs a command history.
151
* @param part the part the commands are managed for
88
153
VCommandHistory( KarbonPart* part );
155
/** Destroys the command history. */
89
156
~VCommandHistory();
91
// Command manipulation.
159
* Clears the command history by removing all commands.
161
* Emits the historyCleared signal
166
* Adds a new command to the history.
168
* @param command the new command to add
169
* @param execute controls if the new command should be executed
94
171
void addCommand( VCommand* command, bool execute = true );
176
* Returns the actual undo limit.
178
* @return the undo limit
98
180
unsigned int undoLimit() const
100
182
return m_undoLimit;
186
* Sets a new undo limit.
188
* The undo limit controls how many commands are stored in the history.
189
* If the new limit is lower than the actual history size, the oldest
190
* commands are removed unitl the size matches the undo limit.
192
* @param limit the new undo limit
103
194
void setUndoLimit( unsigned int limit );
197
* Returns the actual redo limit.
199
* @return the redo limit
106
201
unsigned int redoLimit() const
108
203
return m_redoLimit;
207
* Sets a new redo limit.
209
* The redo limit controls how many undone commands are stored in history.
210
* If the new limit is lower than the actual number of undone commands,
211
* the newest commands are removed until the number matches the redo limit.
213
* @param limit the new redo limit
111
215
void setRedoLimit( unsigned int limit );
218
* Read only access to the command history list.
220
* @return pointer to the list of commands
114
222
const QPtrList<VCommand>* commands() const
116
224
return & m_commands;
228
/** Undoes the last command not already undone. */
231
/** Redoes the last command not already undone. */
235
* Undoes the specified command.
237
* @param command the command to undo
122
239
void undo( VCommand* command );
242
* Redoes the specified command.
244
* @param command the command to redo
123
246
void redo( VCommand* command );
249
* Undoes all command up to the specified command.
251
* @param command the command up to which all later commands should be undone
124
253
void undoAllTo( VCommand* command );
256
* Redoes all command up to the specified command.
258
* @param command the command up to which all former commands should be redone
125
260
void redoAllTo( VCommand* command );
263
* Marks the actual document state as saved.
265
* The position within the list corresponding to the actual document state is saved.
126
267
void documentSaved();
270
/** This signal is emitted when the command history gets cleared. */
129
271
void historyCleared();
274
* This signal is emitted when a command is executed.
276
* The executed command is given as the argument.
130
278
void commandExecuted( VCommand* );
280
/** This signal is emitted when a command is executed. */
131
281
void commandExecuted();
284
* This signal is emitted when a command is added to the history.
286
* The added command is given as the argument.
132
288
void commandAdded( VCommand* );
290
/** This signal is emitted when the first (oldest) command is removed. */
133
291
void firstCommandRemoved();
293
/** This signal is emitted when the last (latest) command is removed. */
134
294
void lastCommandRemoved();
297
* This signal is emitted when the actual document state matches the last saved one.
299
* Use documentSaved to set the last saved document state.
135
301
void documentRestored();