kcommand.h
/* This file is part of the KDE project
Copyright (C) 2000 Werner Trobin <trobin@kde.org>
Copyright (C) 2000 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef kcommand_h
#define kcommand_h
#include <qptrlist.h>
#include <qstring.h>
#include <qobject.h>
#include <kdelibs_export.h>
class KAction;
class KActionCollection;
class QPopupMenu;
class KDEUI_EXPORT KCommand
{
protected:
KCommand() {}
public:
virtual ~KCommand();
virtual void execute() = 0;
virtual void unexecute() = 0;
virtual QString name() const = 0;
protected:
virtual void virtual_hook( int id, void* data );
};
class KDEUI_EXPORT KNamedCommand : public KCommand
{
protected:
KNamedCommand(const QString &name) : KCommand(), m_name(name) {}
public:
virtual QString name() const { return m_name; }
void setName(const QString &name) { m_name=name; }
private:
QString m_name;
protected:
virtual void virtual_hook( int id, void* data );
};
class KDEUI_EXPORT KMacroCommand : public KNamedCommand
{
public:
KMacroCommand( const QString & name );
virtual ~KMacroCommand() {}
void addCommand(KCommand *command);
virtual void execute();
virtual void unexecute();
protected:
QPtrList<KCommand> m_commands;
protected:
virtual void virtual_hook( int id, void* data );
};
class KDEUI_EXPORT KCommandHistory : public QObject {
Q_OBJECT
public:
KCommandHistory();
KCommandHistory(KActionCollection *actionCollection, bool withMenus = true);
virtual ~KCommandHistory();
void clear();
void addCommand(KCommand *command, bool execute=true);
int undoLimit() const { return m_undoLimit; }
void setUndoLimit(int limit);
int redoLimit() const { return m_redoLimit; }
void setRedoLimit(int limit);
void updateActions();
public slots:
virtual void undo();
virtual void redo();
virtual void documentSaved();
protected slots:
void slotUndoAboutToShow();
void slotUndoActivated( int );
void slotRedoAboutToShow();
void slotRedoActivated( int );
signals:
void commandExecuted();
void commandExecuted(KCommand *command);
void documentRestored();
private:
void clipCommands(); // ensures that the limits are kept
QPtrList<KCommand> m_commands;
KAction *m_undo, *m_redo;
QPopupMenu *m_undoPopup, *m_redoPopup;
int m_undoLimit, m_redoLimit;
bool m_first; // attention: it's the first command in the list!
protected:
virtual void virtual_hook( int id, void* data );
private:
class KCommandHistoryPrivate;
KCommandHistoryPrivate *d;
};
#endif
KActionCollection
A managed set of KAction objects.
Definition: kactioncollection.h:78
KCommand::name
virtual QString name() const =0
KNamedCommand::setName
void setName(const QString &name)
Updates the name of this command.
Definition: kcommand.h:97
KCommand::execute
virtual void execute()=0
The main method: executes this command.
KCommand::unexecute
virtual void unexecute()=0
Unexecutes (undo) this command.
KCommandHistory::undoLimit
int undoLimit() const
Definition: kcommand.h:200
KCommand
The abstract base class for all Commands.
Definition: kcommand.h:37
KNamedCommand::KNamedCommand
KNamedCommand(const QString &name)
Creates a command.
Definition: kcommand.h:86
KNamedCommand::name
virtual QString name() const
Definition: kcommand.h:92
KCommandHistory
The command history stores a (user) configurable amount of Commands.
Definition: kcommand.h:156
KCommand::KCommand
KCommand()
Creates a command.
Definition: kcommand.h:43
KCommandHistory::redoLimit
int redoLimit() const
Definition: kcommand.h:208
KNamedCommand
A command which stores its name.
Definition: kcommand.h:78
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:202
KMacroCommand
A Macro Command is a command that holds several sub-commands.
Definition: kcommand.h:110

KDE Home | KDE Accessibility Home | Description of Access Keys