undomanager.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef UNDOMANAGER_H
00028 #define UNDOMANAGER_H
00029
00030 #include <vector>
00031 #include <utility>
00032 #include <QObject>
00033 #include <QPixmap>
00034
00035 #include "scribusapi.h"
00036 #include "transaction.h"
00037 #include "undostate.h"
00038 #include "undoobject.h"
00039 #include "undostack.h"
00040
00041 class QString;
00042 class QPixmap;
00043 class UndoGui;
00044 class TransactionData;
00045 class PrefsContext;
00046
00048 typedef QMap<QString, UndoStack> StackMap;
00049
00056 class TransactionState : public UndoState
00057 {
00058 public:
00060 TransactionState();
00062 ~TransactionState();
00063
00068 void pushBack(UndoObject *target, UndoState *state);
00073 uint sizet();
00075 void useActionName();
00083 UndoState* at(int index);
00090 bool contains(int uid) const;
00091
00101 bool containsOnly(int uid) const;
00108 UndoObject* replace(ulong uid, UndoObject *newUndoObject);
00109
00111 void undo();
00113 void redo();
00114 private:
00116 uint size_;
00118 std::vector<UndoState*> states_;
00119 };
00120
00121
00122
00126 class UndoTransaction : public Transaction
00127 {
00128 public:
00129 UndoTransaction(TransactionData* data);
00130 virtual ~UndoTransaction();
00131 virtual bool commit();
00132 virtual bool cancel();
00133 bool commit(const QString &targetName,
00134 QPixmap *targetPixmap,
00135 const QString &name = "",
00136 const QString &description = "",
00137 QPixmap *actionPixmap = 0);
00138 };
00139
00140
00158 class SCRIBUS_API UndoManager : public QObject
00159 {
00160 Q_OBJECT
00161 public:
00162 friend class UndoTransaction;
00163
00165 static const int GLOBAL_UNDO_MODE = -1;
00166
00171 static const int NO_UNDO_STACK = -2;
00172
00177 static UndoManager* instance();
00178
00184 static void deleteInstance();
00185
00192 void setUndoEnabled(bool isEnabled);
00193
00198 static bool undoEnabled();
00199
00223 UndoTransaction beginTransaction(const QString &targetName = "",
00224 QPixmap *targetPixmap = 0,
00225 const QString &actionName = "",
00226 const QString &description = "",
00227 QPixmap *actionPixmap = 0);
00228
00233
00234
00251
00252
00253
00254
00255
00256
00261 bool isTransactionMode();
00262
00271 void registerGui(UndoGui* gui);
00272
00277 void removeGui(UndoGui* gui);
00278
00287 void switchStack(const QString& stackName);
00288
00293 void renameStack(const QString& newName);
00294
00299 void removeStack(const QString& stackName);
00300
00302 void clearStack();
00303
00312 bool hasUndoActions(int uid = -1);
00313
00319 bool hasRedoActions(int uid = -1);
00320
00327 UndoObject* replaceObject(ulong uid, UndoObject *newUndoObject);
00328
00333 int getHistoryLength();
00334
00339 bool isGlobalMode();
00340
00341 private:
00348 static UndoManager* instance_;
00349
00351 static bool undoEnabled_;
00352
00362 static int undoEnabledCounter_;
00363
00364 PrefsContext *prefs_;
00365
00367 QString currentDoc_;
00368
00373 int currentUndoObjectId_;
00374
00379 std::vector<TransactionData*> transactions_;
00380
00387 std::vector<UndoGui*> undoGuis_;
00388
00394 StackMap stacks_;
00395
00402 void setState(UndoGui* gui, int uid = -1);
00403
00408 void connectGuis();
00413 void disconnectGuis();
00417 void initIcons();
00418
00419 void setTexts();
00420
00421 public:
00422
00428 static QString AddVGuide;
00429 static QString AddHGuide;
00430 static QString DelVGuide;
00431 static QString DelHGuide;
00432 static QString DelVAGuide;
00433 static QString DelHAGuide;
00434 static QString MoveVGuide;
00435 static QString MoveHGuide;
00436 static QString RemoveAllGuides;
00437 static QString RemoveAllPageGuides;
00438 static QString LockGuides;
00439 static QString UnlockGuides;
00440 static QString Move;
00441 static QString Resize;
00442 static QString Rotate;
00443 static QString MoveFromTo;
00444 static QString ResizeFromTo;
00445 static QString ImageOffset;
00446 static QString ImageScale;
00447 static QString ImageOffsetFromTo;
00448 static QString ImageScaleFromTo;
00449 static QString Selection;
00450 static QString Group;
00451 static QString SelectionGroup;
00452 static QString Create;
00453 static QString CreateTo;
00454 static QString AlignDistribute;
00455 static QString ItemsInvolved;
00456 static QString Cancel;
00457 static QString SetFill;
00458 static QString ColorFromTo;
00459 static QString SetShade;
00460 static QString SetLineColor;
00461 static QString SetLineShade;
00462 static QString FlipH;
00463 static QString FlipV;
00464 static QString Lock;
00465 static QString UnLock;
00466 static QString SizeLock;
00467 static QString SizeUnLock;
00468 static QString EnablePrint;
00469 static QString DisablePrint;
00470 static QString Ungroup;
00471 static QString Delete;
00472 static QString Rename;
00473 static QString FromTo;
00474 static QString ApplyMasterPage;
00475 static QString Paste;
00476 static QString Cut;
00477 static QString Transparency;
00478 static QString LineTransparency;
00479 static QString LineStyle;
00480 static QString LineEnd;
00481 static QString LineJoin;
00482 static QString LineWidth;
00483 static QString NoStyle;
00484 static QString CustomLineStyle;
00485 static QString NoLineStyle;
00486 static QString StartArrow;
00487 static QString EndArrow;
00488 static QString StartAndEndArrow;
00489 static QString CreateTable;
00490 static QString RowsCols;
00491 static QString SetFont;
00492 static QString SetFontSize;
00493 static QString SetFontWidth;
00494 static QString SetFontHeight;
00495 static QString SetFontFill;
00496 static QString SetFontStroke;
00497 static QString SetFontFillShade;
00498 static QString SetFontStrokeShade;
00499 static QString SetKerning;
00500 static QString SetLineSpacing;
00501 static QString SetStyle;
00502 static QString SetLanguage;
00503 static QString AlignText;
00504 static QString SetFontEffect;
00505 static QString ImageFrame;
00506 static QString TextFrame;
00507 static QString LatexFrame;
00508 static QString Polygon;
00509 static QString BezierCurve;
00510 static QString Polyline;
00511 static QString PathText;
00512 static QString ConvertTo;
00513 static QString ImportSVG;
00514 static QString ImportEPS;
00515 static QString ImportOOoDraw;
00516 static QString ScratchSpace;
00517
00518 static QString ObjectFrame;
00519 static QString BoundingBox;
00520 static QString ContourLine;
00521 static QString ImageClip;
00522 static QString NoTextFlow;
00523 static QString NoObjectFrame;
00524 static QString NoBoundingBox;
00525 static QString NoContourLine;
00526 static QString PageNmbr;
00527 static QString ImageScaling;
00528 static QString FrameSize;
00529 static QString FreeScaling;
00530 static QString KeepRatio;
00531 static QString BreakRatio;
00532 static QString EditContourLine;
00533 static QString EditShape;
00534 static QString ResetContourLine;
00535 static QString AddPage;
00536 static QString AddPages;
00537 static QString DeletePage;
00538 static QString DeletePages;
00539 static QString AddLayer;
00540 static QString DeleteLayer;
00541 static QString RenameLayer;
00542 static QString RaiseLayer;
00543 static QString LowerLayer;
00544 static QString SendToLayer;
00545 static QString PrintLayer;
00546 static QString DoNotPrintLayer;
00547 static QString SetLayerName;
00548 static QString GetImage;
00549 static QString ChangeFormula;
00550 static QString MultipleDuplicate;
00551 static QString ApplyTextStyle;
00552 static QString MenuUndo;
00553 static QString MenuUndoEmpty;
00554 static QString MenuRedo;
00555 static QString MenuRedoEmpty;
00556 static QString EditContour;
00557 static QString ResetControlPoint;
00558 static QString ResetControlPoints;
00559 static QString ImageEffects;
00560 static QString InsertFrame;
00561 static QString AdjustFrameToImage;
00562 static QString Copy;
00563 static QString CopyPage;
00564 static QString ToOutlines;
00572
00573 static QPixmap *IImageFrame;
00574 static QPixmap *ITextFrame;
00575 static QPixmap *ILatexFrame;
00576 static QPixmap *ILine;
00577 static QPixmap *IPolygon;
00578 static QPixmap *IPolyline;
00579 static QPixmap *IPathText;
00580 static QPixmap *IGroup;
00581 static QPixmap *ILayer;
00582
00583 static QPixmap *IMove;
00584 static QPixmap *IResize;
00585 static QPixmap *IRotate;
00586 static QPixmap *IGuides;
00587 static QPixmap *ILockGuides;
00588 static QPixmap *IAlignDistribute;
00589 static QPixmap *IFill;
00590 static QPixmap *IShade;
00591 static QPixmap *IFlipH;
00592 static QPixmap *IFlipV;
00593 static QPixmap *ILock;
00594 static QPixmap *IUnLock;
00595 static QPixmap *IEnablePrint;
00596 static QPixmap *IDisablePrint;
00597 static QPixmap *IDelete;
00598 static QPixmap *ICreate;
00599 static QPixmap *IPaste;
00600 static QPixmap *ICut;
00601 static QPixmap *ITransparency;
00602 static QPixmap *ILineStyle;
00603 static QPixmap *IArrow;
00604 static QPixmap *ITable;
00605 static QPixmap *IFont;
00606 static QPixmap *ISVG;
00607 static QPixmap *IEPS;
00608 static QPixmap *IImportOOoDraw;
00609 static QPixmap *IImageScaling;
00610 static QPixmap *IBorder;
00611 static QPixmap *IDocument;
00612 static QPixmap *ILayerAction;
00613 static QPixmap *IUp;
00614 static QPixmap *IDown;
00615 static QPixmap *IPrint;
00616 static QPixmap *IGetImage;
00617 static QPixmap *IChangeFormula;
00618 static QPixmap *IMultipleDuplicate;
00621 protected:
00623 UndoManager();
00624
00626 ~UndoManager();
00627
00628 public slots:
00632 void languageChange();
00633
00646 void action(UndoObject* target, UndoState* state, QPixmap *targetPixmap = 0);
00647
00661 void action(UndoObject* target, UndoState* state, const QString &targetName, QPixmap *targetPixmap = 0);
00662
00670 void undo(int steps);
00671
00677 void redo(int steps);
00678
00687 void showObject(int uid);
00688
00695 void setHistoryLength(int steps);
00696 void setAllHistoryLengths(int steps);
00697
00698 signals:
00707 void newAction(UndoObject* target, UndoState* state);
00708
00717 void undoSignal(int steps);
00718
00724 void redoSignal(int steps);
00725
00731 void clearRedo();
00732
00738 void popBack();
00739
00746 void undoRedoDone();
00747
00748 };
00749
00750 typedef UndoManager Um;
00751
00752 #endif