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 <tqvaluelist.h>
00027 #include <tqstringlist.h>
00028
00029 class KAEvent;
00030 class UndoItem;
00031
00032
00033 class Undo : public TQObject
00034 {
00035 Q_OBJECT
00036
00037 public:
00038 enum Type { NONE, UNDO, REDO };
00039
00040 static Undo* instance();
00041 static void saveAdd(const KAEvent&);
00042 static void saveEdit(const KAEvent& oldEvent, const KAEvent& newEvent);
00043 static void saveDelete(const KAEvent&);
00044 static void saveDeletes(const TQValueList<KAEvent>&);
00045 static void saveReactivate(const KAEvent&);
00046 static void saveReactivates(const TQValueList<KAEvent>&);
00047 static bool undo(TQWidget* parent, const TQString& action)
00048 { return undo(mUndoList.begin(), UNDO, parent, action); }
00049 static bool undo(int id, TQWidget* parent, const TQString& action)
00050 { return undo(findItem(id, UNDO), UNDO, parent, action); }
00051 static bool redo(TQWidget* parent, const TQString& action)
00052 { return undo(mRedoList.begin(), REDO, parent, action); }
00053 static bool redo(int id, TQWidget* parent, const TQString& action)
00054 { return undo(findItem(id, REDO), REDO, parent, action); }
00055 static void clear();
00056 static bool haveUndo() { return !mUndoList.isEmpty(); }
00057 static bool haveRedo() { return !mRedoList.isEmpty(); }
00058 static TQString actionText(Type);
00059 static TQString actionText(Type, int id);
00060 static TQString description(Type, int id);
00061 static TQValueList<int> ids(Type);
00062 static void emitChanged();
00063
00064
00065 typedef TQValueList<UndoItem*> List;
00066
00067 signals:
00068 void changed(const TQString& undo, const TQString& redo);
00069
00070 protected:
00071
00072 static void add(UndoItem*, bool undo);
00073 static void remove(UndoItem*, bool undo);
00074 static void replace(UndoItem* old, UndoItem* New);
00075
00076 private:
00077 typedef TQValueList<UndoItem*>::Iterator Iterator;
00078
00079 Undo(TQObject* parent) : TQObject(parent) { }
00080 static void removeRedos(const TQString& eventID);
00081 static bool undo(Iterator, Type, TQWidget* parent, const TQString& action);
00082 static UndoItem* getItem(int id, Type);
00083 static Iterator findItem(int id, Type);
00084 void emitChanged(const TQString& undo, const TQString& redo)
00085 { emit changed(undo, redo); }
00086
00087 static Undo* mInstance;
00088 static List mUndoList;
00089 static List mRedoList;
00090
00091 friend class UndoItem;
00092 };
00093
00094 #endif // UNDO_H