KDE3Support
k3command.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 Werner Trobin <trobin@kde.org> 00003 Copyright (C) 2000,2006 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., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef kcommand_h 00022 #define kcommand_h 00023 00024 #include <kde3support_export.h> 00025 00026 #include <QtCore/QList> 00027 #include <QtCore/QString> 00028 #include <QtCore/QObject> 00029 00030 class KAction; 00031 class KActionCollection; 00032 class QAction; 00033 00041 class KDE3SUPPORT_EXPORT K3Command 00042 { 00043 protected: 00047 K3Command(); 00048 00049 public: 00050 virtual ~K3Command(); 00051 00057 virtual void execute() = 0; 00066 virtual void unexecute() = 0; 00067 00072 virtual QString name() const = 0; 00073 protected: 00074 virtual void virtual_hook( int id, void* data ); 00075 private: 00076 class Private; 00077 Private* const d; 00078 Q_DISABLE_COPY( K3Command ) 00079 }; 00080 00089 class KDE3SUPPORT_EXPORT K3NamedCommand : public K3Command 00090 { 00091 protected: 00097 K3NamedCommand( const QString &name ); 00098 00099 public: 00103 virtual QString name() const; 00108 void setName( const QString &name ); 00109 00110 virtual ~K3NamedCommand(); 00111 00112 protected: 00113 virtual void virtual_hook( int id, void* data ); 00114 00115 private: 00116 class Private; 00117 Private* const d; 00118 Q_DISABLE_COPY( K3NamedCommand ) 00119 }; 00120 00126 class KDE3SUPPORT_EXPORT K3MacroCommand : public K3NamedCommand 00127 { 00128 public: 00135 K3MacroCommand( const QString & name ); 00136 virtual ~K3MacroCommand(); 00137 00142 void addCommand(K3Command *command); 00143 00148 virtual void execute(); 00153 virtual void unexecute(); 00154 00155 protected: 00156 const QList<K3Command *> commands() const; 00157 00158 virtual void virtual_hook( int id, void* data ); 00159 00160 private: 00161 class Private; 00162 Private* const d; 00163 Q_DISABLE_COPY( K3MacroCommand ) 00164 }; 00165 00166 00180 class KDE3SUPPORT_EXPORT K3CommandHistory : public QObject { 00181 Q_OBJECT 00182 public: 00188 K3CommandHistory(); 00189 00198 K3CommandHistory(KActionCollection *actionCollection, bool withMenus = true); 00199 00203 virtual ~K3CommandHistory(); 00204 00210 void clear(); 00211 00222 void addCommand(K3Command *command, bool execute=true); 00223 00227 int undoLimit() const; 00231 void setUndoLimit(int limit); 00235 int redoLimit() const; 00239 void setRedoLimit(int limit); 00240 00247 void updateActions(); 00248 00253 K3Command * presentCommand() const; 00254 00259 bool isUndoAvailable() const; 00260 00265 bool isRedoAvailable() const; 00266 00276 QList<K3Command *> undoCommands( int maxCommands = 0 ) const; 00277 00285 QList<K3Command *> redoCommands( int maxCommands = 0 ) const; 00286 00287 public Q_SLOTS: 00292 virtual void undo(); 00297 virtual void redo(); 00306 virtual void documentSaved(); 00307 00308 Q_SIGNALS: 00315 void commandExecuted(K3Command *command); 00316 00321 void documentRestored(); 00322 00328 void commandHistoryChanged(); 00329 00330 private: 00331 void clipCommands(); // ensures that the limits are kept 00332 00333 private: 00334 class K3CommandHistoryPrivate; 00335 K3CommandHistoryPrivate * const d; 00336 Q_DISABLE_COPY( K3CommandHistory ) 00337 }; 00338 00339 #include <ktoolbarpopupaction.h> 00340 00357 class K3UndoRedoAction : public KToolBarPopupAction 00358 { 00359 Q_OBJECT 00360 public: 00361 enum Type { Undo, Redo }; 00362 K3UndoRedoAction( Type type, KActionCollection* actionCollection, K3CommandHistory* commandHistory ); 00363 00364 private Q_SLOTS: 00365 void slotAboutToShow(); 00366 void slotActionTriggered( QAction *action ); 00367 void slotCommandHistoryChanged(); 00368 00369 private: 00370 class Private; 00371 Private* const d; 00372 Q_DISABLE_COPY( K3UndoRedoAction ) 00373 }; 00374 00375 #endif
KDE 4.6 API Reference