Rev 22600 | Rev 23017 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
1111 | tsoots | 7 | /*************************************************************************** |
8 | * Copyright (C) 2005 by Riku Leino * |
||
5116 | tsoots | 9 | * riku@scribus.info * |
1111 | tsoots | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * |
||
12 | * it under the terms of the GNU General Public License as published by * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | * This program is distributed in the hope that it will be useful, * |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
19 | * GNU General Public License for more details. * |
||
20 | * * |
||
21 | * You should have received a copy of the GNU General Public License * |
||
22 | * along with this program; if not, write to the * |
||
23 | * Free Software Foundation, Inc., * |
||
18122 | mrdocs | 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
1111 | tsoots | 25 | ***************************************************************************/ |
26 | |||
27 | #ifndef UNDOOBJECT_H |
||
28 | #define UNDOOBJECT_H |
||
29 | |||
10223 | cbradney | 30 | #include <QPixmap> |
31 | #include <QString> |
||
2969 | craig | 32 | |
33 | #include "scribusapi.h" |
||
11168 | jghali | 34 | #include "scguardedptr.h" |
1111 | tsoots | 35 | |
11168 | jghali | 36 | class UndoState; |
37 | |||
1111 | tsoots | 38 | /** |
39 | * @brief Superclass for all objects that are wanted to have undoable actions. |
||
40 | * |
||
41 | * The most important feature of UndoObject is the restore() method which must be |
||
42 | * implemented in the subclass. When an action that is wanted to be undoable |
||
43 | * happens UndoObject subclass must use UndoManager::action() method to store the |
||
44 | * action using UndoState object. Then when a user undos this action UndoManager |
||
45 | * will send the UndoState object back to this UndoObject by using the restore() |
||
46 | * method. |
||
47 | * |
||
48 | * What is needed for an undo/redo: |
||
49 | <ol> |
||
50 | <li>UndoObject creates an UndoState object describing the action</li> |
||
51 | <li>Sends it to the UndoManager</li> |
||
52 | <li>When an undo/redo is requested UndoManager will send this very same UndoState |
||
53 | object back to the UndoObject which then uses it to restore the state.</li> |
||
54 | </ol> |
||
55 | * |
||
5116 | tsoots | 56 | * @author Riku Leino riku@scribus.info |
1111 | tsoots | 57 | * @date December 2004 |
58 | */ |
||
2969 | craig | 59 | class SCRIBUS_API UndoObject |
1111 | tsoots | 60 | { |
61 | public: |
||
62 | /** @brief Creates a new anonymous UndoObject instance */ |
||
63 | UndoObject(); |
||
64 | |||
11169 | jghali | 65 | /** @brief Creates a copy of an UndoObject instance */ |
66 | UndoObject(const UndoObject& other); |
||
67 | |||
1111 | tsoots | 68 | /** |
69 | * @brief Creates a new UndoObject instance with the name <code>objectName</code> |
||
70 | * @param objectName Name of the UndoObject |
||
71 | */ |
||
1250 | tsoots | 72 | UndoObject(const QString &objectName, QPixmap *objectIcon = 0); |
1111 | tsoots | 73 | |
74 | /** @brief Destroys the object. */ |
||
11168 | jghali | 75 | virtual ~UndoObject(); |
1111 | tsoots | 76 | |
77 | /** |
||
78 | * @brief Returns the name of the UndoObject. |
||
79 | * @return the name of the UndoObject |
||
80 | */ |
||
22794 | jghali | 81 | virtual QString getUName() const; |
1111 | tsoots | 82 | |
83 | /** |
||
84 | * @brief Set the name of the UndoObject |
||
85 | * @param newUName New name for the UndoObject |
||
86 | */ |
||
22600 | craig | 87 | virtual void setUName(const QString& newUName); |
1111 | tsoots | 88 | |
89 | /** |
||
1250 | tsoots | 90 | * @brief Returns the pixmap connected to this object. |
91 | * @return pixmap connected to this object |
||
92 | */ |
||
22794 | jghali | 93 | virtual QPixmap* getUPixmap() const; |
1250 | tsoots | 94 | |
95 | /** |
||
96 | * @brief Set the pixmap for this object. |
||
97 | * @param newUPixmap pixmap for this object |
||
98 | */ |
||
99 | virtual void setUPixmap(QPixmap *newUPixmap); |
||
100 | |||
101 | /** |
||
1111 | tsoots | 102 | * @brief Returns an unique identifier number for the UndoObject |
103 | * @return unique identifier number for the UndoObjet |
||
104 | */ |
||
8195 | avox | 105 | ulong getUId() const; |
1111 | tsoots | 106 | |
107 | /** |
||
11168 | jghali | 108 | * @brief Returns a guarded pointer |
109 | */ |
||
22794 | jghali | 110 | const ScGuardedPtr<UndoObject>& undoObjectPtr() const; |
11168 | jghali | 111 | |
112 | /** |
||
22794 | jghali | 113 | * @brief Check if current object is owned by some undo state |
114 | */ |
||
115 | int undoStateCount() const; |
||
116 | |||
117 | /** |
||
1111 | tsoots | 118 | * @brief Method used when an undo/redo is requested. |
119 | * |
||
120 | * UndoObject must know how to handle the UndoState object given as a |
||
121 | * parameter. It is the same object that was send from the UndoObject to |
||
122 | * the UndoManager when the action happened. |
||
123 | * @param state State describing the action that is wanted to be undone/redone |
||
124 | * @param isUndo If true undo is wanted else if false redo. |
||
125 | */ |
||
126 | virtual void restore(UndoState* state, bool isUndo) = 0; |
||
22794 | jghali | 127 | |
5116 | tsoots | 128 | private: |
129 | /** @brief id number to be used with the next UndoObject */ |
||
11168 | jghali | 130 | static ulong m_nextId; |
5116 | tsoots | 131 | |
132 | /** @brief unique id number */ |
||
11168 | jghali | 133 | ulong m_id; |
5116 | tsoots | 134 | |
135 | /** |
||
136 | * @brief Name of the UndoObject |
||
137 | * |
||
138 | * This name will be used in UndoGui implementations |
||
139 | */ |
||
11168 | jghali | 140 | QString m_uname; |
5116 | tsoots | 141 | |
142 | /** |
||
143 | * @brief Icon presenting the object. |
||
144 | * |
||
145 | * When used together with an UndoAction that has an image is this image |
||
146 | * drawn first then the action image is drawn on top of this. |
||
147 | */ |
||
11168 | jghali | 148 | QPixmap *m_upixmap; |
149 | |||
150 | /** |
||
151 | * @brief Guarded pointer |
||
152 | * |
||
153 | * Allows to warn undo system of an object deletion |
||
154 | */ |
||
155 | ScGuardedObject<UndoObject> m_objectPtr; |
||
1111 | tsoots | 156 | }; |
11168 | jghali | 157 | typedef ScGuardedPtr<UndoObject> UndoObjectPtr; |
1111 | tsoots | 158 | |
2969 | craig | 159 | class SCRIBUS_API DummyUndoObject : public UndoObject |
1658 | tsoots | 160 | { |
161 | public: |
||
162 | DummyUndoObject() {}; |
||
163 | virtual ~DummyUndoObject() {}; |
||
4645 | subik | 164 | //! \brief dummy implementation of the inherited one |
1658 | tsoots | 165 | void restore(UndoState*, bool) {}; |
166 | }; |
||
167 | |||
1111 | tsoots | 168 | #endif |