~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to karbon/commands/vcommand.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
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.
19
19
*/
20
20
 
21
21
#ifndef __VCOMMAND_H__
33
33
class KarbonPart;
34
34
class KAction;
35
35
 
 
36
/**
 
37
 * The base class for all karbon commands.
 
38
 *
 
39
 * It basically defines the common interface that all commands should implement.
 
40
 */
36
41
class VCommand : public VVisitor
37
42
{
38
43
public:
 
44
        /**
 
45
         * Constructs a new command.
 
46
         *
 
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)
 
50
         */
39
51
        VCommand( VDocument* doc, const QString& name, const QString& icon = "14_action" )
40
52
                        : m_document( doc ), m_name( name ), m_icon( icon )
41
53
        {
44
56
//              assert( doc );
45
57
        }
46
58
 
 
59
        /** Destroys the command */
47
60
        virtual ~VCommand() {}
48
61
 
 
62
        /**
 
63
         * Executes the command.
 
64
         *
 
65
         * All the changes to the document are done here.
 
66
         * All commands have to implement this function.
 
67
         */
49
68
        virtual void execute() = 0;
 
69
 
 
70
        /**
 
71
         * Unexecutes the command.
 
72
         *
 
73
         * All changes to the document have to be undone here.
 
74
         */
50
75
        virtual void unexecute() {}
51
76
 
 
77
        /**
 
78
         * Returns if the command changes the actual document selection.
 
79
         *
 
80
         * This flag is checked to determine if the document has to be redrawn.
 
81
         *
 
82
         * @return true if the selection is changed, else false
 
83
         */
52
84
        virtual bool changesSelection() const { return false; }
53
85
 
 
86
        /**
 
87
         * Returns the name of the command.
 
88
         *
 
89
         * @return the command name
 
90
         */
54
91
        QString name() const
55
92
        {
56
93
                return m_name;
57
94
        }
58
95
 
 
96
        /**
 
97
         * Sets the name of the command.
 
98
         *
 
99
         * @param name the new command name
 
100
         */ 
59
101
        void setName( const QString& name )
60
102
        {
61
103
                m_name = name;
62
104
        }
63
105
 
64
 
 
 
106
        /**
 
107
         * Returns the icon of the command.
 
108
         *
 
109
         * @return the command icon
 
110
         */
65
111
        QString icon() const
66
112
        {
67
113
                return m_icon;
68
114
        }
69
115
 
 
116
        /**
 
117
         * Returns the document the command works on.
 
118
         *
 
119
         * @return the command's document
 
120
         */
70
121
        VDocument* document() const
71
122
        {
72
123
                return m_document;
79
130
        QString m_icon;
80
131
};
81
132
 
82
 
 
 
133
/**
 
134
 * Manages a set of commands.
 
135
 *
 
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.
 
142
 */
83
143
class VCommandHistory : public QObject
84
144
{
85
145
        Q_OBJECT
86
146
 
87
147
public:
 
148
        /**
 
149
         * Constructs a command history.
 
150
         *
 
151
         * @param part the part the commands are managed for
 
152
         */
88
153
        VCommandHistory( KarbonPart* part );
 
154
        
 
155
        /** Destroys the command history. */
89
156
        ~VCommandHistory();
90
157
 
91
 
        // Command manipulation.
 
158
        /**
 
159
         * Clears the command history by removing all commands.
 
160
         *
 
161
         * Emits the historyCleared signal
 
162
         */
92
163
        void clear();
93
164
 
 
165
        /**
 
166
         * Adds a new command to the history.
 
167
         *
 
168
         * @param command the new command to add
 
169
         * @param execute controls if the new command should be executed
 
170
         */
94
171
        void addCommand( VCommand* command, bool execute = true );
95
172
 
96
173
 
97
174
        // limits
 
175
        /**
 
176
         * Returns the actual undo limit.
 
177
         *
 
178
         * @return the undo limit
 
179
         */
98
180
        unsigned int undoLimit() const
99
181
        {
100
182
                return m_undoLimit;
101
183
        }
102
184
 
 
185
        /**
 
186
         * Sets a new undo limit.
 
187
         *
 
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.
 
191
         * 
 
192
         * @param limit the new undo limit
 
193
         */
103
194
        void setUndoLimit( unsigned int limit );
104
195
 
105
 
 
 
196
        /**
 
197
         * Returns the actual redo limit.
 
198
         *
 
199
         * @return the redo limit
 
200
         */
106
201
        unsigned int redoLimit() const
107
202
        {
108
203
                return m_redoLimit;
109
204
        }
110
205
 
 
206
        /**
 
207
         * Sets a new redo limit.
 
208
         *
 
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.
 
212
         *
 
213
         * @param limit the new redo limit
 
214
         */
111
215
        void setRedoLimit( unsigned int limit );
112
216
 
113
 
 
 
217
        /**
 
218
         * Read only access to the command history list.
 
219
         *
 
220
         * @return pointer to the list of commands
 
221
         */
114
222
        const QPtrList<VCommand>* commands() const
115
223
        {
116
224
                return & m_commands;
117
225
        }
118
226
 
119
227
public slots:
 
228
        /** Undoes the last command not already undone. */
120
229
        void undo();
 
230
        
 
231
        /** Redoes the last command not already undone. */
121
232
        void redo();
 
233
        
 
234
        /**
 
235
         * Undoes the specified command.
 
236
         *
 
237
         * @param command the command to undo
 
238
         */
122
239
        void undo( VCommand* command );
 
240
 
 
241
        /**
 
242
         * Redoes the specified command.
 
243
         *
 
244
         * @param command the command to redo
 
245
         */
123
246
        void redo( VCommand* command );
 
247
        
 
248
        /**
 
249
         * Undoes all command up to the specified command.
 
250
         *
 
251
         * @param command the command up to which all later commands should be undone
 
252
         */
124
253
        void undoAllTo( VCommand* command );
 
254
 
 
255
        /**
 
256
         * Redoes all command up to the specified command.
 
257
         *
 
258
         * @param command the command up to which all former commands should be redone
 
259
         */
125
260
        void redoAllTo( VCommand* command );
 
261
 
 
262
        /**
 
263
         * Marks the actual document state as saved.
 
264
         *
 
265
         * The position within the list corresponding to the actual document state is saved.
 
266
         */
126
267
        void documentSaved();
127
268
 
128
269
signals:
 
270
        /** This signal is emitted when the command history gets cleared. */
129
271
        void historyCleared();
 
272
 
 
273
        /** 
 
274
         * This signal is emitted when a command is executed.
 
275
         *
 
276
         * The executed command is given as the argument.
 
277
         */
130
278
        void commandExecuted( VCommand* );
 
279
 
 
280
        /** This signal is emitted when a command is executed. */
131
281
        void commandExecuted();
 
282
 
 
283
        /** 
 
284
         * This signal is emitted when a command is added to the history.
 
285
         *
 
286
         * The added command is given as the argument.
 
287
         */
132
288
        void commandAdded( VCommand* );
 
289
 
 
290
        /** This signal is emitted when the first (oldest) command is removed. */
133
291
        void firstCommandRemoved();
 
292
 
 
293
        /** This signal is emitted when the last (latest) command is removed. */
134
294
        void lastCommandRemoved();
 
295
 
 
296
        /** 
 
297
        * This signal is emitted when the actual document state matches the last saved one.
 
298
        *
 
299
        * Use documentSaved to set the last saved document state.
 
300
        */
135
301
        void documentRestored();
136
302
 
137
303
private: