karbon

vcommand.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, The Karbon Developers
00003    Copyright (C) 2002, The Karbon Developers
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 __VCOMMAND_H__
00022 #define __VCOMMAND_H__
00023 
00024 
00025 //#include <assert.h>
00026 
00027 #include <qobject.h>
00028 #include <qptrlist.h>
00029 
00030 #include "vvisitor.h"
00031 
00032 class VDocument;
00033 class KarbonPart;
00034 class KAction;
00035 
00041 class VCommand : public VVisitor
00042 {
00043 public:
00051     VCommand( VDocument* doc, const QString& name, const QString& icon = "14_action" )
00052             : m_document( doc ), m_name( name ), m_icon( icon )
00053     {
00054 // A crash because of an assert() is not much better than an crash because of a null
00055 // pointer. Allowing null pointers allows the usage of the vitors ascpect of a VCommand.
00056 //      assert( doc );
00057     }
00058 
00060     virtual ~VCommand() {}
00061 
00068     virtual void execute() = 0;
00069 
00075     virtual void unexecute() {}
00076 
00084     virtual bool changesSelection() const { return false; }
00085 
00091     QString name() const
00092     {
00093         return m_name;
00094     }
00095 
00101     void setName( const QString& name )
00102     {
00103         m_name = name;
00104     }
00105 
00111     QString icon() const
00112     {
00113         return m_icon;
00114     }
00115 
00121     VDocument* document() const
00122     {
00123         return m_document;
00124     }
00125 
00126 private:
00127     VDocument* m_document;
00128 
00129     QString m_name;
00130     QString m_icon;
00131 };
00132 
00143 class VCommandHistory : public QObject
00144 {
00145     Q_OBJECT
00146 
00147 public:
00153     VCommandHistory( KarbonPart* part );
00154     
00156     ~VCommandHistory();
00157 
00163     void clear();
00164 
00171     void addCommand( VCommand* command, bool execute = true );
00172 
00173 
00174     // limits
00180     unsigned int undoLimit() const
00181     {
00182         return m_undoLimit;
00183     }
00184 
00194     void setUndoLimit( unsigned int limit );
00195 
00201     unsigned int redoLimit() const
00202     {
00203         return m_redoLimit;
00204     }
00205 
00215     void setRedoLimit( unsigned int limit );
00216 
00222     const QPtrList<VCommand>* commands() const
00223     {
00224         return & m_commands;
00225     }
00226 
00227 public slots:
00229     void undo();
00230     
00232     void redo();
00233     
00239     void undo( VCommand* command );
00240 
00246     void redo( VCommand* command );
00247     
00253     void undoAllTo( VCommand* command );
00254 
00260     void redoAllTo( VCommand* command );
00261 
00267     void documentSaved();
00268 
00269 signals:
00271     void historyCleared();
00272 
00278     void commandExecuted( VCommand* );
00279 
00281     void commandExecuted();
00282 
00288     void commandAdded( VCommand* );
00289 
00291     void firstCommandRemoved();
00292 
00294     void lastCommandRemoved();
00295 
00301     void documentRestored();
00302 
00303 private:
00304     // helpers
00305     void clipCommands();
00306     void updateActions();
00307 
00308     KarbonPart *m_part;
00309     unsigned int m_undoLimit;
00310     unsigned int m_redoLimit;
00311     KAction *m_undo;
00312     KAction *m_redo;
00313     QPtrList<VCommand> m_commands;
00314     int m_savedPos;
00315 };
00316 
00317 #endif
00318 
KDE Home | KDE Accessibility Home | Description of Access Keys