Subversion Repositories Scribus

Rev

Rev 1700 | Rev 2093 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1111 tsoots 1
/***************************************************************************
2
 *   Copyright (C) 2005 by Riku Leino                                      *
3
 *   tsoots@gmail.com                                                      *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 *   (at your option) any later version.                                   *
9
 *                                                                         *
10
 *   This program 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         *
13
 *   GNU General Public License for more details.                          *
14
 *                                                                         *
15
 *   You should have received a copy of the GNU General Public License     *
16
 *   along with this program; if not, write to the                         *
17
 *   Free Software Foundation, Inc.,                                       *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 ***************************************************************************/
20
 
21
#ifndef UNDOMANAGER_H
22
#define UNDOMANAGER_H
23
 
24
#include <vector>
25
#include <utility>
26
#include <qobject.h>
27
#include <qpixmap.h>
1190 tsoots 28
#include <qstring.h>
1111 tsoots 29
#include "undostate.h"
30
#include "undoobject.h"
31
 
1142 tsoots 32
class UndoGui;
1197 tsoots 33
class PrefsContext;
1142 tsoots 34
 
1111 tsoots 35
typedef std::pair<UndoObject*, UndoState*> ActionPair;
36
typedef std::vector<ActionPair> ActionList;
37
typedef std::pair<ActionList::iterator, ActionList> StackPair;
38
typedef QMap<QString, StackPair> StackMap;
39
 
40
/**
41
 * @brief UndoManager handles the undo stack.
42
 *
43
 * UndoManager is the engine of the undo/redo handling. When ever an undoable
44
 * action happens an UndoState object will be sent to the UndoManager which then
1477 tsoots 45
 * stores the state in the undo stack. When an undo is requested the state is
1111 tsoots 46
 * send back to it's creator which is then responsible for doing the actual undo or
47
 * redo.
48
 *
49
 * UndoManager also handles the UndoGuis by linking them together and reporting
50
 * all undo/redo actions to the guis for them to update the visual representation.
51
 * For this to work all UndoGuis need to be registered to the UndoManager with the
52
 * registerGui() method.
53
 *
54
 * @author Riku Leino tsoots@gmail.com
55
 * @date December 2004
56
 */
57
class UndoManager : public QObject
58
{
59
        Q_OBJECT
60
 
61
private:
1213 tsoots 62
 
63
/*** UndoManager::TransactionState ***************************************************/
64
 
65
        /**
66
         * @brief TransactionState provides a container where multiple actions can be stored
67
         * @brief as a single action which then appears in the attached <code>UndoGui</code>s.
68
         * @author Riku Leino tsoots@gmail.com
69
         * @date January 2005
70
         */
71
        class TransactionState : public UndoState
72
        {
73
        private:
74
                /** @brief Number of undo states stored in this transaction */
75
                uint _size;
76
                /** @brief vector to keep the states in */
77
                std::vector<ActionPair*> states;
78
        public:
79
                /** @brief Creates a new TransactionState instance */
80
                TransactionState();
81
                /** @brief Destroys the TransactionState instance */
82
                ~TransactionState();
1477 tsoots 83
                /**
1213 tsoots 84
                 * @brief Add a new <code>UndoState</code> object to the transaction.
85
                 * @param state state to be added to the transaction
86
                 */
87
                void pushBack(UndoObject *target, UndoState *state);
88
                /**
89
                 * @brief Returns the count of the <code>UndoState</code> objects in this transaction.
90
                 * @return count of the <code>UndoState</code> objects in this transaction
91
                 */
92
                uint sizet();
1226 tsoots 93
                /** @brief Use the name from last action added to this <code>TransactionState</code> */
94
                void useActionName();
1213 tsoots 95
                /**
96
                 * @brief Returns an <code>UndoState</code> object at <code>index</code>.
97
                 * @param index index from where an <code>UndoState</code> object is returned.
98
                 * If <code>index</code> is out of scope <code>NULL</code> will be rerturned.
1477 tsoots 99
                 * @return <code>UndoState</code> object from <code>index</code> or <code>NULL</code>
1213 tsoots 100
                 * if <code>index</code> is out of scope.
101
                 */
102
                ActionPair* at(int index);
1238 tsoots 103
                /**
1443 tsoots 104
                 * @brief Returns true if this transaction contains UndoObject with the id <code>uid</code>
105
                 * @brief otherwise returns false.
106
                 * @return true if this transaction contains UndoObject with the ide <code>uid</code>
107
                 * @return otherwise returns false.
108
                 */
109
                bool contains(int uid);
110
                /**
1238 tsoots 111
                 * @brief Replace object with id uid with new UndoObject newUndoObject.
112
                 * @param uid id of the object that is wanted to be replaced
113
                 * @param newUndoObject object that is used for replacing
1658 tsoots 114
                 * @return UndoObject which was replaced
1238 tsoots 115
                 */
1658 tsoots 116
                UndoObject* replace(ulong uid, UndoObject *newUndoObject);
1213 tsoots 117
        };
118
 
119
/*** UndoManager::TransactionObject ***************************************************/
120
 
121
        /**
122
         * @brief Dummy subclass of <code>UndoObject</code> which is used for holding the name
123
         * @brief for the transaction's target object(group) (f.e "Selection", "Group", "Script"...).
124
         * @author Riku Leino tsoots@gmail.com
125
         * @date January 2005
126
         */
127
        class TransactionObject : public UndoObject
128
        {
129
        public:
130
                TransactionObject() {};
1226 tsoots 131
                virtual ~TransactionObject() {};
1213 tsoots 132
                void restore(UndoState*, bool) {};
133
        };
134
 
135
/**************************************************************************************/
136
 
1477 tsoots 137
        /**
1111 tsoots 138
         * @brief The only instance of UndoManager available.
139
         *
140
         * UndoManager is singleton and the instance can be queried with the method
141
         * instance().
142
         */
143
        static UndoManager* _instance;
144
 
145
        /** @brief Should undo states be stored or ignored */
146
        static bool _undoEnabled;
147
 
1477 tsoots 148
        /**
1430 tsoots 149
         * @brief Tracks the state of _undoEnabled.
150
         *
151
         * This value is increased whenever setUndoEnabled(true) is called and decreased
152
         * when setUndoEnabled(false) is called. This means _undoEnabled == true when this
153
         * value is 0 and when its above zero _undoEnabled == false. Counting setUndoEnabled()
1477 tsoots 154
         * calls this way guarantees that undo is not enabled accidentally calling
1430 tsoots 155
         * setUndoEnabled(true) even it has been set false before this false-true pair touched it.
156
         */
157
        static int undoEnabledCounter;
158
 
1197 tsoots 159
        PrefsContext *prefs;
160
 
1111 tsoots 161
        /** @brief Doc to which the currently active stack belongs */
162
        QString currentDoc;
163
 
1477 tsoots 164
        /**
1111 tsoots 165
         * @brief Id number of the object for what the object specific undo is shown
166
         * @brief or -1 if global undo is used.
167
         */
168
        int currentUndoObjectId;
169
 
1213 tsoots 170
        /**
1238 tsoots 171
         * @brief Stores the transactions which are currently started but not
172
         * @brief canceled or commited.
173
         */
174
        std::vector<std::pair<TransactionObject*, TransactionState*> > transactions;
175
 
176
        /**
1213 tsoots 177
         * @brief If in transaction mode this is the container for incoming <code>UndoState</code>
178
         * @brief objects.
179
         *
180
         * It is also used to detect if we are in the transaction mode. When it is <code>NULL</code>
181
         * normal mode is on.
182
         */
183
        TransactionState *transaction;
184
 
185
        /** @brief Dummy object for storing transaction target's name */
186
        TransactionObject *transactionTarget;
187
 
1477 tsoots 188
        /**
1111 tsoots 189
         * @brief UndoGuis attached to this UndoManager
190
         * @sa UndoGui
191
         * @sa UndoWidget
192
         * @sa UndoPalette
193
         */
194
        std::vector<UndoGui*> undoGuis;
195
 
196
        /** @brief Undo stacks for all open documents */
197
        StackMap stacks;
198
 
1262 tsoots 199
        /** @brief Maximum length of the undo stack. 0 marks for infinite length. */
1111 tsoots 200
        int historyLength;
201
 
1262 tsoots 202
        /**
1111 tsoots 203
         * @brief Initializes the UndoGui.
204
         * @param gui UndoGui to be initialized
1477 tsoots 205
         * @param uid UndoObject's id if in object specific mode or -1 to tell
1111 tsoots 206
         * that global undo is used.
207
         */
208
        void setState(UndoGui* gui, int uid = -1);
209
 
1262 tsoots 210
        /**
211
         * @brief Disconnect all attached UndoGui instances from signals provided by this
212
         * @brief class and other UndoGui objects.
213
         */
1111 tsoots 214
        void connectGuis();
1262 tsoots 215
        /**
216
         * @brief Connect all attached UndoGui instances to signals provided by this
217
         * @brief class and other UndoGui objects.
218
         */
1111 tsoots 219
        void disconnectGuis();
1262 tsoots 220
        /**
221
         * @brief Load icons needed for Action History window.
222
         */
1190 tsoots 223
        void initIcons();
1262 tsoots 224
        /**
225
         * @brief Checks the stack length against historyLength variable and removes
226
         * @brief actions until it is of right length.
227
         *
228
         * This method is used when a user alters the history length option in preferences
229
         * and whenever a new action is added to the stack.
230
         */
1197 tsoots 231
        void checkStackLength();
1262 tsoots 232
        /**
233
         * @brief Extracts actions from TransactionState object and undos them.
234
         * @param tstate TransactionState object from where the actions are going to be extracted.
235
         */
1213 tsoots 236
        void doTransactionUndo(TransactionState *tstate);
1262 tsoots 237
        /**
238
         * @brief Extracts actions from TransactionState object and redos them.
239
         * @param tstate TransactionState object from where the actions are going to be extracted.
240
         */
1213 tsoots 241
        void doTransactionRedo(TransactionState *tstate);
1111 tsoots 242
 
1477 tsoots 243
 
1485 tsoots 244
        /** @brief Stores the current position in the undo stack while undoing/redoing */
1477 tsoots 245
        ActionList::iterator currentAction;
1485 tsoots 246
 
247
        /**
248
         * @brief Returns the next <code>ActionPair</code> to undo.
249
         * @return next action to undo
250
         */
1477 tsoots 251
        ActionPair& getNextUndoPair();
1485 tsoots 252
 
253
        /**
254
         * @brief Returns the next <code>ActionPair</code> to redo.
255
         * @return next <code>ActionPair</code> to redo
256
         */
1477 tsoots 257
        ActionPair& getNextRedoPair();
1485 tsoots 258
 
259
        /**
260
         * @brief Sorts the stack after undo.
261
         * @param steps how many undo steps was taken
262
         */
1477 tsoots 263
        void reorderUndoStack(int steps);
1485 tsoots 264
 
265
        /**
266
         * @brief Sorts the stack after redo.
267
         * @param steps how many redo steps was taken
268
         */
1477 tsoots 269
        void reorderRedoStack(int steps);
270
 
1111 tsoots 271
public:
1477 tsoots 272
        /** @brief Marks for a global undo mode where ever UndoOjbect id is requested. */
273
        static const int GLOBAL_UNDO_MODE = -1;
274
 
1111 tsoots 275
        /**
1485 tsoots 276
         * @brief When object specific mode is requested but no suitable object is selected
277
         * @brief this can be passed to showObject() to clear the undo stack representations.
278
         */
279
        static const int NO_UNDO_STACK = -2;
280
 
281
        /**
1111 tsoots 282
         * @brief Returns a pointer to the UndoManager instance
283
         * @return A pointer to the UndoManager instance
284
         */
285
        static UndoManager* instance();
286
 
287
        /**
288
         * @brief Deletes the UndoManager Instance
289
         *
290
         * Must be called when UndoManager is no more needed.
291
         */
292
        static void deleteInstance();
293
 
294
        /**
295
         * @brief Sets the undo action tracking enabled or disabled.
296
         * @param isEnabled If true undo stack is updated with the states sent
297
         * to the UndoManager else undo stack is not updated and attached UndoGuis
298
         * are not informed of the actions.
299
         */
300
        void setUndoEnabled(bool isEnabled);
301
 
302
        /**
303
         * @brief Returns true if undo actions are stored, if not will return false.
304
         * @return true if undo actions are stored, if not will return false
305
         */
306
        static bool undoEnabled();
307
 
308
        /**
1477 tsoots 309
         * @brief Start a transaction.
1213 tsoots 310
         *
311
         * After this method has been invoked <code>UndoManager</code> will switch to the
1477 tsoots 312
     * transaction (silent) mode where it does not report actions to the attached
1357 tsoots 313
         * <code>UndoGui</code> widgets but stores all incoming <code>UndoState</code> objects into
1213 tsoots 314
         * the transaction container which after call to the method commit() will be sent
315
         * to the guis as a single undo action. Transaction can be named when starting it or
316
         * naming can be done when commiting it.
317
         * @param targetName name for the target of this transaction (f.e. "Selection")
1262 tsoots 318
         * @param targetPixmap Icon for the target on which this transaction works.
319
         * this icon will be drawn first when the action is presented in Action History
320
         * window and icon for the action will be drawn over this one.
1213 tsoots 321
         * @param name name for the transaction (f.e. "Move" would make with the above
322
         * "Move Selection")
323
         * @param description description for the transaction
1250 tsoots 324
         * @param actionPixmap icon for the action performed by the transaction
1213 tsoots 325
         * @sa commit()
326
         */
327
        void beginTransaction(const QString &targetName = "",
1250 tsoots 328
                          QPixmap *targetPixmap = 0,
329
                          const QString &actionName = "",
1213 tsoots 330
                          const QString &description = "",
1250 tsoots 331
                          QPixmap *actionPixmap = 0);
1213 tsoots 332
 
1477 tsoots 333
        /**
1213 tsoots 334
         * @brief Cancels the current transaction and deletes groupped <code>UndoState</code>s.
335
         * @brief Nothing from canceled transaction will be sent to the undo gui widgets.
336
         */
337
        void cancelTransaction();
338
 
1477 tsoots 339
        /**
1213 tsoots 340
         * @brief Commit the current transaction.
341
         *
342
         * Current transaction will be commited and <code>UndoManager</code> will be switched
1477 tsoots 343
         * to the normal mode. Commited transaction will be sent to the attached undo gui
1213 tsoots 344
         * widgets and it will show up there as a single undo action. Details used as a parameter
345
         * will be details shown in the gui widgets.
346
         * @param targetName name for the target of this transaction (f.e. "Selection")
1262 tsoots 347
         * @param targetPixmap Icon for the target on which this transaction works.
348
         * this icon will be drawn first when the action is presented in Action History
349
         * window and icon for the action will be drawn over this one.
1213 tsoots 350
         * @param name name for the action
351
         * @param description description for the action
1250 tsoots 352
         * @param actionPixmap icon for the action performed by the transaction
1213 tsoots 353
         * @sa beginTransaction()
354
         */
355
        void commit(const QString &targetName = "",
1250 tsoots 356
                QPixmap *targetPixmap = 0,
1213 tsoots 357
                const QString &name = "",
358
                const QString &description = "",
1250 tsoots 359
                QPixmap *actionPixmap = 0);
1213 tsoots 360
 
361
        /**
362
         * @brief Returns true if in transaction mode if not will return false.
363
         * @return true if in transaction mode if not will return false
364
         */
365
        bool isTransactionMode();
366
 
367
        /**
1111 tsoots 368
         * @brief Register an UndoGui to the UndoManager.
369
         *
370
         * After registering a gui to the manager the gui will be updated with the
371
         * undo action information received by the UndoManager. Actions done with the
372
         * UndoGui to be registered are also handled after registering.
373
         * @param gui A pointer to the UndoGui that is wanted to be registered.
374
         */
375
        void registerGui(UndoGui* gui);
376
 
377
        /**
378
         * @brief Removes an UndoGui from UndoManager.
379
         * @param gui UndoGui to be removed from the UndoManager.
380
         */
381
        void removeGui(UndoGui* gui);
382
 
383
        /**
384
         * @brief Changes the active undo stack.
385
         *
386
         * Sets the stack connected to the name <code>stackName</code> active. Calling
387
         * this method will send clear() signal to the attached <code>UndoGui</code>s and
388
         * will update their undo stack representations.
389
         * @param stackName Name of the stack to be used
390
         */
391
        void switchStack(const QString& stackName);
392
 
393
        /**
394
         * @brief Rename the current stack
395
         * @param newName New name for the current stack.
396
         */
1252 tsoots 397
        void renameStack(const QString& newName);
1111 tsoots 398
 
399
        /**
400
         * @brief Remove the stack with the name <code>stackName</code>
401
         * @param stackName Name of the stack that is wanted to be removed
402
         */
1252 tsoots 403
        void removeStack(const QString& stackName);
1111 tsoots 404
 
405
        /**
406
         * @brief Returns true if there are actions that can be undone otherwise returns false.
407
         *
408
         * This is useful when undo/redo actions are handled with a gui that is not attached to
409
         * the UndoManager (f.e. menu items) and when those gui items are wanted to set enabled
410
         * or disabled depending on the status of the undo stack.
411
         * @return true if there are actions that can be undone otherwise returns false
412
         */
1443 tsoots 413
        bool hasUndoActions(int uid = -1);
1111 tsoots 414
 
415
        /**
416
         * @brief Returns true if there are actions that can be redone otherwise returns false.
417
         * @return true if there are actions that can be redone otherwise returns false
418
         * @sa UndoManager::hasUndoActions()
419
         */
1443 tsoots 420
        bool hasRedoActions(int uid = -1);
1111 tsoots 421
 
422
        /**
1238 tsoots 423
         * @brief Replace an UndoObject with the id uid with a new UndoObject new.
424
         * @param uid Id for the UndoObject that is wanted to be replaced.
425
         * @param newUndoObject UndoObject which will replace an old UndoObject in the stack.
1658 tsoots 426
         * @return UndoObject which was replaced
1238 tsoots 427
         */
1658 tsoots 428
        UndoObject* replaceObject(ulong uid, UndoObject *newUndoObject);
1238 tsoots 429
 
430
        /**
1111 tsoots 431
         * @brief Returns the maximum length of the undostack.
432
         * @return the maximum length of the undostack
433
         */
434
        int getHistoryLength();
435
 
1477 tsoots 436
        /**
1461 tsoots 437
         * @brief Returns true if in global mode and false if in object specific mode.
438
         * @return true if in global mode and false if in object specific mode
439
         */
440
        bool isGlobalMode();
441
 
1199 tsoots 442
        /**
1190 tsoots 443
        * @name Action strings
444
        * Strings describing undo actions
445
        */
446
        /*@{*/
447
        static const QString AddVGuide;
448
        static const QString AddHGuide;
449
        static const QString DelVGuide;
450
        static const QString DelHGuide;
451
        static const QString MoveVGuide;
452
        static const QString MoveHGuide;
453
        static const QString LockGuides;
454
        static const QString UnlockGuides;
1204 tsoots 455
        static const QString Move;
1206 tsoots 456
        static const QString Resize;
1211 tsoots 457
        static const QString Rotate;
458
        static const QString MoveFromTo;
459
        static const QString ResizeFromTo;
1226 tsoots 460
        static const QString Selection;
461
        static const QString Group;
1355 tsoots 462
        static const QString SelectionGroup;
1238 tsoots 463
        static const QString Create;
464
        static const QString CreateTo;
1247 tsoots 465
        static const QString AlignDistribute;
466
        static const QString ItemsInvolved;
467
        static const QString Cancel;
1286 tsoots 468
        static const QString SetFill;
469
        static const QString ColorFromTo;
470
        static const QString SetShade;
471
        static const QString SetLineColor;
472
        static const QString SetLineShade;
1287 tsoots 473
        static const QString FlipH;
474
        static const QString FlipV;
1290 tsoots 475
        static const QString Lock;
476
        static const QString UnLock;
477
        static const QString SizeLock;
478
        static const QString SizeUnLock;
1293 tsoots 479
        static const QString Ungroup;
1340 tsoots 480
        static const QString Delete;
1357 tsoots 481
        static const QString Rename;
482
        static const QString FromTo;
483
        static const QString ApplyTemplate;
1369 tsoots 484
        static const QString Paste;
485
        static const QString Cut;
1371 tsoots 486
        static const QString Transparency;
487
        static const QString LineTransparency;
1383 tsoots 488
        static const QString LineStyle;
1385 tsoots 489
        static const QString LineEnd;
490
        static const QString LineJoin;
491
        static const QString LineWidth;
1386 tsoots 492
        static const QString NoStyle;
493
        static const QString CustomLineStyle;
494
        static const QString NoLineStyle;
1391 tsoots 495
        static const QString StartArrow;
496
        static const QString EndArrow;
1396 tsoots 497
        static const QString CreateTable;
498
        static const QString RowsCols;
1399 tsoots 499
        static const QString SetFont;
1400 tsoots 500
        static const QString SetFontSize;
501
        static const QString SetFontWidth;
1401 tsoots 502
        static const QString SetFontFill;
503
        static const QString SetFontStroke;
1402 tsoots 504
        static const QString SetFontFillShade;
505
        static const QString SetFontStrokeShade;
1403 tsoots 506
        static const QString SetKerning;
507
        static const QString SetLineSpacing;
508
        static const QString SetStyle;
509
        static const QString SetLanguage;
1404 tsoots 510
        static const QString AlignText;
1415 tsoots 511
        static const QString SetFontEffect;
1416 tsoots 512
        static const QString ImageFrame;
513
        static const QString TextFrame;
514
        static const QString Polygon;
515
        static const QString BezierCurve;
516
        static const QString Polyline;
517
        static const QString ConvertTo;
1434 tsoots 518
        static const QString ImportSVG;
519
        static const QString ImportEPS;
520
        static const QString ImportOOoDraw;
1485 tsoots 521
        static const QString ScratchSpace;
1489 tsoots 522
        static const QString TextFlow;
523
        static const QString BoundingBox;
524
        static const QString ContourLine;
525
        static const QString NoTextFlow;
526
        static const QString NoBoundingBox;
527
        static const QString NoContourLine;
1490 tsoots 528
        static const QString PageNmbr;
1495 tsoots 529
        static const QString ImageScaling;
530
        static const QString FrameSize;
531
        static const QString FreeScaling;
532
        static const QString KeepRatio;
533
        static const QString BreakRatio;
1509 tsoots 534
        static const QString EditContourLine;
535
        static const QString EditShape;
1518 tsoots 536
        static const QString ResetContourLine;
1658 tsoots 537
        static const QString AddPage;
538
        static const QString AddPages;
1663 tsoots 539
        static const QString DeletePage;
540
        static const QString DeletePages;
1688 tsoots 541
        static const QString AddLayer;
542
        static const QString DeleteLayer;
543
        static const QString RenameLayer;
1697 tsoots 544
        static const QString RaiseLayer;
545
        static const QString LowerLayer;
1688 tsoots 546
        static const QString SendToLayer;
1697 tsoots 547
        static const QString PrintLayer;
548
        static const QString DoNotPrintLayer;
1700 tsoots 549
        static const QString SetLayerName;
1832 tsoots 550
        static const QString GetImage;
1190 tsoots 551
        /*@}*/
1204 tsoots 552
 
1190 tsoots 553
        /**
554
         * @name Action icons
555
         * Icons for undo actions
556
         */
557
        /*@{*/
1250 tsoots 558
/*** Icons for UndoObjects *******************************************/
559
        static QPixmap *IImageFrame;
560
        static QPixmap *ITextFrame;
561
        static QPixmap *ILine;
562
        static QPixmap *IPolygon;
563
        static QPixmap *IPolyline;
564
        static QPixmap *IPathText;
1254 tsoots 565
        static QPixmap *IGroup;
1688 tsoots 566
        static QPixmap *ILayer;
1250 tsoots 567
/*** Icons for actions ***********************************************/
568
        static QPixmap *IMove;
569
        static QPixmap *IResize;
570
        static QPixmap *IRotate;
1190 tsoots 571
        static QPixmap *IGuides;
572
        static QPixmap *ILockGuides;
1247 tsoots 573
        static QPixmap *IAlignDistribute;
1286 tsoots 574
        static QPixmap *IFill;
575
        static QPixmap *IShade;
1287 tsoots 576
        static QPixmap *IFlipH;
577
        static QPixmap *IFlipV;
1290 tsoots 578
        static QPixmap *ILock;
579
        static QPixmap *IUnLock;
1340 tsoots 580
        static QPixmap *IDelete;
581
        static QPixmap *ICreate;
1369 tsoots 582
        static QPixmap *IPaste;
583
        static QPixmap *ICut;
1371 tsoots 584
        static QPixmap *ITransparency;
1383 tsoots 585
        static QPixmap *ILineStyle;
1391 tsoots 586
        static QPixmap *IArrow;
1396 tsoots 587
        static QPixmap *ITable;
1399 tsoots 588
        static QPixmap *IFont;
1440 tsoots 589
        static QPixmap *ISVG;
590
        static QPixmap *IEPS;
1434 tsoots 591
        static QPixmap *IImportOOoDraw;
1495 tsoots 592
        static QPixmap *IImageScaling;
1509 tsoots 593
        static QPixmap *IBorder;
1658 tsoots 594
        static QPixmap *IDocument;
1688 tsoots 595
        static QPixmap *ILayerAction;
1697 tsoots 596
        static QPixmap *IUp;
597
        static QPixmap *IDown;
598
        static QPixmap *IPrint;
1832 tsoots 599
        static QPixmap *IGetImage;
1190 tsoots 600
        /*@}*/
601
 
1111 tsoots 602
protected:
603
        /** @brief Creates a new UndoManager instance */
604
        UndoManager();
605
 
606
        /** @brief Destroys the UndoManager instance */
607
        ~UndoManager();
608
 
609
private slots:
610
        /**
611
         * @brief Take undo steps the given amount
612
         *
613
         * When an UndoGui is registered to the UndoManager gui's undo() signal
1477 tsoots 614
         * is connected to this slot. Emitting an undo() signal will make the
615
         * UndoManager perform undo actions the given number of steps.
1111 tsoots 616
         * @param steps Number of undo actions to make
617
         */
618
        void doUndo(int steps);
619
 
620
        /**
621
         * @brief Take redo steps the given amount
622
         * @param steps Number of redo actions to make
623
         * @sa UndoManager::doUndo(int steps)
624
         */
625
        void doRedo(int steps);
626
 
627
public slots:
628
        /**
629
         * @brief Adds a new action to the undo stack.
630
         *
631
         * If _unodEnabled is true the action will be stored otherwise it will
632
         * be just ignored. When a new action is added redo items from the stack
633
         * will be removed and the current action will be set to the one which was
634
         * added.
635
         * @param target Source of the action. When undoing/redoing this action
636
         * restore() method of this UndoObject will be called.
637
         * @param state UndoSate describing the state (action).
1356 tsoots 638
         * @param targetPixmap Is used to override the default target icon in this action.
1111 tsoots 639
         */
1340 tsoots 640
        void action(UndoObject* target, UndoState* state, QPixmap *targetPixmap = 0);
1111 tsoots 641
 
642
        /**
1356 tsoots 643
         * @brief Adds a new action to the undo stack.
644
         *
645
         * If _unodEnabled is true the action will be stored otherwise it will
646
         * be just ignored. When a new action is added redo items from the stack
647
         * will be removed and the current action will be set to the one which was
648
         * added.
649
         * @param target Source of the action. When undoing/redoing this action
650
         * restore() method of this UndoObject will be called.
651
         * @param state UndoSate describing the state (action).
652
         * @param targetName Is used to override the default target name in this action.
653
         * @param targetPixmap Is used to override the default target icon in this action.
654
         */
655
        void action(UndoObject* target, UndoState* state, const QString &targetName, QPixmap *targetPixmap = 0);
656
 
657
        /**
1111 tsoots 658
         * @brief Informs UndoManager to perform undo
659
         *
660
         * If an undo is wanted and the caller is not registered UndoGui this method
661
         * can be used. Useful for example with the menu entry for undo.
662
         * @param steps Number of undo steps to take
663
         */
664
        void undo(int steps);
665
 
666
        /**
667
         * @brief Informs UndoManager to perform redo
668
         * @param steps Number of redo steps to take
669
         * @sa UndoManager::undo(int steps)
670
         */
671
        void redo(int steps);
672
 
1197 tsoots 673
        /**
1443 tsoots 674
         * @brief Switches the state of UndoManager (global/object specific undo).
675
         *
676
         * If parameter uid is less than 0 global undo is used else the undo state
677
         * is object specific using the object whose uid is given as a parameter.
678
         * @param uid UndoObject's id for what the object specific undo is wanted or
679
         * -1 if global undo is wanted.
680
         */
681
        void showObject(int uid);
682
 
683
        /**
1197 tsoots 684
         * @brief Sets the length of the undo stack.
685
         *
686
         * Tells how many UndoStates are stored.
687
         * @param steps number of UndoStates to store in the undo stack
688
         */
689
        void setHistoryLength(int steps);
690
 
1111 tsoots 691
signals:
692
        /**
693
         * @brief Emitted when a new undo action is stored to the undo stack.
694
         *
1477 tsoots 695
         * This signal is connected to the registered UndoGuis for them to update the
1111 tsoots 696
         * visual representation of the undo stack.
697
         * @param target Source of the action
698
         * @param state UndoState describing the action
699
         */
700
        void newAction(UndoObject* target, UndoState* state);
701
 
702
        /**
703
         * @brief Emitted when an undo action has been done.
704
         *
705
         * It is connected to attached guis to inform them to update the visual
1190 tsoots 706
         * representation of the undo stack. This signal will be also sent to the
707
         * <code>UndoGui</code> where it came from.
1111 tsoots 708
         * @param steps Number of steps to take
709
         */
710
        void undoSignal(int steps);
711
 
712
        /**
713
         * @brief Emitted when a redo action has been done.
714
         * @param steps Number of steps to take
715
         * @sa UndoManager::undoSignal(int steps)
716
         */
717
        void redoSignal(int steps);
718
 
1477 tsoots 719
        /**
1457 tsoots 720
         * @brief Emitted when a new actions comes in and UndoManager is in object
721
         * @brief specific mode and action does not belong to the currently selected
722
         * @brief object.
723
         */
724
        void clearRedo();
725
 
1111 tsoots 726
        /**
727
         * @brief This signal is used to notify registered UndoGui instances that
1477 tsoots 728
         * @brief history limit is reached and the last item from the stack
1111 tsoots 729
         * @brief representation should be removed.
730
         */
731
        void popBack();
732
 
733
        /**
734
         * @brief This signal is emitted when all requested undo/redo actions have been done.
735
         *
736
         * It could be used in the application as a signal when the view can be rendered
737
         * again after undo/redo.
738
         */
739
        void undoRedoDone();
1190 tsoots 740
 
1111 tsoots 741
};
742
 
1190 tsoots 743
typedef UndoManager Um;
744
 
1111 tsoots 745
#endif