kcommand.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef kcommand_h
00022 #define kcommand_h
00023
00024 #include <qptrlist.h>
00025 #include <qstring.h>
00026 #include <qobject.h>
00027
00028 class KAction;
00029 class KActionCollection;
00030 class QPopupMenu;
00031
00036 class KCommand
00037 {
00038 protected:
00042 KCommand() {}
00043
00044 public:
00045 virtual ~KCommand();
00046
00052 virtual void execute() = 0;
00061 virtual void unexecute() = 0;
00062
00067 virtual QString name() const = 0;
00068 protected:
00069 virtual void virtual_hook( int id, void* data );
00070 };
00071
00077 class KNamedCommand : public KCommand
00078 {
00079 protected:
00085 KNamedCommand(const QString &name) : KCommand(), m_name(name) {}
00086
00087 public:
00091 virtual QString name() const { return m_name; }
00096 void setName(const QString &name) { m_name=name; }
00097
00098 private:
00099 QString m_name;
00100 protected:
00101 virtual void virtual_hook( int id, void* data );
00102 };
00103
00109 class KMacroCommand : public KNamedCommand
00110 {
00111 public:
00118 KMacroCommand( const QString & name );
00119 virtual ~KMacroCommand() {}
00120
00125 void addCommand(KCommand *command);
00126
00131 virtual void execute();
00136 virtual void unexecute();
00137
00138 protected:
00139 QPtrList<KCommand> m_commands;
00140 protected:
00141 virtual void virtual_hook( int id, void* data );
00142 };
00143
00144
00155 class KCommandHistory : public QObject {
00156 Q_OBJECT
00157 public:
00163 KCommandHistory();
00164
00172 KCommandHistory(KActionCollection *actionCollection, bool withMenus = true);
00173
00177 virtual ~KCommandHistory();
00178
00184 void clear();
00185
00193 void addCommand(KCommand *command, bool execute=true);
00194
00198 int undoLimit() const { return m_undoLimit; }
00202 void setUndoLimit(int limit);
00206 int redoLimit() const { return m_redoLimit; }
00210 void setRedoLimit(int limit);
00211
00218 void updateActions();
00219
00220 public slots:
00225 virtual void undo();
00230 virtual void redo();
00239 virtual void documentSaved();
00240
00241 protected slots:
00242 void slotUndoAboutToShow();
00243 void slotUndoActivated( int );
00244 void slotRedoAboutToShow();
00245 void slotRedoActivated( int );
00246
00247 signals:
00253 void commandExecuted();
00258 void documentRestored();
00259
00260 private:
00261 void clipCommands();
00262
00263 QPtrList<KCommand> m_commands;
00264 KAction *m_undo, *m_redo;
00265 QPopupMenu *m_undoPopup, *m_redoPopup;
00266 int m_undoLimit, m_redoLimit;
00267 bool m_first;
00268 protected:
00269 virtual void virtual_hook( int id, void* data );
00270 private:
00271 class KCommandHistoryPrivate;
00272 KCommandHistoryPrivate *d;
00273 };
00274
00275 #endif
This file is part of the documentation for kdelibs Version 3.1.0.