00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00064 typedef QValueList<UndoItem*> List;
00065
00066 signals:
00067 void changed(const QString& undo, const QString& redo);
00068
00069 protected:
00070
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;
00087 static List mUndoList;
00088 static List mRedoList;
00089
00090 friend class UndoItem;
00091 };
00092
00093 #endif // UNDO_H