Subversion Repositories Scribus

Rev

Rev 1111 | Rev 1658 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1111 tsoots 1
/***************************************************************************
2
 *   Copyright (C) 2005 by Riku Leino                                      *
3
 *   tsoots@gmail.com                                                      *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 *   (at your option) any later version.                                   *
9
 *                                                                         *
10
 *   This program is distributed in the hope that it will be useful,       *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 *   GNU General Public License for more details.                          *
14
 *                                                                         *
15
 *   You should have received a copy of the GNU General Public License     *
16
 *   along with this program; if not, write to the                         *
17
 *   Free Software Foundation, Inc.,                                       *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 ***************************************************************************/
20
 
21
#ifndef UNDOOBJECT_H
22
#define UNDOOBJECT_H
23
 
24
#include <qstring.h>
1250 tsoots 25
#include <qpixmap.h>
1111 tsoots 26
#include "undostate.h"
27
 
28
/**
29
 * @brief Superclass for all objects that are wanted to have undoable actions.
30
 *
31
 * The most important feature of UndoObject is the restore() method which must be
32
 * implemented in the subclass. When an action that is wanted to be undoable
33
 * happens UndoObject subclass must use UndoManager::action() method to store the
34
 * action using UndoState object. Then when a user undos this action UndoManager
35
 * will send the UndoState object back to this UndoObject by using the restore()
36
 * method.
37
 *
38
 * What is needed for an undo/redo:
39
 <ol>
40
        <li>UndoObject creates an UndoState object describing the action</li>
41
        <li>Sends it to the UndoManager</li>
42
        <li>When an undo/redo is requested UndoManager will send this very same UndoState
43
        object back to the UndoObject which then uses it to restore the state.</li>
44
 </ol>
45
 *
46
 * @author Riku Leino tsoots@gmail.com
47
 * @date December 2004
48
 */
49
class UndoObject
50
{
51
private:
52
        /** @brief id number to be used with the next UndoObject */
53
        static ulong nextId;
54
 
55
        /** @brief unique id number */
56
        ulong _id;
57
 
58
        /**
59
         * @brief Name of the UndoObject
60
         *
61
         * This name will be used in UndoGui implementations
62
         */
63
        QString uname;
1250 tsoots 64
 
65
        /**
66
         * @brief Icon presenting the object.
67
         *
68
         * When used together with an UndoAction that has an image is this image
69
         * drawn first then the action image is drawn on top of this.
70
         */
71
        QPixmap *upixmap;
1111 tsoots 72
public:
73
        /** @brief Creates a new anonymous UndoObject instance  */
74
        UndoObject();
75
 
76
        /**
77
         * @brief Creates a new UndoObject instance with the name <code>objectName</code>
78
         * @param objectName Name of the UndoObject
79
         */
1250 tsoots 80
        UndoObject(const QString &objectName, QPixmap *objectIcon = 0);
1111 tsoots 81
 
82
        /** @brief Destroys the object. */
83
        virtual ~UndoObject() {};
84
 
85
        /**
86
         * @brief Returns the name of the UndoObject.
87
         * @return the name of the UndoObject
88
         */
89
        virtual QString getUName();
90
 
91
        /**
92
         * @brief Set the name of the UndoObject
93
         * @param newUName New name for the UndoObject
94
         */
95
        virtual void setUName(QString newUName);
96
 
97
        /**
1250 tsoots 98
         * @brief Returns the pixmap connected to this object.
99
         * @return pixmap connected to this object
100
         */
101
        virtual QPixmap* getUPixmap();
102
 
103
        /**
104
         * @brief Set the pixmap for this object.
105
         * @param newUPixmap pixmap for this object
106
         */
107
        virtual void setUPixmap(QPixmap *newUPixmap);
108
 
109
        /**
1111 tsoots 110
         * @brief Returns an unique identifier number for the UndoObject
111
         * @return unique identifier number for the UndoObjet
112
         */
113
        virtual ulong getUId();
114
 
115
        /**
116
         * @brief Method used when an undo/redo is requested.
117
         *
118
         * UndoObject must know how to handle the UndoState object given as a
119
         * parameter. It is the same object that was send from the UndoObject to
120
         * the UndoManager when the action happened.
121
         * @param state State describing the action that is wanted to be undone/redone
122
         * @param isUndo If true undo is wanted else if false redo.
123
         */
124
        virtual void restore(UndoState* state, bool isUndo) = 0;
125
};
126
 
127
#endif