karbon

vcommand.h
1/* This file is part of the KDE project
2 Copyright (C) 2001, The Karbon Developers
3 Copyright (C) 2002, The Karbon Developers
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __VCOMMAND_H__
22#define __VCOMMAND_H__
23
24
25//#include <assert.h>
26
27#include <tqobject.h>
28#include <tqptrlist.h>
29
30#include "vvisitor.h"
31
32class VDocument;
33class KarbonPart;
34class TDEAction;
35
41class VCommand : public VVisitor
42{
43public:
51 VCommand( VDocument* doc, const TQString& name, const TQString& icon = "14_action" )
52 : m_document( doc ), m_name( name ), m_icon( icon )
53 {
54// A crash because of an assert() is not much better than an crash because of a null
55// pointer. Allowing null pointers allows the usage of the vitors ascpect of a VCommand.
56// assert( doc );
57 }
58
60 virtual ~VCommand() {}
61
68 virtual void execute() = 0;
69
75 virtual void unexecute() {}
76
84 virtual bool changesSelection() const { return false; }
85
91 TQString name() const
92 {
93 return m_name;
94 }
95
101 void setName( const TQString& name )
102 {
103 m_name = name;
104 }
105
111 TQString icon() const
112 {
113 return m_icon;
114 }
115
122 {
123 return m_document;
124 }
125
126private:
127 VDocument* m_document;
128
129 TQString m_name;
130 TQString m_icon;
131};
132
143class VCommandHistory : public TQObject
144{
145 TQ_OBJECT
146
147
148public:
155
158
164 void clear();
165
172 void addCommand( VCommand* command, bool execute = true );
173
174
175 // limits
181 unsigned int undoLimit() const
182 {
183 return m_undoLimit;
184 }
185
195 void setUndoLimit( unsigned int limit );
196
202 unsigned int redoLimit() const
203 {
204 return m_redoLimit;
205 }
206
216 void setRedoLimit( unsigned int limit );
217
223 const TQPtrList<VCommand>* commands() const
224 {
225 return & m_commands;
226 }
227
228public slots:
230 void undo();
231
233 void redo();
234
240 void undo( VCommand* command );
241
247 void redo( VCommand* command );
248
254 void undoAllTo( VCommand* command );
255
261 void redoAllTo( VCommand* command );
262
268 void documentSaved();
269
270signals:
273
280
283
290
293
296
303
304private:
305 // helpers
306 void clipCommands();
307 void updateActions();
308
309 KarbonPart *m_part;
310 unsigned int m_undoLimit;
311 unsigned int m_redoLimit;
312 TDEAction *m_undo;
313 TDEAction *m_redo;
314 TQPtrList<VCommand> m_commands;
315 int m_savedPos;
316};
317
318#endif
319
Keeps track of visual per document properties.
Definition karbon_part.h:46
void historyCleared()
This signal is emitted when the command history gets cleared.
unsigned int redoLimit() const
Returns the actual redo limit.
Definition vcommand.h:202
VCommandHistory(KarbonPart *part)
Constructs a command history.
Definition vcommand.cpp:29
void setUndoLimit(unsigned int limit)
Sets a new undo limit.
Definition vcommand.cpp:99
void documentRestored()
This signal is emitted when the actual document state matches the last saved one.
void clear()
Clears the command history by removing all commands.
Definition vcommand.cpp:45
void addCommand(VCommand *command, bool execute=true)
Adds a new command to the history.
Definition vcommand.cpp:70
void undo()
Undoes the last command not already undone.
Definition vcommand.cpp:113
void commandExecuted(VCommand *)
This signal is emitted when a command is executed.
void redo()
Redoes the last command not already undone.
Definition vcommand.cpp:144
void setRedoLimit(unsigned int limit)
Sets a new redo limit.
Definition vcommand.cpp:106
void commandAdded(VCommand *)
This signal is emitted when a command is added to the history.
void lastCommandRemoved()
This signal is emitted when the last (latest) command is removed.
unsigned int undoLimit() const
Returns the actual undo limit.
Definition vcommand.h:181
void redoAllTo(VCommand *command)
Redoes all command up to the specified command.
Definition vcommand.cpp:238
void undoAllTo(VCommand *command)
Undoes all command up to the specified command.
Definition vcommand.cpp:209
void firstCommandRemoved()
This signal is emitted when the first (oldest) command is removed.
void commandExecuted()
This signal is emitted when a command is executed.
void documentSaved()
Marks the actual document state as saved.
Definition vcommand.cpp:267
~VCommandHistory()
Destroys the command history.
Definition vcommand.cpp:40
const TQPtrList< VCommand > * commands() const
Read only access to the command history list.
Definition vcommand.h:223
The base class for all karbon commands.
Definition vcommand.h:42
TQString icon() const
Returns the icon of the command.
Definition vcommand.h:111
void setName(const TQString &name)
Sets the name of the command.
Definition vcommand.h:101
virtual ~VCommand()
Destroys the command.
Definition vcommand.h:60
virtual void unexecute()
Unexecutes the command.
Definition vcommand.h:75
VDocument * document() const
Returns the document the command works on.
Definition vcommand.h:121
TQString name() const
Returns the name of the command.
Definition vcommand.h:91
virtual bool changesSelection() const
Returns if the command changes the actual document selection.
Definition vcommand.h:84
VCommand(VDocument *doc, const TQString &name, const TQString &icon="14_action")
Constructs a new command.
Definition vcommand.h:51
virtual void execute()=0
Executes the command.
All non-visual, static doc info is in here.
Definition vdocument.h:53
VVisitor()
Constructs a new visitor class.
Definition vvisitor.h:56