kalarm

undo.h

Go to the documentation of this file.
00001 /*
00002  *  undo.h  -  undo/redo facility
00003  *  Program:  kalarm
00004  *  Copyright (C) 2005 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef UNDO_H
00022 #define UNDO_H
00023 
00026 #include <qvaluelist.h>
00027 #include <qstringlist.h>
00028 
00029 class KAEvent;
00030 class UndoItem;
00031 
00032 
00033 class Undo : public QObject
00034 {
00035         Q_OBJECT
00036     public:
00037         enum Type { NONE, UNDO, REDO };
00038 
00039         static Undo*       instance();
00040         static void        saveAdd(const KAEvent&);
00041         static void        saveEdit(const KAEvent& oldEvent, const KAEvent& newEvent);
00042         static void        saveDelete(const KAEvent&);
00043         static void        saveDeletes(const QValueList<KAEvent>&);
00044         static void        saveReactivate(const KAEvent&);
00045         static void        saveReactivates(const QValueList<KAEvent>&);
00046         static bool        undo(QWidget* parent, const QString& action)
00047                                               { return undo(mUndoList.begin(), UNDO, parent, action); }
00048         static bool        undo(int id, QWidget* parent, const QString& action)
00049                                               { return undo(findItem(id, UNDO), UNDO, parent, action); }
00050         static bool        redo(QWidget* parent, const QString& action)
00051                                               { return undo(mRedoList.begin(), REDO, parent, action); }
00052         static bool        redo(int id, QWidget* parent, const QString& action)
00053                                               { return undo(findItem(id, REDO), REDO, parent, action); }
00054         static void        clear();
00055         static bool        haveUndo()         { return !mUndoList.isEmpty(); }
00056         static bool        haveRedo()         { return !mRedoList.isEmpty(); }
00057         static QString     actionText(Type);
00058         static QString     actionText(Type, int id);
00059         static QString     description(Type, int id);
00060         static QValueList<int> ids(Type);
00061         static void        emitChanged();
00062 
00063         // Types for use by UndoItem class and its descendants
00064         typedef QValueList<UndoItem*>  List;
00065 
00066     signals:
00067         void               changed(const QString& undo, const QString& redo);
00068 
00069     protected:
00070         // Methods for use by UndoItem class
00071         static void        add(UndoItem*, bool undo);
00072         static void        remove(UndoItem*, bool undo);
00073         static void        replace(UndoItem* old, UndoItem* New);
00074 
00075     private:
00076         typedef QValueList<UndoItem*>::Iterator Iterator;
00077 
00078         Undo(QObject* parent)  : QObject(parent) { }
00079         static void        removeRedos(const QString& eventID);
00080         static bool        undo(Iterator, Type, QWidget* parent, const QString& action);
00081         static UndoItem*   getItem(int id, Type);
00082         static Iterator    findItem(int id, Type);
00083         void               emitChanged(const QString& undo, const QString& redo)
00084                                            { emit changed(undo, redo); }
00085 
00086         static Undo*       mInstance;     // the one and only Undo instance
00087         static List        mUndoList;     // edit history for undo, latest undo first
00088         static List        mRedoList;     // edit history for redo, latest redo first
00089 
00090     friend class UndoItem;
00091 };
00092 
00093 #endif // UNDO_H
KDE Home | KDE Accessibility Home | Description of Access Keys