svgui  1.9
CommandHistory.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     
00008     This program is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU General Public License as
00010     published by the Free Software Foundation; either version 2 of the
00011     License, or (at your option) any later version.  See the file
00012     COPYING included with this distribution for more information.
00013 */
00014 
00015 /*
00016    This is a modified version of a source file from the Rosegarden
00017    MIDI and audio sequencer and notation editor, copyright 2000-2006
00018    Chris Cannam, distributed under the GNU General Public License.
00019 
00020    This file contains traces of the KCommandHistory class from the KDE
00021    project, copyright 2000 Werner Trobin and David Faure and
00022    distributed under the GNU Lesser General Public License.
00023 */
00024 
00025 #ifndef _MULTI_VIEW_COMMAND_HISTORY_H_
00026 #define _MULTI_VIEW_COMMAND_HISTORY_H_
00027 
00028 #include <QObject>
00029 #include <QString>
00030 
00031 #include <stack>
00032 #include <set>
00033 #include <map>
00034 
00035 class Command;
00036 class MacroCommand;
00037 class QAction;
00038 class QMenu;
00039 class QToolBar;
00040 class QTimer;
00041 
00052 class CommandHistory : public QObject
00053 {
00054     Q_OBJECT
00055 
00056 public:
00057     virtual ~CommandHistory();
00058 
00059     static CommandHistory *getInstance();
00060 
00061     void clear();
00062     
00063     void registerMenu(QMenu *menu);
00064     void registerToolbar(QToolBar *toolbar);
00065 
00074     void addCommand(Command *command);
00075     
00098     void addCommand(Command *command, bool execute, bool bundle = false);
00099     
00101     int getUndoLimit() const { return m_undoLimit; }
00102 
00104     void setUndoLimit(int limit);
00105 
00107     int getRedoLimit() const { return m_redoLimit; }
00108 
00110     void setRedoLimit(int limit);
00111     
00113     int getMenuLimit() const { return m_menuLimit; }
00114 
00116     void setMenuLimit(int limit);
00117 
00119     int getBundleTimeout() const { return m_bundleTimeout; }
00120 
00122     void setBundleTimeout(int msec);
00123 
00125     void startCompoundOperation(QString name, bool execute);
00126 
00128     void endCompoundOperation();
00129 
00130 public slots:
00137     virtual void documentSaved();
00138 
00143     void addExecutedCommand(Command *);
00144 
00149     void addCommandAndExecute(Command *);
00150 
00151     void undo();
00152     void redo();
00153 
00154 protected slots:
00155     void undoActivated(QAction *);
00156     void redoActivated(QAction *);
00157     void bundleTimerTimeout();
00158     
00159 signals:
00164     void commandExecuted();
00165 
00170     void commandExecuted(Command *);
00171 
00176     void commandUnexecuted(Command *);
00177 
00182     void documentRestored();
00183 
00187     void activity(QString);
00188 
00189 protected:
00190     CommandHistory();
00191     static CommandHistory *m_instance;
00192 
00193     QAction *m_undoAction;
00194     QAction *m_redoAction;
00195     QAction *m_undoMenuAction;
00196     QAction *m_redoMenuAction;
00197     QMenu *m_undoMenu;
00198     QMenu *m_redoMenu;
00199 
00200     std::map<QAction *, int> m_actionCounts;
00201 
00202     typedef std::stack<Command *> CommandStack;
00203     CommandStack m_undoStack;
00204     CommandStack m_redoStack;
00205 
00206     int m_undoLimit;
00207     int m_redoLimit;
00208     int m_menuLimit;
00209     int m_savedAt;
00210 
00211     MacroCommand *m_currentCompound;
00212     bool m_executeCompound;
00213     void addToCompound(Command *command, bool execute);
00214 
00215     MacroCommand *m_currentBundle;
00216     bool m_bundling;
00217     QString m_currentBundleName;
00218     QTimer *m_bundleTimer;
00219     int m_bundleTimeout;
00220     void addToBundle(Command *command, bool execute);
00221     void closeBundle();
00222     
00223     void updateActions();
00224 
00225     void clipCommands();
00226 
00227     void clipStack(CommandStack &stack, int limit);
00228     void clearStack(CommandStack &stack);
00229 };
00230 
00231 
00232 #endif