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 49 /** @brief Key is the doc name, value is it's undo stack */ 50 typedef QMap<QString, UndoStack> StackMap; 51 52 class SCRIBUS_API TransactionSettings 53 { 54 public: 55 QPixmap* actionPixmap {nullptr}; 56 QPixmap* targetPixmap {nullptr}; 57 QString actionName; 58 QString description; 59 QString targetName; 60 TransactionSettings(void)61 TransactionSettings(void) {} 62 }; 63 64 /** 65 * @brief UndoManager handles the undo stack. 66 * 67 * UndoManager is the engine of the undo/redo handling. When ever an undoable 68 * action happens an UndoState object will be sent to the UndoManager which then 69 * stores the state in the undo stack. When an undo is requested the state is 70 * send back to it's creator which is then responsible for doing the actual undo or 71 * redo. 72 * 73 * UndoManager also handles the UndoGuis by linking them together and reporting 74 * all undo/redo actions to the guis for them to update the visual representation. 75 * For this to work all UndoGuis need to be registered to the UndoManager with the 76 * registerGui() method. 77 * 78 * @author Riku Leino tsoots@gmail.com 79 * @date December 2004 80 */ 81 class SCRIBUS_API UndoManager : public QObject 82 { 83 Q_OBJECT 84 public: 85 friend class UndoTransaction; 86 87 /** @brief Marks for a global undo mode where ever UndoOjbect id is requested. */ 88 static const int GLOBAL_UNDO_MODE = -1; 89 90 /** 91 * @brief When object specific mode is requested but no suitable object is selected 92 * @brief this can be passed to showObject() to clear the undo stack representations. 93 */ 94 static const int NO_UNDO_STACK = -2; 95 96 /** 97 * @brief Returns a pointer to the UndoManager instance 98 * @return A pointer to the UndoManager instance 99 */ 100 static UndoManager* instance(); 101 102 /** 103 * @brief Deletes the UndoManager Instance 104 * 105 * Must be called when UndoManager is no more needed. 106 */ 107 static void deleteInstance(); 108 109 /** 110 * @brief Sets the undo action tracking enabled or disabled. 111 * @param isEnabled If true undo stack is updated with the states sent 112 * to the UndoManager else undo stack is not updated and attached UndoGuis 113 * are not informed of the actions. 114 */ 115 void setUndoEnabled(bool isEnabled); 116 117 /** 118 * @brief Returns true if undo actions are stored, if not will return false. 119 * @return true if undo actions are stored, if not will return false 120 */ 121 static bool undoEnabled(); 122 123 /** 124 * @brief Start a transaction. 125 * 126 * After this method has been invoked <code>UndoManager</code> will switch to the 127 * transaction (silent) mode where it does not report actions to the attached 128 * <code>UndoGui</code> widgets but stores all incoming <code>UndoState</code> objects into 129 * the transaction container which after call to the method commit() will be sent 130 * to the guis as a single undo action. Transaction can be named when starting it or 131 * naming can be done when committing it. 132 * @param targetName name for the target of this transaction (f.e. "Selection") 133 * @param targetPixmap Icon for the target on which this transaction works. 134 * this icon will be drawn first when the action is presented in Action History 135 * window and icon for the action will be drawn over this one. 136 * @param actionName name for the transaction (f.e. "Move" would make with the above 137 * "Move Selection") 138 * The result can only be used for initializing a Transaction object, eg. on the stack: 139 * Transaction groupTransaction(undoManger->beginTransaction(...)); 140 * or the heap: 141 * Transaction* groupTransactionPtr = new Transaction(undoManger->beginTransaction(...)); 142 * @param description description for the transaction 143 * @param actionPixmap icon for the action performed by the transaction 144 * @sa commit() 145 */ 146 UndoTransaction beginTransaction(const QString &targetName = QString(), 147 QPixmap *targetPixmap = nullptr, 148 const QString &actionName = QString(), 149 const QString &description = QString(), 150 QPixmap *actionPixmap = nullptr); 151 152 UndoTransaction beginTransaction(const TransactionSettings& settings); 153 154 /** 155 * @brief Cancels the current transaction and deletes groupped <code>UndoState</code>s. 156 * @brief Nothing from canceled transaction will be sent to the undo gui widgets. 157 */ 158 //void cancelTransaction(); 159 160 /* 161 * @brief Commit the current transaction. 162 * 163 * Current transaction will be committed and <code>UndoManager</code> will be switched 164 * to the normal mode. Committed 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 182 /** 183 * @brief Returns true if in transaction mode if not will return false. 184 * @return bool true if in transaction mode if not will return false 185 */ 186 bool isTransactionMode(); 187 188 /** 189 * @brief Register an UndoGui to the UndoManager. 190 * 191 * After registering a gui to the manager the gui will be updated with the 192 * undo action information received by the UndoManager. Actions done with the 193 * UndoGui to be registered are also handled after registering. 194 * @param gui A pointer to the UndoGui that is wanted to be registered. 195 */ 196 void registerGui(UndoGui* gui); 197 198 /** 199 * @brief Removes an UndoGui from UndoManager. 200 * @param gui UndoGui to be removed from the UndoManager. 201 */ 202 void removeGui(UndoGui* gui); 203 204 /** 205 * @brief Changes the active undo stack. 206 * 207 * Sets the stack connected to the name <code>stackName</code> active. Calling 208 * this method will send clear() signal to the attached <code>UndoGui</code>s and 209 * will update their undo stack representations. 210 * @param stackName Name of the stack to be used 211 */ 212 void switchStack(const QString& stackName); 213 214 /** 215 * @brief Rename the current stack 216 * @param newName New name for the current stack. 217 */ 218 void renameStack(const QString& newName); 219 220 /** 221 * @brief Remove the stack with the name <code>stackName</code> 222 * @param stackName Name of the stack that is wanted to be removed 223 */ 224 void removeStack(const QString& stackName); 225 226 /** clear the current undo stack */ 227 void clearStack(); 228 229 /** 230 * @brief Returns true if there are actions that can be undone otherwise returns false. 231 * 232 * This is useful when undo/redo actions are handled with a gui that is not attached to 233 * the UndoManager (f.e. menu items) and when those gui items are wanted to set enabled 234 * or disabled depending on the status of the undo stack. 235 * @return true if there are actions that can be undone otherwise returns false 236 */ 237 bool hasUndoActions(int uid = -1); 238 239 /** 240 * @brief Returns true if there are actions that can be redone otherwise returns false. 241 * @return true if there are actions that can be redone otherwise returns false 242 * @sa UndoManager::hasUndoActions() 243 */ 244 bool hasRedoActions(int uid = -1); 245 246 /** 247 * @brief Replace an UndoObject with the id uid with a new UndoObject new. 248 * @param uid Id for the UndoObject that is wanted to be replaced. 249 * @param newUndoObject UndoObject which will replace an old UndoObject in the stack. 250 * @return UndoObject which was replaced 251 */ 252 UndoObject* replaceObject(ulong uid, UndoObject *newUndoObject); 253 254 /** 255 * @brief Returns the maximum length of the undostack. 256 * @return the maximum length of the undostack 257 */ 258 int getHistoryLength(); 259 260 /** 261 * @brief Returns true if in global mode and false if in object specific mode. 262 * @return true if in global mode and false if in object specific mode 263 */ 264 bool isGlobalMode(); 265 266 UndoState* getLastUndo(); 267 268 private: 269 /** 270 * @brief The only instance of UndoManager available. 271 * 272 * UndoManager is singleton and the instance can be queried with the method 273 * instance(). 274 */ 275 static UndoManager* m_instance; 276 277 /** @brief Should undo states be stored or ignored */ 278 static bool m_undoEnabled; 279 280 /** 281 * @brief Tracks the state of _undoEnabled. 282 * 283 * This value is increased whenever setUndoEnabled(true) is called and decreased 284 * when setUndoEnabled(false) is called. This means _undoEnabled == true when this 285 * value is 0 and when its above zero _undoEnabled == false. Counting setUndoEnabled() 286 * calls this way guarantees that undo is not enabled accidentally calling 287 * setUndoEnabled(true) even it has been set false before this false-true pair touched it. 288 */ 289 static int m_undoEnabledCounter; 290 291 PrefsContext *prefs_; 292 293 /** @brief Doc to which the currently active stack belongs */ 294 QString m_currentDoc; 295 296 /** 297 * @brief Id number of the object for what the object specific undo is shown 298 * @brief or -1 if global undo is used. 299 */ 300 int m_currentUndoObjectId; 301 302 /** 303 * @brief Stores the transactions which are currently started but not 304 * @brief canceled or committed. 305 */ 306 std::vector<TransactionData*> m_transactions; 307 308 /** 309 * @brief UndoGuis attached to this UndoManager 310 * @sa UndoGui 311 * @sa UndoWidget 312 * @sa UndoPalette 313 */ 314 std::vector<UndoGui*> m_undoGuis; 315 316 /** 317 * @brief Undo stacks for all open document 318 * 319 * Whenever current stack is used it's referred with <code>stacks_[currentDoc_]</code> 320 */ 321 StackMap m_stacks; 322 323 /** 324 * @brief Initializes the UndoGui. 325 * @param gui UndoGui to be initialized 326 * @param uid UndoObject's id if in object specific mode or -1 to tell 327 * that global undo is used. 328 */ 329 void setState(UndoGui* gui, int uid = -1); 330 331 /** 332 * @brief Disconnect all attached UndoGui instances from signals provided by this 333 * @brief class and other UndoGui objects. 334 */ 335 void connectGuis(); 336 /** 337 * @brief Connect all attached UndoGui instances to signals provided by this 338 * @brief class and other UndoGui objects. 339 */ 340 void disconnectGuis(); 341 /** 342 * @brief Load icons needed for Action History window. 343 */ 344 void initIcons(); 345 346 void setTexts(); 347 348 public: 349 350 /** 351 * @name Action strings 352 * Strings describing undo actions 353 */ 354 /*@{*/ 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 int 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 RoundCorner; 461 static QString ImportAI; 462 static QString ImportApplePages; 463 static QString ImportBarcode; 464 static QString ImportCDR; 465 static QString ImportCGM; 466 static QString ImportCVG; 467 static QString ImportDRW; 468 static QString ImportEMF; 469 static QString ImportEPS; 470 static QString ImportFreehand; 471 static QString ImportIDML; 472 static QString ImportOOoDraw; 473 static QString ImportPageMaker; 474 static QString ImportPDF; 475 static QString ImportPict; 476 static QString ImportPublisher; 477 static QString ImportQXP; 478 static QString ImportShape; 479 static QString ImportSML; 480 static QString ImportSVG; 481 static QString ImportSVM; 482 static QString ImportUniconv; 483 static QString ImportViva; 484 static QString ImportVSD; 485 static QString ImportWMF; 486 static QString ImportWPG; 487 static QString ImportXara; 488 static QString ImportXfig; 489 static QString ImportXPS; 490 static QString ImportZMF; 491 static QString ScratchSpace; 492 static QString ObjectFrame; 493 static QString BoundingBox; 494 static QString ContourLine; 495 static QString ImageClip; 496 static QString NoTextFlow; 497 static QString NoObjectFrame; 498 static QString NoBoundingBox; 499 static QString NoContourLine; 500 static QString PageNmbr; 501 static QString ImageScaling; 502 static QString FrameSize; 503 static QString FreeScaling; 504 static QString KeepRatio; 505 static QString BreakRatio; 506 static QString EditContourLine; 507 static QString EditShape; 508 static QString ChangeShapeType; 509 static QString ResetContourLine; 510 static QString AddPage; 511 static QString AddPages; 512 static QString ReplaceText; 513 static QString FirstLineOffset; 514 static QString AppendText; 515 static QString ImportText; 516 static QString ClearText; 517 static QString TruncateText; 518 static QString AddLoremIpsum; 519 static QString DeleteText; 520 static QString InsertText; 521 static QString InsertMark; 522 static QString InsertNote; 523 static QString EditMark; 524 static QString DeleteMark; 525 static QString NewNotesStyle; 526 static QString EditNotesStyle; 527 static QString DeleteNotesStyle; 528 static QString DeleteNote; 529 static QString DeletePage; 530 static QString DeletePages; 531 static QString ChangePageProps; 532 static QString AddLayer; 533 static QString DuplicateLayer; 534 static QString DeleteLayer; 535 static QString RenameLayer; 536 static QString RaiseLayer; 537 static QString LowerLayer; 538 static QString SendToLayer; 539 static QString PrintLayer; 540 static QString DoNotPrintLayer; 541 static QString SetLayerName; 542 static QString FlowLayer; 543 static QString DisableFlowLayer; 544 static QString SetLayerBlendMode; 545 static QString SetLayerTransparency; 546 static QString MeshGradient; 547 static QString ChangeMeshGradient; 548 static QString SetLayerLocked; 549 static QString SetLayerUnlocked; 550 static QString RemoveMeshPatch; 551 static QString StartArrowScale; 552 static QString EndArrowScale; 553 static QString GetImage; 554 static QString ChangeFormula; 555 static QString GradType; 556 static QString GradTypeMask; 557 static QString GradPos; 558 static QString GradVal; 559 static QString GradValStroke; 560 static QString GradCol; 561 static QString GradTypeStroke; 562 static QString MultipleDuplicate; 563 static QString Duplicate; 564 static QString Transform; 565 static QString ApplyTextStyle; 566 static QString RemoveTextStyle; 567 static QString Columns; 568 static QString ColumnsGap; 569 static QString TextFrameDist; 570 static QString MenuUndo; 571 static QString MenuUndoEmpty; 572 static QString MenuRedo; 573 static QString MenuRedoEmpty; 574 static QString EditContour; 575 static QString ResetControlPoint; 576 static QString ResetControlPoints; 577 static QString ImageEffects; 578 static QString LevelUp; 579 static QString LevelDown; 580 static QString LevelBottom; 581 static QString LevelTop; 582 static QString InsertFrame; 583 static QString AdjustFrameToImage; 584 static QString Copy; 585 static QString CopyPage; 586 static QString ChangePageAttrs; 587 static QString ImportPage; 588 static QString MovePage; 589 static QString SwapPage; 590 static QString ToOutlines; 591 static QString LinkTextFrame; 592 static QString UnlinkTextFrame; 593 static QString ClearImage; 594 static QString PathOperation; 595 static QString WeldItems; 596 static QString UnweldItems; 597 static QString SoftShadow; 598 static QString SoftShadowColor; 599 static QString SoftShadowShade; 600 static QString SoftShadowBlurRadius; 601 static QString SoftShadowXOffset; 602 static QString SoftShadowYOffset; 603 static QString SoftShadowOpacity; 604 static QString SoftShadowBlendMode; 605 static QString SoftShadowErase; 606 static QString SoftShadowObjectTrans; 607 /*@}*/ 608 609 /** 610 * @name Action icons 611 * Icons for undo actions 612 */ 613 /*@{*/ 614 /*** Icons for UndoObjects *******************************************/ 615 static QPixmap *IImageFrame; 616 static QPixmap *ITextFrame; 617 static QPixmap *ILatexFrame; 618 static QPixmap *ILine; 619 static QPixmap *IPolygon; 620 static QPixmap *IPolyline; 621 static QPixmap *IPathText; 622 static QPixmap *IGroup; 623 static QPixmap *ILayer; 624 /*** Icons for actions ***********************************************/ 625 static QPixmap *IMove; 626 static QPixmap *IResize; 627 static QPixmap *IRotate; 628 static QPixmap *IGuides; 629 static QPixmap *ILockGuides; 630 static QPixmap *IAlignDistribute; 631 static QPixmap *IFill; 632 static QPixmap *IShade; 633 static QPixmap *IFlipH; 634 static QPixmap *IFlipV; 635 static QPixmap *ILock; 636 static QPixmap *IUnLock; 637 static QPixmap *IEnablePrint; 638 static QPixmap *IDisablePrint; 639 static QPixmap *IDelete; 640 static QPixmap *ICreate; 641 static QPixmap *IPaste; 642 static QPixmap *ICut; 643 static QPixmap *ITransparency; 644 static QPixmap *ILineStyle; 645 static QPixmap *IArrow; 646 static QPixmap *ITable; 647 static QPixmap *IFont; 648 static QPixmap *IAI; 649 static QPixmap *IEPS; 650 static QPixmap *IImportOOoDraw; 651 static QPixmap *ISVG; 652 static QPixmap *IUniconv; 653 static QPixmap *IWMF; 654 static QPixmap *IXFIG; 655 static QPixmap *IImageScaling; 656 static QPixmap *IBorder; 657 static QPixmap *IDocument; 658 static QPixmap *ILayerAction; 659 static QPixmap *IUp; 660 static QPixmap *IDown; 661 static QPixmap *IPrint; 662 static QPixmap *IGetImage; 663 static QPixmap *IChangeFormula; 664 static QPixmap *IMultipleDuplicate; 665 /*@}*/ 666 667 protected: 668 /** @brief Creates a new UndoManager instance */ 669 UndoManager(); 670 671 /** @brief Destroys the UndoManager instance */ 672 ~UndoManager(); 673 674 public slots: 675 /** 676 * @brief Updates strings when the GUI language is changed. 677 */ 678 void languageChange(); 679 680 /** 681 * @brief Adds a new action to the undo stack. 682 * 683 * If _unodEnabled is true the action will be stored otherwise it will 684 * be just ignored. When a new action is added redo items from the stack 685 * will be removed and the current action will be set to the one which was 686 * added. 687 * @param target Source of the action. When undoing/redoing this action 688 * restore() method of this UndoObject will be called. 689 * @param state UndoSate describing the state (action). 690 * @param targetPixmap Is used to override the default target icon in this action. 691 */ 692 void action(UndoObject* target, UndoState* state, QPixmap *targetPixmap = nullptr); 693 694 /** 695 * @brief Adds a new action to the undo stack. 696 * 697 * If _unodEnabled is true the action will be stored otherwise it will 698 * be just ignored. When a new action is added redo items from the stack 699 * will be removed and the current action will be set to the one which was 700 * added. 701 * @param target Source of the action. When undoing/redoing this action 702 * restore() method of this UndoObject will be called. 703 * @param state UndoSate describing the state (action). 704 * @param targetName Is used to override the default target name in this action. 705 * @param targetPixmap Is used to override the default target icon in this action. 706 */ 707 void action(UndoObject* target, UndoState* state, const QString &targetName, QPixmap *targetPixmap = nullptr); 708 709 /** 710 * @brief Informs UndoManager to perform undo 711 * 712 * If an undo is wanted and the caller is not registered UndoGui this method 713 * can be used. Useful for example with the menu entry for undo. 714 * @param steps Number of undo steps to take 715 */ 716 void undo(int steps); 717 718 /** 719 * @brief Informs UndoManager to perform redo 720 * @param steps Number of redo steps to take 721 * @sa UndoManager::undo(int steps) 722 */ 723 void redo(int steps); 724 725 /** 726 * @brief Switches the state of UndoManager (global/object specific undo). 727 * 728 * If parameter uid is less than 0 global undo is used else the undo state 729 * is object specific using the object whose uid is given as a parameter. 730 * @param uid UndoObject's id for what the object specific undo is wanted or 731 * -1 if global undo is wanted. 732 */ 733 void showObject(int uid); 734 735 /** 736 * @brief Sets the length of the undo stack. 737 * 738 * Tells how many UndoStates are stored. 739 * @param steps number of UndoStates to store in the undo stack 740 */ 741 void setHistoryLength(int steps); 742 void setAllHistoryLengths(int steps); 743 744 signals: 745 /** 746 * @brief Emitted when a new undo action is stored to the undo stack. 747 * 748 * This signal is connected to the registered UndoGuis for them to update the 749 * visual representation of the undo stack. 750 * @param target Source of the action 751 * @param state UndoState describing the action 752 */ 753 void newAction(UndoObject* target, UndoState* state); 754 755 /** 756 * @brief Emitted when an undo action has been done. 757 * 758 * It is connected to attached guis to inform them to update the visual 759 * representation of the undo stack. This signal will be also sent to the 760 * <code>UndoGui</code> where it came from. 761 * @param steps Number of steps to take 762 */ 763 void undoSignal(int steps); 764 765 /** 766 * @brief Emitted when a redo action has been done. 767 * @param steps Number of steps to take 768 * @sa UndoManager::undoSignal(int steps) 769 */ 770 void redoSignal(int steps); 771 772 /** 773 * @brief Emitted when a new actions comes in and UndoManager is in object 774 * @brief specific mode and action does not belong to the currently selected 775 * @brief object. 776 */ 777 void clearRedo(); 778 779 /** 780 * @brief This signal is used to notify registered UndoGui instances that 781 * @brief history limit is reached and the last item from the stack 782 * @brief representation should be removed. 783 */ 784 void popBack(); 785 786 /** 787 * @brief This signal is emitted when beginning a series of undo/redo actions 788 * 789 * It could be used in the application as a signal to disable temporarily gui 790 * updates. 791 */ 792 void undoRedoBegin(); 793 794 /** 795 * @brief This signal is emitted when all requested undo/redo actions have been done. 796 * 797 * It could be used in the application as a signal when the view can be rendered 798 * again after undo/redo. 799 */ 800 void undoRedoDone(); 801 802 }; 803 804 typedef UndoManager Um; 805 806 class SCRIBUS_API UndoBlocker 807 { 808 public: UndoBlocker()809 UndoBlocker() 810 { 811 UndoManager::instance()->setUndoEnabled(false); 812 } 813 ~UndoBlocker()814 ~UndoBlocker() 815 { 816 UndoManager::instance()->setUndoEnabled(true); 817 } 818 }; 819 820 #endif 821