Chris@16
|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@16
|
2
|
Chris@16
|
3 /*
|
Chris@16
|
4 A waveform viewer and audio annotation editor.
|
Chris@16
|
5 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@16
|
6
|
Chris@16
|
7 This is experimental software. Not for distribution.
|
Chris@16
|
8 */
|
Chris@16
|
9
|
Chris@16
|
10 /*
|
Chris@16
|
11 This is a modified version of a source file from the Rosegarden
|
Chris@16
|
12 MIDI and audio sequencer and notation editor, copyright 2000-2006
|
Chris@16
|
13 Chris Cannam, distributed under the GNU General Public License.
|
Chris@16
|
14
|
Chris@16
|
15 This file contains traces of the KCommandHistory class from the KDE
|
Chris@16
|
16 project, copyright 2000 Werner Trobin and David Faure and
|
Chris@16
|
17 distributed under the GNU Lesser General Public License.
|
Chris@16
|
18 */
|
Chris@16
|
19
|
Chris@16
|
20 #ifndef _MULTI_VIEW_COMMAND_HISTORY_H_
|
Chris@16
|
21 #define _MULTI_VIEW_COMMAND_HISTORY_H_
|
Chris@16
|
22
|
Chris@16
|
23 #include <QObject>
|
Chris@16
|
24 #include <QString>
|
Chris@16
|
25
|
Chris@16
|
26 #include <stack>
|
Chris@16
|
27 #include <set>
|
Chris@16
|
28 #include <map>
|
Chris@16
|
29
|
Chris@16
|
30 class Command;
|
Chris@16
|
31 class QAction;
|
Chris@16
|
32 class QMenu;
|
Chris@16
|
33 class QToolBar;
|
Chris@16
|
34
|
Chris@16
|
35 /**
|
Chris@16
|
36 * The MultiViewCommandHistory class stores a list of executed
|
Chris@16
|
37 * commands and maintains Undo and Redo actions synchronised with
|
Chris@16
|
38 * those commands.
|
Chris@16
|
39 *
|
Chris@16
|
40 * MultiViewCommandHistory also allows you to associate more than one
|
Chris@16
|
41 * Undo and Redo action with the same command history, and it keeps
|
Chris@16
|
42 * them all up-to-date at once. This makes it effective in systems
|
Chris@16
|
43 * where multiple views may be editing the same data at once.
|
Chris@16
|
44 */
|
Chris@16
|
45
|
Chris@16
|
46 class MultiViewCommandHistory : public QObject
|
Chris@16
|
47 {
|
Chris@16
|
48 Q_OBJECT
|
Chris@16
|
49
|
Chris@16
|
50 public:
|
Chris@16
|
51 MultiViewCommandHistory();
|
Chris@16
|
52 virtual ~MultiViewCommandHistory();
|
Chris@16
|
53
|
Chris@16
|
54 void clear();
|
Chris@16
|
55
|
Chris@16
|
56 void registerMenu(QMenu *menu);
|
Chris@16
|
57 void registerToolbar(QToolBar *toolbar);
|
Chris@16
|
58
|
Chris@16
|
59 void addCommand(Command *command, bool execute = true);
|
Chris@16
|
60
|
Chris@16
|
61 /// Return the maximum number of items in the undo history.
|
Chris@16
|
62 int undoLimit() { return m_undoLimit; }
|
Chris@16
|
63
|
Chris@16
|
64 /// Set the maximum number of items in the undo history.
|
Chris@16
|
65 void setUndoLimit(int limit);
|
Chris@16
|
66
|
Chris@16
|
67 /// Return the maximum number of items in the redo history.
|
Chris@16
|
68 int redoLimit() { return m_redoLimit; }
|
Chris@16
|
69
|
Chris@16
|
70 /// Set the maximum number of items in the redo history.
|
Chris@16
|
71 void setRedoLimit(int limit);
|
Chris@16
|
72
|
Chris@16
|
73 public slots:
|
Chris@16
|
74 /**
|
Chris@16
|
75 * Checkpoint function that should be called when the document is
|
Chris@16
|
76 * saved. If the undo/redo stack later returns to the point at
|
Chris@16
|
77 * which the document was saved, the documentRestored signal will
|
Chris@16
|
78 * be emitted.
|
Chris@16
|
79 */
|
Chris@16
|
80 virtual void documentSaved();
|
Chris@16
|
81
|
Chris@16
|
82 protected slots:
|
Chris@16
|
83 void undo();
|
Chris@16
|
84 void redo();
|
Chris@16
|
85 void undoActivated(QAction *);
|
Chris@16
|
86 void redoActivated(QAction *);
|
Chris@16
|
87
|
Chris@16
|
88 signals:
|
Chris@16
|
89 /**
|
Chris@16
|
90 * Emitted whenever a command has just been executed, whether by
|
Chris@16
|
91 * addCommand, undo, or redo.
|
Chris@16
|
92 */
|
Chris@16
|
93 void commandExecuted(Command *);
|
Chris@16
|
94
|
Chris@16
|
95 /**
|
Chris@16
|
96 * Emitted whenever a command has just been executed, whether by
|
Chris@16
|
97 * addCommand, undo, or redo.
|
Chris@16
|
98 */
|
Chris@16
|
99 void commandExecuted();
|
Chris@16
|
100
|
Chris@16
|
101 /**
|
Chris@16
|
102 * Emitted when the undo/redo stack has reached the same state at
|
Chris@16
|
103 * which the documentSaved slot was last called.
|
Chris@16
|
104 */
|
Chris@16
|
105 void documentRestored();
|
Chris@16
|
106
|
Chris@16
|
107 private:
|
Chris@16
|
108 QAction *m_undoAction;
|
Chris@16
|
109 QAction *m_redoAction;
|
Chris@16
|
110 QMenu *m_undoMenu;
|
Chris@16
|
111 QMenu *m_redoMenu;
|
Chris@16
|
112
|
Chris@16
|
113 std::map<QAction *, int> m_actionCounts;
|
Chris@16
|
114
|
Chris@16
|
115 typedef std::stack<Command *> CommandStack;
|
Chris@16
|
116 CommandStack m_undoStack;
|
Chris@16
|
117 CommandStack m_redoStack;
|
Chris@16
|
118
|
Chris@16
|
119 int m_undoLimit;
|
Chris@16
|
120 int m_redoLimit;
|
Chris@16
|
121 int m_savedAt;
|
Chris@16
|
122
|
Chris@16
|
123 void updateActions();
|
Chris@16
|
124 // void updateMenus();
|
Chris@16
|
125
|
Chris@16
|
126 // void updateButtons();
|
Chris@16
|
127 // void updateButton(bool undo, const QString &name, CommandStack &stack);
|
Chris@16
|
128 // void updateMenu(bool undo, const QString &name, CommandStack &stack);
|
Chris@16
|
129 void clipCommands();
|
Chris@16
|
130
|
Chris@16
|
131 void clipStack(CommandStack &stack, int limit);
|
Chris@16
|
132 void clearStack(CommandStack &stack);
|
Chris@16
|
133 };
|
Chris@16
|
134
|
Chris@16
|
135
|
Chris@16
|
136 #endif
|