Subversion Repositories Scribus

Rev

Rev 4430 | Rev 8495 | 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.,                                       *
24
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
25
 ***************************************************************************/
26
 
27
#include "undostate.h"
5116 tsoots 28
#include "undoobject.h"
1111 tsoots 29
 
5116 tsoots 30
UndoState::UndoState(const QString& name, const QString& description, QPixmap* pixmap) :
31
actionName_(name),
32
actionDescription_(description),
33
actionPixmap_(pixmap),
34
undoObject_(0)
1111 tsoots 35
{
5116 tsoots 36
 
1111 tsoots 37
}
38
 
39
QString UndoState::getName()
40
{
5116 tsoots 41
        return actionName_;
1111 tsoots 42
}
43
 
1213 tsoots 44
void UndoState::setName(const QString &newName)
45
{
5116 tsoots 46
        actionName_ = newName;
1213 tsoots 47
}
48
 
1111 tsoots 49
QString UndoState::getDescription()
50
{
5116 tsoots 51
        return actionDescription_;
1111 tsoots 52
}
53
 
1213 tsoots 54
void UndoState::setDescription(const QString &newDescription)
55
{
5116 tsoots 56
        actionDescription_ = newDescription;
1213 tsoots 57
}
58
 
1111 tsoots 59
QPixmap* UndoState::getPixmap()
60
{
5116 tsoots 61
        return actionPixmap_;
1111 tsoots 62
}
63
 
1213 tsoots 64
void UndoState::setPixmap(QPixmap *pixmap)
65
{
5116 tsoots 66
        actionPixmap_ = pixmap;
1213 tsoots 67
}
68
 
5116 tsoots 69
void UndoState::undo()
70
{
71
        if (undoObject_) // if !undoObject_ there's an error, hmmm
72
                undoObject_->restore(this, true);
73
}
74
 
75
void UndoState::redo()
76
{
77
        if (undoObject_)
78
                undoObject_->restore(this, false);
79
}
80
 
81
void UndoState::setUndoObject(UndoObject *object)
82
{
83
        undoObject_ = object;
84
}
85
 
86
UndoObject* UndoState::undoObject()
87
{
88
        return undoObject_;
89
}
90
 
1111 tsoots 91
UndoState::~UndoState()
92
{
1518 tsoots 93
 
1111 tsoots 94
}
95
 
96
/*** SimpleState **************************************************************/
97
 
98
SimpleState::SimpleState(const QString& name, const QString& description, QPixmap* pixmap)
99
: UndoState(name, description, pixmap)
100
{
101
 
102
}
103
 
104
bool SimpleState::contains(const QString& key)
105
{
5116 tsoots 106
        return values_.contains(key);
1111 tsoots 107
}
108
 
109
QString SimpleState::get(const QString& key, const QString& def)
110
{
5116 tsoots 111
        if (values_.contains(key))
112
                return values_[key];
1111 tsoots 113
 
5116 tsoots 114
        values_[key] = def;
115
        return values_[key];
1111 tsoots 116
}
117
 
118
int SimpleState::getInt(const QString& key, int def)
119
{
120
        bool ok = false;
121
        QString retString = get(key, QString("%1").arg(def));
122
        int ret = retString.toInt(&ok);
123
        if (!ok)
124
                ret = def;
125
        return ret;
126
}
127
 
1238 tsoots 128
uint SimpleState::getUInt(const QString& key, uint def)
129
{
130
        bool ok = false;
131
        QString retString = get(key, QString("%1").arg(def));
132
        uint ret = retString.toUInt(&ok);
133
        if (!ok)
134
                ret = def;
135
        return ret;
136
}
137
 
1111 tsoots 138
double SimpleState::getDouble(const QString& key, double def)
139
{
140
        bool ok = false;
141
        QString retString = get(key, QString("%1").arg(def));
142
        double ret = retString.toDouble(&ok);
143
        if (!ok)
144
                ret = def;
145
        return ret;
146
}
147
 
1179 tsoots 148
bool SimpleState::getBool(const QString& key, bool def)
149
{
150
        bool ok = false;
151
        QString retString = get(key, QString("%1").arg(def));
152
        int ret = retString.toInt(&ok);
153
        if (!ok)
154
                ret = def;
155
        return ret;
156
}
157
 
1111 tsoots 158
void SimpleState::set(const QString& key, const QString& value)
159
{
5116 tsoots 160
        values_[key] = value;
1111 tsoots 161
}
162
 
163
void SimpleState::set(const QString& key, int value)
164
{
5116 tsoots 165
        values_[key] = QString("%1").arg(value);
1111 tsoots 166
}
167
 
1238 tsoots 168
void SimpleState::set(const QString& key, uint value)
169
{
5116 tsoots 170
        values_[key] = QString("%1").arg(value);
1238 tsoots 171
}
172
 
1111 tsoots 173
void SimpleState::set(const QString& key, double value)
174
{
5116 tsoots 175
        values_[key] = QString("%1").arg(value, 0, 'f', 20);
1111 tsoots 176
}
177
 
1179 tsoots 178
void SimpleState::set(const QString& key, bool value)
179
{
5116 tsoots 180
        values_[key] = QString("%1").arg(value);
1179 tsoots 181
}
1111 tsoots 182
 
1179 tsoots 183
 
1518 tsoots 184
SimpleState::~SimpleState()
1111 tsoots 185
{
186
 
187
}