Scribus
Open source desktop publishing at your fingertips
undomanager.h
1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8  * Copyright (C) 2005 by Riku Leino *
9  * riku@scribus.info *
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License *
22  * along with this program; if not, write to the *
23  * Free Software Foundation, Inc., *
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25  ***************************************************************************/
26 
27 #ifndef UNDOMANAGER_H
28 #define UNDOMANAGER_H
29 
30 #include <vector>
31 #include <utility>
32 #include <QObject>
33 
34 #include "scribusapi.h"
35 #include "transaction.h"
36 #include "undostate.h"
37 #include "undoobject.h"
38 #include "undostack.h"
39 #include "undotransaction.h"
40 
41 class QString;
42 class QPixmap;
43 class UndoGui;
44 class PrefsContext;
45 
46 class TransactionData;
47 class UndoTransaction;
48 
50 typedef QMap<QString, UndoStack> StackMap;
51 
52 class SCRIBUS_API TransactionSettings
53 {
54 public:
55  QString targetName;
56  QPixmap *targetPixmap;
57  QString actionName;
58  QString description;
59  QPixmap *actionPixmap;
60 
61  TransactionSettings(void) { targetPixmap = actionPixmap = NULL; }
62 };
63 
81 class SCRIBUS_API UndoManager : public QObject
82 {
83  Q_OBJECT
84 public:
85  friend class UndoTransaction;
86 
88  static const int GLOBAL_UNDO_MODE = -1;
89 
94  static const int NO_UNDO_STACK = -2;
95 
100  static UndoManager* instance();
101 
107  static void deleteInstance();
108 
115  void setUndoEnabled(bool isEnabled);
116 
121  static bool undoEnabled();
122 
146  UndoTransaction beginTransaction(const QString &targetName = "",
147  QPixmap *targetPixmap = 0,
148  const QString &actionName = "",
149  const QString &description = "",
150  QPixmap *actionPixmap = 0);
151 
152  UndoTransaction beginTransaction(const TransactionSettings& settings);
153 
158  //void cancelTransaction();
159 
160  /*
161  * @brief Commit the current transaction.
162  *
163  * Current transaction will be commited and <code>UndoManager</code> will be switched
164  * to the normal mode. Commited transaction will be sent to the attached undo gui
165  * widgets and it will show up there as a single undo action. Details used as a parameter
166  * will be details shown in the gui widgets.
167  * @param targetName name for the target of this transaction (f.e. "Selection")
168  * @param targetPixmap Icon for the target on which this transaction works.
169  * this icon will be drawn first when the action is presented in Action History
170  * window and icon for the action will be drawn over this one.
171  * @param name name for the action
172  * @param description description for the action
173  * @param actionPixmap icon for the action performed by the transaction
174  * @sa beginTransaction()
175  */
176 // void commit(const QString &targetName = "",
177 // QPixmap *targetPixmap = 0,
178 // const QString &name = "",
179 // const QString &description = "",
180 // QPixmap *actionPixmap = 0);
181 
186  bool isTransactionMode();
187 
196  void registerGui(UndoGui* gui);
197 
202  void removeGui(UndoGui* gui);
203 
212  void switchStack(const QString& stackName);
213 
218  void renameStack(const QString& newName);
219 
224  void removeStack(const QString& stackName);
225 
227  void clearStack();
228 
237  bool hasUndoActions(int uid = -1);
238 
244  bool hasRedoActions(int uid = -1);
245 
252  UndoObject* replaceObject(ulong uid, UndoObject *newUndoObject);
253 
258  int getHistoryLength();
259 
264  bool isGlobalMode();
265 
266  UndoState* getLastUndo();
267 
268 private:
275  static UndoManager* instance_;
276 
278  static bool undoEnabled_;
279 
289  static int undoEnabledCounter_;
290 
291  PrefsContext *prefs_;
292 
294  QString currentDoc_;
295 
300  int currentUndoObjectId_;
301 
306  std::vector<TransactionData*> transactions_;
307 
314  std::vector<UndoGui*> undoGuis_;
315 
321  StackMap stacks_;
322 
329  void setState(UndoGui* gui, int uid = -1);
330 
335  void connectGuis();
340  void disconnectGuis();
344  void initIcons();
345 
346  void setTexts();
347 
348 public:
349 
355  static QString ConnectPath;
356  static QString AddVGuide;
357  static QString AddHGuide;
358  static QString DelVGuide;
359  static QString DelHGuide;
360  static QString DelVAGuide;
361  static QString DelHAGuide;
362  static QString MoveVGuide;
363  static QString MoveHGuide;
364  static QString UniteItem;
365  static QString Overprint;
366  static QString BlendMode;
367  static QString ActionPDF;
368  static QString SplitItem;
369  static QString RemoveAllGuides;
370  static QString RemoveAllPageGuides;
371  static QString LockGuides;
372  static QString UnlockGuides;
373  static QString Move;
374  static QString NewMasterPage;
375  static QString DelMasterPage;
376  static QString ImportMasterPage;
377  static QString DuplicateMasterPage;
378  static QString ApplyMasterPage;
379  static QString RenameMasterPage;
380  static QString Resize;
381  static QString Rotate;
382  static QString MoveFromTo;
383  static QString ResizeFromTo;
384  static QString ImageOffset;
385  static QString ImageScale;
386  static QString ImageOffsetFromTo;
387  static QString ImageScaleFromTo;
388  static QString Selection;
389  static QString Group;
390  static QString SelectionGroup;
391  static QString Create;
392  static QString CreateTo;
393  static QString AlignDistribute;
394  static QString ItemsInvolved;
395  static QString ItemsInvolved2;
396  static uint ItemsInvolvedLimit;
397  static QString Cancel;
398  static QString SetFill;
399  static QString ColorFromTo;
400  static QString SetShade;
401  static QString SetLineColor;
402  static QString SetLineShade;
403  static QString FlipH;
404  static QString FlipV;
405  static QString Lock;
406  static QString UnLock;
407  static QString SizeLock;
408  static QString SizeUnLock;
409  static QString EnablePrint;
410  static QString DisablePrint;
411  static QString Ungroup;
412  static QString Delete;
413  static QString Rename;
414  static QString FromTo;
415  static QString Mode;
416  static QString Paste;
417  static QString Cut;
418  static QString Transparency;
419  static QString LineTransparency;
420  static QString LineStyle;
421  static QString LineEnd;
422  static QString LineJoin;
423  static QString LineWidth;
424  static QString NoStyle;
425  static QString CustomLineStyle;
426  static QString NoLineStyle;
427  static QString StartArrow;
428  static QString EndArrow;
429  static QString StartAndEndArrow;
430  static QString CreateTable;
431  static QString RowsCols;
432  static QString SetFont;
433  static QString SetFontSize;
434  static QString SetFontWidth;
435  static QString SetFontHeight;
436  static QString SetFontFill;
437  static QString SetFontStroke;
438  static QString SetFontFillShade;
439  static QString SetFontStrokeShade;
440  static QString SetKerning;
441  static QString SetLineSpacing;
442  static QString SetStyle;
443  static QString SetLanguage;
444  static QString AlignText;
445  static QString SetFontEffect;
446  static QString ImageFrame;
447  static QString TextFrame;
448  static QString Layer;
449  static QString LatexFrame;
450  static QString ResTyp;
451  static QString Polygon;
452  static QString EditPolygon;
453  static QString EditArc;
454  static QString EditSpiral;
455  static QString BezierCurve;
456  static QString ShowImage;
457  static QString Polyline;
458  static QString PathText;
459  static QString ConvertTo;
460  static QString ImportSVG;
461  static QString RoundCorner;
462  static QString ImportUniconv;
463  static QString ImportEPS;
464  static QString ImportBarcode;
465  static QString ImportOOoDraw;
466  static QString ImportAI;
467  static QString ImportXfig;
468  static QString ImportWMF;
469  static QString ScratchSpace;
470  //static QString TextFlow;
471  static QString ObjectFrame;
472  static QString BoundingBox;
473  static QString ContourLine;
474  static QString ImageClip;
475  static QString NoTextFlow;
476  static QString NoObjectFrame;
477  static QString NoBoundingBox;
478  static QString NoContourLine;
479  static QString PageNmbr;
480  static QString ImageScaling;
481  static QString FrameSize;
482  static QString FreeScaling;
483  static QString KeepRatio;
484  static QString BreakRatio;
485  static QString EditContourLine;
486  static QString EditShape;
487  static QString ChangeShapeType;
488  static QString ResetContourLine;
489  static QString AddPage;
490  static QString AddPages;
491  static QString ReplaceText;
492  static QString FirstLineOffset;
493  static QString AppendText;
494  static QString ImportText;
495  static QString ClearText;
496  static QString TruncateText;
497  static QString AddLoremIpsum;
498  static QString DeleteText;
499  static QString InsertText;
500  static QString InsertMark;
501  static QString InsertNote;
502  static QString EditMark;
503  static QString DeleteMark;
504  static QString NewNotesStyle;
505  static QString EditNotesStyle;
506  static QString DeleteNotesStyle;
507  static QString DeleteNote;
508  static QString DeletePage;
509  static QString DeletePages;
510  static QString ChangePageProps;
511  static QString AddLayer;
512  static QString DuplicateLayer;
513  static QString DeleteLayer;
514  static QString RenameLayer;
515  static QString RaiseLayer;
516  static QString LowerLayer;
517  static QString SendToLayer;
518  static QString PrintLayer;
519  static QString DoNotPrintLayer;
520  static QString SetLayerName;
521  static QString FlowLayer;
522  static QString DisableFlowLayer;
523  static QString SetLayerBlendMode;
524  static QString SetLayerTransparency;
525  static QString MeshGradient;
526  static QString ChangeMeshGradient;
527  static QString SetLayerLocked;
528  static QString SetLayerUnlocked;
529  static QString RemoveMeshPatch;
530  static QString StartArrowScale;
531  static QString EndArrowScale;
532  static QString GetImage;
533  static QString ChangeFormula;
534  static QString GradType;
535  static QString GradTypeMask;
536  static QString GradPos;
537  static QString GradVal;
538  static QString GradValStroke;
539  static QString GradCol;
540  static QString GradTypeStroke;
541  static QString MultipleDuplicate;
542  static QString Duplicate;
543  static QString Transform;
544  static QString ApplyTextStyle;
545  static QString RemoveTextStyle;
546  static QString Columns;
547  static QString ColumnsGap;
548  static QString TextFrameDist;
549  static QString MenuUndo;
550  static QString MenuUndoEmpty;
551  static QString MenuRedo;
552  static QString MenuRedoEmpty;
553  static QString EditContour;
554  static QString ResetControlPoint;
555  static QString ResetControlPoints;
556  static QString ImageEffects;
557  static QString LevelUp;
558  static QString LevelDown;
559  static QString LevelBottom;
560  static QString LevelTop;
561  static QString InsertFrame;
562  static QString AdjustFrameToImage;
563  static QString Copy;
564  static QString CopyPage;
565  static QString ChangePageAttrs;
566  static QString ImportPage;
567  static QString MovePage;
568  static QString SwapPage;
569  static QString ToOutlines;
570  static QString LinkTextFrame;
571  static QString UnlinkTextFrame;
572  static QString ClearImage;
573  static QString PathOperation;
574  static QString WeldItems;
575  static QString UnweldItems;
576  static QString SoftShadow;
577  static QString SoftShadowColor;
578  static QString SoftShadowShade;
579  static QString SoftShadowBlurRadius;
580  static QString SoftShadowXOffset;
581  static QString SoftShadowYOffset;
582  static QString SoftShadowOpacity;
583  static QString SoftShadowBlendMode;
584  static QString SoftShadowErase;
585  static QString SoftShadowObjectTrans;
593 /*** Icons for UndoObjects *******************************************/
594  static QPixmap *IImageFrame;
595  static QPixmap *ITextFrame;
596  static QPixmap *ILatexFrame;
597  static QPixmap *ILine;
598  static QPixmap *IPolygon;
599  static QPixmap *IPolyline;
600  static QPixmap *IPathText;
601  static QPixmap *IGroup;
602  static QPixmap *ILayer;
603 /*** Icons for actions ***********************************************/
604  static QPixmap *IMove;
605  static QPixmap *IResize;
606  static QPixmap *IRotate;
607  static QPixmap *IGuides;
608  static QPixmap *ILockGuides;
609  static QPixmap *IAlignDistribute;
610  static QPixmap *IFill;
611  static QPixmap *IShade;
612  static QPixmap *IFlipH;
613  static QPixmap *IFlipV;
614  static QPixmap *ILock;
615  static QPixmap *IUnLock;
616  static QPixmap *IEnablePrint;
617  static QPixmap *IDisablePrint;
618  static QPixmap *IDelete;
619  static QPixmap *ICreate;
620  static QPixmap *IPaste;
621  static QPixmap *ICut;
622  static QPixmap *ITransparency;
623  static QPixmap *ILineStyle;
624  static QPixmap *IArrow;
625  static QPixmap *ITable;
626  static QPixmap *IFont;
627  static QPixmap *ISVG;
628  static QPixmap *IUniconv;
629  static QPixmap *IEPS;
630  static QPixmap *IAI;
631  static QPixmap *IXFIG;
632  static QPixmap *IWMF;
633  static QPixmap *IImportOOoDraw;
634  static QPixmap *IImageScaling;
635  static QPixmap *IBorder;
636  static QPixmap *IDocument;
637  static QPixmap *ILayerAction;
638  static QPixmap *IUp;
639  static QPixmap *IDown;
640  static QPixmap *IPrint;
641  static QPixmap *IGetImage;
642  static QPixmap *IChangeFormula;
643  static QPixmap *IMultipleDuplicate;
646 protected:
648  UndoManager();
649 
651  ~UndoManager();
652 
653 public slots:
657  void languageChange();
658 
671  void action(UndoObject* target, UndoState* state, QPixmap *targetPixmap = 0);
672 
686  void action(UndoObject* target, UndoState* state, const QString &targetName, QPixmap *targetPixmap = 0);
687 
695  void undo(int steps);
696 
702  void redo(int steps);
703 
712  void showObject(int uid);
713 
720  void setHistoryLength(int steps);
721  void setAllHistoryLengths(int steps);
722 
723 signals:
732  void newAction(UndoObject* target, UndoState* state);
733 
742  void undoSignal(int steps);
743 
749  void redoSignal(int steps);
750 
756  void clearRedo();
757 
763  void popBack();
764 
771  void undoRedoBegin();
772 
779  void undoRedoDone();
780 
781 };
782 
783 typedef UndoManager Um;
784 
785 class SCRIBUS_API UndoBlocker
786 {
787 public:
788  UndoBlocker() {
790  }
791 
792  ~UndoBlocker() {
794  }
795 };
796 
797 #endif
void setUndoEnabled(bool isEnabled)
Sets the undo action tracking enabled or disabled.
Definition: undomanager.cpp:56
Definition: storytext.cpp:1996
Definition: undotransaction.h:45
static UndoManager * instance()
Returns a pointer to the UndoManager instance.
Definition: undomanager.cpp:48
Definition: multipleduplicate.h:13
Definition: linestyle.h:24
UndoState describes an undoable state (action).
Definition: undostate.h:59
UndoGui is a virtual superclass for undo/redo widgets.
Definition: undogui.h:59
Superclass for all objects that are wanted to have undoable actions.
Definition: undoobject.h:59
Definition: undotransaction.h:64
Definition: undomanager.h:52
Definition: prefscontext.h:40
UndoManager handles the undo stack.
Definition: undomanager.h:81
Definition: undomanager.h:785
Definition: selection.h:34