Subversion Repositories Scribus

Rev

Rev 11169 | Rev 22600 | 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
         */
81
        virtual QString getUName();
82
 
83
        /**
84
         * @brief Set the name of the UndoObject
85
         * @param newUName New name for the UndoObject
86
         */
87
        virtual void setUName(QString newUName);
88
 
89
        /**
1250 tsoots 90
         * @brief Returns the pixmap connected to this object.
91
         * @return pixmap connected to this object
92
         */
93
        virtual QPixmap* getUPixmap();
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
         */
110
        const ScGuardedPtr<UndoObject>& undoObjectPtr();
111
 
112
        /**
1111 tsoots 113
         * @brief Method used when an undo/redo is requested.
114
         *
115
         * UndoObject must know how to handle the UndoState object given as a
116
         * parameter. It is the same object that was send from the UndoObject to
117
         * the UndoManager when the action happened.
118
         * @param state State describing the action that is wanted to be undone/redone
119
         * @param isUndo If true undo is wanted else if false redo.
120
         */
121
        virtual void restore(UndoState* state, bool isUndo) = 0;
5116 tsoots 122
private:
123
        /** @brief id number to be used with the next UndoObject */
11168 jghali 124
        static ulong m_nextId;
5116 tsoots 125
 
126
        /** @brief unique id number */
11168 jghali 127
        ulong m_id;
5116 tsoots 128
 
129
        /**
130
         * @brief Name of the UndoObject
131
         *
132
         * This name will be used in UndoGui implementations
133
         */
11168 jghali 134
        QString m_uname;
5116 tsoots 135
 
136
        /**
137
         * @brief Icon presenting the object.
138
         *
139
         * When used together with an UndoAction that has an image is this image
140
         * drawn first then the action image is drawn on top of this.
141
         */
11168 jghali 142
        QPixmap *m_upixmap;
143
 
144
        /**
145
         * @brief Guarded pointer
146
         *
147
         * Allows to warn undo system of an object deletion
148
         */
149
        ScGuardedObject<UndoObject> m_objectPtr;
1111 tsoots 150
};
11168 jghali 151
typedef ScGuardedPtr<UndoObject> UndoObjectPtr;
1111 tsoots 152
 
2969 craig 153
class SCRIBUS_API DummyUndoObject : public UndoObject
1658 tsoots 154
{
155
public:
156
        DummyUndoObject() {};
157
        virtual ~DummyUndoObject() {};
4645 subik 158
        //! \brief dummy implementation of the inherited one
1658 tsoots 159
        void restore(UndoState*, bool) {};
160
};
161
 
1111 tsoots 162
#endif