Chris@16: /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ Chris@16: Chris@16: /* Chris@16: A waveform viewer and audio annotation editor. Chris@16: Chris Cannam, Queen Mary University of London, 2005-2006 Chris@16: Chris@16: This is experimental software. Not for distribution. Chris@16: */ Chris@16: Chris@16: /* Chris@16: This is a modified version of a source file from the Rosegarden Chris@16: MIDI and audio sequencer and notation editor, copyright 2000-2006 Chris@16: Chris Cannam, distributed under the GNU General Public License. Chris@16: Chris@16: This file contains traces of the KCommandHistory class from the KDE Chris@16: project, copyright 2000 Werner Trobin and David Faure and Chris@16: distributed under the GNU Lesser General Public License. Chris@16: */ Chris@16: Chris@16: #ifndef _MULTI_VIEW_COMMAND_HISTORY_H_ Chris@16: #define _MULTI_VIEW_COMMAND_HISTORY_H_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: class Command; Chris@16: class QAction; Chris@16: class QMenu; Chris@16: class QToolBar; Chris@16: Chris@16: /** Chris@16: * The MultiViewCommandHistory class stores a list of executed Chris@16: * commands and maintains Undo and Redo actions synchronised with Chris@16: * those commands. Chris@16: * Chris@16: * MultiViewCommandHistory also allows you to associate more than one Chris@16: * Undo and Redo action with the same command history, and it keeps Chris@16: * them all up-to-date at once. This makes it effective in systems Chris@16: * where multiple views may be editing the same data at once. Chris@16: */ Chris@16: Chris@16: class MultiViewCommandHistory : public QObject Chris@16: { Chris@16: Q_OBJECT Chris@16: Chris@16: public: Chris@16: MultiViewCommandHistory(); Chris@16: virtual ~MultiViewCommandHistory(); Chris@16: Chris@16: void clear(); Chris@16: Chris@16: void registerMenu(QMenu *menu); Chris@16: void registerToolbar(QToolBar *toolbar); Chris@16: Chris@16: void addCommand(Command *command, bool execute = true); Chris@16: Chris@16: /// Return the maximum number of items in the undo history. Chris@16: int undoLimit() { return m_undoLimit; } Chris@16: Chris@16: /// Set the maximum number of items in the undo history. Chris@16: void setUndoLimit(int limit); Chris@16: Chris@16: /// Return the maximum number of items in the redo history. Chris@16: int redoLimit() { return m_redoLimit; } Chris@16: Chris@16: /// Set the maximum number of items in the redo history. Chris@16: void setRedoLimit(int limit); Chris@16: Chris@16: public slots: Chris@16: /** Chris@16: * Checkpoint function that should be called when the document is Chris@16: * saved. If the undo/redo stack later returns to the point at Chris@16: * which the document was saved, the documentRestored signal will Chris@16: * be emitted. Chris@16: */ Chris@16: virtual void documentSaved(); Chris@16: Chris@16: protected slots: Chris@16: void undo(); Chris@16: void redo(); Chris@16: void undoActivated(QAction *); Chris@16: void redoActivated(QAction *); Chris@16: Chris@16: signals: Chris@16: /** Chris@16: * Emitted whenever a command has just been executed, whether by Chris@16: * addCommand, undo, or redo. Chris@16: */ Chris@16: void commandExecuted(Command *); Chris@16: Chris@16: /** Chris@16: * Emitted whenever a command has just been executed, whether by Chris@16: * addCommand, undo, or redo. Chris@16: */ Chris@16: void commandExecuted(); Chris@16: Chris@16: /** Chris@16: * Emitted when the undo/redo stack has reached the same state at Chris@16: * which the documentSaved slot was last called. Chris@16: */ Chris@16: void documentRestored(); Chris@16: Chris@16: private: Chris@16: QAction *m_undoAction; Chris@16: QAction *m_redoAction; Chris@16: QMenu *m_undoMenu; Chris@16: QMenu *m_redoMenu; Chris@16: Chris@16: std::map m_actionCounts; Chris@16: Chris@16: typedef std::stack CommandStack; Chris@16: CommandStack m_undoStack; Chris@16: CommandStack m_redoStack; Chris@16: Chris@16: int m_undoLimit; Chris@16: int m_redoLimit; Chris@16: int m_savedAt; Chris@16: Chris@16: void updateActions(); Chris@16: // void updateMenus(); Chris@16: Chris@16: // void updateButtons(); Chris@16: // void updateButton(bool undo, const QString &name, CommandStack &stack); Chris@16: // void updateMenu(bool undo, const QString &name, CommandStack &stack); Chris@16: void clipCommands(); Chris@16: Chris@16: void clipStack(CommandStack &stack, int limit); Chris@16: void clearStack(CommandStack &stack); Chris@16: }; Chris@16: Chris@16: Chris@16: #endif