kdeui
kcommand.h
Go to the documentation of this file.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 #include <kdelibs_export.h>
00028
00029 class KAction;
00030 class KActionCollection;
00031 class QPopupMenu;
00032
00037 class KDEUI_EXPORT KCommand
00038 {
00039 protected:
00043 KCommand() {}
00044
00045 public:
00046 virtual ~KCommand();
00047
00053 virtual void execute() = 0;
00062 virtual void unexecute() = 0;
00063
00068 virtual QString name() const = 0;
00069 protected:
00070 virtual void virtual_hook( int id, void* data );
00071 };
00072
00078 class KDEUI_EXPORT KNamedCommand : public KCommand
00079 {
00080 protected:
00086 KNamedCommand(const QString &name) : KCommand(), m_name(name) {}
00087
00088 public:
00092 virtual QString name() const { return m_name; }
00097 void setName(const QString &name) { m_name=name; }
00098
00099 private:
00100 QString m_name;
00101 protected:
00102 virtual void virtual_hook( int id, void* data );
00103 };
00104
00110 class KDEUI_EXPORT KMacroCommand : public KNamedCommand
00111 {
00112 public:
00119 KMacroCommand( const QString & name );
00120 virtual ~KMacroCommand() {}
00121
00126 void addCommand(KCommand *command);
00127
00132 virtual void execute();
00137 virtual void unexecute();
00138
00139 protected:
00140 QPtrList<KCommand> m_commands;
00141 protected:
00142 virtual void virtual_hook( int id, void* data );
00143 };
00144
00145
00156 class KDEUI_EXPORT KCommandHistory : public QObject {
00157 Q_OBJECT
00158 public:
00164 KCommandHistory();
00165
00174 KCommandHistory(KActionCollection *actionCollection, bool withMenus = true);
00175
00179 virtual ~KCommandHistory();
00180
00186 void clear();
00187
00195 void addCommand(KCommand *command, bool execute=true);
00196
00200 int undoLimit() const { return m_undoLimit; }
00204 void setUndoLimit(int limit);
00208 int redoLimit() const { return m_redoLimit; }
00212 void setRedoLimit(int limit);
00213
00220 void updateActions();
00221
00222 public slots:
00227 virtual void undo();
00232 virtual void redo();
00241 virtual void documentSaved();
00242
00243 protected slots:
00244 void slotUndoAboutToShow();
00245 void slotUndoActivated( int );
00246 void slotRedoAboutToShow();
00247 void slotRedoActivated( int );
00248
00249 signals:
00257 void commandExecuted();
00258
00266 void commandExecuted(KCommand *command);
00267
00272 void documentRestored();
00273
00274 private:
00275 void clipCommands();
00276
00277 QPtrList<KCommand> m_commands;
00278 KAction *m_undo, *m_redo;
00279 QPopupMenu *m_undoPopup, *m_redoPopup;
00280 int m_undoLimit, m_redoLimit;
00281 bool m_first;
00282 protected:
00283 virtual void virtual_hook( int id, void* data );
00284 private:
00285 class KCommandHistoryPrivate;
00286 KCommandHistoryPrivate *d;
00287 };
00288
00289 #endif