Back to index

scribus-ng  1.3.4.dfsg+svn20071115
undomanager.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2005 by Riku Leino                                      *
00009  *   riku@scribus.info                                                     *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #ifndef UNDOMANAGER_H
00028 #define UNDOMANAGER_H
00029 
00030 #include <vector>
00031 #include <utility>
00032 #include <qobject.h>
00033 
00034 #include "scribusapi.h"
00035 #include "undostate.h"
00036 #include "undoobject.h"
00037 #include "undostack.h"
00038 
00039 class QString;
00040 class QPixmap;
00041 class UndoGui;
00042 class PrefsContext;
00043 
00045 typedef QMap<QString, UndoStack> StackMap;
00046 
00053 class TransactionState : public UndoState
00054 {
00055 public:
00057        TransactionState();
00059        ~TransactionState();
00064        void pushBack(UndoObject *target, UndoState *state);
00069        uint sizet();
00071        void useActionName();
00079        UndoState* at(int index);
00086        bool contains(int uid) const;
00087        
00097        bool containsOnly(int uid) const;
00104        UndoObject* replace(ulong uid, UndoObject *newUndoObject);
00105 
00107        void undo();
00109        void redo();
00110 private:
00112        uint size_;
00114        std::vector<UndoState*> states_;
00115 };
00116 
00134 class SCRIBUS_API UndoManager : public QObject
00135 {
00136        Q_OBJECT
00137 public:
00139        static const int GLOBAL_UNDO_MODE = -1;
00140        
00145        static const int NO_UNDO_STACK = -2;
00146        
00151        static UndoManager* instance();
00152        
00158        static void deleteInstance();
00159        
00166        void setUndoEnabled(bool isEnabled);
00167        
00172        static bool undoEnabled();
00173        
00193        void beginTransaction(const QString &targetName = "",
00194                              QPixmap *targetPixmap = 0,
00195                              const QString &actionName = "",
00196                              const QString &description = "",
00197                              QPixmap *actionPixmap = 0);
00198        
00203        void cancelTransaction();
00204        
00221        void commit(const QString &targetName = "",
00222                    QPixmap *targetPixmap = 0,
00223                    const QString &name = "",
00224                    const QString &description = "",
00225                    QPixmap *actionPixmap = 0);
00226        
00231        bool isTransactionMode();
00232        
00241        void registerGui(UndoGui* gui);
00242        
00247        void removeGui(UndoGui* gui);
00248        
00257        void switchStack(const QString& stackName);
00258        
00263        void renameStack(const QString& newName);
00264        
00269        void removeStack(const QString& stackName);
00270 
00272        void clearStack();
00273 
00282        bool hasUndoActions(int uid = -1);
00283        
00289        bool hasRedoActions(int uid = -1);
00290        
00297        UndoObject* replaceObject(ulong uid, UndoObject *newUndoObject);
00298        
00303        int getHistoryLength();
00304 
00309        bool isGlobalMode();
00310 
00311 private:
00312 
00313 /*** UndoManager::TransactionObject ***************************************************/
00314 
00321        class TransactionObject : public UndoObject
00322        {
00323        public:
00324               TransactionObject() {};
00325               virtual ~TransactionObject() {};
00326               void restore(UndoState*, bool) {};
00327        };
00328 
00329 /**************************************************************************************/
00330 
00337        static UndoManager* instance_;
00338 
00340        static bool undoEnabled_;
00341 
00351        static int undoEnabledCounter_;
00352 
00353        PrefsContext *prefs_;
00354 
00356        QString currentDoc_;
00357 
00362        int currentUndoObjectId_;
00363 
00368        std::vector<std::pair<TransactionObject*, TransactionState*> > transactions_;
00369 
00377        TransactionState *transaction_;
00378 
00380        TransactionObject *transactionTarget_;
00381 
00388        std::vector<UndoGui*> undoGuis_;
00389 
00395        StackMap stacks_;
00396 
00403        void setState(UndoGui* gui, int uid = -1);
00404 
00409        void connectGuis();
00414        void disconnectGuis();
00418        void initIcons();
00419 
00420        void setMenuTexts();
00421 
00422 public:
00423 
00429        static QString AddVGuide;
00430        static QString AddHGuide;
00431        static QString DelVGuide;
00432        static QString DelHGuide;
00433        static QString DelVAGuide;
00434        static QString DelHAGuide;
00435        static QString MoveVGuide;
00436        static QString MoveHGuide;
00437        static QString RemoveAllGuides;
00438        static QString RemoveAllPageGuides;
00439        static QString LockGuides;
00440        static QString UnlockGuides;
00441        static QString Move;
00442        static QString Resize;
00443        static QString Rotate;
00444        static QString MoveFromTo;
00445        static QString ResizeFromTo;
00446        static QString ImageOffset;
00447        static QString ImageScale;
00448        static QString ImageOffsetFromTo;
00449        static QString ImageScaleFromTo;
00450        static QString Selection;
00451        static QString Group;
00452        static QString SelectionGroup;
00453        static QString Create;
00454        static QString CreateTo;
00455        static QString AlignDistribute;
00456        static QString ItemsInvolved;
00457        static QString Cancel;
00458        static QString SetFill;
00459        static QString ColorFromTo;
00460        static QString SetShade;
00461        static QString SetLineColor;
00462        static QString SetLineShade;
00463        static QString FlipH;
00464        static QString FlipV;
00465        static QString Lock;
00466        static QString UnLock;
00467        static QString SizeLock;
00468        static QString SizeUnLock;
00469        static QString EnablePrint;
00470        static QString DisablePrint;
00471        static QString Ungroup;
00472        static QString Delete;
00473        static QString Rename;
00474        static QString FromTo;
00475        static QString ApplyMasterPage;
00476        static QString Paste;
00477        static QString Cut;
00478        static QString Transparency;
00479        static QString LineTransparency;
00480        static QString LineStyle;
00481        static QString LineEnd;
00482        static QString LineJoin;
00483        static QString LineWidth;
00484        static QString NoStyle;
00485        static QString CustomLineStyle;
00486        static QString NoLineStyle;
00487        static QString StartArrow;
00488        static QString EndArrow;
00489        static QString StartAndEndArrow;
00490        static QString CreateTable;
00491        static QString RowsCols;
00492        static QString SetFont;
00493        static QString SetFontSize;
00494        static QString SetFontWidth;
00495        static QString SetFontHeight;
00496        static QString SetFontFill;
00497        static QString SetFontStroke;
00498        static QString SetFontFillShade;
00499        static QString SetFontStrokeShade;
00500        static QString SetKerning;
00501        static QString SetLineSpacing;
00502        static QString SetStyle;
00503        static QString SetLanguage;
00504        static QString AlignText;
00505        static QString SetFontEffect;
00506        static QString ImageFrame;
00507        static QString TextFrame;
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        //static QString TextFlow;
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 MultipleDuplicate;
00550        static QString ApplyTextStyle;
00551        static QString MenuUndo;
00552        static QString MenuUndoEmpty;
00553        static QString MenuRedo;
00554        static QString MenuRedoEmpty;
00555        static QString EditContour;
00556        static QString ResetControlPoint;
00557        static QString ResetControlPoints;
00558        static QString ImageEffects;
00559        static QString InsertFrame;
00560        static QString AdjustFrameToImage;
00561        static QString Copy;
00562        static QString CopyPage;
00563        static QString ToOutlines;
00571 /*** Icons for UndoObjects *******************************************/
00572        static QPixmap *IImageFrame;
00573        static QPixmap *ITextFrame;
00574        static QPixmap *ILine;
00575        static QPixmap *IPolygon;
00576        static QPixmap *IPolyline;
00577        static QPixmap *IPathText;
00578        static QPixmap *IGroup;
00579        static QPixmap *ILayer;
00580 /*** Icons for actions ***********************************************/
00581        static QPixmap *IMove;
00582        static QPixmap *IResize;
00583        static QPixmap *IRotate;
00584        static QPixmap *IGuides;
00585        static QPixmap *ILockGuides;
00586        static QPixmap *IAlignDistribute;
00587        static QPixmap *IFill;
00588        static QPixmap *IShade;
00589        static QPixmap *IFlipH;
00590        static QPixmap *IFlipV;
00591        static QPixmap *ILock;
00592        static QPixmap *IUnLock;
00593        static QPixmap *IEnablePrint;
00594        static QPixmap *IDisablePrint;
00595        static QPixmap *IDelete;
00596        static QPixmap *ICreate;
00597        static QPixmap *IPaste;
00598        static QPixmap *ICut;
00599        static QPixmap *ITransparency;
00600        static QPixmap *ILineStyle;
00601        static QPixmap *IArrow;
00602        static QPixmap *ITable;
00603        static QPixmap *IFont;
00604        static QPixmap *ISVG;
00605        static QPixmap *IEPS;
00606        static QPixmap *IImportOOoDraw;
00607        static QPixmap *IImageScaling;
00608        static QPixmap *IBorder;
00609        static QPixmap *IDocument;
00610        static QPixmap *ILayerAction;
00611        static QPixmap *IUp;
00612        static QPixmap *IDown;
00613        static QPixmap *IPrint;
00614        static QPixmap *IGetImage;
00615        static QPixmap *IMultipleDuplicate;
00618 protected:
00620        UndoManager();
00621 
00623        ~UndoManager();
00624 
00625 public slots:
00629        void languageChange();
00630        
00643        void action(UndoObject* target, UndoState* state, QPixmap *targetPixmap = 0);
00644 
00658        void action(UndoObject* target, UndoState* state, const QString &targetName, QPixmap *targetPixmap = 0);
00659 
00667        void undo(int steps);
00668 
00674        void redo(int steps);
00675 
00684        void showObject(int uid);
00685 
00692        void setHistoryLength(int steps);
00693        void setAllHistoryLengths(int steps);
00694 
00695 signals:
00704        void newAction(UndoObject* target, UndoState* state);
00705 
00714        void undoSignal(int steps);
00715 
00721        void redoSignal(int steps);
00722 
00728        void clearRedo();
00729 
00735        void popBack();
00736 
00743        void undoRedoDone();
00744 
00745 };
00746 
00747 typedef UndoManager Um;
00748 
00749 #endif