Back to index

scribus-ng  1.3.4.dfsg+svn20071115
undostate.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2005 by Riku Leino                                      *
00009  *   riku@scribus.info                                                     *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #include "undostate.h"
00028 #include "undoobject.h"
00029 
00030 UndoState::UndoState(const QString& name, const QString& description, QPixmap* pixmap) :
00031 actionName_(name),
00032 actionDescription_(description),
00033 actionPixmap_(pixmap),
00034 undoObject_(0)
00035 {
00036 
00037 }
00038 
00039 QString UndoState::getName()
00040 {
00041        return actionName_;
00042 }
00043 
00044 void UndoState::setName(const QString &newName)
00045 {
00046        actionName_ = newName;
00047 }
00048 
00049 QString UndoState::getDescription()
00050 {
00051        return actionDescription_;
00052 }
00053 
00054 void UndoState::setDescription(const QString &newDescription)
00055 {
00056        actionDescription_ = newDescription;
00057 }
00058 
00059 QPixmap* UndoState::getPixmap()
00060 {
00061        return actionPixmap_;
00062 }
00063 
00064 void UndoState::setPixmap(QPixmap *pixmap)
00065 {
00066        actionPixmap_ = pixmap;
00067 }
00068 
00069 void UndoState::undo()
00070 {
00071        if (undoObject_) // if !undoObject_ there's an error, hmmm
00072               undoObject_->restore(this, true);
00073 }
00074 
00075 void UndoState::redo()
00076 {
00077        if (undoObject_)
00078               undoObject_->restore(this, false);
00079 }
00080 
00081 void UndoState::setUndoObject(UndoObject *object)
00082 {
00083        undoObject_ = object;
00084 }
00085 
00086 UndoObject* UndoState::undoObject()
00087 {
00088        return undoObject_;
00089 }
00090 
00091 UndoState::~UndoState()
00092 {
00093 
00094 }
00095 
00096 /*** SimpleState **************************************************************/
00097 
00098 SimpleState::SimpleState(const QString& name, const QString& description, QPixmap* pixmap)
00099 : UndoState(name, description, pixmap)
00100 {
00101 
00102 }
00103 
00104 bool SimpleState::contains(const QString& key)
00105 {
00106        return values_.contains(key);
00107 }
00108 
00109 QString SimpleState::get(const QString& key, const QString& def)
00110 {
00111        if (values_.contains(key))
00112               return values_[key];
00113 
00114        values_[key] = def;
00115        return values_[key];
00116 }
00117 
00118 int SimpleState::getInt(const QString& key, int def)
00119 {
00120        bool ok = false;
00121        QString retString = get(key, QString("%1").arg(def));
00122        int ret = retString.toInt(&ok);
00123        if (!ok)
00124               ret = def;
00125        return ret;
00126 }
00127 
00128 uint SimpleState::getUInt(const QString& key, uint def)
00129 {
00130        bool ok = false;
00131        QString retString = get(key, QString("%1").arg(def));
00132        uint ret = retString.toUInt(&ok);
00133        if (!ok)
00134               ret = def;
00135        return ret;
00136 }
00137 
00138 double SimpleState::getDouble(const QString& key, double def)
00139 {
00140        bool ok = false;
00141        QString retString = get(key, QString("%1").arg(def));
00142        double ret = retString.toDouble(&ok);
00143        if (!ok)
00144               ret = def;
00145        return ret;
00146 }
00147 
00148 bool SimpleState::getBool(const QString& key, bool def)
00149 {
00150        bool ok = false;
00151        QString retString = get(key, QString("%1").arg(def));
00152        int ret = retString.toInt(&ok);
00153        if (!ok)
00154               ret = def;
00155        return ret;
00156 }
00157 
00158 void SimpleState::set(const QString& key, const QString& value)
00159 {
00160        values_[key] = value;
00161 }
00162 
00163 void SimpleState::set(const QString& key, int value)
00164 {
00165        values_[key] = QString("%1").arg(value);
00166 }
00167 
00168 void SimpleState::set(const QString& key, uint value)
00169 {
00170        values_[key] = QString("%1").arg(value);
00171 }
00172 
00173 void SimpleState::set(const QString& key, double value)
00174 {
00175        values_[key] = QString("%1").arg(value, 0, 'f', 20);
00176 }
00177 
00178 void SimpleState::set(const QString& key, bool value)
00179 {
00180        values_[key] = QString("%1").arg(value);
00181 }
00182 
00183 
00184 SimpleState::~SimpleState()
00185 {
00186 
00187 }