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) 2004 by Riku Leino *
9 * tsoots@gmail.com *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************/
26
27 #include "gtparagraphstyle.h"
28 #include "scribusstructs.h"
29
gtParagraphStyle(const QString & name)30 gtParagraphStyle::gtParagraphStyle(const QString& name) :
31 gtStyle(name)
32 {
33 init();
34 }
35
gtParagraphStyle(const gtParagraphStyle & p)36 gtParagraphStyle::gtParagraphStyle(const gtParagraphStyle& p) : gtStyle(p)
37 {
38 defaultStyle = false;
39 lineSpacing = p.lineSpacing;
40 alignment = p.alignment;
41 indent = p.indent;
42 firstLineIndent = p.firstLineIndent;
43 spaceAbove = p.spaceAbove;
44 spaceBelow = p.spaceBelow;
45 dropCap = p.dropCap;
46 m_bullet = p.m_bullet;
47 m_bulletStr = p.m_bulletStr;
48 dropCapHeight = p.dropCapHeight;
49 m_numeration = p.m_numeration;
50 m_numFormat = p.m_numFormat;
51 m_numLevel = p.m_numLevel;
52 m_numStart = p.m_numStart;
53 m_numPrefix = p.m_numPrefix;
54 m_numSuffix = p.m_numSuffix;
55 adjToBaseline = p.adjToBaseline;
56 autoLineSpacing = p.autoLineSpacing;
57 isVisible = p.isVisible;
58 flags = p.flags;
59 }
60
gtParagraphStyle(const gtStyle & s)61 gtParagraphStyle::gtParagraphStyle(const gtStyle& s) : gtStyle(s)
62 {
63 init();
64 }
65
init()66 void gtParagraphStyle::init()
67 {
68 defaultStyle = false;
69 lineSpacing = 15;
70 alignment = LEFT;
71 indent = 0;
72 firstLineIndent = 0;
73 spaceAbove = 0;
74 spaceBelow = 0;
75 dropCap = false;
76 dropCapHeight = 2;
77 m_bullet = false;
78 m_bulletStr = QString(QChar(0x2022));
79 m_numeration = false;
80 m_numFormat = 0;
81 m_numLevel = 0;
82 m_numStart = 1;
83 m_numPrefix.clear();
84 m_numSuffix.clear();
85 adjToBaseline = false;
86 autoLineSpacing = false;
87 isVisible = true;
88 flags = 0;
89 }
90
target() const91 QString gtParagraphStyle::target() const
92 {
93 return QString("paragraph");
94 }
95
getFlags() const96 int gtParagraphStyle::getFlags() const
97 {
98 return flags;
99 }
100
isDefaultStyle() const101 bool gtParagraphStyle::isDefaultStyle() const
102 {
103 return defaultStyle;
104 }
105
setDefaultStyle(bool defStyle)106 void gtParagraphStyle::setDefaultStyle(bool defStyle)
107 {
108 defaultStyle = defStyle;
109 }
110
getLineSpacing() const111 double gtParagraphStyle::getLineSpacing() const
112 {
113 return lineSpacing;
114 }
115
setLineSpacing(double newLineSpacing)116 void gtParagraphStyle::setLineSpacing(double newLineSpacing)
117 {
118 lineSpacing = newLineSpacing;
119 flags |= lineSpacingWasSet;
120 }
121
getAutoLineSpacing() const122 bool gtParagraphStyle::getAutoLineSpacing() const
123 {
124 return autoLineSpacing;
125 }
126
setAutoLineSpacing(bool newALS)127 void gtParagraphStyle::setAutoLineSpacing(bool newALS)
128 {
129 autoLineSpacing = newALS;
130 flags |= autoLineSpacingWasSet;
131 }
132
getAlignment() const133 int gtParagraphStyle::getAlignment() const
134 {
135 return alignment;
136 }
137
setAlignment(Alignment newAlignment)138 void gtParagraphStyle::setAlignment(Alignment newAlignment)
139 {
140 alignment = newAlignment;
141 flags |= alignmentWasSet;
142 }
143
setAlignment(int newAlignment)144 void gtParagraphStyle::setAlignment(int newAlignment)
145 {
146 if ((newAlignment > -1) && (newAlignment < AlignmentMAX))
147 {
148 alignment = newAlignment;
149 flags |= alignmentWasSet;
150 }
151 }
152
getIndent() const153 double gtParagraphStyle::getIndent() const
154 {
155 return indent;
156 }
157
setIndent(double newIndent)158 void gtParagraphStyle::setIndent(double newIndent)
159 {
160 indent = newIndent;
161 flags |= indentWasSet;
162 }
163
getFirstLineIndent() const164 double gtParagraphStyle::getFirstLineIndent() const
165 {
166 return firstLineIndent;
167 }
168
setFirstLineIndent(double newFirstLineIndent)169 void gtParagraphStyle::setFirstLineIndent(double newFirstLineIndent)
170 {
171 firstLineIndent = newFirstLineIndent;
172 flags |= firstIndentWasSet;
173 }
174
getSpaceAbove() const175 double gtParagraphStyle::getSpaceAbove() const
176 {
177 return spaceAbove;
178 }
179
setSpaceAbove(double newSpaceAbove)180 void gtParagraphStyle::setSpaceAbove(double newSpaceAbove)
181 {
182 spaceAbove = newSpaceAbove;
183 flags |= spaceAboveWasSet;
184 }
185
getSpaceBelow() const186 double gtParagraphStyle::getSpaceBelow() const
187 {
188 return spaceBelow;
189 }
190
setSpaceBelow(double newSpaceBelow)191 void gtParagraphStyle::setSpaceBelow(double newSpaceBelow)
192 {
193 spaceBelow = newSpaceBelow;
194 flags |= spaceBelowWasSet;
195 }
196
getTabValues() const197 const QList<ParagraphStyle::TabRecord>& gtParagraphStyle::getTabValues() const
198 {
199 return tabValues;
200 }
201
setTabValue(double newTabValue,TabType ttype)202 void gtParagraphStyle::setTabValue(double newTabValue, TabType ttype)
203 {
204 ParagraphStyle::TabRecord tb;
205 tb.tabPosition = newTabValue;
206 tb.tabType = ttype;
207 tb.tabFillChar = QChar();
208 tabValues.append(tb);
209 flags |= tabValueWasSet;
210 }
211
hasDropCap() const212 bool gtParagraphStyle::hasDropCap() const
213 {
214 return dropCap;
215 }
216
setDropCap(bool newDropCap)217 void gtParagraphStyle::setDropCap(bool newDropCap)
218 {
219 dropCap = newDropCap;
220 flags |= dropCapWasSet;
221 }
222
setDropCap(int newHeight)223 void gtParagraphStyle::setDropCap(int newHeight)
224 {
225 setDropCap(true);
226 dropCapHeight = newHeight;
227 flags |= dropCapHeightWasSet;
228 }
229
getDropCapHeight() const230 int gtParagraphStyle::getDropCapHeight() const
231 {
232 return dropCapHeight;
233 }
234
setDropCapHeight(int newHeight)235 void gtParagraphStyle::setDropCapHeight(int newHeight)
236 {
237 dropCapHeight = newHeight;
238 flags |= dropCapHeightWasSet;
239 }
240
hasBullet() const241 bool gtParagraphStyle::hasBullet() const
242 {
243 return m_bullet;
244 }
245
getBullet() const246 QString gtParagraphStyle::getBullet() const
247 {
248 return m_bulletStr;
249 }
250
setBullet(bool newBullet,const QString & str)251 void gtParagraphStyle::setBullet(bool newBullet, const QString& str)
252 {
253 m_bullet = newBullet;
254 if (str != "")
255 m_bulletStr = str;
256 else
257 m_bulletStr = QString(QChar(0x2022));
258 flags |= bulletWasSet;
259 }
260
hasNum() const261 bool gtParagraphStyle::hasNum() const
262 {
263 return m_numeration;
264 }
265
setNum(bool newNum,int format,int level,int start,const QString & prefix,const QString & suffix)266 void gtParagraphStyle::setNum(bool newNum, int format, int level, int start, const QString& prefix, const QString& suffix)
267 {
268 m_numeration = newNum;
269 if (newNum)
270 {
271 m_numFormat = format;
272 m_numLevel = level;
273 m_numStart = start;
274 m_numPrefix = prefix;
275 m_numSuffix = suffix;
276 }
277 flags |= numWasSet;
278 }
279
getNumLevel() const280 int gtParagraphStyle::getNumLevel() const
281 {
282 return m_numLevel;
283 }
284
getNumFormat() const285 int gtParagraphStyle::getNumFormat() const
286 {
287 return m_numFormat;
288 }
289
getNumStart() const290 int gtParagraphStyle::getNumStart() const
291 {
292 return m_numStart;
293 }
294
getNumPrefix() const295 QString gtParagraphStyle::getNumPrefix() const
296 {
297 return m_numPrefix;
298 }
299
getNumSuffix() const300 QString gtParagraphStyle::getNumSuffix() const
301 {
302 return m_numSuffix;
303 }
304
isAdjToBaseline() const305 bool gtParagraphStyle::isAdjToBaseline() const
306 {
307 return adjToBaseline;
308 }
309
setAdjToBaseline(bool newAdjToBaseline)310 void gtParagraphStyle::setAdjToBaseline(bool newAdjToBaseline)
311 {
312 adjToBaseline = newAdjToBaseline;
313 flags |= adjToBaselineWasSet;
314 }
315
getStyle(gtStyle * style)316 void gtParagraphStyle::getStyle(gtStyle* style)
317 {
318 *style = gtStyle(*this);
319 }
320