kdeui Library API Documentation

kcommand.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2000 Werner Trobin <trobin@kde.org>
00003    Copyright (C) 2000 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
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 <kdemacros.h>
00028 
00029 class KAction;
00030 class KActionCollection;
00031 class QPopupMenu;
00032 
00037 class 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 
00079 class KDE_DEPRECATED KNamedCommand : public KCommand
00080 {
00081 protected:
00087     KNamedCommand(const QString &name) : KCommand(), m_name(name) {}
00088 
00089 public:
00093     virtual QString name() const { return m_name; }
00098     void setName(const QString &name) { m_name=name; }
00099 
00100 private:
00101     QString m_name;
00102 protected:
00103     virtual void virtual_hook( int id, void* data );
00104 };
00105 
00111 class KMacroCommand : public KNamedCommand
00112 {
00113 public:
00120     KMacroCommand( const QString & name );
00121     virtual ~KMacroCommand() {}
00122 
00127     void addCommand(KCommand *command);
00128 
00133     virtual void execute();
00138     virtual void unexecute();
00139 
00140 protected:
00141     QPtrList<KCommand> m_commands;
00142 protected:
00143     virtual void virtual_hook( int id, void* data );
00144 };
00145 
00146 
00157 class KCommandHistory : public QObject {
00158     Q_OBJECT
00159 public:
00165     KCommandHistory();
00166 
00175     KCommandHistory(KActionCollection *actionCollection, bool withMenus = true);
00176 
00180     virtual ~KCommandHistory();
00181 
00187     void clear();
00188 
00196     void addCommand(KCommand *command, bool execute=true);
00197 
00201     int undoLimit() const { return m_undoLimit; }
00205     void setUndoLimit(int limit);
00209     int redoLimit() const { return m_redoLimit; }
00213     void setRedoLimit(int limit);
00214 
00221     void updateActions();
00222 
00223 public slots:
00228     virtual void undo();
00233     virtual void redo();
00242     virtual void documentSaved();
00243 
00244 protected slots:
00245     void slotUndoAboutToShow();
00246     void slotUndoActivated( int );
00247     void slotRedoAboutToShow();
00248     void slotRedoActivated( int );
00249 
00250 signals:
00256     void commandExecuted();
00261     void documentRestored();
00262 
00263 private:
00264     void clipCommands();  // ensures that the limits are kept
00265 
00266     QPtrList<KCommand> m_commands;
00267     KAction *m_undo, *m_redo;
00268     QPopupMenu *m_undoPopup, *m_redoPopup;
00269     int m_undoLimit, m_redoLimit;
00270     bool m_first;  // attention: it's the first command in the list!
00271 protected:
00272     virtual void virtual_hook( int id, void* data );
00273 private:
00274     class KCommandHistoryPrivate;
00275     KCommandHistoryPrivate *d;
00276 };
00277 
00278 #endif
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun May 16 22:01:58 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003