home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / undoobject.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-12-03  |  5.3 KB  |  163 lines

  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. */
  7. /***************************************************************************
  8.  *   Copyright (C) 2005 by Riku Leino                                      *
  9.  *   riku@scribus.info                                                     *
  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.,                                       *
  24.  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  25.  ***************************************************************************/
  26.  
  27. #ifndef UNDOOBJECT_H
  28. #define UNDOOBJECT_H
  29.  
  30. #include <QPixmap>
  31. #include <QString>
  32.  
  33. #include "scribusapi.h"
  34. #include "scguardedptr.h"
  35.  
  36. class UndoState;
  37.  
  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.  *
  56.  * @author Riku Leino riku@scribus.info
  57.  * @date December 2004
  58.  */
  59. class SCRIBUS_API UndoObject
  60. {
  61. public:
  62.     /** @brief Creates a new anonymous UndoObject instance  */
  63.     UndoObject();
  64.  
  65.     /** @brief Creates a copy of an UndoObject instance  */
  66.     UndoObject(const UndoObject& other);
  67.  
  68.     /** 
  69.      * @brief Creates a new UndoObject instance with the name <code>objectName</code>
  70.      * @param objectName Name of the UndoObject
  71.      */
  72.     UndoObject(const QString &objectName, QPixmap *objectIcon = 0);
  73.  
  74.     /** @brief Destroys the object. */
  75.     virtual ~UndoObject();
  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.     /**
  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.     /**
  102.      * @brief Returns an unique identifier number for the UndoObject
  103.      * @return unique identifier number for the UndoObjet
  104.      */
  105.     ulong getUId() const;
  106.  
  107.     /**
  108.      * @brief Returns a guarded pointer
  109.      */
  110.     const ScGuardedPtr<UndoObject>& undoObjectPtr();
  111.  
  112.     /**
  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;
  122. private:
  123.     /** @brief id number to be used with the next UndoObject */
  124.     static ulong m_nextId;
  125.     
  126.     /** @brief unique id number */
  127.     ulong m_id;
  128.     
  129.     /**
  130.      * @brief Name of the UndoObject
  131.      *
  132.      * This name will be used in UndoGui implementations
  133.      */
  134.     QString m_uname;
  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.      */
  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;
  150. };
  151. typedef ScGuardedPtr<UndoObject> UndoObjectPtr;
  152.  
  153. class SCRIBUS_API DummyUndoObject : public UndoObject
  154. {
  155. public:
  156.     DummyUndoObject() {};
  157.     virtual ~DummyUndoObject() {};
  158.     //! \brief dummy implementation of the inherited one
  159.     void restore(UndoState*, bool) {};
  160. };
  161.  
  162. #endif
  163.