1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
4 | ** All rights reserved. |
5 | ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 | ** |
7 | ** This file is part of the QtGui module of the Qt Toolkit. |
8 | ** |
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
10 | ** No Commercial Usage |
11 | ** This file contains pre-release code and may not be distributed. |
12 | ** You may use this file in accordance with the terms and conditions |
13 | ** contained in the Technology Preview License Agreement accompanying |
14 | ** this package. |
15 | ** |
16 | ** GNU Lesser General Public License Usage |
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
18 | ** General Public License version 2.1 as published by the Free Software |
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
20 | ** packaging of this file. Please review the following information to |
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
23 | ** |
24 | ** In addition, as a special exception, Nokia gives you certain additional |
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception |
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
27 | ** |
28 | ** If you have questions regarding the use of this file, please contact |
29 | ** Nokia at qt-info@nokia.com. |
30 | ** |
31 | ** |
32 | ** |
33 | ** |
34 | ** |
35 | ** |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef KUNDO2STACK_H |
43 | #define KUNDO2STACK_H |
44 | |
45 | #include <QObject> |
46 | #include <QString> |
47 | #include <QList> |
48 | #include <QAction> |
49 | |
50 | #include "kundo2_export.h" |
51 | |
52 | class QAction; |
53 | class KUndo2CommandPrivate; |
54 | class KUndo2Group; |
55 | class KActionCollection; |
56 | |
57 | #ifndef QT_NO_UNDOCOMMAND |
58 | |
59 | #include "kundo2magicstring.h" |
60 | |
61 | class KUNDO2_EXPORT KUndo2Command |
62 | { |
63 | KUndo2CommandPrivate *d; |
64 | |
65 | public: |
66 | explicit KUndo2Command(KUndo2Command *parent = 0); |
67 | explicit KUndo2Command(const KUndo2MagicString &text, KUndo2Command *parent = 0); |
68 | virtual ~KUndo2Command(); |
69 | |
70 | virtual void undo(); |
71 | virtual void redo(); |
72 | |
73 | QString actionText() const; |
74 | KUndo2MagicString text() const; |
75 | void setText(const KUndo2MagicString &text); |
76 | |
77 | virtual int id() const; |
78 | virtual bool mergeWith(const KUndo2Command *other); |
79 | |
80 | int childCount() const; |
81 | const KUndo2Command *child(int index) const; |
82 | |
83 | bool hasParent(); |
84 | |
85 | private: |
86 | Q_DISABLE_COPY(KUndo2Command) |
87 | friend class KUndo2QStack; |
88 | |
89 | bool m_hasParent; |
90 | }; |
91 | |
92 | #endif // QT_NO_UNDOCOMMAND |
93 | |
94 | #ifndef QT_NO_UNDOSTACK |
95 | |
96 | class KUNDO2_EXPORT KUndo2QStack : public QObject |
97 | { |
98 | Q_OBJECT |
99 | // Q_DECLARE_PRIVATE(KUndo2QStack) |
100 | Q_PROPERTY(bool active READ isActive WRITE setActive) |
101 | Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit) |
102 | |
103 | public: |
104 | explicit KUndo2QStack(QObject *parent = 0); |
105 | virtual ~KUndo2QStack(); |
106 | void clear(); |
107 | |
108 | void push(KUndo2Command *cmd); |
109 | |
110 | bool canUndo() const; |
111 | bool canRedo() const; |
112 | QString undoText() const; |
113 | QString redoText() const; |
114 | |
115 | int count() const; |
116 | int index() const; |
117 | QString actionText(int idx) const; |
118 | QString text(int idx) const; |
119 | |
120 | #ifndef QT_NO_ACTION |
121 | QAction *createUndoAction(QObject *parent) const; |
122 | QAction *createRedoAction(QObject *parent) const; |
123 | #endif // QT_NO_ACTION |
124 | |
125 | bool isActive() const; |
126 | bool isClean() const; |
127 | int cleanIndex() const; |
128 | |
129 | void beginMacro(const KUndo2MagicString &text); |
130 | void endMacro(); |
131 | |
132 | void setUndoLimit(int limit); |
133 | int undoLimit() const; |
134 | |
135 | const KUndo2Command *command(int index) const; |
136 | |
137 | public Q_SLOTS: |
138 | void setClean(); |
139 | virtual void setIndex(int idx); |
140 | virtual void undo(); |
141 | virtual void redo(); |
142 | void setActive(bool active = true); |
143 | |
144 | Q_SIGNALS: |
145 | void indexChanged(int idx); |
146 | void cleanChanged(bool clean); |
147 | void canUndoChanged(bool canUndo); |
148 | void canRedoChanged(bool canRedo); |
149 | void undoTextChanged(const QString &undoActionText); |
150 | void redoTextChanged(const QString &redoActionText); |
151 | |
152 | private: |
153 | // from QUndoStackPrivate |
154 | QList<KUndo2Command*> m_command_list; |
155 | QList<KUndo2Command*> m_macro_stack; |
156 | int m_index; |
157 | int m_clean_index; |
158 | KUndo2Group *m_group; |
159 | int m_undo_limit; |
160 | |
161 | // also from QUndoStackPrivate |
162 | void setIndex(int idx, bool clean); |
163 | bool checkUndoLimit(); |
164 | |
165 | Q_DISABLE_COPY(KUndo2QStack) |
166 | friend class KUndo2Group; |
167 | }; |
168 | |
169 | class KUNDO2_EXPORT KUndo2Stack : public KUndo2QStack |
170 | { |
171 | public: |
172 | explicit KUndo2Stack(QObject *parent = 0); |
173 | |
174 | // functions from KUndoStack |
175 | QAction* createRedoAction(KActionCollection* actionCollection, const QString& actionName = QString()); |
176 | QAction* createUndoAction(KActionCollection* actionCollection, const QString& actionName = QString()); |
177 | }; |
178 | |
179 | #endif // QT_NO_UNDOSTACK |
180 | |
181 | #endif // KUNDO2STACK_H |
182 | |