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 
00184 protected:
00185     CommandHistory();
00186     static CommandHistory *m_instance;
00187 
00188     QAction *m_undoAction;
00189     QAction *m_redoAction;
00190     QAction *m_undoMenuAction;
00191     QAction *m_redoMenuAction;
00192     QMenu *m_undoMenu;
00193     QMenu *m_redoMenu;
00194 
00195     std::map<QAction *, int> m_actionCounts;
00196 
00197     typedef std::stack<Command *> CommandStack;
00198     CommandStack m_undoStack;
00199     CommandStack m_redoStack;
00200 
00201     int m_undoLimit;
00202     int m_redoLimit;
00203     int m_menuLimit;
00204     int m_savedAt;
00205 
00206     MacroCommand *m_currentCompound;
00207     bool m_executeCompound;
00208     void addToCompound(Command *command, bool execute);
00209 
00210     MacroCommand *m_currentBundle;
00211     QString m_currentBundleName;
00212     QTimer *m_bundleTimer;
00213     int m_bundleTimeout;
00214     void addToBundle(Command *command, bool execute);
00215     void closeBundle();
00216     
00217     void updateActions();
00218 
00219     void clipCommands();
00220 
00221     void clipStack(CommandStack &stack, int limit);
00222     void clearStack(CommandStack &stack);
00223 };
00224 
00225 
00226 #endif

Generated on Wed Feb 20 15:45:25 2008 for SonicVisualiser by  doxygen 1.5.1