Merge lp:~marcelstimberg/ubuntu/precise/scribus/merge-1.4-from-debian into lp:ubuntu/precise/scribus
- Precise (12.04)
- merge-1.4-from-debian
- Merge into precise
Proposed by
Marcel Stimberg
Status: | Merged |
---|---|
Merged at revision: | 30 |
Proposed branch: | lp:~marcelstimberg/ubuntu/precise/scribus/merge-1.4-from-debian |
Merge into: | lp:ubuntu/precise/scribus |
Diff against target: | 525900 lines |
To merge this branch: | bzr merge lp:~marcelstimberg/ubuntu/precise/scribus/merge-1.4-from-debian |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Felix Geyer (community) | Disapprove | ||
Ubuntu branches | Pending | ||
Review via email: mp+92623@code.launchpad.net |
Commit message
Description of the change
This merges the updated debian version that now ships the final 1.4 release instead of the release candidate.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed directory '.pc/0001-qreal-double-fixes.patch' | |||
2 | === removed directory '.pc/0001-qreal-double-fixes.patch/scribus' | |||
3 | === removed directory '.pc/0001-qreal-double-fixes.patch/scribus/fonts' | |||
4 | === removed file '.pc/0001-qreal-double-fixes.patch/scribus/fonts/scfontmetrics.cpp' | |||
5 | --- .pc/0001-qreal-double-fixes.patch/scribus/fonts/scfontmetrics.cpp 2011-09-11 22:10:03 +0000 | |||
6 | +++ .pc/0001-qreal-double-fixes.patch/scribus/fonts/scfontmetrics.cpp 1970-01-01 00:00:00 +0000 | |||
7 | @@ -1,623 +0,0 @@ | |||
8 | 1 | /* | ||
9 | 2 | For general Scribus (>=1.3.2) copyright and licensing information please refer | ||
10 | 3 | to the COPYING file provided with the program. Following this notice may exist | ||
11 | 4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 | ||
12 | 5 | for which a new license (GPL+exception) is in place. | ||
13 | 6 | */ | ||
14 | 7 | #include <QColor> | ||
15 | 8 | #include <QDebug> | ||
16 | 9 | #include <QMap> | ||
17 | 10 | #include <QMatrix> | ||
18 | 11 | #include <QPainter> | ||
19 | 12 | #include <QPixmap> | ||
20 | 13 | #include <QRegExp> | ||
21 | 14 | #include <QStringList> | ||
22 | 15 | |||
23 | 16 | #include "fpoint.h" | ||
24 | 17 | #include "fpointarray.h" | ||
25 | 18 | #include "page.h" | ||
26 | 19 | #include "scfontmetrics.h" | ||
27 | 20 | #include "scfonts.h" | ||
28 | 21 | #include "scpainter.h" | ||
29 | 22 | #include "scribusdoc.h" | ||
30 | 23 | #include "style.h" | ||
31 | 24 | #include "util_math.h" | ||
32 | 25 | |||
33 | 26 | |||
34 | 27 | // this code contains a set of font related functions | ||
35 | 28 | // that don't really fit within ScFonts. | ||
36 | 29 | |||
37 | 30 | static FPoint firstP; | ||
38 | 31 | static bool FirstM; | ||
39 | 32 | static QMap<FT_ULong, QString> adobeGlyphNames; | ||
40 | 33 | static const char* table[] = { | ||
41 | 34 | //#include "glyphnames.txt.q" | ||
42 | 35 | NULL}; | ||
43 | 36 | |||
44 | 37 | // private functions | ||
45 | 38 | static void readAdobeGlyphNames(); | ||
46 | 39 | static QString adobeGlyphName(FT_ULong charcode); | ||
47 | 40 | static int traceMoveto( FT_Vector *to, FPointArray *composite ); | ||
48 | 41 | static int traceLineto( FT_Vector *to, FPointArray *composite ); | ||
49 | 42 | static int traceQuadraticBezier( FT_Vector *control, FT_Vector *to, FPointArray *composite ); | ||
50 | 43 | static int traceCubicBezier( FT_Vector *p, FT_Vector *q, FT_Vector *to, FPointArray *composite ); | ||
51 | 44 | |||
52 | 45 | FT_Outline_Funcs OutlineMethods = | ||
53 | 46 | { | ||
54 | 47 | (FT_Outline_MoveTo_Func) traceMoveto, | ||
55 | 48 | (FT_Outline_LineTo_Func) traceLineto, | ||
56 | 49 | (FT_Outline_ConicTo_Func) traceQuadraticBezier, | ||
57 | 50 | (FT_Outline_CubicTo_Func) traceCubicBezier, | ||
58 | 51 | 0, | ||
59 | 52 | 0 | ||
60 | 53 | }; | ||
61 | 54 | |||
62 | 55 | |||
63 | 56 | const qreal FTSCALE = 64.0; | ||
64 | 57 | |||
65 | 58 | |||
66 | 59 | int setBestEncoding(FT_Face face) | ||
67 | 60 | { | ||
68 | 61 | FT_ULong charcode; | ||
69 | 62 | FT_UInt gindex; | ||
70 | 63 | bool foundEncoding = false; | ||
71 | 64 | int countUniCode = 0; | ||
72 | 65 | int chmapUniCode = -1; | ||
73 | 66 | int chmapCustom = -1; | ||
74 | 67 | int retVal = 0; | ||
75 | 68 | //FT_CharMap defaultEncoding = face->charmap; | ||
76 | 69 | // int defaultchmap=face->charmap ? FT_Get_Charmap_Index(face->charmap) : 0; | ||
77 | 70 | // Since the above function is only available in FreeType 2.1.10 its replaced by | ||
78 | 71 | // the following line, assuming that the default charmap has the index 0 | ||
79 | 72 | int defaultchmap = 0; | ||
80 | 73 | for(int u = 0; u < face->num_charmaps; u++) | ||
81 | 74 | { | ||
82 | 75 | if (face->charmaps[u]->encoding == FT_ENCODING_UNICODE ) | ||
83 | 76 | { | ||
84 | 77 | FT_Set_Charmap(face, face->charmaps[u]); | ||
85 | 78 | chmapUniCode = u; | ||
86 | 79 | gindex = 0; | ||
87 | 80 | charcode = FT_Get_First_Char( face, &gindex ); | ||
88 | 81 | while ( gindex != 0 ) | ||
89 | 82 | { | ||
90 | 83 | countUniCode++; | ||
91 | 84 | charcode = FT_Get_Next_Char( face, charcode, &gindex ); | ||
92 | 85 | } | ||
93 | 86 | // qDebug() << "found Unicode enc for" << face->family_name << face->style_name << "as map" << chmapUniCode << "with" << countUniCode << "glyphs"; | ||
94 | 87 | |||
95 | 88 | } | ||
96 | 89 | if (face->charmaps[u]->encoding == FT_ENCODING_ADOBE_CUSTOM) | ||
97 | 90 | { | ||
98 | 91 | chmapCustom = u; | ||
99 | 92 | foundEncoding = true; | ||
100 | 93 | retVal = 1; | ||
101 | 94 | // qDebug() << "found Custom enc for" << face->family_name << face->style_name; | ||
102 | 95 | break; | ||
103 | 96 | } | ||
104 | 97 | else if (face->charmaps[u]->encoding == FT_ENCODING_MS_SYMBOL) | ||
105 | 98 | { | ||
106 | 99 | // qDebug() << "found Symbol enc for" << face->family_name << face->style_name; | ||
107 | 100 | |||
108 | 101 | chmapCustom = u; | ||
109 | 102 | foundEncoding = true; | ||
110 | 103 | retVal = 2; | ||
111 | 104 | break; | ||
112 | 105 | } | ||
113 | 106 | } | ||
114 | 107 | int mapToSet=defaultchmap; | ||
115 | 108 | if (chmapUniCode >= 0 && countUniCode >= face->num_glyphs-1) | ||
116 | 109 | { | ||
117 | 110 | // qDebug() << "using Unicode enc for" << face->family_name << face->style_name; | ||
118 | 111 | |||
119 | 112 | mapToSet=chmapUniCode; | ||
120 | 113 | //FT_Set_Charmap(face, face->charmaps[chmapUniCode]); | ||
121 | 114 | retVal = 0; | ||
122 | 115 | } | ||
123 | 116 | else | ||
124 | 117 | if (foundEncoding) | ||
125 | 118 | { | ||
126 | 119 | // qDebug() << "using special enc for" << face->family_name << face->style_name; | ||
127 | 120 | mapToSet=chmapCustom; | ||
128 | 121 | //FT_Set_Charmap(face, face->charmaps[chmapCustom]); | ||
129 | 122 | } | ||
130 | 123 | else | ||
131 | 124 | { | ||
132 | 125 | // qDebug() << "using default enc for" << face->family_name << face->style_name; | ||
133 | 126 | mapToSet=defaultchmap; | ||
134 | 127 | //FT_Set_Charmap(face, defaultEncoding); | ||
135 | 128 | retVal = 0; | ||
136 | 129 | } | ||
137 | 130 | |||
138 | 131 | //Fixes #2199, missing glyphs from 1.2.1->1.2.2 | ||
139 | 132 | //If the currently wanted character map is not already Unicode... | ||
140 | 133 | //if (FT_Get_Charmap_Index(face->charmap)!=chmapUniCode) | ||
141 | 134 | if (mapToSet!=chmapUniCode) | ||
142 | 135 | { | ||
143 | 136 | //Change map so we can count the chars in it | ||
144 | 137 | FT_Set_Charmap(face, face->charmaps[mapToSet]); | ||
145 | 138 | //Count the characters in the current map | ||
146 | 139 | gindex = 0; | ||
147 | 140 | int countCurrMap=0; | ||
148 | 141 | charcode = FT_Get_First_Char( face, &gindex ); | ||
149 | 142 | while ( gindex != 0 ) | ||
150 | 143 | { | ||
151 | 144 | countCurrMap++; | ||
152 | 145 | charcode = FT_Get_Next_Char( face, charcode, &gindex ); | ||
153 | 146 | } | ||
154 | 147 | //If the last Unicode map we found before has more characters, | ||
155 | 148 | //then set it to be the current map. | ||
156 | 149 | |||
157 | 150 | if (countUniCode>countCurrMap) | ||
158 | 151 | { | ||
159 | 152 | // qDebug() << "override with Unicode enc for" << face->family_name << face->style_name << "map" << mapToSet << "has only" << countCurrMap << "glyphs"; | ||
160 | 153 | mapToSet=chmapUniCode; | ||
161 | 154 | //FT_Set_Charmap(face, face->charmaps[chmapUniCode]); | ||
162 | 155 | retVal = 0; | ||
163 | 156 | } | ||
164 | 157 | } | ||
165 | 158 | // if (face->charmap == NULL || mapToSet!=FT_Get_Charmap_Index(face->charmap)) | ||
166 | 159 | FT_Set_Charmap(face, face->charmaps[mapToSet]); | ||
167 | 160 | // qDebug() << "set map" << mapToSet << "for" << face->family_name << face->style_name; | ||
168 | 161 | // qDebug() << "glyphsForNumbers 0-9:" << FT_Get_Char_Index(face, QChar('0').unicode()) | ||
169 | 162 | // << FT_Get_Char_Index(face, QChar('1').unicode()) << FT_Get_Char_Index(face, QChar('2').unicode()) << FT_Get_Char_Index(face, QChar('3').unicode()) | ||
170 | 163 | // << FT_Get_Char_Index(face, QChar('4').unicode()) << FT_Get_Char_Index(face, QChar('5').unicode()) << FT_Get_Char_Index(face, QChar('6').unicode()) | ||
171 | 164 | // << FT_Get_Char_Index(face, QChar('7').unicode()) << FT_Get_Char_Index(face, QChar('8').unicode()) << FT_Get_Char_Index(face, QChar('9').unicode()); | ||
172 | 165 | return retVal; | ||
173 | 166 | } | ||
174 | 167 | |||
175 | 168 | FPointArray traceGlyph(FT_Face face, FT_UInt glyphIndex, int chs, qreal *x, qreal *y, bool *err) | ||
176 | 169 | { | ||
177 | 170 | bool error = false; | ||
178 | 171 | //AV: not threadsave, but tracechar is only used in ReadMetrics() and fontSample() | ||
179 | 172 | static FPointArray pts; | ||
180 | 173 | FPointArray pts2; | ||
181 | 174 | pts.resize(0); | ||
182 | 175 | pts2.resize(0); | ||
183 | 176 | firstP = FPoint(0,0); | ||
184 | 177 | FirstM = true; | ||
185 | 178 | error = FT_Set_Char_Size( face, 0, chs*6400, 72, 72 ); | ||
186 | 179 | if (error) | ||
187 | 180 | { | ||
188 | 181 | *err = error; | ||
189 | 182 | return pts2; | ||
190 | 183 | } | ||
191 | 184 | if (glyphIndex == 0) | ||
192 | 185 | { | ||
193 | 186 | *err = true; | ||
194 | 187 | return pts2; | ||
195 | 188 | } | ||
196 | 189 | error = FT_Load_Glyph( face, glyphIndex, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP ); | ||
197 | 190 | if (error) | ||
198 | 191 | { | ||
199 | 192 | *err = error; | ||
200 | 193 | return pts2; | ||
201 | 194 | } | ||
202 | 195 | error = FT_Outline_Decompose(&face->glyph->outline, &OutlineMethods, reinterpret_cast<void*>(&pts)); | ||
203 | 196 | if (error) | ||
204 | 197 | { | ||
205 | 198 | *err = error; | ||
206 | 199 | return pts2; | ||
207 | 200 | } | ||
208 | 201 | *x = face->glyph->metrics.horiBearingX / 6400.0; | ||
209 | 202 | *y = face->glyph->metrics.horiBearingY / 6400.0; | ||
210 | 203 | QMatrix ma; | ||
211 | 204 | ma.scale(0.01, -0.01); | ||
212 | 205 | pts.map(ma); | ||
213 | 206 | pts.translate(0, chs); | ||
214 | 207 | pts2.putPoints(0, pts.size()-2, pts, 0); | ||
215 | 208 | |||
216 | 209 | return pts2; | ||
217 | 210 | } | ||
218 | 211 | |||
219 | 212 | |||
220 | 213 | FPointArray traceChar(FT_Face face, uint chr, int chs, qreal *x, qreal *y, bool *err) | ||
221 | 214 | { | ||
222 | 215 | bool error = false; | ||
223 | 216 | FT_UInt glyphIndex; | ||
224 | 217 | error = FT_Set_Char_Size( face, 0, chs*64, 72, 72 ); | ||
225 | 218 | if (error) | ||
226 | 219 | { | ||
227 | 220 | *err = error; | ||
228 | 221 | return FPointArray(); | ||
229 | 222 | } | ||
230 | 223 | glyphIndex = FT_Get_Char_Index(face, chr); | ||
231 | 224 | return traceGlyph(face, glyphIndex, chs, x, y, err); | ||
232 | 225 | } | ||
233 | 226 | |||
234 | 227 | |||
235 | 228 | QPixmap FontSample(const ScFace& fnt, int s, QString ts, QColor back, bool force) | ||
236 | 229 | { | ||
237 | 230 | FT_Face face; | ||
238 | 231 | FT_Library library; | ||
239 | 232 | qreal x, y, ymax; | ||
240 | 233 | bool error; | ||
241 | 234 | int pen_x; | ||
242 | 235 | FPoint gp; | ||
243 | 236 | error = FT_Init_FreeType( &library ); | ||
244 | 237 | error = FT_New_Face( library, QFile::encodeName(fnt.fontFilePath()), fnt.faceIndex(), &face ); | ||
245 | 238 | int encode = setBestEncoding(face); | ||
246 | 239 | qreal uniEM = static_cast<qreal>(face->units_per_EM); | ||
247 | 240 | |||
248 | 241 | qreal m_descent = face->descender / uniEM; | ||
249 | 242 | qreal m_height = face->height / uniEM; | ||
250 | 243 | if (m_height == 0) | ||
251 | 244 | m_height = (face->bbox.yMax - face->bbox.yMin) / uniEM; | ||
252 | 245 | |||
253 | 246 | int h = qRound(m_height * s) + 1; | ||
254 | 247 | qreal a = m_descent * s + 1; | ||
255 | 248 | int w = qRound((face->bbox.xMax - face->bbox.xMin) / uniEM) * s * (ts.length()+1); | ||
256 | 249 | if (w < 1) | ||
257 | 250 | w = s * (ts.length()+1); | ||
258 | 251 | if (h < 1) | ||
259 | 252 | h = s; | ||
260 | 253 | QImage pm(w, h, QImage::Format_ARGB32); | ||
261 | 254 | pen_x = 0; | ||
262 | 255 | ymax = 0.0; | ||
263 | 256 | ScPainter *p = new ScPainter(&pm, pm.width(), pm.height()); | ||
264 | 257 | p->clear(back); | ||
265 | 258 | p->setFillMode(1); | ||
266 | 259 | p->setLineWidth(0.0); | ||
267 | 260 | // p->setBrush(back); | ||
268 | 261 | // p->drawRect(0.0, 0.0, static_cast<qreal>(w), static_cast<qreal>(h)); | ||
269 | 262 | p->setBrush(Qt::black); | ||
270 | 263 | FPointArray gly; | ||
271 | 264 | uint dv; | ||
272 | 265 | dv = ts[0].unicode(); | ||
273 | 266 | error = false; | ||
274 | 267 | gly = traceChar(face, dv, s, &x, &y, &error); | ||
275 | 268 | if (((encode != 0) || (error)) && (!force)) | ||
276 | 269 | { | ||
277 | 270 | error = false; | ||
278 | 271 | FT_ULong charcode; | ||
279 | 272 | FT_UInt gindex; | ||
280 | 273 | gindex = 0; | ||
281 | 274 | charcode = FT_Get_First_Char(face, &gindex ); | ||
282 | 275 | for (int n = 0; n < ts.length(); ++n) | ||
283 | 276 | { | ||
284 | 277 | gly = traceChar(face, charcode, s, &x, &y, &error); | ||
285 | 278 | if (error) | ||
286 | 279 | break; | ||
287 | 280 | if (gly.size() > 3) | ||
288 | 281 | { | ||
289 | 282 | gly.translate(static_cast<qreal>(pen_x) / 6400.0, a); | ||
290 | 283 | gp = getMaxClipF(&gly); | ||
291 | 284 | ymax = qMax(ymax, gp.y()); | ||
292 | 285 | p->setupPolygon(&gly); | ||
293 | 286 | p->fillPath(); | ||
294 | 287 | } | ||
295 | 288 | pen_x += face->glyph->advance.x; | ||
296 | 289 | charcode = FT_Get_Next_Char(face, charcode, &gindex ); | ||
297 | 290 | if (gindex == 0) | ||
298 | 291 | break; | ||
299 | 292 | } | ||
300 | 293 | } | ||
301 | 294 | else | ||
302 | 295 | { | ||
303 | 296 | for (int n = 0; n < ts.length(); ++n) | ||
304 | 297 | { | ||
305 | 298 | dv = ts[n].unicode(); | ||
306 | 299 | error = false; | ||
307 | 300 | gly = traceChar(face, dv, s, &x, &y, &error); | ||
308 | 301 | if (gly.size() > 3) | ||
309 | 302 | { | ||
310 | 303 | gly.translate(static_cast<qreal>(pen_x) / 6400.0, a); | ||
311 | 304 | gp = getMaxClipF(&gly); | ||
312 | 305 | ymax = qMax(ymax, gp.y()); | ||
313 | 306 | p->setupPolygon(&gly); | ||
314 | 307 | p->fillPath(); | ||
315 | 308 | } | ||
316 | 309 | pen_x += face->glyph->advance.x; | ||
317 | 310 | } | ||
318 | 311 | } | ||
319 | 312 | p->end(); | ||
320 | 313 | QPixmap pmr; | ||
321 | 314 | pmr=QPixmap::fromImage(pm.copy(0, 0, qMin(qRound(gp.x()), w), qMin(qRound(ymax), h))); | ||
322 | 315 | // this one below gives some funny results | ||
323 | 316 | // pmr.convertFromImage(pm.scaled(qMin(qRound(gp.x()), w), qMin(qRound(ymax), h), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); | ||
324 | 317 | // pmr.resize(qMin(qRound(gp.x()), w), qMin(qRound(ymax), h)); | ||
325 | 318 | delete p; | ||
326 | 319 | FT_Done_FreeType( library ); | ||
327 | 320 | return pmr; | ||
328 | 321 | } | ||
329 | 322 | |||
330 | 323 | /** Same as FontSample() with \n strings support added. | ||
331 | 324 | 09/26/2004 petr vanek | ||
332 | 325 | |||
333 | 326 | QPixmap fontSamples(ScFace * fnt, int s, QString ts, QColor back) | ||
334 | 327 | { | ||
335 | 328 | QStringList lines = QStringList::split("\n", ts); | ||
336 | 329 | QPixmap ret(640, 480); | ||
337 | 330 | QPixmap sample; | ||
338 | 331 | QPainter *painter = new QPainter(&ret); | ||
339 | 332 | int y = 0; | ||
340 | 333 | int x = 0; | ||
341 | 334 | ret.fill(back); | ||
342 | 335 | for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) | ||
343 | 336 | { | ||
344 | 337 | sample = FontSample(fnt, s, *it, back); | ||
345 | 338 | if (!sample.isNull()) | ||
346 | 339 | painter->drawPixmap(0, y, sample, 0, 0); | ||
347 | 340 | y = y + sample.height(); | ||
348 | 341 | if (x < sample.width()) | ||
349 | 342 | x = sample.width(); | ||
350 | 343 | } // for | ||
351 | 344 | delete(painter); | ||
352 | 345 | QPixmap final(x, y); | ||
353 | 346 | if ((x != 0) && (y != 0)) | ||
354 | 347 | { | ||
355 | 348 | QPainter *fpainter = new QPainter(&final); | ||
356 | 349 | fpainter->drawPixmap(0, 0, ret, 0, 0, x, y); | ||
357 | 350 | delete(fpainter); | ||
358 | 351 | } | ||
359 | 352 | return final; | ||
360 | 353 | } | ||
361 | 354 | */ | ||
362 | 355 | |||
363 | 356 | bool GlyNames(FT_Face face, QMap<uint, std::pair<QChar, QString> >& GList) | ||
364 | 357 | { | ||
365 | 358 | char buf[50]; | ||
366 | 359 | FT_ULong charcode; | ||
367 | 360 | FT_UInt gindex; | ||
368 | 361 | setBestEncoding(face); | ||
369 | 362 | gindex = 0; | ||
370 | 363 | charcode = FT_Get_First_Char(face, &gindex ); | ||
371 | 364 | const bool hasPSNames = FT_HAS_GLYPH_NAMES(face); | ||
372 | 365 | if (adobeGlyphNames.empty()) | ||
373 | 366 | readAdobeGlyphNames(); | ||
374 | 367 | // qDebug() << "reading metrics for" << face->family_name << face->style_name; | ||
375 | 368 | while (gindex != 0) | ||
376 | 369 | { | ||
377 | 370 | bool notfound = true; | ||
378 | 371 | if (hasPSNames) | ||
379 | 372 | notfound = FT_Get_Glyph_Name(face, gindex, &buf, 50); | ||
380 | 373 | |||
381 | 374 | // just in case FT gives empty string or ".notdef" | ||
382 | 375 | // no valid glyphname except ".notdef" starts with '.' | ||
383 | 376 | // qDebug() << "\t" << gindex << " '" << charcode << "' --> '" << (notfound? "notfound" : buf) << "'"; | ||
384 | 377 | if (notfound || buf[0] == '\0' || buf[0] == '.') | ||
385 | 378 | GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)),adobeGlyphName(charcode))); | ||
386 | 379 | else | ||
387 | 380 | GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)),QString(reinterpret_cast<char*>(buf)))); | ||
388 | 381 | |||
389 | 382 | charcode = FT_Get_Next_Char(face, charcode, &gindex ); | ||
390 | 383 | } | ||
391 | 384 | // Let's see if we can find some more... | ||
392 | 385 | int maxSlot1 = face->num_glyphs; | ||
393 | 386 | if (hasPSNames) | ||
394 | 387 | for (int gindex = 1; gindex < maxSlot1; ++gindex) | ||
395 | 388 | { | ||
396 | 389 | if (!GList.contains(gindex)) | ||
397 | 390 | { | ||
398 | 391 | bool found = ! FT_Get_Glyph_Name(face, gindex, &buf, 50); | ||
399 | 392 | if (found) | ||
400 | 393 | { | ||
401 | 394 | QString glyphname(reinterpret_cast<char*>(buf)); | ||
402 | 395 | charcode = 0; | ||
403 | 396 | QMap<uint,std::pair<QChar,QString> >::Iterator gli; | ||
404 | 397 | for (gli = GList.begin(); gli != GList.end(); ++gli) | ||
405 | 398 | { | ||
406 | 399 | if (glyphname == gli.value().second) | ||
407 | 400 | { | ||
408 | 401 | charcode = gli.value().first.unicode(); | ||
409 | 402 | break; | ||
410 | 403 | } | ||
411 | 404 | } | ||
412 | 405 | // qDebug() << "\tmore: " << gindex << " '" << charcode << "' --> '" << buf << "'"; | ||
413 | 406 | GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)), glyphname)); | ||
414 | 407 | } | ||
415 | 408 | } | ||
416 | 409 | } | ||
417 | 410 | |||
418 | 411 | return true; | ||
419 | 412 | } | ||
420 | 413 | |||
421 | 414 | |||
422 | 415 | static int traceMoveto( FT_Vector *to, FPointArray *composite ) | ||
423 | 416 | { | ||
424 | 417 | qreal tox = ( to->x / FTSCALE ); | ||
425 | 418 | qreal toy = ( to->y / FTSCALE ); | ||
426 | 419 | if (!FirstM) | ||
427 | 420 | { | ||
428 | 421 | composite->addPoint(firstP); | ||
429 | 422 | composite->addPoint(firstP); | ||
430 | 423 | composite->setMarker(); | ||
431 | 424 | } | ||
432 | 425 | else | ||
433 | 426 | FirstM = false; | ||
434 | 427 | composite->addPoint(tox, toy); | ||
435 | 428 | composite->addPoint(tox, toy); | ||
436 | 429 | firstP.setXY(tox, toy); | ||
437 | 430 | return 0; | ||
438 | 431 | } | ||
439 | 432 | |||
440 | 433 | static int traceLineto( FT_Vector *to, FPointArray *composite ) | ||
441 | 434 | { | ||
442 | 435 | qreal tox = ( to->x / FTSCALE ); | ||
443 | 436 | qreal toy = ( to->y / FTSCALE ); | ||
444 | 437 | if ( !composite->hasLastQuadPoint(tox, toy, tox, toy, tox, toy, tox, toy)) | ||
445 | 438 | composite->addQuadPoint(tox, toy, tox, toy, tox, toy, tox, toy); | ||
446 | 439 | return 0; | ||
447 | 440 | } | ||
448 | 441 | |||
449 | 442 | static int traceQuadraticBezier( FT_Vector *control, FT_Vector *to, FPointArray *composite ) | ||
450 | 443 | { | ||
451 | 444 | qreal x1 = ( control->x / FTSCALE ); | ||
452 | 445 | qreal y1 = ( control->y / FTSCALE ); | ||
453 | 446 | qreal x2 = ( to->x / FTSCALE ); | ||
454 | 447 | qreal y2 = ( to->y / FTSCALE ); | ||
455 | 448 | if ( !composite->hasLastQuadPoint(x2, y2, x1, y1, x2, y2, x2, y2)) | ||
456 | 449 | composite->addQuadPoint(x2, y2, x1, y1, x2, y2, x2, y2); | ||
457 | 450 | return 0; | ||
458 | 451 | } | ||
459 | 452 | |||
460 | 453 | static int traceCubicBezier( FT_Vector *p, FT_Vector *q, FT_Vector *to, FPointArray *composite ) | ||
461 | 454 | { | ||
462 | 455 | qreal x1 = ( p->x / FTSCALE ); | ||
463 | 456 | qreal y1 = ( p->y / FTSCALE ); | ||
464 | 457 | qreal x2 = ( q->x / FTSCALE ); | ||
465 | 458 | qreal y2 = ( q->y / FTSCALE ); | ||
466 | 459 | qreal x3 = ( to->x / FTSCALE ); | ||
467 | 460 | qreal y3 = ( to->y / FTSCALE ); | ||
468 | 461 | if ( !composite->hasLastQuadPoint(x3, y3, x2, y2, x3, y3, x3, y3) ) | ||
469 | 462 | { | ||
470 | 463 | composite->setPoint(composite->size()-1, FPoint(x1, y1)); | ||
471 | 464 | composite->addQuadPoint(x3, y3, x2, y2, x3, y3, x3, y3); | ||
472 | 465 | } | ||
473 | 466 | return 0; | ||
474 | 467 | } | ||
475 | 468 | |||
476 | 469 | /// init the Adobe Glyph List | ||
477 | 470 | void readAdobeGlyphNames() | ||
478 | 471 | { | ||
479 | 472 | adobeGlyphNames.clear(); | ||
480 | 473 | QRegExp pattern("(\\w*);([0-9A-Fa-f]{4})"); | ||
481 | 474 | for (uint i=0; table[i]; ++i) { | ||
482 | 475 | if (pattern.indexIn(table[i]) >= 0) { | ||
483 | 476 | FT_ULong unicode = pattern.cap(2).toULong(0, 16); | ||
484 | 477 | qDebug() << QString("reading glyph name %1 for unicode %2(%3)").arg(pattern.cap(1)).arg(unicode).arg(pattern.cap(2)); | ||
485 | 478 | adobeGlyphNames.insert(unicode, pattern.cap(1)); | ||
486 | 479 | } | ||
487 | 480 | } | ||
488 | 481 | } | ||
489 | 482 | |||
490 | 483 | |||
491 | 484 | /// if in AGL, use that name, else use "uni1234" or "u12345" | ||
492 | 485 | QString adobeGlyphName(FT_ULong charcode) | ||
493 | 486 | { | ||
494 | 487 | static const char HEX[] = "0123456789ABCDEF"; | ||
495 | 488 | QString result; | ||
496 | 489 | if (adobeGlyphNames.contains(charcode)) | ||
497 | 490 | return adobeGlyphNames[charcode]; | ||
498 | 491 | else if (charcode < 0x10000) { | ||
499 | 492 | result = QString("uni") + HEX[charcode>>12 & 0xF] | ||
500 | 493 | + HEX[charcode>> 8 & 0xF] | ||
501 | 494 | + HEX[charcode>> 4 & 0xF] | ||
502 | 495 | + HEX[charcode & 0xF]; | ||
503 | 496 | } | ||
504 | 497 | else { | ||
505 | 498 | result = QString("u"); | ||
506 | 499 | for (int i= 28; i >= 0; i-=4) { | ||
507 | 500 | if (charcode & (0xF << i)) | ||
508 | 501 | result += HEX[charcode >> i & 0xF]; | ||
509 | 502 | } | ||
510 | 503 | } | ||
511 | 504 | return result; | ||
512 | 505 | } | ||
513 | 506 | |||
514 | 507 | /* | ||
515 | 508 | qreal Cwidth(ScribusDoc *, ScFace* scFace, QString ch, int Size, QString ch2) | ||
516 | 509 | { | ||
517 | 510 | qreal width; | ||
518 | 511 | FT_Vector delta; | ||
519 | 512 | FT_Face face; | ||
520 | 513 | uint c1 = ch.at(0).unicode(); | ||
521 | 514 | uint c2 = ch2.at(0).unicode(); | ||
522 | 515 | qreal size10=Size/10.0; | ||
523 | 516 | if (scFace->canRender(ch[0])) | ||
524 | 517 | { | ||
525 | 518 | width = scFace->charWidth(ch[0])*size10; | ||
526 | 519 | face = scFace->ftFace(); | ||
527 | 520 | /\**** | ||
528 | 521 | Ok, this looks like a regression between Freetype 2.1.9 -> 2.1.10. | ||
529 | 522 | Ignoring the value of FT_HAS_KERNING for now -- AV | ||
530 | 523 | ****\/ | ||
531 | 524 | if (true || FT_HAS_KERNING(face) ) | ||
532 | 525 | { | ||
533 | 526 | uint cl = FT_Get_Char_Index(face, c1); | ||
534 | 527 | uint cr = FT_Get_Char_Index(face, c2); | ||
535 | 528 | FT_Error error = FT_Get_Kerning(face, cl, cr, FT_KERNING_UNSCALED, &delta); | ||
536 | 529 | if (error) { | ||
537 | 530 | qDebug() << QString("Error %2 when accessing kerning pair for font %1").arg(scFace->scName()).arg(error); | ||
538 | 531 | } | ||
539 | 532 | else { | ||
540 | 533 | qreal uniEM = static_cast<qreal>(face->units_per_EM); | ||
541 | 534 | width += delta.x / uniEM * size10; | ||
542 | 535 | } | ||
543 | 536 | } | ||
544 | 537 | else { | ||
545 | 538 | qDebug() << QString("Font %1 has no kerning pairs (according to Freetype)").arg(scFace->scName()); | ||
546 | 539 | } | ||
547 | 540 | return width; | ||
548 | 541 | } | ||
549 | 542 | else | ||
550 | 543 | return size10; | ||
551 | 544 | } | ||
552 | 545 | |||
553 | 546 | qreal RealCWidth(ScribusDoc *, ScFace* scFace, QString ch, int Size) | ||
554 | 547 | { | ||
555 | 548 | qreal w, ww; | ||
556 | 549 | uint c1 = ch.at(0).unicode(); | ||
557 | 550 | FT_Face face; | ||
558 | 551 | if (scFace->canRender(ch.at(0))) | ||
559 | 552 | { | ||
560 | 553 | face = scFace->ftFace(); | ||
561 | 554 | uint cl = FT_Get_Char_Index(face, c1); | ||
562 | 555 | int error = FT_Load_Glyph(face, cl, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ); | ||
563 | 556 | if (!error) { | ||
564 | 557 | qreal uniEM = static_cast<qreal>(face->units_per_EM); | ||
565 | 558 | w = (face->glyph->metrics.width + fabs((qreal)face->glyph->metrics.horiBearingX)) / uniEM * (Size / 10.0); | ||
566 | 559 | ww = face->glyph->metrics.horiAdvance / uniEM * (Size / 10.0); | ||
567 | 560 | return qMax(ww, w); | ||
568 | 561 | } | ||
569 | 562 | else | ||
570 | 563 | sDebug(QString("internal error: missing glyph: %1 (char %2) error=%3").arg(c1).arg(ch).arg(error)); | ||
571 | 564 | |||
572 | 565 | } | ||
573 | 566 | return static_cast<qreal>(Size / 10.0); | ||
574 | 567 | } | ||
575 | 568 | |||
576 | 569 | qreal RealCHeight(ScribusDoc *, ScFace* scFace, QString ch, int Size) | ||
577 | 570 | { | ||
578 | 571 | qreal w; | ||
579 | 572 | uint c1 = ch.at(0).unicode(); | ||
580 | 573 | FT_Face face; | ||
581 | 574 | if (scFace->canRender(ch.at(0))) | ||
582 | 575 | { | ||
583 | 576 | face = scFace->ftFace(); | ||
584 | 577 | uint cl = FT_Get_Char_Index(face, c1); | ||
585 | 578 | int error = FT_Load_Glyph(face, cl, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ); | ||
586 | 579 | if (!error) { | ||
587 | 580 | qreal uniEM = static_cast<qreal>(face->units_per_EM); | ||
588 | 581 | w = face->glyph->metrics.height / uniEM * (Size / 10.0); | ||
589 | 582 | } | ||
590 | 583 | else { | ||
591 | 584 | sDebug(QString("internal error: missing glyph: %1 (char %2) error=%3").arg(c1).arg(ch).arg(error)); | ||
592 | 585 | w = Size / 10.0; | ||
593 | 586 | } | ||
594 | 587 | return w; | ||
595 | 588 | } | ||
596 | 589 | else | ||
597 | 590 | return static_cast<qreal>(Size / 10.0); | ||
598 | 591 | } | ||
599 | 592 | |||
600 | 593 | qreal RealCAscent(ScribusDoc *, ScFace* scFace, QString ch, int Size) | ||
601 | 594 | { | ||
602 | 595 | qreal w; | ||
603 | 596 | uint c1 = ch.at(0).unicode(); | ||
604 | 597 | FT_Face face; | ||
605 | 598 | if (scFace->canRender(ch.at(0))) | ||
606 | 599 | { | ||
607 | 600 | face = scFace->ftFace(); | ||
608 | 601 | uint cl = FT_Get_Char_Index(face, c1); | ||
609 | 602 | int error = FT_Load_Glyph(face, cl, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ); | ||
610 | 603 | if (! error) { | ||
611 | 604 | qreal uniEM = static_cast<qreal>(face->units_per_EM); | ||
612 | 605 | w = face->glyph->metrics.horiBearingY / uniEM * (Size / 10.0); | ||
613 | 606 | } | ||
614 | 607 | else { | ||
615 | 608 | sDebug(QString("internal error: missing glyph: %1 (char %2) error=%3").arg(c1).arg(ch).arg(error)); | ||
616 | 609 | w = Size / 10.0; | ||
617 | 610 | } | ||
618 | 611 | return w; | ||
619 | 612 | } | ||
620 | 613 | else | ||
621 | 614 | return static_cast<qreal>(Size / 10.0); | ||
622 | 615 | } | ||
623 | 616 | |||
624 | 617 | qreal RealFHeight(ScribusDoc *, ScFace* scFace, int Size) | ||
625 | 618 | { | ||
626 | 619 | FT_Face face = scFace->ftFace(); | ||
627 | 620 | qreal uniEM = static_cast<qreal>(face->units_per_EM); | ||
628 | 621 | return face->height / uniEM * (Size / 10.0); | ||
629 | 622 | } | ||
630 | 623 | */ | ||
631 | 624 | 0 | ||
632 | === removed file '.pc/0001-qreal-double-fixes.patch/scribus/pageitem.cpp' | |||
633 | --- .pc/0001-qreal-double-fixes.patch/scribus/pageitem.cpp 2011-09-11 22:10:03 +0000 | |||
634 | +++ .pc/0001-qreal-double-fixes.patch/scribus/pageitem.cpp 1970-01-01 00:00:00 +0000 | |||
635 | @@ -1,5999 +0,0 @@ | |||
636 | 1 | /* | ||
637 | 2 | For general Scribus (>=1.3.2) copyright and licensing information please refer | ||
638 | 3 | to the COPYING file provided with the program. Following this notice may exist | ||
639 | 4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 | ||
640 | 5 | for which a new license (GPL+exception) is in place. | ||
641 | 6 | */ | ||
642 | 7 | /*************************************************************************** | ||
643 | 8 | pageitem.cpp - description | ||
644 | 9 | ------------------- | ||
645 | 10 | begin : Sat Apr 7 2001 | ||
646 | 11 | copyright : (C) 2001 by Franz Schmid | ||
647 | 12 | email : Franz.Schmid@altmuehlnet.de | ||
648 | 13 | ***************************************************************************/ | ||
649 | 14 | |||
650 | 15 | /*************************************************************************** | ||
651 | 16 | * * | ||
652 | 17 | * This program is free software; you can redistribute it and/or modify * | ||
653 | 18 | * it under the terms of the GNU General Public License as published by * | ||
654 | 19 | * the Free Software Foundation; either version 2 of the License, or * | ||
655 | 20 | * (at your option) any later version. * | ||
656 | 21 | * * | ||
657 | 22 | ***************************************************************************/ | ||
658 | 23 | |||
659 | 24 | #include "pageitem.h" | ||
660 | 25 | #include <QPainter> | ||
661 | 26 | #include <QPen> | ||
662 | 27 | #include <QFont> | ||
663 | 28 | #include <QRegion> | ||
664 | 29 | #include <QPoint> | ||
665 | 30 | #include <QFileInfo> | ||
666 | 31 | #include <qdrawutil.h> | ||
667 | 32 | #include <QRegExp> | ||
668 | 33 | #include <QMessageBox> | ||
669 | 34 | #include <QPolygon> | ||
670 | 35 | #include <cassert> | ||
671 | 36 | #include <QDebug> | ||
672 | 37 | #include <iostream> | ||
673 | 38 | #include <sstream> | ||
674 | 39 | #include <string> | ||
675 | 40 | |||
676 | 41 | #include "canvas.h" | ||
677 | 42 | #include "cmsettings.h" | ||
678 | 43 | #include "colorblind.h" | ||
679 | 44 | #include "commonstrings.h" | ||
680 | 45 | #include "cpalette.h" | ||
681 | 46 | #include "guidemanager.h" | ||
682 | 47 | #include "page.h" | ||
683 | 48 | #include "pageitem_latexframe.h" | ||
684 | 49 | #include "pageitem_textframe.h" | ||
685 | 50 | #include "prefsmanager.h" | ||
686 | 51 | #include "propertiespalette.h" | ||
687 | 52 | #include "resourcecollection.h" | ||
688 | 53 | #include "scclocale.h" | ||
689 | 54 | #include "sccolorengine.h" | ||
690 | 55 | #include "scconfig.h" | ||
691 | 56 | #include "scpainter.h" | ||
692 | 57 | #include "scpaths.h" | ||
693 | 58 | #include "scpattern.h" | ||
694 | 59 | #include "scribus.h" | ||
695 | 60 | #include "scribusapp.h" | ||
696 | 61 | #include "scribuscore.h" | ||
697 | 62 | #include "scribusdoc.h" | ||
698 | 63 | #include "scribusstructs.h" | ||
699 | 64 | #include "scribuswin.h" | ||
700 | 65 | #include "sctextstream.h" | ||
701 | 66 | #include "serializer.h" | ||
702 | 67 | #include "selection.h" | ||
703 | 68 | #include "sclimits.h" | ||
704 | 69 | #include "text/nlsconfig.h" | ||
705 | 70 | #include "desaxe/saxXML.h" | ||
706 | 71 | #include "undomanager.h" | ||
707 | 72 | #include "undostate.h" | ||
708 | 73 | #include "util.h" | ||
709 | 74 | #include "util_formats.h" | ||
710 | 75 | #include "util_math.h" | ||
711 | 76 | #include "util_text.h" | ||
712 | 77 | #include "util_file.h" | ||
713 | 78 | #ifdef HAVE_CAIRO | ||
714 | 79 | #include <cairo.h> | ||
715 | 80 | #endif | ||
716 | 81 | |||
717 | 82 | using namespace std; | ||
718 | 83 | |||
719 | 84 | PageItem::PageItem(const PageItem & other) | ||
720 | 85 | : QObject(other.parent()), | ||
721 | 86 | UndoObject(other), SingleObservable<PageItem>(other.m_Doc->itemsChanged()), | ||
722 | 87 | |||
723 | 88 | // 200 attributes! That is madness, or to quote some famous people from Kriquet: | ||
724 | 89 | // "THAT ALL HAS TO GO!" | ||
725 | 90 | gXpos(other.gXpos), | ||
726 | 91 | gYpos(other.gYpos), | ||
727 | 92 | gWidth(other.gWidth), | ||
728 | 93 | gHeight(other.gHeight), | ||
729 | 94 | GrType(other.GrType), | ||
730 | 95 | GrStartX(other.GrStartX), | ||
731 | 96 | GrStartY(other.GrStartY), | ||
732 | 97 | GrEndX(other.GrEndX), | ||
733 | 98 | GrEndY(other.GrEndY), | ||
734 | 99 | Cols(other.Cols), | ||
735 | 100 | ColGap(other.ColGap), | ||
736 | 101 | PLineArt(other.PLineArt), | ||
737 | 102 | PLineEnd(other.PLineEnd), | ||
738 | 103 | PLineJoin(other.PLineJoin), | ||
739 | 104 | NamedLStyle(other.NamedLStyle), | ||
740 | 105 | Clip(other.Clip), | ||
741 | 106 | PoLine(other.PoLine), | ||
742 | 107 | ContourLine(other.ContourLine), | ||
743 | 108 | imageClip(other.imageClip), | ||
744 | 109 | Segments(other.Segments), | ||
745 | 110 | effectsInUse(other.effectsInUse), | ||
746 | 111 | PoShow(other.PoShow), | ||
747 | 112 | BaseOffs(other.BaseOffs), | ||
748 | 113 | textPathType(other.textPathType), | ||
749 | 114 | textPathFlipped(other.textPathFlipped), | ||
750 | 115 | ClipEdited(other.ClipEdited), | ||
751 | 116 | FrameType(other.FrameType), | ||
752 | 117 | ItemNr(other.ItemNr), | ||
753 | 118 | Frame(other.Frame), | ||
754 | 119 | OwnPage(other.OwnPage), | ||
755 | 120 | oldOwnPage(other.oldOwnPage), | ||
756 | 121 | pixm(other.pixm), | ||
757 | 122 | Pfile(other.Pfile), | ||
758 | 123 | Pfile2(other.Pfile2), | ||
759 | 124 | Pfile3(other.Pfile3), | ||
760 | 125 | IProfile(other.IProfile), | ||
761 | 126 | UseEmbedded(other.UseEmbedded), | ||
762 | 127 | EmProfile(other.EmProfile), | ||
763 | 128 | IRender(other.IRender), | ||
764 | 129 | |||
765 | 130 | PictureIsAvailable(other.PictureIsAvailable), | ||
766 | 131 | OrigW(other.OrigW), | ||
767 | 132 | OrigH(other.OrigH), | ||
768 | 133 | BBoxX(other.BBoxX), | ||
769 | 134 | BBoxH(other.BBoxH), | ||
770 | 135 | CurX(other.CurX), | ||
771 | 136 | CurY(other.CurY), | ||
772 | 137 | CPos(other.CPos), | ||
773 | 138 | itemText(other.itemText), | ||
774 | 139 | isBookmark(other.isBookmark), | ||
775 | 140 | HasSel(other.HasSel), | ||
776 | 141 | // Tinput(other.Tinput), | ||
777 | 142 | isAutoText(other.isAutoText), | ||
778 | 143 | BackBox(NULL), // otherwise other.BackBox->NextBox would be inconsistent | ||
779 | 144 | NextBox(NULL), // otherwise other.NextBox->BackBox would be inconsistent | ||
780 | 145 | firstChar(0), // since this box is unlinked now | ||
781 | 146 | MaxChars(0), // since the layout is invalid now | ||
782 | 147 | inPdfArticle(other.inPdfArticle), | ||
783 | 148 | isRaster(other.isRaster), | ||
784 | 149 | OldB(other.OldB), | ||
785 | 150 | OldH(other.OldH), | ||
786 | 151 | OldB2(other.OldB2), | ||
787 | 152 | OldH2(other.OldH2), | ||
788 | 153 | Sizing(other.Sizing), | ||
789 | 154 | toPixmap(other.toPixmap), | ||
790 | 155 | LayerNr(other.LayerNr), | ||
791 | 156 | ScaleType(other.ScaleType), | ||
792 | 157 | AspectRatio(other.AspectRatio), | ||
793 | 158 | Groups(other.Groups), | ||
794 | 159 | DashValues(other.DashValues), | ||
795 | 160 | DashOffset(other.DashOffset), | ||
796 | 161 | fill_gradient(other.fill_gradient), | ||
797 | 162 | fillRule(other.fillRule), | ||
798 | 163 | doOverprint(other.doOverprint), | ||
799 | 164 | LeftLink(other.LeftLink), | ||
800 | 165 | RightLink(other.RightLink), | ||
801 | 166 | TopLink(other.TopLink), | ||
802 | 167 | BottomLink(other.BottomLink), | ||
803 | 168 | LeftLinkID(other.LeftLinkID), | ||
804 | 169 | RightLinkID(other.RightLinkID), | ||
805 | 170 | TopLinkID(other.TopLinkID), | ||
806 | 171 | BottomLinkID(other.BottomLinkID), | ||
807 | 172 | LeftLine(other.LeftLine), | ||
808 | 173 | RightLine(other.RightLine), | ||
809 | 174 | TopLine(other.TopLine), | ||
810 | 175 | BottomLine(other.BottomLine), | ||
811 | 176 | isTableItem(other.isTableItem), | ||
812 | 177 | isSingleSel(other.isSingleSel), | ||
813 | 178 | isGroupControl(other.isGroupControl), | ||
814 | 179 | groupsLastItem(other.groupsLastItem), | ||
815 | 180 | BoundingX(other.BoundingX), | ||
816 | 181 | BoundingY(other.BoundingY), | ||
817 | 182 | BoundingW(other.BoundingW), | ||
818 | 183 | BoundingH(other.BoundingH), | ||
819 | 184 | ChangedMasterItem(other.ChangedMasterItem), | ||
820 | 185 | OnMasterPage(other.OnMasterPage), | ||
821 | 186 | isEmbedded(other.isEmbedded), | ||
822 | 187 | |||
823 | 188 | // protected | ||
824 | 189 | undoManager(other.undoManager), | ||
825 | 190 | m_ItemType(other.m_ItemType), | ||
826 | 191 | AnName(other.AnName), | ||
827 | 192 | patternVal(other.patternVal), | ||
828 | 193 | patternScaleX(other.patternScaleX), | ||
829 | 194 | patternScaleY(other.patternScaleY), | ||
830 | 195 | patternOffsetX(other.patternOffsetX), | ||
831 | 196 | patternOffsetY(other.patternOffsetY), | ||
832 | 197 | patternRotation(other.patternRotation), | ||
833 | 198 | fillColorVal(other.fillColorVal), | ||
834 | 199 | lineColorVal(other.lineColorVal), | ||
835 | 200 | lineShadeVal(other.lineShadeVal), | ||
836 | 201 | fillShadeVal(other.fillShadeVal), | ||
837 | 202 | fillTransparencyVal(other.fillTransparencyVal), | ||
838 | 203 | lineTransparencyVal(other.lineTransparencyVal), | ||
839 | 204 | fillBlendmodeVal(other.fillBlendmodeVal), | ||
840 | 205 | lineBlendmodeVal(other.lineBlendmodeVal), | ||
841 | 206 | m_ImageIsFlippedH(other.m_ImageIsFlippedH), | ||
842 | 207 | m_ImageIsFlippedV(other.m_ImageIsFlippedV), | ||
843 | 208 | m_Locked(other.m_Locked), | ||
844 | 209 | m_SizeLocked(other.m_SizeLocked), | ||
845 | 210 | textFlowModeVal(other.textFlowModeVal), | ||
846 | 211 | pageItemAttributes(other.pageItemAttributes), | ||
847 | 212 | m_PrintEnabled(other.m_PrintEnabled), | ||
848 | 213 | tagged(other.tagged), | ||
849 | 214 | fillQColor(other.fillQColor), | ||
850 | 215 | strokeQColor(other.strokeQColor), | ||
851 | 216 | Xpos(other.Xpos), | ||
852 | 217 | Ypos(other.Ypos), | ||
853 | 218 | Width(other.Width), | ||
854 | 219 | Height(other.Height), | ||
855 | 220 | Rot(other.Rot), | ||
856 | 221 | Select(other.Select), | ||
857 | 222 | LocalScX(other.LocalScX), | ||
858 | 223 | LocalScY(other.LocalScY), | ||
859 | 224 | LocalX(other.LocalX), | ||
860 | 225 | LocalY(other.LocalY), | ||
861 | 226 | Reverse(other.Reverse), | ||
862 | 227 | m_startArrowIndex(other.m_startArrowIndex), | ||
863 | 228 | m_endArrowIndex(other.m_endArrowIndex), | ||
864 | 229 | Extra(other.Extra), | ||
865 | 230 | TExtra(other.TExtra), | ||
866 | 231 | BExtra(other.BExtra), | ||
867 | 232 | RExtra(other.RExtra), | ||
868 | 233 | firstLineOffsetP(other.firstLineOffsetP), | ||
869 | 234 | RadRect(other.RadRect), | ||
870 | 235 | oldXpos(other.oldXpos), | ||
871 | 236 | oldYpos(other.oldYpos), | ||
872 | 237 | oldWidth(other.oldWidth), | ||
873 | 238 | oldHeight(other.oldHeight), | ||
874 | 239 | oldRot(other.oldRot), | ||
875 | 240 | oldLocalScX(other.oldLocalScX), | ||
876 | 241 | oldLocalScY(other.oldLocalScY), | ||
877 | 242 | oldLocalX(other.oldLocalX), | ||
878 | 243 | oldLocalY(other.oldLocalY), | ||
879 | 244 | m_Doc(other.m_Doc), | ||
880 | 245 | m_isAnnotation(other.m_isAnnotation), | ||
881 | 246 | m_annotation(other.m_annotation), | ||
882 | 247 | PicArt(other.PicArt), | ||
883 | 248 | m_lineWidth(other.m_lineWidth), | ||
884 | 249 | Oldm_lineWidth(other.Oldm_lineWidth) | ||
885 | 250 | { | ||
886 | 251 | QString tmp; | ||
887 | 252 | m_Doc->TotalItems++; | ||
888 | 253 | AnName += tmp.setNum(m_Doc->TotalItems); | ||
889 | 254 | uniqueNr = m_Doc->TotalItems; | ||
890 | 255 | invalid = true; | ||
891 | 256 | if (other.isInlineImage) | ||
892 | 257 | { | ||
893 | 258 | QFileInfo inlFi(Pfile); | ||
894 | 259 | QString ext = inlFi.suffix(); | ||
895 | 260 | tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_XXXXXX." + ext); | ||
896 | 261 | tempImageFile->open(); | ||
897 | 262 | QString fileName = getLongPathName(tempImageFile->fileName()); | ||
898 | 263 | tempImageFile->close(); | ||
899 | 264 | copyFile(Pfile, fileName); | ||
900 | 265 | Pfile = fileName; | ||
901 | 266 | isInlineImage = true; | ||
902 | 267 | } | ||
903 | 268 | else | ||
904 | 269 | { | ||
905 | 270 | tempImageFile = NULL; | ||
906 | 271 | isInlineImage = false; | ||
907 | 272 | } | ||
908 | 273 | } | ||
909 | 274 | |||
910 | 275 | |||
911 | 276 | PageItem::PageItem(ScribusDoc *pa, ItemType newType, double x, double y, double w, double h, double w2, QString fill, QString outline) | ||
912 | 277 | // Initialize superclass(es) | ||
913 | 278 | : QObject(pa), SingleObservable<PageItem>(pa->itemsChanged()), | ||
914 | 279 | // Initialize member variables | ||
915 | 280 | itemText(pa), | ||
916 | 281 | undoManager(UndoManager::instance()), | ||
917 | 282 | lineShadeVal(100), | ||
918 | 283 | fillShadeVal(100), | ||
919 | 284 | fillTransparencyVal(0.0), | ||
920 | 285 | lineTransparencyVal(0.0), | ||
921 | 286 | fillBlendmodeVal(0), | ||
922 | 287 | lineBlendmodeVal(0), | ||
923 | 288 | m_ImageIsFlippedH(0), | ||
924 | 289 | m_ImageIsFlippedV(0), | ||
925 | 290 | m_Locked(false), | ||
926 | 291 | m_SizeLocked(false), | ||
927 | 292 | textFlowModeVal(TextFlowDisabled) | ||
928 | 293 | { | ||
929 | 294 | m_Doc = pa; | ||
930 | 295 | QString tmp; | ||
931 | 296 | BackBox = 0; | ||
932 | 297 | NextBox = 0; | ||
933 | 298 | oldXpos = Xpos = x; | ||
934 | 299 | oldYpos = Ypos = y; | ||
935 | 300 | //CB Surely we can remove some of these? | ||
936 | 301 | OldB2 = OldB = oldWidth = Width = w; | ||
937 | 302 | OldH2 = OldH = oldHeight = Height = h; | ||
938 | 303 | BoundingX = x; | ||
939 | 304 | BoundingY = y; | ||
940 | 305 | BoundingW = w; | ||
941 | 306 | BoundingH = h; | ||
942 | 307 | m_ItemType = newType; | ||
943 | 308 | oldRot = Rot = 0; | ||
944 | 309 | fillColorVal = fill; | ||
945 | 310 | lineColorVal = m_ItemType == PageItem::TextFrame ? fill : outline; | ||
946 | 311 | gXpos = gYpos = 0; | ||
947 | 312 | gWidth = gHeight = 0; | ||
948 | 313 | GrType = 0; | ||
949 | 314 | GrStartX = 0; | ||
950 | 315 | GrStartY = 0; | ||
951 | 316 | GrEndX = w; | ||
952 | 317 | GrEndY = 0; | ||
953 | 318 | patternVal = ""; | ||
954 | 319 | patternScaleX = 100; | ||
955 | 320 | patternScaleY = 100; | ||
956 | 321 | patternOffsetX = 0; | ||
957 | 322 | patternOffsetY = 0; | ||
958 | 323 | patternRotation = 0; | ||
959 | 324 | m_lineWidth = w2; | ||
960 | 325 | Oldm_lineWidth = w2; | ||
961 | 326 | PLineArt = Qt::PenStyle(m_Doc->toolSettings.dLineArt); | ||
962 | 327 | PLineEnd = Qt::FlatCap; | ||
963 | 328 | PLineJoin = Qt::MiterJoin; | ||
964 | 329 | Select = false; | ||
965 | 330 | ClipEdited = false; | ||
966 | 331 | FrameType = 0; | ||
967 | 332 | CurX = 0; | ||
968 | 333 | CurY = 0; | ||
969 | 334 | CPos = 0; | ||
970 | 335 | oldCPos = 0; | ||
971 | 336 | Extra = 0; | ||
972 | 337 | TExtra = 0; | ||
973 | 338 | BExtra = 0; | ||
974 | 339 | RExtra = 0; | ||
975 | 340 | firstChar = 0; | ||
976 | 341 | MaxChars = 0; | ||
977 | 342 | Pfile = ""; | ||
978 | 343 | pixm = ScImage(); | ||
979 | 344 | pixm.imgInfo.lowResType = m_Doc->toolSettings.lowResType; | ||
980 | 345 | Pfile2 = ""; | ||
981 | 346 | Pfile3 = ""; | ||
982 | 347 | oldLocalScX = LocalScX = 1; | ||
983 | 348 | oldLocalScY = LocalScY = 1; | ||
984 | 349 | OrigW = 0; | ||
985 | 350 | OrigH = 0; | ||
986 | 351 | oldLocalX = LocalX = 0; | ||
987 | 352 | oldLocalY = LocalY = 0; | ||
988 | 353 | BBoxX = 0; | ||
989 | 354 | BBoxH = 0; | ||
990 | 355 | RadRect = 0; | ||
991 | 356 | if ((m_ItemType == TextFrame) || (m_ItemType == ImageFrame) || (m_ItemType == PathText)) | ||
992 | 357 | // TODO: Frame should become a read-only calculated property | ||
993 | 358 | Frame = true; | ||
994 | 359 | else | ||
995 | 360 | Frame = false; | ||
996 | 361 | switch (m_ItemType) | ||
997 | 362 | { | ||
998 | 363 | case Polygon: | ||
999 | 364 | Clip.setPoints(4, static_cast<int>(w/2), 0, static_cast<int>(w), static_cast<int>(h/2), | ||
1000 | 365 | static_cast<int>(w/2), static_cast<int>(h), 0,static_cast<int>(h/2)); | ||
1001 | 366 | break; | ||
1002 | 367 | default: | ||
1003 | 368 | Clip.setPoints(4, 0,0, static_cast<int>(w),0, static_cast<int>(w), static_cast<int>(h), 0,static_cast<int>(h)); | ||
1004 | 369 | break; | ||
1005 | 370 | } | ||
1006 | 371 | PoLine.resize(0); | ||
1007 | 372 | ContourLine.resize(0); | ||
1008 | 373 | imageClip.resize(0); | ||
1009 | 374 | Segments.clear(); | ||
1010 | 375 | PoShow = false; | ||
1011 | 376 | BaseOffs = 0; | ||
1012 | 377 | textPathType = 0; | ||
1013 | 378 | textPathFlipped = false; | ||
1014 | 379 | OwnPage = m_Doc->currentPage()->pageNr(); | ||
1015 | 380 | oldOwnPage = OwnPage; | ||
1016 | 381 | savedOwnPage = OwnPage; | ||
1017 | 382 | PicArt = true; | ||
1018 | 383 | PictureIsAvailable = false; | ||
1019 | 384 | m_PrintEnabled = true; | ||
1020 | 385 | isBookmark = false; | ||
1021 | 386 | m_isAnnotation = false; | ||
1022 | 387 | |||
1023 | 388 | switch (m_ItemType) | ||
1024 | 389 | { | ||
1025 | 390 | case ImageFrame: | ||
1026 | 391 | case LatexFrame: | ||
1027 | 392 | //We can't determine if this is a latex frame here | ||
1028 | 393 | // because c++'s typeinfos are still saying it's | ||
1029 | 394 | // a plain pageitem | ||
1030 | 395 | // This is fixed in the PageItem_LatexFrame constructor | ||
1031 | 396 | AnName = tr("Image"); | ||
1032 | 397 | setUPixmap(Um::IImageFrame); | ||
1033 | 398 | break; | ||
1034 | 399 | case TextFrame: | ||
1035 | 400 | AnName = tr("Text"); | ||
1036 | 401 | setUPixmap(Um::ITextFrame); | ||
1037 | 402 | break; | ||
1038 | 403 | case Line: | ||
1039 | 404 | AnName = tr("Line"); | ||
1040 | 405 | setUPixmap(Um::ILine); | ||
1041 | 406 | break; | ||
1042 | 407 | case Polygon: | ||
1043 | 408 | AnName = tr("Polygon"); | ||
1044 | 409 | setUPixmap(Um::IPolygon); | ||
1045 | 410 | break; | ||
1046 | 411 | case PolyLine: | ||
1047 | 412 | AnName = tr("Polyline"); | ||
1048 | 413 | setUPixmap(Um::IPolyline); | ||
1049 | 414 | break; | ||
1050 | 415 | case PathText: | ||
1051 | 416 | AnName = tr("PathText"); | ||
1052 | 417 | setUPixmap(Um::IPathText); | ||
1053 | 418 | break; | ||
1054 | 419 | default: | ||
1055 | 420 | AnName = "Item"; | ||
1056 | 421 | break; | ||
1057 | 422 | } | ||
1058 | 423 | m_Doc->TotalItems++; | ||
1059 | 424 | AnName += tmp.setNum(m_Doc->TotalItems); // +" "+QDateTime::currentDateTime().toString(); | ||
1060 | 425 | uniqueNr = m_Doc->TotalItems; | ||
1061 | 426 | AutoName = true; | ||
1062 | 427 | setUName(AnName); | ||
1063 | 428 | m_annotation.setBorderColor(outline); | ||
1064 | 429 | HasSel = false; | ||
1065 | 430 | // Tinput = false; | ||
1066 | 431 | isAutoText = false; | ||
1067 | 432 | inPdfArticle = false; | ||
1068 | 433 | isRaster = false; | ||
1069 | 434 | Sizing = false; | ||
1070 | 435 | toPixmap = false; | ||
1071 | 436 | UseEmbedded = true; | ||
1072 | 437 | IRender = Intent_Relative_Colorimetric; | ||
1073 | 438 | EmProfile = ""; | ||
1074 | 439 | Groups.clear(); | ||
1075 | 440 | LayerNr = m_Doc->activeLayer(); | ||
1076 | 441 | ScaleType = true; | ||
1077 | 442 | AspectRatio = true; | ||
1078 | 443 | Reverse = false; | ||
1079 | 444 | NamedLStyle = ""; | ||
1080 | 445 | DashValues.clear(); | ||
1081 | 446 | DashOffset = 0; | ||
1082 | 447 | fillRule = true; | ||
1083 | 448 | doOverprint = false; | ||
1084 | 449 | fill_gradient = VGradient(VGradient::linear); | ||
1085 | 450 | fill_gradient.clearStops(); | ||
1086 | 451 | if (fillColorVal != CommonStrings::None) | ||
1087 | 452 | { | ||
1088 | 453 | const ScColor& col = m_Doc->PageColors[fillColorVal]; | ||
1089 | 454 | QColor qcol = ScColorEngine::getRGBColor(col, m_Doc); | ||
1090 | 455 | fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, fillColorVal, 100); | ||
1091 | 456 | fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, fillColorVal, 100); | ||
1092 | 457 | } | ||
1093 | 458 | else | ||
1094 | 459 | { | ||
1095 | 460 | if (m_Doc->toolSettings.dBrush != CommonStrings::None) | ||
1096 | 461 | { | ||
1097 | 462 | const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dBrush]; | ||
1098 | 463 | QColor qcol = ScColorEngine::getRGBColor(col, m_Doc); | ||
1099 | 464 | fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100); | ||
1100 | 465 | fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100); | ||
1101 | 466 | } | ||
1102 | 467 | else | ||
1103 | 468 | { | ||
1104 | 469 | if (lineColorVal != CommonStrings::None) | ||
1105 | 470 | { | ||
1106 | 471 | const ScColor& col = m_Doc->PageColors[lineColorVal]; | ||
1107 | 472 | QColor qcol = ScColorEngine::getRGBColor(col, m_Doc); | ||
1108 | 473 | fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, lineColorVal, 100); | ||
1109 | 474 | fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, lineColorVal, 100); | ||
1110 | 475 | } | ||
1111 | 476 | else | ||
1112 | 477 | { | ||
1113 | 478 | if (m_Doc->toolSettings.dPen != CommonStrings::None) | ||
1114 | 479 | { | ||
1115 | 480 | const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dPen]; | ||
1116 | 481 | QColor qcol = ScColorEngine::getRGBColor(col, m_Doc); | ||
1117 | 482 | fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100); | ||
1118 | 483 | fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100); | ||
1119 | 484 | } | ||
1120 | 485 | else if (m_Doc->PageColors.contains("Black")) | ||
1121 | 486 | { | ||
1122 | 487 | const ScColor& col = m_Doc->PageColors["Black"]; | ||
1123 | 488 | QColor qcol = ScColorEngine::getRGBColor(col, m_Doc); | ||
1124 | 489 | fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, "Black", 100); | ||
1125 | 490 | fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, "Black", 100); | ||
1126 | 491 | } | ||
1127 | 492 | } | ||
1128 | 493 | } | ||
1129 | 494 | } | ||
1130 | 495 | firstLineOffsetP = FLOPRealGlyphHeight; | ||
1131 | 496 | Cols = m_Doc->toolSettings.dCols; | ||
1132 | 497 | ColGap = m_Doc->toolSettings.dGap; | ||
1133 | 498 | LeftLink = 0; | ||
1134 | 499 | RightLink = 0; | ||
1135 | 500 | TopLink = 0; | ||
1136 | 501 | BottomLink = 0; | ||
1137 | 502 | LeftLinkID = 0; | ||
1138 | 503 | RightLinkID = 0; | ||
1139 | 504 | TopLinkID = 0; | ||
1140 | 505 | BottomLinkID = 0; | ||
1141 | 506 | LeftLine = 0; | ||
1142 | 507 | RightLine = false; | ||
1143 | 508 | TopLine = false; | ||
1144 | 509 | BottomLine = false; | ||
1145 | 510 | isTableItem = false; | ||
1146 | 511 | isSingleSel = false; | ||
1147 | 512 | Dirty = false; | ||
1148 | 513 | invalid = true; | ||
1149 | 514 | isGroupControl = false; | ||
1150 | 515 | groupsLastItem = 0; | ||
1151 | 516 | ChangedMasterItem = false; | ||
1152 | 517 | isEmbedded = false; | ||
1153 | 518 | OnMasterPage = m_Doc->currentPage()->pageName(); | ||
1154 | 519 | m_startArrowIndex = m_Doc->toolSettings.dStartArrow; | ||
1155 | 520 | m_endArrowIndex = m_Doc->toolSettings.dEndArrow; | ||
1156 | 521 | effectsInUse.clear(); | ||
1157 | 522 | //Page Item Attributes | ||
1158 | 523 | pageItemAttributes.clear(); | ||
1159 | 524 | for(ObjAttrVector::Iterator objAttrIt = m_Doc->docItemAttributes.begin() ; objAttrIt != m_Doc->docItemAttributes.end(); ++objAttrIt ) | ||
1160 | 525 | { | ||
1161 | 526 | if (((*objAttrIt).autoaddto=="textframes" && m_ItemType==TextFrame) || | ||
1162 | 527 | ((*objAttrIt).autoaddto=="imageframes" && m_ItemType==ImageFrame) | ||
1163 | 528 | ) | ||
1164 | 529 | pageItemAttributes.append(*objAttrIt); | ||
1165 | 530 | } | ||
1166 | 531 | tempImageFile = NULL; | ||
1167 | 532 | isInlineImage = false; | ||
1168 | 533 | } | ||
1169 | 534 | |||
1170 | 535 | void PageItem::setXPos(const double newXPos, bool drawingOnly) | ||
1171 | 536 | { | ||
1172 | 537 | Xpos = newXPos; | ||
1173 | 538 | if (drawingOnly || m_Doc->isLoading()) | ||
1174 | 539 | return; | ||
1175 | 540 | checkChanges(); | ||
1176 | 541 | emit position(Xpos, Ypos); | ||
1177 | 542 | } | ||
1178 | 543 | |||
1179 | 544 | void PageItem::setYPos(const double newYPos, bool drawingOnly) | ||
1180 | 545 | { | ||
1181 | 546 | Ypos = newYPos; | ||
1182 | 547 | if (drawingOnly || m_Doc->isLoading()) | ||
1183 | 548 | return; | ||
1184 | 549 | checkChanges(); | ||
1185 | 550 | emit position(Xpos, Ypos); | ||
1186 | 551 | } | ||
1187 | 552 | |||
1188 | 553 | void PageItem::setXYPos(const double newXPos, const double newYPos, bool drawingOnly) | ||
1189 | 554 | { | ||
1190 | 555 | Xpos = newXPos; | ||
1191 | 556 | Ypos = newYPos; | ||
1192 | 557 | if (drawingOnly || m_Doc->isLoading()) | ||
1193 | 558 | return; | ||
1194 | 559 | checkChanges(); | ||
1195 | 560 | emit position(Xpos, Ypos); | ||
1196 | 561 | } | ||
1197 | 562 | |||
1198 | 563 | void PageItem::moveBy(const double dX, const double dY, bool drawingOnly) | ||
1199 | 564 | { | ||
1200 | 565 | if (dX==0.0 && dY==0.0) | ||
1201 | 566 | return; | ||
1202 | 567 | invalid = true; | ||
1203 | 568 | if (dX!=0.0) | ||
1204 | 569 | Xpos+=dX; | ||
1205 | 570 | if (dY!=0.0) | ||
1206 | 571 | Ypos+=dY; | ||
1207 | 572 | if (drawingOnly || m_Doc->isLoading()) | ||
1208 | 573 | return; | ||
1209 | 574 | checkChanges(); | ||
1210 | 575 | emit position(Xpos, Ypos); | ||
1211 | 576 | } | ||
1212 | 577 | |||
1213 | 578 | void PageItem::setWidth(const double newWidth) | ||
1214 | 579 | { | ||
1215 | 580 | Width = newWidth; | ||
1216 | 581 | updateConstants(); | ||
1217 | 582 | checkChanges(); | ||
1218 | 583 | emit widthAndHeight(Width, Height); | ||
1219 | 584 | } | ||
1220 | 585 | |||
1221 | 586 | void PageItem::setHeight(const double newHeight) | ||
1222 | 587 | { | ||
1223 | 588 | Height = newHeight; | ||
1224 | 589 | updateConstants(); | ||
1225 | 590 | checkChanges(); | ||
1226 | 591 | emit widthAndHeight(Width, Height); | ||
1227 | 592 | } | ||
1228 | 593 | |||
1229 | 594 | void PageItem::setWidthHeight(const double newWidth, const double newHeight, bool drawingOnly) | ||
1230 | 595 | { | ||
1231 | 596 | Width = newWidth; | ||
1232 | 597 | Height = newHeight; | ||
1233 | 598 | updateConstants(); | ||
1234 | 599 | if (drawingOnly) | ||
1235 | 600 | return; | ||
1236 | 601 | checkChanges(); | ||
1237 | 602 | emit widthAndHeight(Width, Height); | ||
1238 | 603 | } | ||
1239 | 604 | |||
1240 | 605 | void PageItem::setWidthHeight(const double newWidth, const double newHeight) | ||
1241 | 606 | { | ||
1242 | 607 | Width = newWidth; | ||
1243 | 608 | Height = newHeight; | ||
1244 | 609 | updateConstants(); | ||
1245 | 610 | checkChanges(); | ||
1246 | 611 | emit widthAndHeight(Width, Height); | ||
1247 | 612 | } | ||
1248 | 613 | |||
1249 | 614 | void PageItem::resizeBy(const double dH, const double dW) | ||
1250 | 615 | { | ||
1251 | 616 | if (dH==0.0 && dW==0.0) | ||
1252 | 617 | return; | ||
1253 | 618 | if (dH!=0.0) | ||
1254 | 619 | Width+=dH; | ||
1255 | 620 | if (dW!=0.0) | ||
1256 | 621 | Height+=dW; | ||
1257 | 622 | updateConstants(); | ||
1258 | 623 | checkChanges(); | ||
1259 | 624 | emit widthAndHeight(Width, Height); | ||
1260 | 625 | } | ||
1261 | 626 | |||
1262 | 627 | void PageItem::setRotation(const double newRotation, bool drawingOnly) | ||
1263 | 628 | { | ||
1264 | 629 | Rot=newRotation; | ||
1265 | 630 | checkChanges(); | ||
1266 | 631 | if (drawingOnly || m_Doc->isLoading()) | ||
1267 | 632 | return; | ||
1268 | 633 | emit rotation(Rot); | ||
1269 | 634 | } | ||
1270 | 635 | |||
1271 | 636 | void PageItem::rotateBy(const double dR) | ||
1272 | 637 | { | ||
1273 | 638 | if (dR==0.0) | ||
1274 | 639 | return; | ||
1275 | 640 | Rot+=dR; | ||
1276 | 641 | checkChanges(); | ||
1277 | 642 | emit rotation(Rot); | ||
1278 | 643 | } | ||
1279 | 644 | |||
1280 | 645 | void PageItem::setSelected(const bool toSelect) | ||
1281 | 646 | { | ||
1282 | 647 | Select=toSelect; | ||
1283 | 648 | } | ||
1284 | 649 | |||
1285 | 650 | void PageItem::setImageXScale(const double newImageXScale) | ||
1286 | 651 | { | ||
1287 | 652 | LocalScX=newImageXScale; | ||
1288 | 653 | checkChanges(); | ||
1289 | 654 | emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY); | ||
1290 | 655 | } | ||
1291 | 656 | |||
1292 | 657 | void PageItem::setImageYScale(const double newImageYScale) | ||
1293 | 658 | { | ||
1294 | 659 | LocalScY=newImageYScale; | ||
1295 | 660 | checkChanges(); | ||
1296 | 661 | emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY); | ||
1297 | 662 | } | ||
1298 | 663 | |||
1299 | 664 | void PageItem::setImageXYScale(const double newImageXScale, const double newImageYScale) | ||
1300 | 665 | { | ||
1301 | 666 | LocalScX=newImageXScale; | ||
1302 | 667 | LocalScY=newImageYScale; | ||
1303 | 668 | checkChanges(); | ||
1304 | 669 | emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY); | ||
1305 | 670 | } | ||
1306 | 671 | |||
1307 | 672 | void PageItem::setImageXOffset(const double newImageXOffset) | ||
1308 | 673 | { | ||
1309 | 674 | LocalX=newImageXOffset; | ||
1310 | 675 | checkChanges(); | ||
1311 | 676 | emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY); | ||
1312 | 677 | } | ||
1313 | 678 | |||
1314 | 679 | void PageItem::setImageYOffset(const double newImageYOffset) | ||
1315 | 680 | { | ||
1316 | 681 | LocalY=newImageYOffset; | ||
1317 | 682 | checkChanges(); | ||
1318 | 683 | emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY); | ||
1319 | 684 | } | ||
1320 | 685 | |||
1321 | 686 | void PageItem::setImageXYOffset(const double newImageXOffset, const double newImageYOffset) | ||
1322 | 687 | { | ||
1323 | 688 | LocalX=newImageXOffset; | ||
1324 | 689 | LocalY=newImageYOffset; | ||
1325 | 690 | checkChanges(); | ||
1326 | 691 | emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY); | ||
1327 | 692 | } | ||
1328 | 693 | |||
1329 | 694 | void PageItem::moveImageXYOffsetBy(const double dX, const double dY) | ||
1330 | 695 | { | ||
1331 | 696 | if (dX==0.0 && dY==0.0) | ||
1332 | 697 | return; | ||
1333 | 698 | if (dX!=0.0) | ||
1334 | 699 | LocalX+=dX; | ||
1335 | 700 | if (dY!=0.0) | ||
1336 | 701 | LocalY+=dY; | ||
1337 | 702 | checkChanges(); | ||
1338 | 703 | emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY); | ||
1339 | 704 | } | ||
1340 | 705 | |||
1341 | 706 | void PageItem::setReversed(bool newReversed) | ||
1342 | 707 | { | ||
1343 | 708 | Reverse=newReversed; | ||
1344 | 709 | } | ||
1345 | 710 | |||
1346 | 711 | |||
1347 | 712 | /// returns true if text overflows | ||
1348 | 713 | bool PageItem::frameOverflows() const | ||
1349 | 714 | { | ||
1350 | 715 | #ifndef NLS_PROTO | ||
1351 | 716 | // Fix #6991 : "Text overflow" warning when there is a text underflow in fact | ||
1352 | 717 | /*return NextBox == NULL && itemText.length() > static_cast<int>(MaxChars);*/ | ||
1353 | 718 | return ( NextBox == NULL ) | ||
1354 | 719 | && ( static_cast<int> ( firstChar ) < itemText.length() ) | ||
1355 | 720 | // Fix #7766 : scribus.textOverflows() returns 0 if there is no place for the overflow mark | ||
1356 | 721 | /*&& ( firstChar < MaxChars )*/ | ||
1357 | 722 | && ( firstChar <= MaxChars ) | ||
1358 | 723 | && ( itemText.length() > static_cast<int> ( MaxChars ) ); | ||
1359 | 724 | #else | ||
1360 | 725 | return false; // FIXME:NLS | ||
1361 | 726 | #endif | ||
1362 | 727 | } | ||
1363 | 728 | |||
1364 | 729 | int PageItem::firstInFrame() const | ||
1365 | 730 | { | ||
1366 | 731 | return firstChar; | ||
1367 | 732 | } | ||
1368 | 733 | int PageItem::lastInFrame() const | ||
1369 | 734 | { | ||
1370 | 735 | #ifndef NLS_PROTO | ||
1371 | 736 | return qMin(signed(MaxChars), itemText.length()) - 1; | ||
1372 | 737 | #else | ||
1373 | 738 | return itemText.length() - 1; | ||
1374 | 739 | #endif | ||
1375 | 740 | } | ||
1376 | 741 | |||
1377 | 742 | |||
1378 | 743 | void PageItem::link(PageItem* nxt) | ||
1379 | 744 | { | ||
1380 | 745 | assert( !nextInChain() ); | ||
1381 | 746 | assert( !nxt->prevInChain() ); | ||
1382 | 747 | for (PageItem* ff=nxt; ff; ff=ff->nextInChain()) | ||
1383 | 748 | { | ||
1384 | 749 | assert (ff != this); | ||
1385 | 750 | } | ||
1386 | 751 | // Append only if necessary to avoid the | ||
1387 | 752 | // charstyle: access at end of text warning | ||
1388 | 753 | if (nxt->itemText.length() > 0) | ||
1389 | 754 | itemText.append(nxt->itemText); | ||
1390 | 755 | NextBox = nxt; | ||
1391 | 756 | nxt->BackBox = this; | ||
1392 | 757 | // update AutoText | ||
1393 | 758 | if (isAutoText) | ||
1394 | 759 | { | ||
1395 | 760 | PageItem* after = nxt; | ||
1396 | 761 | while (after) | ||
1397 | 762 | { | ||
1398 | 763 | after->isAutoText = true; | ||
1399 | 764 | m_Doc->LastAuto = after; | ||
1400 | 765 | after = after->NextBox; | ||
1401 | 766 | } | ||
1402 | 767 | } | ||
1403 | 768 | else if (nxt->isAutoText) | ||
1404 | 769 | { | ||
1405 | 770 | PageItem* before = this; | ||
1406 | 771 | while (before) | ||
1407 | 772 | { | ||
1408 | 773 | before->isAutoText = true; | ||
1409 | 774 | m_Doc->FirstAuto = before; | ||
1410 | 775 | before = before->BackBox; | ||
1411 | 776 | } | ||
1412 | 777 | } | ||
1413 | 778 | invalid = true; | ||
1414 | 779 | while (nxt) | ||
1415 | 780 | { | ||
1416 | 781 | nxt->itemText = itemText; | ||
1417 | 782 | nxt->invalid = true; | ||
1418 | 783 | nxt->firstChar = 0; | ||
1419 | 784 | nxt = nxt->NextBox; | ||
1420 | 785 | } | ||
1421 | 786 | if (UndoManager::undoEnabled()) | ||
1422 | 787 | { | ||
1423 | 788 | ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >(UndoManager::LinkTextFrame); | ||
1424 | 789 | is->set("LINK_TEXT_FRAME", "linkTextFrame"); | ||
1425 | 790 | is->setItem(std::pair<PageItem*, PageItem*>(this, NextBox)); | ||
1426 | 791 | undoManager->action(this, is); | ||
1427 | 792 | } | ||
1428 | 793 | } | ||
1429 | 794 | |||
1430 | 795 | void PageItem::unlink() | ||
1431 | 796 | { | ||
1432 | 797 | if( NextBox ) | ||
1433 | 798 | { | ||
1434 | 799 | PageItem *undoNextBox=NextBox; | ||
1435 | 800 | // make sure lastInFrame is valid | ||
1436 | 801 | layout(); | ||
1437 | 802 | /* | ||
1438 | 803 | //<< CB #6332: Stop the StoryText cut and break and act like other publishing apps | ||
1439 | 804 | // move following text to new StoryText | ||
1440 | 805 | itemText.select(lastInFrame()+1, itemText.length()-lastInFrame()-1); | ||
1441 | 806 | */ | ||
1442 | 807 | StoryText follow(m_Doc); | ||
1443 | 808 | /* | ||
1444 | 809 | follow.setDefaultStyle(itemText.defaultStyle()); | ||
1445 | 810 | follow.insert(0, itemText, true); | ||
1446 | 811 | // remove following text from this chain | ||
1447 | 812 | itemText.removeSelection(); | ||
1448 | 813 | //>> | ||
1449 | 814 | */ | ||
1450 | 815 | // update auto pointers | ||
1451 | 816 | if (isAutoText) | ||
1452 | 817 | { | ||
1453 | 818 | PageItem* before = this; | ||
1454 | 819 | while (before) | ||
1455 | 820 | { | ||
1456 | 821 | before->isAutoText = false; | ||
1457 | 822 | before = before->BackBox; | ||
1458 | 823 | } | ||
1459 | 824 | m_Doc->FirstAuto = NextBox; | ||
1460 | 825 | } | ||
1461 | 826 | // link following frames to new text | ||
1462 | 827 | NextBox->firstChar = 0; | ||
1463 | 828 | NextBox->BackBox = NULL; | ||
1464 | 829 | while (NextBox) { | ||
1465 | 830 | NextBox->itemText = follow; | ||
1466 | 831 | NextBox->invalid = true; | ||
1467 | 832 | NextBox->firstChar = 0; | ||
1468 | 833 | NextBox = NextBox->NextBox; | ||
1469 | 834 | } | ||
1470 | 835 | // NextBox == NULL now | ||
1471 | 836 | NextBox = NULL; | ||
1472 | 837 | if (UndoManager::undoEnabled()) | ||
1473 | 838 | { | ||
1474 | 839 | ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >(UndoManager::UnlinkTextFrame); | ||
1475 | 840 | is->set("UNLINK_TEXT_FRAME", "unlinkTextFrame"); | ||
1476 | 841 | is->setItem(std::pair<PageItem*, PageItem*>(this, undoNextBox)); | ||
1477 | 842 | undoManager->action(this, is); | ||
1478 | 843 | } | ||
1479 | 844 | } | ||
1480 | 845 | } | ||
1481 | 846 | |||
1482 | 847 | |||
1483 | 848 | void PageItem::dropLinks() | ||
1484 | 849 | { | ||
1485 | 850 | // update auto pointers | ||
1486 | 851 | if (isAutoText && NextBox == 0) | ||
1487 | 852 | { | ||
1488 | 853 | m_Doc->LastAuto = BackBox; | ||
1489 | 854 | } | ||
1490 | 855 | if (isAutoText && BackBox == 0) | ||
1491 | 856 | { | ||
1492 | 857 | m_Doc->FirstAuto = NextBox; | ||
1493 | 858 | } | ||
1494 | 859 | isAutoText = false; | ||
1495 | 860 | |||
1496 | 861 | // leave text in remaining chain | ||
1497 | 862 | PageItem* before = BackBox; | ||
1498 | 863 | PageItem* after = NextBox; | ||
1499 | 864 | if (after != 0 || before != 0) | ||
1500 | 865 | { | ||
1501 | 866 | itemText = StoryText(m_Doc); | ||
1502 | 867 | if (before) | ||
1503 | 868 | before->NextBox = after; | ||
1504 | 869 | if (after) | ||
1505 | 870 | { | ||
1506 | 871 | after->BackBox = before; | ||
1507 | 872 | while (after) | ||
1508 | 873 | { | ||
1509 | 874 | after->invalid = true; | ||
1510 | 875 | after->firstChar = 0; | ||
1511 | 876 | after = after->NextBox; | ||
1512 | 877 | } | ||
1513 | 878 | } | ||
1514 | 879 | // JG we should set BackBox and NextBox to NULL at a point | ||
1515 | 880 | BackBox = NextBox = NULL; | ||
1516 | 881 | } | ||
1517 | 882 | } | ||
1518 | 883 | |||
1519 | 884 | /// tests if a character is displayed by this frame | ||
1520 | 885 | bool PageItem::frameDisplays(int textpos) const | ||
1521 | 886 | { | ||
1522 | 887 | #ifndef NLS_PROTO | ||
1523 | 888 | return 0 <= textpos && textpos < signed(MaxChars) && textpos < itemText.length(); | ||
1524 | 889 | #else | ||
1525 | 890 | return true; // FIXME:NLS | ||
1526 | 891 | #endif | ||
1527 | 892 | } | ||
1528 | 893 | |||
1529 | 894 | |||
1530 | 895 | /// returns the style at the current charpos | ||
1531 | 896 | const ParagraphStyle& PageItem::currentStyle() const | ||
1532 | 897 | { | ||
1533 | 898 | if (frameDisplays(CPos)) | ||
1534 | 899 | return itemText.paragraphStyle(CPos); | ||
1535 | 900 | else | ||
1536 | 901 | return itemText.defaultStyle(); | ||
1537 | 902 | } | ||
1538 | 903 | |||
1539 | 904 | /// returns the style at the current charpos for changing | ||
1540 | 905 | ParagraphStyle& PageItem::changeCurrentStyle() | ||
1541 | 906 | { | ||
1542 | 907 | if (frameDisplays(CPos)) | ||
1543 | 908 | return const_cast<ParagraphStyle&>(itemText.paragraphStyle(CPos)); | ||
1544 | 909 | else | ||
1545 | 910 | return const_cast<ParagraphStyle&>(itemText.defaultStyle()); | ||
1546 | 911 | } | ||
1547 | 912 | |||
1548 | 913 | /// returns the style at the current charpos | ||
1549 | 914 | const CharStyle& PageItem::currentCharStyle() const | ||
1550 | 915 | { | ||
1551 | 916 | if (frameDisplays(CPos)) | ||
1552 | 917 | return itemText.charStyle(CPos); | ||
1553 | 918 | else | ||
1554 | 919 | return itemText.defaultStyle().charStyle(); | ||
1555 | 920 | } | ||
1556 | 921 | |||
1557 | 922 | void PageItem::setTextToFrameDistLeft(double newLeft) | ||
1558 | 923 | { | ||
1559 | 924 | Extra=newLeft; | ||
1560 | 925 | emit textToFrameDistances(Extra, TExtra, BExtra, RExtra); | ||
1561 | 926 | } | ||
1562 | 927 | |||
1563 | 928 | void PageItem::setTextToFrameDistRight(double newRight) | ||
1564 | 929 | { | ||
1565 | 930 | RExtra=newRight; | ||
1566 | 931 | emit textToFrameDistances(Extra, TExtra, BExtra, RExtra); | ||
1567 | 932 | } | ||
1568 | 933 | |||
1569 | 934 | void PageItem::setTextToFrameDistTop(double newTop) | ||
1570 | 935 | { | ||
1571 | 936 | TExtra=newTop; | ||
1572 | 937 | emit textToFrameDistances(Extra, TExtra, BExtra, RExtra); | ||
1573 | 938 | } | ||
1574 | 939 | |||
1575 | 940 | void PageItem::setTextToFrameDistBottom(double newBottom) | ||
1576 | 941 | { | ||
1577 | 942 | BExtra=newBottom; | ||
1578 | 943 | emit textToFrameDistances(Extra, TExtra, BExtra, RExtra); | ||
1579 | 944 | } | ||
1580 | 945 | |||
1581 | 946 | void PageItem::setTextToFrameDist(double newLeft, double newRight, double newTop, double newBottom) | ||
1582 | 947 | { | ||
1583 | 948 | Extra=newLeft; | ||
1584 | 949 | RExtra=newRight; | ||
1585 | 950 | TExtra=newTop; | ||
1586 | 951 | BExtra=newBottom; | ||
1587 | 952 | emit textToFrameDistances(Extra, TExtra, BExtra, RExtra); | ||
1588 | 953 | } | ||
1589 | 954 | |||
1590 | 955 | double PageItem::gridOffset() const { return m_Doc->typographicSettings.offsetBaseGrid; } | ||
1591 | 956 | double PageItem::gridDistance() const { return m_Doc->typographicSettings.valueBaseGrid; } | ||
1592 | 957 | |||
1593 | 958 | void PageItem::setGridOffset(double) { } // FIXME | ||
1594 | 959 | void PageItem::setGridDistance(double) { } // FIXME | ||
1595 | 960 | void PageItem::setColumns(int n) | ||
1596 | 961 | { | ||
1597 | 962 | Cols = qMax(1, n); //FIXME: undo | ||
1598 | 963 | } | ||
1599 | 964 | void PageItem::setColumnGap(double gap) | ||
1600 | 965 | { | ||
1601 | 966 | ColGap = gap; //FIXME: undo | ||
1602 | 967 | } | ||
1603 | 968 | |||
1604 | 969 | void PageItem::setCornerRadius(double newRadius) | ||
1605 | 970 | { | ||
1606 | 971 | RadRect=newRadius; | ||
1607 | 972 | emit cornerRadius(RadRect); | ||
1608 | 973 | } | ||
1609 | 974 | |||
1610 | 975 | |||
1611 | 976 | |||
1612 | 977 | |||
1613 | 978 | |||
1614 | 979 | |||
1615 | 980 | |||
1616 | 981 | |||
1617 | 982 | |||
1618 | 983 | /** Paints the item. | ||
1619 | 984 | CHANGE: cullingArea is in doc coordinates! | ||
1620 | 985 | */ | ||
1621 | 986 | void PageItem::DrawObj(ScPainter *p, QRectF cullingArea) | ||
1622 | 987 | { | ||
1623 | 988 | // qDebug << "PageItem::DrawObj"; | ||
1624 | 989 | double sc; | ||
1625 | 990 | if (!m_Doc->DoDrawing) | ||
1626 | 991 | { | ||
1627 | 992 | // Tinput = false; | ||
1628 | 993 | return; | ||
1629 | 994 | } | ||
1630 | 995 | if (cullingArea.isNull()) | ||
1631 | 996 | { | ||
1632 | 997 | cullingArea = QRectF(QPointF(m_Doc->minCanvasCoordinate.x(), m_Doc->minCanvasCoordinate.y()), | ||
1633 | 998 | QPointF(m_Doc->maxCanvasCoordinate.x(), m_Doc->maxCanvasCoordinate.y())).toAlignedRect(); | ||
1634 | 999 | } | ||
1635 | 1000 | |||
1636 | 1001 | DrawObj_Pre(p, sc); | ||
1637 | 1002 | if (m_Doc->layerOutline(LayerNr)) | ||
1638 | 1003 | { | ||
1639 | 1004 | if ((itemType()==TextFrame || itemType()==ImageFrame || itemType()==PathText || itemType()==Line || itemType()==PolyLine) && (!isGroupControl)) | ||
1640 | 1005 | DrawObj_Item(p, cullingArea, sc); | ||
1641 | 1006 | } | ||
1642 | 1007 | else | ||
1643 | 1008 | { | ||
1644 | 1009 | if (!isGroupControl) | ||
1645 | 1010 | DrawObj_Item(p, cullingArea, sc); | ||
1646 | 1011 | } | ||
1647 | 1012 | DrawObj_Post(p); | ||
1648 | 1013 | } | ||
1649 | 1014 | |||
1650 | 1015 | void PageItem::DrawObj_Pre(ScPainter *p, double &sc) | ||
1651 | 1016 | { | ||
1652 | 1017 | ScribusView* view = m_Doc->view(); | ||
1653 | 1018 | sc = view->scale(); | ||
1654 | 1019 | p->save(); | ||
1655 | 1020 | if (!isEmbedded) | ||
1656 | 1021 | p->translate(Xpos, Ypos); | ||
1657 | 1022 | p->rotate(Rot); | ||
1658 | 1023 | if (m_Doc->layerOutline(LayerNr)) | ||
1659 | 1024 | { | ||
1660 | 1025 | p->setPen(m_Doc->layerMarker(LayerNr), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
1661 | 1026 | p->setFillMode(ScPainter::None); | ||
1662 | 1027 | p->setBrushOpacity(1.0); | ||
1663 | 1028 | p->setPenOpacity(1.0); | ||
1664 | 1029 | } | ||
1665 | 1030 | else | ||
1666 | 1031 | { | ||
1667 | 1032 | if (!isGroupControl) | ||
1668 | 1033 | { | ||
1669 | 1034 | if (fillBlendmode() != 0) | ||
1670 | 1035 | p->beginLayer(1.0 - fillTransparency(), fillBlendmode()); | ||
1671 | 1036 | |||
1672 | 1037 | p->setLineWidth(m_lineWidth); | ||
1673 | 1038 | if (GrType != 0) | ||
1674 | 1039 | { | ||
1675 | 1040 | if (GrType == 8) | ||
1676 | 1041 | { | ||
1677 | 1042 | if ((patternVal.isEmpty()) || (!m_Doc->docPatterns.contains(patternVal))) | ||
1678 | 1043 | { | ||
1679 | 1044 | p->fill_gradient = VGradient(VGradient::linear); | ||
1680 | 1045 | if (fillColor() != CommonStrings::None) | ||
1681 | 1046 | { | ||
1682 | 1047 | p->setBrush(fillQColor); | ||
1683 | 1048 | p->setFillMode(ScPainter::Solid); | ||
1684 | 1049 | } | ||
1685 | 1050 | else | ||
1686 | 1051 | p->setFillMode(ScPainter::None); | ||
1687 | 1052 | if ((!patternVal.isEmpty()) && (!m_Doc->docPatterns.contains(patternVal))) | ||
1688 | 1053 | { | ||
1689 | 1054 | GrType = 0; | ||
1690 | 1055 | patternVal = ""; | ||
1691 | 1056 | } | ||
1692 | 1057 | } | ||
1693 | 1058 | else | ||
1694 | 1059 | { | ||
1695 | 1060 | p->setPattern(&m_Doc->docPatterns[patternVal], patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation); | ||
1696 | 1061 | p->setFillMode(ScPainter::Pattern); | ||
1697 | 1062 | } | ||
1698 | 1063 | } | ||
1699 | 1064 | else | ||
1700 | 1065 | { | ||
1701 | 1066 | if (fill_gradient.Stops() < 2) // fall back to solid filling if there are not enough colorstops in the gradient. | ||
1702 | 1067 | { | ||
1703 | 1068 | if (fillColor() != CommonStrings::None) | ||
1704 | 1069 | { | ||
1705 | 1070 | p->setBrush(fillQColor); | ||
1706 | 1071 | p->setFillMode(ScPainter::Solid); | ||
1707 | 1072 | } | ||
1708 | 1073 | else | ||
1709 | 1074 | p->setFillMode(ScPainter::None); | ||
1710 | 1075 | } | ||
1711 | 1076 | else | ||
1712 | 1077 | { | ||
1713 | 1078 | p->setFillMode(ScPainter::Gradient); | ||
1714 | 1079 | p->fill_gradient = fill_gradient; | ||
1715 | 1080 | QMatrix grm; | ||
1716 | 1081 | grm.rotate(Rot); | ||
1717 | 1082 | FPointArray gra; | ||
1718 | 1083 | switch (GrType) | ||
1719 | 1084 | { | ||
1720 | 1085 | case 1: | ||
1721 | 1086 | case 2: | ||
1722 | 1087 | case 3: | ||
1723 | 1088 | case 4: | ||
1724 | 1089 | case 6: | ||
1725 | 1090 | p->setGradient(VGradient::linear, FPoint(GrStartX, GrStartY), FPoint(GrEndX, GrEndY)); | ||
1726 | 1091 | break; | ||
1727 | 1092 | case 5: | ||
1728 | 1093 | case 7: | ||
1729 | 1094 | gra.setPoints(2, GrStartX, GrStartY, GrEndX, GrEndY); | ||
1730 | 1095 | p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0)); | ||
1731 | 1096 | break; | ||
1732 | 1097 | } | ||
1733 | 1098 | } | ||
1734 | 1099 | } | ||
1735 | 1100 | } | ||
1736 | 1101 | else | ||
1737 | 1102 | { | ||
1738 | 1103 | p->fill_gradient = VGradient(VGradient::linear); | ||
1739 | 1104 | if (fillColor() != CommonStrings::None) | ||
1740 | 1105 | { | ||
1741 | 1106 | p->setBrush(fillQColor); | ||
1742 | 1107 | p->setFillMode(ScPainter::Solid); | ||
1743 | 1108 | } | ||
1744 | 1109 | else | ||
1745 | 1110 | p->setFillMode(ScPainter::None); | ||
1746 | 1111 | } | ||
1747 | 1112 | if (lineColor() != CommonStrings::None) | ||
1748 | 1113 | { | ||
1749 | 1114 | // if ((m_lineWidth == 0) && ! asLine()) | ||
1750 | 1115 | // p->setLineWidth(0); | ||
1751 | 1116 | // else | ||
1752 | 1117 | // { | ||
1753 | 1118 | p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin); | ||
1754 | 1119 | if (DashValues.count() != 0) | ||
1755 | 1120 | p->setDash(DashValues, DashOffset); | ||
1756 | 1121 | // } | ||
1757 | 1122 | } | ||
1758 | 1123 | else | ||
1759 | 1124 | p->setLineWidth(0); | ||
1760 | 1125 | if (fillBlendmode() == 0) | ||
1761 | 1126 | p->setBrushOpacity(1.0 - fillTransparency()); | ||
1762 | 1127 | if (lineBlendmode() == 0) | ||
1763 | 1128 | p->setPenOpacity(1.0 - lineTransparency()); | ||
1764 | 1129 | p->setFillRule(fillRule); | ||
1765 | 1130 | } | ||
1766 | 1131 | } | ||
1767 | 1132 | } | ||
1768 | 1133 | |||
1769 | 1134 | void PageItem::DrawObj_Post(ScPainter *p) | ||
1770 | 1135 | { | ||
1771 | 1136 | bool doStroke=true; | ||
1772 | 1137 | ScribusView* view = m_Doc->view(); | ||
1773 | 1138 | if (!isGroupControl) | ||
1774 | 1139 | { | ||
1775 | 1140 | if (m_Doc->layerOutline(LayerNr)) | ||
1776 | 1141 | { | ||
1777 | 1142 | if (itemType()!=Line) | ||
1778 | 1143 | { | ||
1779 | 1144 | p->setPen(m_Doc->layerMarker(LayerNr), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
1780 | 1145 | p->setFillMode(ScPainter::None); | ||
1781 | 1146 | p->setBrushOpacity(1.0); | ||
1782 | 1147 | p->setPenOpacity(1.0); | ||
1783 | 1148 | if (itemType()==PolyLine) | ||
1784 | 1149 | p->setupPolygon(&PoLine, false); | ||
1785 | 1150 | else if (itemType() == PathText) | ||
1786 | 1151 | { | ||
1787 | 1152 | if (PoShow) | ||
1788 | 1153 | p->setupPolygon(&PoLine, false); | ||
1789 | 1154 | else | ||
1790 | 1155 | doStroke = false; | ||
1791 | 1156 | } | ||
1792 | 1157 | else | ||
1793 | 1158 | p->setupPolygon(&PoLine); | ||
1794 | 1159 | if (doStroke) | ||
1795 | 1160 | p->strokePath(); | ||
1796 | 1161 | if (itemType()==ImageFrame) | ||
1797 | 1162 | { | ||
1798 | 1163 | if (imageClip.size() != 0) | ||
1799 | 1164 | { | ||
1800 | 1165 | p->setupPolygon(&imageClip); | ||
1801 | 1166 | p->strokePath(); | ||
1802 | 1167 | } | ||
1803 | 1168 | } | ||
1804 | 1169 | } | ||
1805 | 1170 | } | ||
1806 | 1171 | else | ||
1807 | 1172 | { | ||
1808 | 1173 | if (fillBlendmode() != 0) | ||
1809 | 1174 | p->endLayer(); | ||
1810 | 1175 | if (itemType()==PathText || itemType()==PolyLine || itemType()==Line) | ||
1811 | 1176 | doStroke=false; | ||
1812 | 1177 | if ((doStroke) && (!m_Doc->RePos)) | ||
1813 | 1178 | { | ||
1814 | 1179 | if (lineBlendmode() != 0) | ||
1815 | 1180 | p->beginLayer(1.0 - lineTransparency(), lineBlendmode()); | ||
1816 | 1181 | // if (lineColor() != CommonStrings::None) | ||
1817 | 1182 | // { | ||
1818 | 1183 | // p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin); | ||
1819 | 1184 | // if (DashValues.count() != 0) | ||
1820 | 1185 | // p->setDash(DashValues, DashOffset); | ||
1821 | 1186 | // } | ||
1822 | 1187 | // else | ||
1823 | 1188 | // p->setLineWidth(0); | ||
1824 | 1189 | if (!isTableItem) | ||
1825 | 1190 | { | ||
1826 | 1191 | if ((itemType() == LatexFrame) || (itemType() == ImageFrame)) | ||
1827 | 1192 | p->setupPolygon(&PoLine); | ||
1828 | 1193 | if (NamedLStyle.isEmpty()) | ||
1829 | 1194 | { | ||
1830 | 1195 | if (lineColor() != CommonStrings::None) | ||
1831 | 1196 | { | ||
1832 | 1197 | p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin); | ||
1833 | 1198 | if (DashValues.count() != 0) | ||
1834 | 1199 | p->setDash(DashValues, DashOffset); | ||
1835 | 1200 | p->strokePath(); | ||
1836 | 1201 | } | ||
1837 | 1202 | } | ||
1838 | 1203 | else | ||
1839 | 1204 | { | ||
1840 | 1205 | multiLine ml = m_Doc->MLineStyles[NamedLStyle]; | ||
1841 | 1206 | QColor tmp; | ||
1842 | 1207 | for (int it = ml.size()-1; it > -1; it--) | ||
1843 | 1208 | { | ||
1844 | 1209 | struct SingleLine& sl = ml[it]; | ||
1845 | 1210 | // Qt4 if ((!sl.Color != CommonStrings::None) && (sl.Width != 0)) | ||
1846 | 1211 | if (sl.Color != CommonStrings::None) // && (sl.Width != 0)) | ||
1847 | 1212 | { | ||
1848 | 1213 | SetQColor(&tmp, sl.Color, sl.Shade); | ||
1849 | 1214 | p->setPen(tmp, sl.Width, static_cast<Qt::PenStyle>(sl.Dash), static_cast<Qt::PenCapStyle>(sl.LineEnd), static_cast<Qt::PenJoinStyle>(sl.LineJoin)); | ||
1850 | 1215 | p->strokePath(); | ||
1851 | 1216 | } | ||
1852 | 1217 | } | ||
1853 | 1218 | } | ||
1854 | 1219 | } | ||
1855 | 1220 | if (lineBlendmode() != 0) | ||
1856 | 1221 | p->endLayer(); | ||
1857 | 1222 | } | ||
1858 | 1223 | } | ||
1859 | 1224 | } | ||
1860 | 1225 | if ((!isEmbedded) && (!m_Doc->RePos)) | ||
1861 | 1226 | { | ||
1862 | 1227 | double aestheticFactor(5.0); | ||
1863 | 1228 | double scpInv = 1.0 / (qMax(view->scale(), 1.0) * aestheticFactor); | ||
1864 | 1229 | if (!isGroupControl) | ||
1865 | 1230 | { | ||
1866 | 1231 | if ((Frame) && (m_Doc->guidesSettings.framesShown) && ((itemType() == ImageFrame) || (itemType() == LatexFrame) || (itemType() == PathText))) | ||
1867 | 1232 | { | ||
1868 | 1233 | p->setPen(PrefsManager::instance()->appPrefs.DFrameNormColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
1869 | 1234 | if ((isBookmark) || (m_isAnnotation)) | ||
1870 | 1235 | p->setPen(PrefsManager::instance()->appPrefs.DFrameAnnotationColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
1871 | 1236 | if ((BackBox != 0) || (NextBox != 0)) | ||
1872 | 1237 | p->setPen(PrefsManager::instance()->appPrefs.DFrameLinkColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
1873 | 1238 | if (m_Locked) | ||
1874 | 1239 | p->setPen(PrefsManager::instance()->appPrefs.DFrameLockColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
1875 | 1240 | p->setFillMode(0); | ||
1876 | 1241 | if (itemType()==PathText) | ||
1877 | 1242 | { | ||
1878 | 1243 | if (Clip.count() != 0) | ||
1879 | 1244 | { | ||
1880 | 1245 | FPointArray tclip; | ||
1881 | 1246 | FPoint np = FPoint(Clip.point(0)); | ||
1882 | 1247 | tclip.resize(2); | ||
1883 | 1248 | tclip.setPoint(0, np); | ||
1884 | 1249 | tclip.setPoint(1, np); | ||
1885 | 1250 | for (int a = 1; a < Clip.size(); ++a) | ||
1886 | 1251 | { | ||
1887 | 1252 | np = FPoint(Clip.point(a)); | ||
1888 | 1253 | tclip.putPoints(tclip.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y()); | ||
1889 | 1254 | } | ||
1890 | 1255 | np = FPoint(Clip.point(0)); | ||
1891 | 1256 | tclip.putPoints(tclip.size(), 2, np.x(), np.y(), np.x(), np.y()); | ||
1892 | 1257 | p->setupPolygon(&tclip); | ||
1893 | 1258 | } | ||
1894 | 1259 | } | ||
1895 | 1260 | else | ||
1896 | 1261 | // Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows | ||
1897 | 1262 | #ifdef HAVE_CAIRO | ||
1898 | 1263 | #if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0))) | ||
1899 | 1264 | p->setupPolygon(&PoLine, false); | ||
1900 | 1265 | #else | ||
1901 | 1266 | p->setupPolygon(&PoLine); | ||
1902 | 1267 | #endif | ||
1903 | 1268 | #else | ||
1904 | 1269 | p->setupPolygon(&PoLine); | ||
1905 | 1270 | #endif | ||
1906 | 1271 | p->strokePath(); | ||
1907 | 1272 | } | ||
1908 | 1273 | } | ||
1909 | 1274 | if ((m_Doc->guidesSettings.framesShown) && textFlowUsesContourLine() && (ContourLine.size() != 0)) | ||
1910 | 1275 | { | ||
1911 | 1276 | p->setPen(Qt::darkGray, 1.0 / qMax(view->scale(), 1.0), Qt::DotLine, Qt::FlatCap, Qt::MiterJoin); | ||
1912 | 1277 | // Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows | ||
1913 | 1278 | #ifdef HAVE_CAIRO | ||
1914 | 1279 | #if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0))) | ||
1915 | 1280 | p->setupPolygon(&ContourLine, false); | ||
1916 | 1281 | #else | ||
1917 | 1282 | p->setupPolygon(&ContourLine); | ||
1918 | 1283 | #endif | ||
1919 | 1284 | #else | ||
1920 | 1285 | p->setupPolygon(&ContourLine); | ||
1921 | 1286 | #endif | ||
1922 | 1287 | p->strokePath(); | ||
1923 | 1288 | } | ||
1924 | 1289 | if ((m_Doc->guidesSettings.layerMarkersShown) && (m_Doc->layerCount() > 1) && (!m_Doc->layerOutline(LayerNr)) && ((isGroupControl) || (Groups.count() == 0)) && (!view->m_canvas->isPreviewMode())) | ||
1925 | 1290 | { | ||
1926 | 1291 | p->setPen(Qt::black, 0.5/ m_Doc->view()->scale(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
1927 | 1292 | p->setPenOpacity(1.0); | ||
1928 | 1293 | p->setBrush(m_Doc->layerMarker(LayerNr)); | ||
1929 | 1294 | p->setBrushOpacity(1.0); | ||
1930 | 1295 | p->setFillMode(ScPainter::Solid); | ||
1931 | 1296 | double ofwh = 10; | ||
1932 | 1297 | double ofx = Width - ofwh/2; | ||
1933 | 1298 | double ofy = Height - ofwh*3; | ||
1934 | 1299 | p->drawRect(ofx, ofy, ofwh, ofwh); | ||
1935 | 1300 | } | ||
1936 | 1301 | //CB disabled for now | ||
1937 | 1302 | //if (m_Doc->m_Selection->findItem(this)!=-1) | ||
1938 | 1303 | // drawLockedMarker(p); | ||
1939 | 1304 | } | ||
1940 | 1305 | // Tinput = false; | ||
1941 | 1306 | FrameOnly = false; | ||
1942 | 1307 | p->restore(); | ||
1943 | 1308 | } | ||
1944 | 1309 | |||
1945 | 1310 | void PageItem::DrawObj_Embedded(ScPainter *p, QRectF cullingArea, const CharStyle& style, PageItem* cembedded) | ||
1946 | 1311 | { | ||
1947 | 1312 | if (!cembedded) | ||
1948 | 1313 | return; | ||
1949 | 1314 | if (!m_Doc->DoDrawing) | ||
1950 | 1315 | return; | ||
1951 | 1316 | QList<PageItem*> emG; | ||
1952 | 1317 | QStack<PageItem*> groupStack; | ||
1953 | 1318 | groupStack.clear(); | ||
1954 | 1319 | emG.clear(); | ||
1955 | 1320 | emG.append(cembedded); | ||
1956 | 1321 | if (cembedded->Groups.count() != 0) | ||
1957 | 1322 | { | ||
1958 | 1323 | for (int ga=0; ga<m_Doc->FrameItems.count(); ++ga) | ||
1959 | 1324 | { | ||
1960 | 1325 | if (m_Doc->FrameItems.at(ga)->Groups.count() != 0) | ||
1961 | 1326 | { | ||
1962 | 1327 | if (m_Doc->FrameItems.at(ga)->Groups.top() == cembedded->Groups.top()) | ||
1963 | 1328 | { | ||
1964 | 1329 | if (m_Doc->FrameItems.at(ga)->ItemNr != cembedded->ItemNr) | ||
1965 | 1330 | { | ||
1966 | 1331 | if (!emG.contains(m_Doc->FrameItems.at(ga))) | ||
1967 | 1332 | emG.append(m_Doc->FrameItems.at(ga)); | ||
1968 | 1333 | } | ||
1969 | 1334 | } | ||
1970 | 1335 | } | ||
1971 | 1336 | } | ||
1972 | 1337 | } | ||
1973 | 1338 | for (int em = 0; em < emG.count(); ++em) | ||
1974 | 1339 | { | ||
1975 | 1340 | PageItem* embedded = emG.at(em); | ||
1976 | 1341 | if (embedded->isGroupControl) | ||
1977 | 1342 | { | ||
1978 | 1343 | p->save(); | ||
1979 | 1344 | FPointArray cl = embedded->PoLine.copy(); | ||
1980 | 1345 | QMatrix mm; | ||
1981 | 1346 | mm.translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0))); | ||
1982 | 1347 | if (style.baselineOffset() != 0) | ||
1983 | 1348 | mm.translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0)); | ||
1984 | 1349 | mm.scale(style.scaleH() / 1000.0, style.scaleV() / 1000.0); | ||
1985 | 1350 | mm.rotate(embedded->rotation()); | ||
1986 | 1351 | cl.map( mm ); | ||
1987 | 1352 | p->beginLayer(1.0 - embedded->fillTransparency(), embedded->fillBlendmode(), &cl); | ||
1988 | 1353 | groupStack.push(embedded->groupsLastItem); | ||
1989 | 1354 | continue; | ||
1990 | 1355 | } | ||
1991 | 1356 | p->save(); | ||
1992 | 1357 | double x = embedded->xPos(); | ||
1993 | 1358 | double y = embedded->yPos(); | ||
1994 | 1359 | embedded->Xpos = embedded->gXpos; | ||
1995 | 1360 | embedded->Ypos = (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos; | ||
1996 | 1361 | p->translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0))); | ||
1997 | 1362 | if (style.baselineOffset() != 0) | ||
1998 | 1363 | { | ||
1999 | 1364 | p->translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0)); | ||
2000 | 1365 | embedded->Ypos -= embedded->gHeight * (style.baselineOffset() / 1000.0); | ||
2001 | 1366 | } | ||
2002 | 1367 | p->scale(style.scaleH() / 1000.0, style.scaleV() / 1000.0); | ||
2003 | 1368 | embedded->Dirty = Dirty; | ||
2004 | 1369 | embedded->invalid = true; | ||
2005 | 1370 | double sc; | ||
2006 | 1371 | double pws = embedded->m_lineWidth; | ||
2007 | 1372 | embedded->DrawObj_Pre(p, sc); | ||
2008 | 1373 | switch(embedded->itemType()) | ||
2009 | 1374 | { | ||
2010 | 1375 | case ImageFrame: | ||
2011 | 1376 | case TextFrame: | ||
2012 | 1377 | case LatexFrame: | ||
2013 | 1378 | case Polygon: | ||
2014 | 1379 | case PathText: | ||
2015 | 1380 | embedded->DrawObj_Item(p, cullingArea, sc); | ||
2016 | 1381 | break; | ||
2017 | 1382 | case Line: | ||
2018 | 1383 | case PolyLine: | ||
2019 | 1384 | embedded->m_lineWidth = pws * qMin(style.scaleH() / 1000.0, style.scaleV() / 1000.0); | ||
2020 | 1385 | embedded->DrawObj_Item(p, cullingArea, sc); | ||
2021 | 1386 | break; | ||
2022 | 1387 | default: | ||
2023 | 1388 | break; | ||
2024 | 1389 | } | ||
2025 | 1390 | embedded->m_lineWidth = pws * qMin(style.scaleH() / 1000.0, style.scaleV() / 1000.0); | ||
2026 | 1391 | embedded->DrawObj_Post(p); | ||
2027 | 1392 | embedded->Xpos = x; | ||
2028 | 1393 | embedded->Ypos = y; | ||
2029 | 1394 | p->restore(); | ||
2030 | 1395 | if (groupStack.count() != 0) | ||
2031 | 1396 | { | ||
2032 | 1397 | while (embedded == groupStack.top()) | ||
2033 | 1398 | { | ||
2034 | 1399 | p->endLayer(); | ||
2035 | 1400 | p->restore(); | ||
2036 | 1401 | groupStack.pop(); | ||
2037 | 1402 | if (groupStack.count() == 0) | ||
2038 | 1403 | break; | ||
2039 | 1404 | } | ||
2040 | 1405 | } | ||
2041 | 1406 | embedded->m_lineWidth = pws; | ||
2042 | 1407 | } | ||
2043 | 1408 | for (int em = 0; em < emG.count(); ++em) | ||
2044 | 1409 | { | ||
2045 | 1410 | PageItem* embedded = emG.at(em); | ||
2046 | 1411 | if (!embedded->isTableItem) | ||
2047 | 1412 | continue; | ||
2048 | 1413 | p->save(); | ||
2049 | 1414 | double x = embedded->xPos(); | ||
2050 | 1415 | double y = embedded->yPos(); | ||
2051 | 1416 | embedded->Xpos = embedded->gXpos; | ||
2052 | 1417 | embedded->Ypos = (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos; | ||
2053 | 1418 | p->translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0))); | ||
2054 | 1419 | if (style.baselineOffset() != 0) | ||
2055 | 1420 | { | ||
2056 | 1421 | p->translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0)); | ||
2057 | 1422 | embedded->Ypos -= embedded->gHeight * (style.baselineOffset() / 1000.0); | ||
2058 | 1423 | } | ||
2059 | 1424 | p->scale(style.scaleH() / 1000.0, style.scaleV() / 1000.0); | ||
2060 | 1425 | p->rotate(embedded->rotation()); | ||
2061 | 1426 | double pws = embedded->m_lineWidth; | ||
2062 | 1427 | embedded->m_lineWidth = pws * qMin(style.scaleH() / 1000.0, style.scaleV() / 1000.0); | ||
2063 | 1428 | if ((embedded->lineColor() != CommonStrings::None) && (embedded->lineWidth() != 0.0)) | ||
2064 | 1429 | { | ||
2065 | 1430 | QColor tmp; | ||
2066 | 1431 | embedded->SetQColor(&tmp, embedded->lineColor(), embedded->lineShade()); | ||
2067 | 1432 | if ((embedded->TopLine) || (embedded->RightLine) || (embedded->BottomLine) || (embedded->LeftLine)) | ||
2068 | 1433 | { | ||
2069 | 1434 | p->setPen(tmp, embedded->lineWidth(), embedded->PLineArt, Qt::SquareCap, embedded->PLineJoin); | ||
2070 | 1435 | if (embedded->TopLine) | ||
2071 | 1436 | p->drawLine(FPoint(0.0, 0.0), FPoint(embedded->width(), 0.0)); | ||
2072 | 1437 | if (embedded->RightLine) | ||
2073 | 1438 | p->drawLine(FPoint(embedded->width(), 0.0), FPoint(embedded->width(), embedded->height())); | ||
2074 | 1439 | if (embedded->BottomLine) | ||
2075 | 1440 | p->drawLine(FPoint(embedded->width(), embedded->height()), FPoint(0.0, embedded->height())); | ||
2076 | 1441 | if (embedded->LeftLine) | ||
2077 | 1442 | p->drawLine(FPoint(0.0, embedded->height()), FPoint(0.0, 0.0)); | ||
2078 | 1443 | } | ||
2079 | 1444 | } | ||
2080 | 1445 | embedded->m_lineWidth = pws; | ||
2081 | 1446 | embedded->Xpos = x; | ||
2082 | 1447 | embedded->Ypos = y; | ||
2083 | 1448 | p->restore(); | ||
2084 | 1449 | } | ||
2085 | 1450 | } | ||
2086 | 1451 | |||
2087 | 1452 | |||
2088 | 1453 | void PageItem::paintObj(QPainter *p) | ||
2089 | 1454 | { | ||
2090 | 1455 | if ((!m_Doc->DoDrawing) || (m_Doc->RePos)) | ||
2091 | 1456 | { | ||
2092 | 1457 | FrameOnly = false; | ||
2093 | 1458 | return; | ||
2094 | 1459 | } | ||
2095 | 1460 | double sc = m_Doc->view()->scale(); | ||
2096 | 1461 | double handleSize = 6.0 / sc; | ||
2097 | 1462 | double halfSize = 3.0 / sc; | ||
2098 | 1463 | if ((!FrameOnly) && (!m_Doc->RePos)) | ||
2099 | 1464 | { | ||
2100 | 1465 | if (!m_Doc->m_Selection->isEmpty()) | ||
2101 | 1466 | { | ||
2102 | 1467 | // qDebug() << "Item: " << ItemNr << "W: " << Width << "H: " << Height; | ||
2103 | 1468 | if (Groups.count() == 0) | ||
2104 | 1469 | { | ||
2105 | 1470 | //Locked line colour selection | ||
2106 | 1471 | if (m_Locked) | ||
2107 | 1472 | p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameLockColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); | ||
2108 | 1473 | else | ||
2109 | 1474 | p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); | ||
2110 | 1475 | p->setBrush(Qt::NoBrush); | ||
2111 | 1476 | double lw2 = 1.0 / sc; | ||
2112 | 1477 | double lw = 1.0 / sc; | ||
2113 | 1478 | Qt::PenCapStyle le = Qt::FlatCap; | ||
2114 | 1479 | if (NamedLStyle.isEmpty()) | ||
2115 | 1480 | { | ||
2116 | 1481 | lw2 = (m_lineWidth / 2.0) / sc; | ||
2117 | 1482 | lw = qMax(m_lineWidth, 1.0) / sc; | ||
2118 | 1483 | le = PLineEnd; | ||
2119 | 1484 | } | ||
2120 | 1485 | else | ||
2121 | 1486 | { | ||
2122 | 1487 | multiLine ml = m_Doc->MLineStyles[NamedLStyle]; | ||
2123 | 1488 | lw2 = (ml[ml.size()-1].Width / 2.0) / sc; | ||
2124 | 1489 | lw = qMax(ml[ml.size()-1].Width, 1.0) / sc; | ||
2125 | 1490 | le = static_cast<Qt::PenCapStyle>(ml[ml.size()-1].LineEnd); | ||
2126 | 1491 | } | ||
2127 | 1492 | //Draw our frame outline | ||
2128 | 1493 | if (asLine()) | ||
2129 | 1494 | { | ||
2130 | 1495 | if (le != Qt::FlatCap) | ||
2131 | 1496 | p->drawRect(QRectF(-lw2, -lw2, Width+lw, lw)); | ||
2132 | 1497 | else | ||
2133 | 1498 | p->drawRect(QRectF(-1 / sc, -lw2, Width, lw)); | ||
2134 | 1499 | } | ||
2135 | 1500 | else | ||
2136 | 1501 | p->drawRect(QRectF(0, 0, Width, Height)); | ||
2137 | 1502 | // p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); | ||
2138 | 1503 | p->setBrush(PrefsManager::instance()->appPrefs.DFrameColor); | ||
2139 | 1504 | p->setPen(Qt::NoPen); | ||
2140 | 1505 | if ((!m_Locked) && (!m_SizeLocked)) | ||
2141 | 1506 | { | ||
2142 | 1507 | if (! asLine()) | ||
2143 | 1508 | { | ||
2144 | 1509 | p->drawRect(QRectF(0.0, 0.0, handleSize, handleSize)); | ||
2145 | 1510 | p->drawRect(QRectF(Width - handleSize, Height - handleSize, handleSize, handleSize)); | ||
2146 | 1511 | p->drawRect(QRectF(Width - handleSize, 0.0, handleSize, handleSize)); | ||
2147 | 1512 | p->drawRect(QRectF(0.0, Height - handleSize, handleSize, handleSize)); | ||
2148 | 1513 | if (Width > 6) | ||
2149 | 1514 | { | ||
2150 | 1515 | p->drawRect(QRectF(Width / 2.0 - halfSize, Height - handleSize, handleSize, handleSize)); | ||
2151 | 1516 | p->drawRect(QRectF(Width / 2.0 - halfSize, 0.0, handleSize, handleSize)); | ||
2152 | 1517 | } | ||
2153 | 1518 | if (Height > 6) | ||
2154 | 1519 | { | ||
2155 | 1520 | p->drawRect(QRectF(Width - handleSize, Height / 2.0 - halfSize, handleSize, handleSize)); | ||
2156 | 1521 | p->drawRect(QRectF(0.0, Height / 2.0 - halfSize, handleSize, handleSize)); | ||
2157 | 1522 | } | ||
2158 | 1523 | } | ||
2159 | 1524 | else | ||
2160 | 1525 | { | ||
2161 | 1526 | p->drawRect(QRectF(-halfSize, -halfSize, handleSize, handleSize)); | ||
2162 | 1527 | p->drawRect(QRectF(Width + halfSize, -halfSize, -handleSize, handleSize)); | ||
2163 | 1528 | } | ||
2164 | 1529 | } | ||
2165 | 1530 | } | ||
2166 | 1531 | else | ||
2167 | 1532 | { | ||
2168 | 1533 | p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameGroupColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); | ||
2169 | 1534 | p->setBrush(Qt::NoBrush); | ||
2170 | 1535 | p->drawRect(QRectF(0.0, 0.0, Width, Height)); | ||
2171 | 1536 | if (m_Doc->m_Selection->count() == 1) | ||
2172 | 1537 | { | ||
2173 | 1538 | p->setPen(Qt::NoPen); | ||
2174 | 1539 | // p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameGroupColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); | ||
2175 | 1540 | p->setBrush(PrefsManager::instance()->appPrefs.DFrameGroupColor); | ||
2176 | 1541 | p->drawRect(QRectF(0.0, 0.0, handleSize, handleSize)); | ||
2177 | 1542 | p->drawRect(QRectF(Width - handleSize, Height - handleSize, handleSize, handleSize)); | ||
2178 | 1543 | p->drawRect(QRectF(Width - handleSize, 0.0, handleSize, handleSize)); | ||
2179 | 1544 | p->drawRect(QRectF(0.0, Height - handleSize, handleSize, handleSize)); | ||
2180 | 1545 | if (Width > 6) | ||
2181 | 1546 | { | ||
2182 | 1547 | p->drawRect(QRectF(Width / 2.0 - halfSize, Height - handleSize, handleSize, handleSize)); | ||
2183 | 1548 | p->drawRect(QRectF(Width / 2.0 - halfSize, 0.0, handleSize, handleSize)); | ||
2184 | 1549 | } | ||
2185 | 1550 | if (Height > 6) | ||
2186 | 1551 | { | ||
2187 | 1552 | p->drawRect(QRectF(Width - handleSize, Height / 2.0 - halfSize, handleSize, handleSize)); | ||
2188 | 1553 | p->drawRect(QRectF(0.0, Height / 2.0 - halfSize, handleSize, handleSize)); | ||
2189 | 1554 | } | ||
2190 | 1555 | } | ||
2191 | 1556 | } | ||
2192 | 1557 | } | ||
2193 | 1558 | } | ||
2194 | 1559 | FrameOnly = false; | ||
2195 | 1560 | } | ||
2196 | 1561 | |||
2197 | 1562 | QImage PageItem::DrawObj_toImage() | ||
2198 | 1563 | { | ||
2199 | 1564 | QList<PageItem*> emG; | ||
2200 | 1565 | emG.clear(); | ||
2201 | 1566 | double minx = std::numeric_limits<double>::max(); | ||
2202 | 1567 | double miny = std::numeric_limits<double>::max(); | ||
2203 | 1568 | double maxx = -std::numeric_limits<double>::max(); | ||
2204 | 1569 | double maxy = -std::numeric_limits<double>::max(); | ||
2205 | 1570 | if (Groups.count() != 0) | ||
2206 | 1571 | { | ||
2207 | 1572 | for (int ga=0; ga<m_Doc->Items->count(); ++ga) | ||
2208 | 1573 | { | ||
2209 | 1574 | if (m_Doc->Items->at(ga)->Groups.count() != 0) | ||
2210 | 1575 | { | ||
2211 | 1576 | if (m_Doc->Items->at(ga)->Groups.top() == Groups.top()) | ||
2212 | 1577 | { | ||
2213 | 1578 | if (!emG.contains(m_Doc->Items->at(ga))) | ||
2214 | 1579 | { | ||
2215 | 1580 | emG.append(m_Doc->Items->at(ga)); | ||
2216 | 1581 | PageItem *currItem = m_Doc->Items->at(ga); | ||
2217 | 1582 | double x1, x2, y1, y2; | ||
2218 | 1583 | currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2); | ||
2219 | 1584 | minx = qMin(minx, x1); | ||
2220 | 1585 | miny = qMin(miny, y1); | ||
2221 | 1586 | maxx = qMax(maxx, x2); | ||
2222 | 1587 | maxy = qMax(maxy, y2); | ||
2223 | 1588 | } | ||
2224 | 1589 | } | ||
2225 | 1590 | } | ||
2226 | 1591 | } | ||
2227 | 1592 | for (int em = 0; em < emG.count(); ++em) | ||
2228 | 1593 | { | ||
2229 | 1594 | PageItem* currItem = emG.at(em); | ||
2230 | 1595 | currItem->gXpos = currItem->xPos() - minx; | ||
2231 | 1596 | currItem->gYpos = currItem->yPos() - miny; | ||
2232 | 1597 | currItem->gWidth = maxx - minx; | ||
2233 | 1598 | currItem->gHeight = maxy - miny; | ||
2234 | 1599 | } | ||
2235 | 1600 | } | ||
2236 | 1601 | else | ||
2237 | 1602 | { | ||
2238 | 1603 | double x1, x2, y1, y2; | ||
2239 | 1604 | getVisualBoundingRect(&x1, &y1, &x2, &y2); | ||
2240 | 1605 | minx = qMin(minx, x1); | ||
2241 | 1606 | miny = qMin(miny, y1); | ||
2242 | 1607 | maxx = qMax(maxx, x2); | ||
2243 | 1608 | maxy = qMax(maxy, y2); | ||
2244 | 1609 | gXpos = xPos() - minx; | ||
2245 | 1610 | gYpos = yPos() - miny; | ||
2246 | 1611 | gWidth = maxx - minx; | ||
2247 | 1612 | gHeight = maxy - miny; | ||
2248 | 1613 | emG.append(this); | ||
2249 | 1614 | } | ||
2250 | 1615 | return DrawObj_toImage(emG); | ||
2251 | 1616 | } | ||
2252 | 1617 | |||
2253 | 1618 | QImage PageItem::DrawObj_toImage(QList<PageItem*> &emG) | ||
2254 | 1619 | { | ||
2255 | 1620 | QImage retImg = QImage(qRound(gWidth), qRound(gHeight), QImage::Format_ARGB32); | ||
2256 | 1621 | // retImg.fill( qRgba(255, 255, 255, 0) ); | ||
2257 | 1622 | retImg.fill( qRgba(0, 0, 0, 0) ); | ||
2258 | 1623 | ScPainter *painter = new ScPainter(&retImg, retImg.width(), retImg.height(), 1, 0); | ||
2259 | 1624 | // painter->setZoomFactor(1.0); | ||
2260 | 1625 | painter->setZoomFactor(qMax(qRound(gWidth) / gWidth, qRound(gHeight) / gHeight)); | ||
2261 | 1626 | QStack<PageItem*> groupStack; | ||
2262 | 1627 | for (int em = 0; em < emG.count(); ++em) | ||
2263 | 1628 | { | ||
2264 | 1629 | PageItem* embedded = emG.at(em); | ||
2265 | 1630 | if (embedded->isGroupControl) | ||
2266 | 1631 | { | ||
2267 | 1632 | painter->save(); | ||
2268 | 1633 | FPointArray cl = embedded->PoLine.copy(); | ||
2269 | 1634 | QMatrix mm; | ||
2270 | 1635 | mm.translate(embedded->gXpos, embedded->gYpos); | ||
2271 | 1636 | mm.rotate(embedded->rotation()); | ||
2272 | 1637 | cl.map( mm ); | ||
2273 | 1638 | painter->beginLayer(1.0 - embedded->fillTransparency(), embedded->fillBlendmode(), &cl); | ||
2274 | 1639 | groupStack.push(embedded->groupsLastItem); | ||
2275 | 1640 | continue; | ||
2276 | 1641 | } | ||
2277 | 1642 | painter->save(); | ||
2278 | 1643 | // qDebug()<<embedded<<embedded->xPos()<<embedded->yPos()<<embedded->gXpos<<embedded->gYpos; | ||
2279 | 1644 | // double x = embedded->xPos(); | ||
2280 | 1645 | // double y = embedded->yPos(); | ||
2281 | 1646 | // embedded->Xpos = embedded->gXpos; | ||
2282 | 1647 | // embedded->Ypos = embedded->gYpos; | ||
2283 | 1648 | // Seems to work without all this coordinates mess. To monitor tho | ||
2284 | 1649 | painter->translate(embedded->gXpos, embedded->gYpos); | ||
2285 | 1650 | embedded->isEmbedded = true; | ||
2286 | 1651 | embedded->invalid = true; | ||
2287 | 1652 | embedded->DrawObj(painter, QRectF()); | ||
2288 | 1653 | // embedded->Xpos = x; | ||
2289 | 1654 | // embedded->Ypos = y; | ||
2290 | 1655 | embedded->isEmbedded = false; | ||
2291 | 1656 | painter->restore(); | ||
2292 | 1657 | if (groupStack.count() != 0) | ||
2293 | 1658 | { | ||
2294 | 1659 | while (embedded == groupStack.top()) | ||
2295 | 1660 | { | ||
2296 | 1661 | painter->endLayer(); | ||
2297 | 1662 | painter->restore(); | ||
2298 | 1663 | groupStack.pop(); | ||
2299 | 1664 | if (groupStack.count() == 0) | ||
2300 | 1665 | break; | ||
2301 | 1666 | } | ||
2302 | 1667 | } | ||
2303 | 1668 | } | ||
2304 | 1669 | for (int em = 0; em < emG.count(); ++em) | ||
2305 | 1670 | { | ||
2306 | 1671 | PageItem* embedded = emG.at(em); | ||
2307 | 1672 | if (!embedded->isTableItem) | ||
2308 | 1673 | continue; | ||
2309 | 1674 | painter->save(); | ||
2310 | 1675 | // double x = embedded->xPos(); | ||
2311 | 1676 | // double y = embedded->yPos(); | ||
2312 | 1677 | // embedded->Xpos = embedded->gXpos; | ||
2313 | 1678 | // embedded->Ypos = embedded->gYpos; | ||
2314 | 1679 | painter->translate(embedded->gXpos, embedded->gYpos); | ||
2315 | 1680 | painter->rotate(embedded->rotation()); | ||
2316 | 1681 | embedded->isEmbedded = true; | ||
2317 | 1682 | embedded->invalid = true; | ||
2318 | 1683 | if ((embedded->lineColor() != CommonStrings::None) && (embedded->lineWidth() != 0.0)) | ||
2319 | 1684 | { | ||
2320 | 1685 | QColor tmp; | ||
2321 | 1686 | embedded->SetQColor(&tmp, embedded->lineColor(), embedded->lineShade()); | ||
2322 | 1687 | if ((embedded->TopLine) || (embedded->RightLine) || (embedded->BottomLine) || (embedded->LeftLine)) | ||
2323 | 1688 | { | ||
2324 | 1689 | painter->setPen(tmp, embedded->lineWidth(), embedded->PLineArt, Qt::SquareCap, embedded->PLineJoin); | ||
2325 | 1690 | if (embedded->TopLine) | ||
2326 | 1691 | painter->drawLine(FPoint(0.0, 0.0), FPoint(embedded->width(), 0.0)); | ||
2327 | 1692 | if (embedded->RightLine) | ||
2328 | 1693 | painter->drawLine(FPoint(embedded->width(), 0.0), FPoint(embedded->width(), embedded->height())); | ||
2329 | 1694 | if (embedded->BottomLine) | ||
2330 | 1695 | painter->drawLine(FPoint(embedded->width(), embedded->height()), FPoint(0.0, embedded->height())); | ||
2331 | 1696 | if (embedded->LeftLine) | ||
2332 | 1697 | painter->drawLine(FPoint(0.0, embedded->height()), FPoint(0.0, 0.0)); | ||
2333 | 1698 | } | ||
2334 | 1699 | } | ||
2335 | 1700 | embedded->isEmbedded = false; | ||
2336 | 1701 | // embedded->Xpos = x; | ||
2337 | 1702 | // embedded->Ypos = y; | ||
2338 | 1703 | painter->restore(); | ||
2339 | 1704 | } | ||
2340 | 1705 | painter->end(); | ||
2341 | 1706 | delete painter; | ||
2342 | 1707 | return retImg; | ||
2343 | 1708 | } | ||
2344 | 1709 | |||
2345 | 1710 | QString PageItem::ExpandToken(uint base) | ||
2346 | 1711 | { | ||
2347 | 1712 | uint zae = 0; | ||
2348 | 1713 | QChar ch = itemText.text(base); | ||
2349 | 1714 | QString chstr = ch; | ||
2350 | 1715 | if (ch == SpecialChars::PAGENUMBER) | ||
2351 | 1716 | { | ||
2352 | 1717 | // compatibility mode: ignore subsequent pagenumber chars | ||
2353 | 1718 | if (base > 0 && itemText.text(base-1) == SpecialChars::PAGENUMBER) | ||
2354 | 1719 | return ""; | ||
2355 | 1720 | if ((!m_Doc->masterPageMode()) && (OwnPage != -1)) | ||
2356 | 1721 | { | ||
2357 | 1722 | QString out("%1"); | ||
2358 | 1723 | //CB Section numbering | ||
2359 | 1724 | chstr = out.arg(m_Doc->getSectionPageNumberForPageIndex(OwnPage), -(int)zae); | ||
2360 | 1725 | } | ||
2361 | 1726 | else | ||
2362 | 1727 | return "#"; | ||
2363 | 1728 | } | ||
2364 | 1729 | else if (ch == SpecialChars::PAGECOUNT) | ||
2365 | 1730 | { | ||
2366 | 1731 | if (!m_Doc->masterPageMode()) | ||
2367 | 1732 | { | ||
2368 | 1733 | QString out("%1"); | ||
2369 | 1734 | int key = m_Doc->getSectionKeyForPageIndex(OwnPage); | ||
2370 | 1735 | if (key == -1) | ||
2371 | 1736 | return "%"; | ||
2372 | 1737 | chstr = out.arg(getStringFromSequence(m_Doc->sections[key].type, m_Doc->sections[key].toindex - m_Doc->sections[key].fromindex + 1)); | ||
2373 | 1738 | } | ||
2374 | 1739 | else | ||
2375 | 1740 | return "%"; | ||
2376 | 1741 | } | ||
2377 | 1742 | return chstr; | ||
2378 | 1743 | } | ||
2379 | 1744 | |||
2380 | 1745 | void PageItem::SetQColor(QColor *tmp, QString farbe, double shad) | ||
2381 | 1746 | { | ||
2382 | 1747 | const ScColor& col = m_Doc->PageColors[farbe]; | ||
2383 | 1748 | *tmp = ScColorEngine::getShadeColorProof(col, m_Doc, shad); | ||
2384 | 1749 | if ((m_Doc->view()) && (m_Doc->view()->m_canvas->usePreviewVisual())) | ||
2385 | 1750 | { | ||
2386 | 1751 | VisionDefectColor defect; | ||
2387 | 1752 | *tmp = defect.convertDefect(*tmp, m_Doc->view()->m_canvas->previewVisual()); | ||
2388 | 1753 | } | ||
2389 | 1754 | } | ||
2390 | 1755 | |||
2391 | 1756 | /** | ||
2392 | 1757 | layout glyphs translates the chars into a number of glyphs, applying the Charstyle | ||
2393 | 1758 | 'style'. The following fields are set in layout: glyph, more, scaleH, scaleV, xoffset, yoffset, xadvance. | ||
2394 | 1759 | If the DropCap-bit in style.effects is set and yadvance is > 0, scaleH/V, x/yoffset and xadvance | ||
2395 | 1760 | are modified to scale the glyphs to this height. | ||
2396 | 1761 | Otherwise yadvance is set to the max ascender of all generated glyphs. | ||
2397 | 1762 | It scales according to smallcaps and | ||
2398 | 1763 | sets xadvance to the advance width without kerning. If more than one glyph | ||
2399 | 1764 | is generated, kerning is included in all but the last xadvance. | ||
2400 | 1765 | */ | ||
2401 | 1766 | double PageItem::layoutGlyphs(const CharStyle& style, const QString& chars, GlyphLayout& layout) | ||
2402 | 1767 | { | ||
2403 | 1768 | double retval = 0.0; | ||
2404 | 1769 | double asce = style.font().ascent(style.fontSize() / 10.0); | ||
2405 | 1770 | int chst = style.effects() & 1919; | ||
2406 | 1771 | /* if (chars[0] == SpecialChars::ZWSPACE || | ||
2407 | 1772 | chars[0] == SpecialChars::ZWNBSPACE || | ||
2408 | 1773 | chars[0] == SpecialChars::NBSPACE || | ||
2409 | 1774 | chars[0] == SpecialChars::NBHYPHEN || | ||
2410 | 1775 | chars[0] == SpecialChars::SHYPHEN || | ||
2411 | 1776 | chars[0] == SpecialChars::PARSEP || | ||
2412 | 1777 | chars[0] == SpecialChars::COLBREAK || | ||
2413 | 1778 | chars[0] == SpecialChars::LINEBREAK || | ||
2414 | 1779 | chars[0] == SpecialChars::FRAMEBREAK || | ||
2415 | 1780 | chars[0] == SpecialChars::TAB) | ||
2416 | 1781 | { | ||
2417 | 1782 | layout.glyph = ScFace::CONTROL_GLYPHS + chars[0].unicode(); | ||
2418 | 1783 | } | ||
2419 | 1784 | else */ | ||
2420 | 1785 | { | ||
2421 | 1786 | layout.glyph = style.font().char2CMap(chars[0].unicode()); | ||
2422 | 1787 | } | ||
2423 | 1788 | |||
2424 | 1789 | double tracking = 0.0; | ||
2425 | 1790 | if ( (style.effects() & ScStyle_StartOfLine) == 0) | ||
2426 | 1791 | tracking = style.fontSize() * style.tracking() / 10000.0; | ||
2427 | 1792 | |||
2428 | 1793 | layout.xoffset = tracking; | ||
2429 | 1794 | layout.yoffset = 0; | ||
2430 | 1795 | if (chst != ScStyle_Default) | ||
2431 | 1796 | { | ||
2432 | 1797 | if (chst & ScStyle_Superscript) | ||
2433 | 1798 | { | ||
2434 | 1799 | retval -= asce * m_Doc->typographicSettings.valueSuperScript / 100.0; | ||
2435 | 1800 | layout.yoffset -= asce * m_Doc->typographicSettings.valueSuperScript / 100.0; | ||
2436 | 1801 | layout.scaleV = layout.scaleH = qMax(m_Doc->typographicSettings.scalingSuperScript / 100.0, 10.0 / style.fontSize()); | ||
2437 | 1802 | } | ||
2438 | 1803 | else if (chst & ScStyle_Subscript) | ||
2439 | 1804 | { | ||
2440 | 1805 | retval += asce * m_Doc->typographicSettings.valueSubScript / 100.0; | ||
2441 | 1806 | layout.yoffset += asce * m_Doc->typographicSettings.valueSubScript / 100.0; | ||
2442 | 1807 | layout.scaleV = layout.scaleH = qMax(m_Doc->typographicSettings.scalingSubScript / 100.0, 10.0 / style.fontSize()); | ||
2443 | 1808 | } | ||
2444 | 1809 | else { | ||
2445 | 1810 | layout.scaleV = layout.scaleH = 1.0; | ||
2446 | 1811 | } | ||
2447 | 1812 | layout.scaleH *= style.scaleH() / 1000.0; | ||
2448 | 1813 | layout.scaleV *= style.scaleV() / 1000.0; | ||
2449 | 1814 | if (chst & ScStyle_AllCaps) | ||
2450 | 1815 | { | ||
2451 | 1816 | layout.glyph = style.font().char2CMap(chars[0].toUpper().unicode()); | ||
2452 | 1817 | } | ||
2453 | 1818 | if (chst & ScStyle_SmallCaps) | ||
2454 | 1819 | { | ||
2455 | 1820 | double smallcapsScale = m_Doc->typographicSettings.valueSmallCaps / 100.0; | ||
2456 | 1821 | QChar uc = chars[0].toUpper(); | ||
2457 | 1822 | if (uc != chars[0]) | ||
2458 | 1823 | { | ||
2459 | 1824 | layout.glyph = style.font().char2CMap(chars[0].toUpper().unicode()); | ||
2460 | 1825 | layout.scaleV *= smallcapsScale; | ||
2461 | 1826 | layout.scaleH *= smallcapsScale; | ||
2462 | 1827 | } | ||
2463 | 1828 | } | ||
2464 | 1829 | } | ||
2465 | 1830 | else { | ||
2466 | 1831 | layout.scaleH = style.scaleH() / 1000.0; | ||
2467 | 1832 | layout.scaleV = style.scaleV() / 1000.0; | ||
2468 | 1833 | } | ||
2469 | 1834 | |||
2470 | 1835 | /* if (layout.glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBSPACE.unicode())) { | ||
2471 | 1836 | uint replGlyph = style.font().char2CMap(QChar(' ')); | ||
2472 | 1837 | layout.xadvance = style.font().glyphWidth(replGlyph, style.fontSize() / 10) * layout.scaleH; | ||
2473 | 1838 | layout.yadvance = style.font().glyphBBox(replGlyph, style.fontSize() / 10).ascent * layout.scaleV; | ||
2474 | 1839 | } | ||
2475 | 1840 | else if (layout.glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBHYPHEN.unicode())) { | ||
2476 | 1841 | uint replGlyph = style.font().char2CMap(QChar('-')); | ||
2477 | 1842 | layout.xadvance = style.font().glyphWidth(replGlyph, style.fontSize() / 10) * layout.scaleH; | ||
2478 | 1843 | layout.yadvance = style.font().glyphBBox(replGlyph, style.fontSize() / 10).ascent * layout.scaleV; | ||
2479 | 1844 | } | ||
2480 | 1845 | else if (layout.glyph >= ScFace::CONTROL_GLYPHS) { | ||
2481 | 1846 | layout.xadvance = 0; | ||
2482 | 1847 | layout.yadvance = 0; | ||
2483 | 1848 | } | ||
2484 | 1849 | else */ | ||
2485 | 1850 | { | ||
2486 | 1851 | layout.xadvance = style.font().glyphWidth(layout.glyph, style.fontSize() / 10) * layout.scaleH; | ||
2487 | 1852 | layout.yadvance = style.font().glyphBBox(layout.glyph, style.fontSize() / 10).ascent * layout.scaleV; | ||
2488 | 1853 | } | ||
2489 | 1854 | if (layout.xadvance > 0) | ||
2490 | 1855 | layout.xadvance += tracking; | ||
2491 | 1856 | |||
2492 | 1857 | if (chars.length() > 1) { | ||
2493 | 1858 | layout.grow(); | ||
2494 | 1859 | layoutGlyphs(style, chars.mid(1), *layout.more); | ||
2495 | 1860 | layout.xadvance += style.font().glyphKerning(layout.glyph, layout.more->glyph, style.fontSize() / 10) * layout.scaleH; | ||
2496 | 1861 | if (layout.more->yadvance > layout.yadvance) | ||
2497 | 1862 | layout.yadvance = layout.more->yadvance; | ||
2498 | 1863 | } | ||
2499 | 1864 | else { | ||
2500 | 1865 | layout.shrink(); | ||
2501 | 1866 | } | ||
2502 | 1867 | return retval; | ||
2503 | 1868 | } | ||
2504 | 1869 | |||
2505 | 1870 | void PageItem::drawGlyphs(ScPainter *p, const CharStyle& style, GlyphLayout& glyphs) | ||
2506 | 1871 | { | ||
2507 | 1872 | uint glyph = glyphs.glyph; | ||
2508 | 1873 | if ((m_Doc->guidesSettings.showControls) && | ||
2509 | 1874 | (glyph == style.font().char2CMap(QChar(' ')) || glyph >= ScFace::CONTROL_GLYPHS)) | ||
2510 | 1875 | { | ||
2511 | 1876 | bool stroke = false; | ||
2512 | 1877 | if (glyph >= ScFace::CONTROL_GLYPHS) | ||
2513 | 1878 | glyph -= ScFace::CONTROL_GLYPHS; | ||
2514 | 1879 | else | ||
2515 | 1880 | glyph = 32; | ||
2516 | 1881 | QMatrix chma, chma4, chma5; | ||
2517 | 1882 | FPointArray points; | ||
2518 | 1883 | if (glyph == SpecialChars::TAB.unicode()) | ||
2519 | 1884 | { | ||
2520 | 1885 | points = m_Doc->symTab.copy(); | ||
2521 | 1886 | chma4.translate(glyphs.xoffset + glyphs.xadvance - ((style.fontSize() / 10.0) * glyphs.scaleH * 0.7), glyphs.yoffset - ((style.fontSize() / 10.0) * glyphs.scaleV * 0.5)); | ||
2522 | 1887 | } | ||
2523 | 1888 | else if (glyph == SpecialChars::COLBREAK.unicode()) | ||
2524 | 1889 | { | ||
2525 | 1890 | points = m_Doc->symNewCol.copy(); | ||
2526 | 1891 | chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.6)); | ||
2527 | 1892 | } | ||
2528 | 1893 | else if (glyph == SpecialChars::FRAMEBREAK.unicode()) | ||
2529 | 1894 | { | ||
2530 | 1895 | points = m_Doc->symNewFrame.copy(); | ||
2531 | 1896 | chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.6)); | ||
2532 | 1897 | } | ||
2533 | 1898 | else if (glyph == SpecialChars::PARSEP.unicode()) | ||
2534 | 1899 | { | ||
2535 | 1900 | points = m_Doc->symReturn.copy(); | ||
2536 | 1901 | chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.8)); | ||
2537 | 1902 | } | ||
2538 | 1903 | else if (glyph == SpecialChars::LINEBREAK.unicode()) | ||
2539 | 1904 | { | ||
2540 | 1905 | points = m_Doc->symNewLine.copy(); | ||
2541 | 1906 | chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.4)); | ||
2542 | 1907 | } | ||
2543 | 1908 | else if (glyph == SpecialChars::NBSPACE.unicode() || | ||
2544 | 1909 | glyph == 32) | ||
2545 | 1910 | { | ||
2546 | 1911 | stroke = (glyph == 32); | ||
2547 | 1912 | points = m_Doc->symNonBreak.copy(); | ||
2548 | 1913 | chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.4)); | ||
2549 | 1914 | } | ||
2550 | 1915 | else if (glyph == SpecialChars::NBHYPHEN.unicode()) | ||
2551 | 1916 | { | ||
2552 | 1917 | points = style.font().glyphOutline(style.font().char2CMap(QChar('-')), style.fontSize() / 100); | ||
2553 | 1918 | chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV)); | ||
2554 | 1919 | } | ||
2555 | 1920 | else if (glyph == SpecialChars::SHYPHEN.unicode()) | ||
2556 | 1921 | { | ||
2557 | 1922 | points.resize(0); | ||
2558 | 1923 | points.addQuadPoint(0, -10, 0, -10, 0, -6, 0, -6); | ||
2559 | 1924 | stroke = true; | ||
2560 | 1925 | } | ||
2561 | 1926 | else // ??? | ||
2562 | 1927 | { | ||
2563 | 1928 | points.resize(0); | ||
2564 | 1929 | points.addQuadPoint(0, -10, 0, -10, 0, -9, 0, -9); | ||
2565 | 1930 | points.addQuadPoint(0, -9, 0, -9, 1, -9, 1, -9); | ||
2566 | 1931 | points.addQuadPoint(1, -9, 1, -9, 1, -10, 1, -10); | ||
2567 | 1932 | points.addQuadPoint(1, -10, 1, -10, 0, -10, 0, -10); | ||
2568 | 1933 | } | ||
2569 | 1934 | chma.scale(glyphs.scaleH * style.fontSize() / 100.0, glyphs.scaleV * style.fontSize() / 100.0); | ||
2570 | 1935 | points.map(chma * chma4); | ||
2571 | 1936 | p->setupPolygon(&points, true); | ||
2572 | 1937 | QColor oldBrush = p->brush(); | ||
2573 | 1938 | p->setBrush( (style.effects() & ScStyle_SuppressSpace) ? Qt::green | ||
2574 | 1939 | : PrefsManager::instance()->appPrefs.DControlCharColor); | ||
2575 | 1940 | if (stroke) | ||
2576 | 1941 | { | ||
2577 | 1942 | QColor tmp = p->pen(); | ||
2578 | 1943 | p->setPen(p->brush(), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
2579 | 1944 | p->setLineWidth(style.fontSize() * glyphs.scaleV / 200.0); | ||
2580 | 1945 | p->strokePath(); | ||
2581 | 1946 | p->setPen(tmp, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
2582 | 1947 | } | ||
2583 | 1948 | else | ||
2584 | 1949 | { | ||
2585 | 1950 | p->setFillMode(1); | ||
2586 | 1951 | p->fillPath(); | ||
2587 | 1952 | } | ||
2588 | 1953 | p->setBrush(oldBrush); | ||
2589 | 1954 | if (glyphs.more) | ||
2590 | 1955 | { | ||
2591 | 1956 | p->translate(glyphs.xadvance, 0); | ||
2592 | 1957 | drawGlyphs(p, style, *glyphs.more); | ||
2593 | 1958 | } | ||
2594 | 1959 | return; | ||
2595 | 1960 | } | ||
2596 | 1961 | else if (glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBSPACE.unicode()) || | ||
2597 | 1962 | glyph == (ScFace::CONTROL_GLYPHS + 32)) | ||
2598 | 1963 | glyph = style.font().char2CMap(QChar(' ')); | ||
2599 | 1964 | else if (glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBHYPHEN.unicode())) | ||
2600 | 1965 | glyph = style.font().char2CMap(QChar('-')); | ||
2601 | 1966 | |||
2602 | 1967 | if (glyph >= ScFace::CONTROL_GLYPHS || (style.effects() & ScStyle_SuppressSpace)) { | ||
2603 | 1968 | // qDebug("drawGlyphs: skipping %d", glyph); | ||
2604 | 1969 | // all those are empty | ||
2605 | 1970 | if (glyphs.more) | ||
2606 | 1971 | { | ||
2607 | 1972 | p->translate(glyphs.xadvance, 0); | ||
2608 | 1973 | drawGlyphs(p, style, *glyphs.more); | ||
2609 | 1974 | } | ||
2610 | 1975 | return; | ||
2611 | 1976 | } | ||
2612 | 1977 | // if (style.font().canRender(QChar(glyph))) | ||
2613 | 1978 | { | ||
2614 | 1979 | FPointArray gly = style.font().glyphOutline(glyph); | ||
2615 | 1980 | // Do underlining first so you can get typographically correct | ||
2616 | 1981 | // underlines when drawing a white outline | ||
2617 | 1982 | if (((style.effects() & ScStyle_Underline) || ((style.effects() & ScStyle_UnderlineWords) && glyph != style.font().char2CMap(QChar(' ')))) && (style.strokeColor() != CommonStrings::None)) | ||
2618 | 1983 | { | ||
2619 | 1984 | double st, lw; | ||
2620 | 1985 | if ((style.underlineOffset() != -1) || (style.underlineWidth() != -1)) | ||
2621 | 1986 | { | ||
2622 | 1987 | if (style.underlineOffset() != -1) | ||
2623 | 1988 | st = (style.underlineOffset() / 1000.0) * (style.font().descent(style.fontSize() / 10.0)); | ||
2624 | 1989 | else | ||
2625 | 1990 | st = style.font().underlinePos(style.fontSize() / 10.0); | ||
2626 | 1991 | if (style.underlineWidth() != -1) | ||
2627 | 1992 | lw = (style.underlineWidth() / 1000.0) * (style.fontSize() / 10.0); | ||
2628 | 1993 | else | ||
2629 | 1994 | lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), 1.0); | ||
2630 | 1995 | } | ||
2631 | 1996 | else | ||
2632 | 1997 | { | ||
2633 | 1998 | st = style.font().underlinePos(style.fontSize() / 10.0); | ||
2634 | 1999 | lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), 1.0); | ||
2635 | 2000 | } | ||
2636 | 2001 | if (style.baselineOffset() != 0) | ||
2637 | 2002 | st += (style.fontSize() / 10.0) * glyphs.scaleV * (style.baselineOffset() / 1000.0); | ||
2638 | 2003 | QColor tmpC = p->pen(); | ||
2639 | 2004 | p->setPen(p->brush()); | ||
2640 | 2005 | p->setLineWidth(lw); | ||
2641 | 2006 | if (style.effects() & ScStyle_Subscript) | ||
2642 | 2007 | p->drawLine(FPoint(glyphs.xoffset, glyphs.yoffset - st), FPoint(glyphs.xoffset + glyphs.xadvance, glyphs.yoffset - st)); | ||
2643 | 2008 | else | ||
2644 | 2009 | p->drawLine(FPoint(glyphs.xoffset, -st), FPoint(glyphs.xoffset + glyphs.xadvance, -st)); | ||
2645 | 2010 | p->setPen(tmpC); | ||
2646 | 2011 | } | ||
2647 | 2012 | if (gly.size() > 3) | ||
2648 | 2013 | { | ||
2649 | 2014 | if (glyph == 0) | ||
2650 | 2015 | { | ||
2651 | 2016 | // qDebug() << QString("glyph 0: (%1,%2) * %3 %4 + %5").arg(glyphs.xoffset).arg(glyphs.yoffset).arg(glyphs.scaleH).arg(glyphs.scaleV).arg(glyphs.xadvance)); | ||
2652 | 2017 | } | ||
2653 | 2018 | p->save(); | ||
2654 | 2019 | p->translate(glyphs.xoffset, glyphs.yoffset - ((style.fontSize() / 10.0) * glyphs.scaleV)); | ||
2655 | 2020 | if (Reverse) | ||
2656 | 2021 | { | ||
2657 | 2022 | p->scale(-1, 1); | ||
2658 | 2023 | p->translate(-glyphs.xadvance, 0); | ||
2659 | 2024 | } | ||
2660 | 2025 | if (style.baselineOffset() != 0) | ||
2661 | 2026 | p->translate(0, -(style.fontSize() / 10.0) * (style.baselineOffset() / 1000.0)); | ||
2662 | 2027 | double glxSc = glyphs.scaleH * style.fontSize() / 100.00; | ||
2663 | 2028 | double glySc = glyphs.scaleV * style.fontSize() / 100.0; | ||
2664 | 2029 | p->scale(glxSc, glySc); | ||
2665 | 2030 | // p->setFillMode(1); | ||
2666 | 2031 | bool fr = p->fillRule(); | ||
2667 | 2032 | p->setFillRule(false); | ||
2668 | 2033 | // double a = gly.point(0).x(); | ||
2669 | 2034 | // double b = gly.point(0).y(); | ||
2670 | 2035 | // double c = gly.point(3).x(); | ||
2671 | 2036 | // double d = gly.point(3).y(); | ||
2672 | 2037 | // qDebug() << QString("drawglyphs: %1 (%2,%3) (%4,%5) scaled %6,%7 trans %8,%9") | ||
2673 | 2038 | // .arg(gly.size()).arg(a).arg(b).arg(c).arg(d) | ||
2674 | 2039 | // .arg(p->worldMatrix().m11()).arg(p->worldMatrix().m22()).arg(p->worldMatrix().dx()).arg(p->worldMatrix().dy()); | ||
2675 | 2040 | p->setupPolygon(&gly, true); | ||
2676 | 2041 | if (m_Doc->layerOutline(LayerNr)) | ||
2677 | 2042 | { | ||
2678 | 2043 | p->save(); | ||
2679 | 2044 | p->setPen(m_Doc->layerMarker(LayerNr), 0.5, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
2680 | 2045 | p->setFillMode(ScPainter::None); | ||
2681 | 2046 | p->setBrushOpacity(1.0); | ||
2682 | 2047 | p->setPenOpacity(1.0); | ||
2683 | 2048 | p->strokePath(); | ||
2684 | 2049 | p->restore(); | ||
2685 | 2050 | p->setFillRule(fr); | ||
2686 | 2051 | p->restore(); | ||
2687 | 2052 | if (glyphs.more) | ||
2688 | 2053 | { | ||
2689 | 2054 | p->translate(glyphs.xadvance, 0); | ||
2690 | 2055 | drawGlyphs(p, style, *glyphs.more); | ||
2691 | 2056 | } | ||
2692 | 2057 | return; | ||
2693 | 2058 | } | ||
2694 | 2059 | if (glyph == 0) | ||
2695 | 2060 | { | ||
2696 | 2061 | p->setPen(PrefsManager::instance()->appPrefs.DControlCharColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
2697 | 2062 | p->setLineWidth(style.fontSize() * glyphs.scaleV * style.outlineWidth() * 2 / 10000.0); | ||
2698 | 2063 | p->strokePath(); | ||
2699 | 2064 | } | ||
2700 | 2065 | else if ((style.font().isStroked()) && (style.strokeColor() != CommonStrings::None) && ((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) != 0)) | ||
2701 | 2066 | { | ||
2702 | 2067 | QColor tmp = p->brush(); | ||
2703 | 2068 | p->setPen(tmp, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); | ||
2704 | 2069 | p->setLineWidth(style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0); | ||
2705 | 2070 | p->strokePath(); | ||
2706 | 2071 | } | ||
2707 | 2072 | else | ||
2708 | 2073 | { | ||
2709 | 2074 | if ((style.effects() & ScStyle_Shadowed) && (style.strokeColor() != CommonStrings::None)) | ||
2710 | 2075 | { | ||
2711 | 2076 | p->save(); | ||
2712 | 2077 | p->translate((style.fontSize() * glyphs.scaleH * style.shadowXOffset() / 10000.0) / glxSc, -(style.fontSize() * glyphs.scaleV * style.shadowYOffset() / 10000.0) / glySc); | ||
2713 | 2078 | QColor tmp = p->brush(); | ||
2714 | 2079 | p->setBrush(p->pen()); | ||
2715 | 2080 | p->setupPolygon(&gly, true); | ||
2716 | 2081 | p->fillPath(); | ||
2717 | 2082 | p->setBrush(tmp); | ||
2718 | 2083 | p->restore(); | ||
2719 | 2084 | p->setupPolygon(&gly, true); | ||
2720 | 2085 | } | ||
2721 | 2086 | if (style.fillColor() != CommonStrings::None) | ||
2722 | 2087 | p->fillPath(); | ||
2723 | 2088 | if ((style.effects() & ScStyle_Outline) && (style.strokeColor() != CommonStrings::None) && ((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) != 0)) | ||
2724 | 2089 | { | ||
2725 | 2090 | p->setLineWidth((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) / glySc); | ||
2726 | 2091 | p->strokePath(); | ||
2727 | 2092 | } | ||
2728 | 2093 | } | ||
2729 | 2094 | p->setFillRule(fr); | ||
2730 | 2095 | p->restore(); | ||
2731 | 2096 | } | ||
2732 | 2097 | else { | ||
2733 | 2098 | // qDebug() << "drawGlyphs: empty glyph" << glyph; | ||
2734 | 2099 | } | ||
2735 | 2100 | if ((style.effects() & ScStyle_Strikethrough) && (style.strokeColor() != CommonStrings::None)) | ||
2736 | 2101 | { | ||
2737 | 2102 | double st, lw; | ||
2738 | 2103 | if ((style.strikethruOffset() != -1) || (style.strikethruWidth() != -1)) | ||
2739 | 2104 | { | ||
2740 | 2105 | if (style.strikethruOffset() != -1) | ||
2741 | 2106 | st = (style.strikethruOffset() / 1000.0) * (style.font().ascent(style.fontSize() / 10.0)); | ||
2742 | 2107 | else | ||
2743 | 2108 | st = style.font().strikeoutPos(style.fontSize() / 10.0); | ||
2744 | 2109 | if (style.strikethruWidth() != -1) | ||
2745 | 2110 | lw = (style.strikethruWidth() / 1000.0) * (style.fontSize() / 10.0); | ||
2746 | 2111 | else | ||
2747 | 2112 | lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), 1.0); | ||
2748 | 2113 | } | ||
2749 | 2114 | else | ||
2750 | 2115 | { | ||
2751 | 2116 | st = style.font().strikeoutPos(style.fontSize() / 10.0); | ||
2752 | 2117 | lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), 1.0); | ||
2753 | 2118 | } | ||
2754 | 2119 | if (style.baselineOffset() != 0) | ||
2755 | 2120 | st += (style.fontSize() / 10.0) * glyphs.scaleV * (style.baselineOffset() / 1000.0); | ||
2756 | 2121 | p->setPen(p->brush()); | ||
2757 | 2122 | p->setLineWidth(lw); | ||
2758 | 2123 | p->drawLine(FPoint(glyphs.xoffset, glyphs.yoffset - st), FPoint(glyphs.xoffset + glyphs.xadvance, glyphs.yoffset - st)); | ||
2759 | 2124 | } | ||
2760 | 2125 | } | ||
2761 | 2126 | /* else | ||
2762 | 2127 | { | ||
2763 | 2128 | p->setLineWidth(1); | ||
2764 | 2129 | p->setPen(red); | ||
2765 | 2130 | p->setBrush(red); | ||
2766 | 2131 | p->setFillMode(1); | ||
2767 | 2132 | p->drawRect(glyphs.xoffset, glyphs.yoffset - (style.fontSize() / 10.0) * glyphs.scaleV , (style.fontSize() / 10.0) * glyphs.scaleH, (style.fontSize() / 10.0) * glyphs.scaleV); | ||
2768 | 2133 | } | ||
2769 | 2134 | */ | ||
2770 | 2135 | if (glyphs.more) | ||
2771 | 2136 | { | ||
2772 | 2137 | p->translate(glyphs.xadvance, 0); | ||
2773 | 2138 | drawGlyphs(p, style, *glyphs.more); | ||
2774 | 2139 | } | ||
2775 | 2140 | } | ||
2776 | 2141 | |||
2777 | 2142 | void PageItem::DrawPolyL(QPainter *p, QPolygon pts) | ||
2778 | 2143 | { | ||
2779 | 2144 | if (Segments.count() != 0) | ||
2780 | 2145 | { | ||
2781 | 2146 | QList<uint>::Iterator it2end=Segments.end(); | ||
2782 | 2147 | uint FirstVal = 0; | ||
2783 | 2148 | for (QList<uint>::Iterator it2 = Segments.begin(); it2 != it2end; ++it2) | ||
2784 | 2149 | { | ||
2785 | 2150 | p->drawPolygon(pts.constData() + FirstVal, (*it2)-FirstVal); | ||
2786 | 2151 | FirstVal = (*it2); | ||
2787 | 2152 | } | ||
2788 | 2153 | p->drawPolygon(pts.constData() + FirstVal, pts.size() - FirstVal); | ||
2789 | 2154 | } | ||
2790 | 2155 | else | ||
2791 | 2156 | p->drawPolygon(pts); | ||
2792 | 2157 | /* | ||
2793 | 2158 | QColor tmp; | ||
2794 | 2159 | if (Segments.count() != 0) | ||
2795 | 2160 | { | ||
2796 | 2161 | QList<uint>::Iterator it2end=Segments.end(); | ||
2797 | 2162 | uint FirstVal = 0; | ||
2798 | 2163 | for (QList<uint>::Iterator it2 = Segments.begin(); it2 != it2end; ++it2) | ||
2799 | 2164 | { | ||
2800 | 2165 | if (NamedLStyle.isEmpty()) | ||
2801 | 2166 | { | ||
2802 | 2167 | if (lineColor() != CommonStrings::None) | ||
2803 | 2168 | p->setPen(QPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin)); | ||
2804 | 2169 | p->drawPolygon(pts.constData() + FirstVal, (*it2)-FirstVal); | ||
2805 | 2170 | } | ||
2806 | 2171 | else | ||
2807 | 2172 | { | ||
2808 | 2173 | multiLine ml = m_Doc->MLineStyles[NamedLStyle]; | ||
2809 | 2174 | for (int it = ml.size()-1; it > -1; it--) | ||
2810 | 2175 | { | ||
2811 | 2176 | SetQColor(&tmp, ml[it].Color, ml[it].Shade); | ||
2812 | 2177 | p->setPen(QPen(tmp, | ||
2813 | 2178 | qMax(static_cast<int>(ml[it].Width), 1), | ||
2814 | 2179 | static_cast<Qt::PenStyle>(ml[it].Dash), | ||
2815 | 2180 | static_cast<Qt::PenCapStyle>(ml[it].LineEnd), | ||
2816 | 2181 | static_cast<Qt::PenJoinStyle>(ml[it].LineJoin))); | ||
2817 | 2182 | p->drawPolygon(pts.constData() + FirstVal, (*it2)-FirstVal); | ||
2818 | 2183 | } | ||
2819 | 2184 | } | ||
2820 | 2185 | FirstVal = (*it2); | ||
2821 | 2186 | } | ||
2822 | 2187 | if (NamedLStyle.isEmpty()) | ||
2823 | 2188 | { | ||
2824 | 2189 | if (lineColor() != CommonStrings::None) | ||
2825 | 2190 | p->setPen(QPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin)); | ||
2826 | 2191 | p->drawPolygon(pts.constData() + FirstVal, pts.size() - FirstVal); | ||
2827 | 2192 | } | ||
2828 | 2193 | else | ||
2829 | 2194 | { | ||
2830 | 2195 | multiLine ml = m_Doc->MLineStyles[NamedLStyle]; | ||
2831 | 2196 | for (int it = ml.size()-1; it > -1; it--) | ||
2832 | 2197 | { | ||
2833 | 2198 | SetQColor(&tmp, ml[it].Color, ml[it].Shade); | ||
2834 | 2199 | p->setPen(QPen(tmp, | ||
2835 | 2200 | qMax(static_cast<int>(ml[it].Width), 1), | ||
2836 | 2201 | static_cast<Qt::PenStyle>(ml[it].Dash), | ||
2837 | 2202 | static_cast<Qt::PenCapStyle>(ml[it].LineEnd), | ||
2838 | 2203 | static_cast<Qt::PenJoinStyle>(ml[it].LineJoin))); | ||
2839 | 2204 | p->drawPolygon(pts.constData() + FirstVal, pts.size() - FirstVal); | ||
2840 | 2205 | } | ||
2841 | 2206 | } | ||
2842 | 2207 | } | ||
2843 | 2208 | else | ||
2844 | 2209 | { | ||
2845 | 2210 | if (NamedLStyle.isEmpty()) | ||
2846 | 2211 | { | ||
2847 | 2212 | if (lineColor() != CommonStrings::None) | ||
2848 | 2213 | p->setPen(QPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin)); | ||
2849 | 2214 | p->drawPolygon(pts); | ||
2850 | 2215 | } | ||
2851 | 2216 | else | ||
2852 | 2217 | { | ||
2853 | 2218 | multiLine ml = m_Doc->MLineStyles[NamedLStyle]; | ||
2854 | 2219 | for (int it = ml.size()-1; it > -1; it--) | ||
2855 | 2220 | { | ||
2856 | 2221 | SetQColor(&tmp, ml[it].Color, ml[it].Shade); | ||
2857 | 2222 | p->setPen(QPen(tmp, | ||
2858 | 2223 | qMax(static_cast<int>(ml[it].Width), 1), | ||
2859 | 2224 | static_cast<Qt::PenStyle>(ml[it].Dash), | ||
2860 | 2225 | static_cast<Qt::PenCapStyle>(ml[it].LineEnd), | ||
2861 | 2226 | static_cast<Qt::PenJoinStyle>(ml[it].LineJoin))); | ||
2862 | 2227 | p->drawPolygon(pts); | ||
2863 | 2228 | } | ||
2864 | 2229 | } | ||
2865 | 2230 | } */ | ||
2866 | 2231 | } | ||
2867 | 2232 | |||
2868 | 2233 | void PageItem::setItemName(const QString& newName) | ||
2869 | 2234 | { | ||
2870 | 2235 | if (AnName == newName) | ||
2871 | 2236 | return; // nothing to do -> return | ||
2872 | 2237 | if (newName.isEmpty()) | ||
2873 | 2238 | return; | ||
2874 | 2239 | QString oldName = AnName; | ||
2875 | 2240 | AnName = generateUniqueCopyName(newName); | ||
2876 | 2241 | AutoName = false; | ||
2877 | 2242 | if (UndoManager::undoEnabled()) | ||
2878 | 2243 | { | ||
2879 | 2244 | SimpleState *ss = new SimpleState(Um::Rename, QString(Um::FromTo).arg(AnName).arg(newName)); | ||
2880 | 2245 | ss->set("OLD_NAME", oldName); | ||
2881 | 2246 | ss->set("NEW_NAME", newName); | ||
2882 | 2247 | undoManager->action(this, ss); | ||
2883 | 2248 | } | ||
2884 | 2249 | setUName(AnName); // set the name for the UndoObject too | ||
2885 | 2250 | } | ||
2886 | 2251 | |||
2887 | 2252 | void PageItem::setPattern(const QString &newPattern) | ||
2888 | 2253 | { | ||
2889 | 2254 | if (patternVal != newPattern) | ||
2890 | 2255 | patternVal = newPattern; | ||
2891 | 2256 | } | ||
2892 | 2257 | |||
2893 | 2258 | void PageItem::gradientVector(double& startX, double& startY, double& endX, double& endY) const | ||
2894 | 2259 | { | ||
2895 | 2260 | startX = GrStartX; | ||
2896 | 2261 | startY = GrStartY; | ||
2897 | 2262 | endX = GrEndX; | ||
2898 | 2263 | endY = GrEndY; | ||
2899 | 2264 | } | ||
2900 | 2265 | |||
2901 | 2266 | void PageItem::setGradientVector(double startX, double startY, double endX, double endY) | ||
2902 | 2267 | { | ||
2903 | 2268 | GrStartX = startX; | ||
2904 | 2269 | GrStartY = startY; | ||
2905 | 2270 | GrEndX = endX; | ||
2906 | 2271 | GrEndY = endY; | ||
2907 | 2272 | } | ||
2908 | 2273 | |||
2909 | 2274 | void PageItem::setPatternTransform(double scaleX, double scaleY, double offsetX, double offsetY, double rotation) | ||
2910 | 2275 | { | ||
2911 | 2276 | patternScaleX = scaleX; | ||
2912 | 2277 | patternScaleY = scaleY; | ||
2913 | 2278 | patternOffsetX = offsetX; | ||
2914 | 2279 | patternOffsetY = offsetY; | ||
2915 | 2280 | patternRotation = rotation; | ||
2916 | 2281 | } | ||
2917 | 2282 | |||
2918 | 2283 | void PageItem::patternTransform(double &scaleX, double &scaleY, double &offsetX, double &offsetY, double &rotation) const | ||
2919 | 2284 | { | ||
2920 | 2285 | scaleX = patternScaleX; | ||
2921 | 2286 | scaleY = patternScaleY; | ||
2922 | 2287 | offsetX = patternOffsetX; | ||
2923 | 2288 | offsetY = patternOffsetY; | ||
2924 | 2289 | rotation = patternRotation; | ||
2925 | 2290 | } | ||
2926 | 2291 | |||
2927 | 2292 | void PageItem::setFillColor(const QString &newColor) | ||
2928 | 2293 | { | ||
2929 | 2294 | QString tmp = newColor; | ||
2930 | 2295 | if (tmp != CommonStrings::None) | ||
2931 | 2296 | { | ||
2932 | 2297 | if (!m_Doc->PageColors.contains(newColor)) | ||
2933 | 2298 | { | ||
2934 | 2299 | switch(itemType()) | ||
2935 | 2300 | { | ||
2936 | 2301 | case ImageFrame: | ||
2937 | 2302 | case LatexFrame: | ||
2938 | 2303 | tmp = m_Doc->toolSettings.dBrushPict; | ||
2939 | 2304 | case TextFrame: | ||
2940 | 2305 | case PathText: | ||
2941 | 2306 | tmp = m_Doc->toolSettings.dTextBackGround; | ||
2942 | 2307 | break; | ||
2943 | 2308 | case Line: | ||
2944 | 2309 | case PolyLine: | ||
2945 | 2310 | case Polygon: | ||
2946 | 2311 | tmp = m_Doc->toolSettings.dBrush; | ||
2947 | 2312 | break; | ||
2948 | 2313 | default: | ||
2949 | 2314 | break; | ||
2950 | 2315 | } | ||
2951 | 2316 | } | ||
2952 | 2317 | } | ||
2953 | 2318 | if (fillColorVal == tmp) | ||
2954 | 2319 | { | ||
2955 | 2320 | setFillQColor(); | ||
2956 | 2321 | return; | ||
2957 | 2322 | } | ||
2958 | 2323 | if (UndoManager::undoEnabled()) | ||
2959 | 2324 | { | ||
2960 | 2325 | SimpleState *ss = new SimpleState(Um::SetFill, | ||
2961 | 2326 | QString(Um::ColorFromTo).arg(fillColorVal).arg(tmp), | ||
2962 | 2327 | Um::IFill); | ||
2963 | 2328 | ss->set("FILL", "fill"); | ||
2964 | 2329 | ss->set("OLD_FILL", fillColorVal); | ||
2965 | 2330 | ss->set("NEW_FILL", tmp); | ||
2966 | 2331 | undoManager->action(this, ss); | ||
2967 | 2332 | } | ||
2968 | 2333 | fillColorVal = tmp; | ||
2969 | 2334 | if (GrType == 0) | ||
2970 | 2335 | { | ||
2971 | 2336 | fill_gradient = VGradient(VGradient::linear); | ||
2972 | 2337 | fill_gradient.clearStops(); | ||
2973 | 2338 | if (fillColorVal != CommonStrings::None) | ||
2974 | 2339 | { | ||
2975 | 2340 | const ScColor& col = m_Doc->PageColors[fillColorVal]; | ||
2976 | 2341 | fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, fillColorVal, 100); | ||
2977 | 2342 | fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, fillColorVal, 100); | ||
2978 | 2343 | } | ||
2979 | 2344 | } | ||
2980 | 2345 | setFillQColor(); | ||
2981 | 2346 | //CB unused in 135 emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal); | ||
2982 | 2347 | } | ||
2983 | 2348 | |||
2984 | 2349 | void PageItem::setFillShade(double newShade) | ||
2985 | 2350 | { | ||
2986 | 2351 | if (fillShadeVal == newShade) | ||
2987 | 2352 | { | ||
2988 | 2353 | setFillQColor(); | ||
2989 | 2354 | return; | ||
2990 | 2355 | } | ||
2991 | 2356 | if (UndoManager::undoEnabled()) | ||
2992 | 2357 | { | ||
2993 | 2358 | SimpleState *ss = new SimpleState(Um::SetShade, | ||
2994 | 2359 | QString(Um::FromTo).arg(fillShadeVal).arg(newShade), | ||
2995 | 2360 | Um::IShade); | ||
2996 | 2361 | ss->set("SHADE", "shade"); | ||
2997 | 2362 | ss->set("OLD_SHADE", fillShadeVal); | ||
2998 | 2363 | ss->set("NEW_SHADE", newShade); | ||
2999 | 2364 | undoManager->action(this, ss); | ||
3000 | 2365 | } | ||
3001 | 2366 | fillShadeVal = newShade; | ||
3002 | 2367 | setFillQColor(); | ||
3003 | 2368 | //CB unused in 135 emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal); | ||
3004 | 2369 | } | ||
3005 | 2370 | |||
3006 | 2371 | void PageItem::setFillTransparency(double newTransparency) | ||
3007 | 2372 | { | ||
3008 | 2373 | if (fillTransparencyVal == newTransparency) | ||
3009 | 2374 | return; // nothing to do -> return | ||
3010 | 2375 | if (UndoManager::undoEnabled()) | ||
3011 | 2376 | { | ||
3012 | 2377 | SimpleState *ss = new SimpleState(Um::Transparency, | ||
3013 | 2378 | QString(Um::FromTo).arg(fillTransparencyVal).arg(newTransparency), | ||
3014 | 2379 | Um::ITransparency); | ||
3015 | 2380 | ss->set("TRANSPARENCY", "transparency"); | ||
3016 | 2381 | ss->set("OLD_TP", fillTransparencyVal); | ||
3017 | 2382 | ss->set("NEW_TP", newTransparency); | ||
3018 | 2383 | undoManager->action(this, ss); | ||
3019 | 2384 | } | ||
3020 | 2385 | fillTransparencyVal = newTransparency; | ||
3021 | 2386 | } | ||
3022 | 2387 | |||
3023 | 2388 | void PageItem::setFillBlendmode(int newBlendmode) | ||
3024 | 2389 | { | ||
3025 | 2390 | if (fillBlendmodeVal == newBlendmode) | ||
3026 | 2391 | return; // nothing to do -> return | ||
3027 | 2392 | fillBlendmodeVal = newBlendmode; | ||
3028 | 2393 | } | ||
3029 | 2394 | |||
3030 | 2395 | void PageItem::setLineColor(const QString &newColor) | ||
3031 | 2396 | { | ||
3032 | 2397 | QString tmp = newColor; | ||
3033 | 2398 | if (tmp != CommonStrings::None) | ||
3034 | 2399 | { | ||
3035 | 2400 | if (!m_Doc->PageColors.contains(newColor)) | ||
3036 | 2401 | { | ||
3037 | 2402 | switch(itemType()) | ||
3038 | 2403 | { | ||
3039 | 2404 | case TextFrame: | ||
3040 | 2405 | case PathText: | ||
3041 | 2406 | tmp = m_Doc->toolSettings.dTextLineColor; | ||
3042 | 2407 | break; | ||
3043 | 2408 | case Line: | ||
3044 | 2409 | tmp = m_Doc->toolSettings.dPenLine; | ||
3045 | 2410 | break; | ||
3046 | 2411 | case PolyLine: | ||
3047 | 2412 | case Polygon: | ||
3048 | 2413 | case ImageFrame: | ||
3049 | 2414 | case LatexFrame: | ||
3050 | 2415 | tmp = m_Doc->toolSettings.dPen; | ||
3051 | 2416 | break; | ||
3052 | 2417 | default: | ||
3053 | 2418 | break; | ||
3054 | 2419 | } | ||
3055 | 2420 | } | ||
3056 | 2421 | } | ||
3057 | 2422 | if (lineColorVal == tmp) | ||
3058 | 2423 | { | ||
3059 | 2424 | setLineQColor(); | ||
3060 | 2425 | return; | ||
3061 | 2426 | } | ||
3062 | 2427 | if (UndoManager::undoEnabled()) | ||
3063 | 2428 | { | ||
3064 | 2429 | SimpleState *ss = new SimpleState(Um::SetLineColor, | ||
3065 | 2430 | QString(Um::ColorFromTo).arg(lineColorVal).arg(tmp), | ||
3066 | 2431 | Um::IFill); | ||
3067 | 2432 | ss->set("LINE_COLOR", "line_color"); | ||
3068 | 2433 | ss->set("OLD_COLOR", lineColorVal); | ||
3069 | 2434 | ss->set("NEW_COLOR", tmp); | ||
3070 | 2435 | undoManager->action(this, ss); | ||
3071 | 2436 | } | ||
3072 | 2437 | lineColorVal = tmp; | ||
3073 | 2438 | setLineQColor(); | ||
3074 | 2439 | //CB unused in 135 emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal); | ||
3075 | 2440 | } | ||
3076 | 2441 | |||
3077 | 2442 | void PageItem::setLineShade(double newShade) | ||
3078 | 2443 | { | ||
3079 | 2444 | if (lineShadeVal == newShade) | ||
3080 | 2445 | { | ||
3081 | 2446 | setLineQColor(); | ||
3082 | 2447 | return; | ||
3083 | 2448 | } | ||
3084 | 2449 | if (UndoManager::undoEnabled()) | ||
3085 | 2450 | { | ||
3086 | 2451 | SimpleState *ss = new SimpleState(Um::SetLineShade, | ||
3087 | 2452 | QString(Um::FromTo).arg(lineShadeVal).arg(newShade), | ||
3088 | 2453 | Um::IShade); | ||
3089 | 2454 | ss->set("LINE_SHADE", "line_shade"); | ||
3090 | 2455 | ss->set("OLD_SHADE", lineShadeVal); | ||
3091 | 2456 | ss->set("NEW_SHADE", newShade); | ||
3092 | 2457 | undoManager->action(this, ss); | ||
3093 | 2458 | } | ||
3094 | 2459 | lineShadeVal = newShade; | ||
3095 | 2460 | setLineQColor(); | ||
3096 | 2461 | //CB unused in 135 emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal); | ||
3097 | 2462 | } | ||
3098 | 2463 | |||
3099 | 2464 | void PageItem::setLineQColor() | ||
3100 | 2465 | { | ||
3101 | 2466 | if (lineColorVal != CommonStrings::None) | ||
3102 | 2467 | { | ||
3103 | 2468 | if (!m_Doc->PageColors.contains(lineColorVal)) | ||
3104 | 2469 | { | ||
3105 | 2470 | switch(itemType()) | ||
3106 | 2471 | { | ||
3107 | 2472 | case TextFrame: | ||
3108 | 2473 | case PathText: | ||
3109 | 2474 | lineColorVal = m_Doc->toolSettings.dTextLineColor; | ||
3110 | 2475 | break; | ||
3111 | 2476 | case Line: | ||
3112 | 2477 | lineColorVal = m_Doc->toolSettings.dPenLine; | ||
3113 | 2478 | break; | ||
3114 | 2479 | case PolyLine: | ||
3115 | 2480 | case Polygon: | ||
3116 | 2481 | case ImageFrame: | ||
3117 | 2482 | case LatexFrame: | ||
3118 | 2483 | lineColorVal = m_Doc->toolSettings.dPen; | ||
3119 | 2484 | break; | ||
3120 | 2485 | default: | ||
3121 | 2486 | break; | ||
3122 | 2487 | } | ||
3123 | 2488 | } | ||
3124 | 2489 | if (!m_Doc->PageColors.contains(lineColorVal)) | ||
3125 | 2490 | lineColorVal = m_Doc->toolSettings.dPen; | ||
3126 | 2491 | const ScColor& col = m_Doc->PageColors[lineColorVal]; | ||
3127 | 2492 | strokeQColor = ScColorEngine::getShadeColorProof(col, m_Doc, lineShadeVal); | ||
3128 | 2493 | } | ||
3129 | 2494 | if ((m_Doc->view()) && (m_Doc->view()->m_canvas->usePreviewVisual())) | ||
3130 | 2495 | { | ||
3131 | 2496 | VisionDefectColor defect; | ||
3132 | 2497 | strokeQColor = defect.convertDefect(strokeQColor, m_Doc->view()->m_canvas->previewVisual()); | ||
3133 | 2498 | } | ||
3134 | 2499 | } | ||
3135 | 2500 | |||
3136 | 2501 | void PageItem::setFillQColor() | ||
3137 | 2502 | { | ||
3138 | 2503 | if (fillColorVal != CommonStrings::None) | ||
3139 | 2504 | { | ||
3140 | 2505 | if (!m_Doc->PageColors.contains(fillColorVal)) | ||
3141 | 2506 | { | ||
3142 | 2507 | switch(itemType()) | ||
3143 | 2508 | { | ||
3144 | 2509 | case ImageFrame: | ||
3145 | 2510 | case LatexFrame: | ||
3146 | 2511 | fillColorVal = m_Doc->toolSettings.dBrushPict; | ||
3147 | 2512 | case TextFrame: | ||
3148 | 2513 | case PathText: | ||
3149 | 2514 | fillColorVal = m_Doc->toolSettings.dTextBackGround; | ||
3150 | 2515 | break; | ||
3151 | 2516 | case Line: | ||
3152 | 2517 | case PolyLine: | ||
3153 | 2518 | case Polygon: | ||
3154 | 2519 | fillColorVal = m_Doc->toolSettings.dBrush; | ||
3155 | 2520 | break; | ||
3156 | 2521 | default: | ||
3157 | 2522 | break; | ||
3158 | 2523 | } | ||
3159 | 2524 | } | ||
3160 | 2525 | const ScColor& col = m_Doc->PageColors[fillColorVal]; | ||
3161 | 2526 | fillQColor = ScColorEngine::getShadeColorProof(col, m_Doc, fillShadeVal); | ||
3162 | 2527 | } | ||
3163 | 2528 | if ((m_Doc->view()) && (m_Doc->view()->m_canvas->usePreviewVisual())) | ||
3164 | 2529 | { | ||
3165 | 2530 | VisionDefectColor defect; | ||
3166 | 2531 | fillQColor = defect.convertDefect(fillQColor, m_Doc->view()->m_canvas->previewVisual()); | ||
3167 | 2532 | } | ||
3168 | 2533 | } | ||
3169 | 2534 | |||
3170 | 2535 | void PageItem::setLineTransparency(double newTransparency) | ||
3171 | 2536 | { | ||
3172 | 2537 | if (lineTransparencyVal == newTransparency) | ||
3173 | 2538 | return; // nothing to do -> return | ||
3174 | 2539 | if (UndoManager::undoEnabled()) | ||
3175 | 2540 | { | ||
3176 | 2541 | SimpleState *ss = new SimpleState(Um::LineTransparency, | ||
3177 | 2542 | QString(Um::FromTo).arg(lineTransparencyVal).arg(newTransparency), | ||
3178 | 2543 | Um::ITransparency); | ||
3179 | 2544 | ss->set("LINE_TRANSPARENCY", "transparency"); | ||
3180 | 2545 | ss->set("OLD_TP", lineTransparencyVal); | ||
3181 | 2546 | ss->set("NEW_TP", newTransparency); | ||
3182 | 2547 | undoManager->action(this, ss); | ||
3183 | 2548 | } | ||
3184 | 2549 | lineTransparencyVal = newTransparency; | ||
3185 | 2550 | } | ||
3186 | 2551 | |||
3187 | 2552 | void PageItem::setLineBlendmode(int newBlendmode) | ||
3188 | 2553 | { | ||
3189 | 2554 | if (lineBlendmodeVal == newBlendmode) | ||
3190 | 2555 | return; // nothing to do -> return | ||
3191 | 2556 | lineBlendmodeVal = newBlendmode; | ||
3192 | 2557 | } | ||
3193 | 2558 | |||
3194 | 2559 | void PageItem::setLineStyle(Qt::PenStyle newStyle) | ||
3195 | 2560 | { | ||
3196 | 2561 | if (PLineArt == newStyle) | ||
3197 | 2562 | return; // nothing to do -> return | ||
3198 | 2563 | if (UndoManager::undoEnabled()) | ||
3199 | 2564 | { | ||
3200 | 2565 | SimpleState *ss = new SimpleState(Um::LineStyle,"",Um::ILineStyle); | ||
3201 | 2566 | ss->set("LINE_STYLE", "line_style"); | ||
3202 | 2567 | ss->set("OLD_STYLE", static_cast<int>(PLineArt)); | ||
3203 | 2568 | ss->set("NEW_STYLE", static_cast<int>(newStyle)); | ||
3204 | 2569 | undoManager->action(this, ss); | ||
3205 | 2570 | } | ||
3206 | 2571 | PLineArt = newStyle; | ||
3207 | 2572 | } | ||
3208 | 2573 | |||
3209 | 2574 | void PageItem::setLineWidth(double newWidth) | ||
3210 | 2575 | { | ||
3211 | 2576 | if (m_lineWidth == newWidth) | ||
3212 | 2577 | return; // nothing to do -> return | ||
3213 | 2578 | if (UndoManager::undoEnabled()) | ||
3214 | 2579 | { | ||
3215 | 2580 | SimpleState *ss = new SimpleState(Um::LineWidth, | ||
3216 | 2581 | QString(Um::FromTo).arg(m_lineWidth).arg(newWidth),Um::ILineStyle); | ||
3217 | 2582 | ss->set("LINE_WIDTH", "line_width"); | ||
3218 | 2583 | ss->set("OLD_WIDTH", m_lineWidth); | ||
3219 | 2584 | ss->set("NEW_WIDTH", newWidth); | ||
3220 | 2585 | undoManager->action(this, ss); | ||
3221 | 2586 | } | ||
3222 | 2587 | Oldm_lineWidth=m_lineWidth; | ||
3223 | 2588 | m_lineWidth = newWidth; | ||
3224 | 2589 | } | ||
3225 | 2590 | |||
3226 | 2591 | void PageItem::setLineEnd(Qt::PenCapStyle newStyle) | ||
3227 | 2592 | { | ||
3228 | 2593 | if (PLineEnd == newStyle) | ||
3229 | 2594 | return; // nothing to do -> return | ||
3230 | 2595 | if (UndoManager::undoEnabled()) | ||
3231 | 2596 | { | ||
3232 | 2597 | SimpleState *ss = new SimpleState(Um::LineEnd,"",Um::ILineStyle); | ||
3233 | 2598 | ss->set("LINE_END", "line_end"); | ||
3234 | 2599 | ss->set("OLD_STYLE", static_cast<int>(PLineEnd)); | ||
3235 | 2600 | ss->set("NEW_STYLE", static_cast<int>(newStyle)); | ||
3236 | 2601 | undoManager->action(this, ss); | ||
3237 | 2602 | } | ||
3238 | 2603 | PLineEnd = newStyle; | ||
3239 | 2604 | } | ||
3240 | 2605 | |||
3241 | 2606 | void PageItem::setLineJoin(Qt::PenJoinStyle newStyle) | ||
3242 | 2607 | { | ||
3243 | 2608 | if (PLineJoin == newStyle) | ||
3244 | 2609 | return; // nothing to do -> return | ||
3245 | 2610 | if (UndoManager::undoEnabled()) | ||
3246 | 2611 | { | ||
3247 | 2612 | SimpleState *ss = new SimpleState(Um::LineJoin,"",Um::ILineStyle); | ||
3248 | 2613 | ss->set("LINE_JOIN", "line_join"); | ||
3249 | 2614 | ss->set("OLD_STYLE", static_cast<int>(PLineJoin)); | ||
3250 | 2615 | ss->set("NEW_STYLE", static_cast<int>(newStyle)); | ||
3251 | 2616 | undoManager->action(this, ss); | ||
3252 | 2617 | } | ||
3253 | 2618 | PLineJoin = newStyle; | ||
3254 | 2619 | } | ||
3255 | 2620 | |||
3256 | 2621 | void PageItem::setCustomLineStyle(const QString& newStyle) | ||
3257 | 2622 | { | ||
3258 | 2623 | if (NamedLStyle == newStyle) | ||
3259 | 2624 | return; // nothing to do -> return | ||
3260 | 2625 | if (UndoManager::undoEnabled()) | ||
3261 | 2626 | { | ||
3262 | 2627 | QString oldStyle = NamedLStyle.isEmpty() ? Um::NoStyle : NamedLStyle; | ||
3263 | 2628 | QString nStyle = newStyle.isEmpty() ? Um::NoStyle : newStyle; | ||
3264 | 2629 | QString action = newStyle.isEmpty() ? Um::NoLineStyle : Um::CustomLineStyle; | ||
3265 | 2630 | SimpleState *ss = new SimpleState(action, | ||
3266 | 2631 | QString(Um::FromTo).arg(oldStyle).arg(nStyle),Um::ILineStyle); | ||
3267 | 2632 | ss->set("CUSTOM_LINE_STYLE", "customlinestyle"); | ||
3268 | 2633 | ss->set("OLD_STYLE", NamedLStyle); | ||
3269 | 2634 | ss->set("NEW_STYLE", newStyle); | ||
3270 | 2635 | undoManager->action(this, ss); | ||
3271 | 2636 | } | ||
3272 | 2637 | NamedLStyle = newStyle; | ||
3273 | 2638 | } | ||
3274 | 2639 | |||
3275 | 2640 | void PageItem::setStartArrowIndex(int newIndex) | ||
3276 | 2641 | { | ||
3277 | 2642 | if (m_startArrowIndex == newIndex) | ||
3278 | 2643 | return; // nothing to do -> return | ||
3279 | 2644 | if (UndoManager::undoEnabled()) | ||
3280 | 2645 | { | ||
3281 | 2646 | SimpleState *ss = new SimpleState(Um::StartArrow,"",Um::IArrow); | ||
3282 | 2647 | ss->set("START_ARROW", "startarrow"); | ||
3283 | 2648 | ss->set("OLD_INDEX", m_startArrowIndex); | ||
3284 | 2649 | ss->set("NEW_INDEX", newIndex); | ||
3285 | 2650 | undoManager->action(this, ss); | ||
3286 | 2651 | } | ||
3287 | 2652 | m_startArrowIndex = newIndex; | ||
3288 | 2653 | } | ||
3289 | 2654 | |||
3290 | 2655 | void PageItem::setEndArrowIndex(int newIndex) | ||
3291 | 2656 | { | ||
3292 | 2657 | if (m_endArrowIndex == newIndex) | ||
3293 | 2658 | return; // nothing to do -> return | ||
3294 | 2659 | if (UndoManager::undoEnabled()) | ||
3295 | 2660 | { | ||
3296 | 2661 | SimpleState *ss = new SimpleState(Um::EndArrow,"",Um::IArrow); | ||
3297 | 2662 | ss->set("END_ARROW", "endarrow"); | ||
3298 | 2663 | ss->set("OLD_INDEX", m_endArrowIndex); | ||
3299 | 2664 | ss->set("NEW_INDEX", newIndex); | ||
3300 | 2665 | undoManager->action(this, ss); | ||
3301 | 2666 | } | ||
3302 | 2667 | m_endArrowIndex = newIndex; | ||
3303 | 2668 | } | ||
3304 | 2669 | |||
3305 | 2670 | void PageItem::setImageFlippedH(bool flipped) | ||
3306 | 2671 | { | ||
3307 | 2672 | if (flipped != m_ImageIsFlippedH) | ||
3308 | 2673 | flipImageH(); | ||
3309 | 2674 | } | ||
3310 | 2675 | |||
3311 | 2676 | void PageItem::flipImageH() | ||
3312 | 2677 | { | ||
3313 | 2678 | if (UndoManager::undoEnabled()) | ||
3314 | 2679 | { | ||
3315 | 2680 | SimpleState *ss = new SimpleState(Um::FlipH, 0, Um::IFlipH); | ||
3316 | 2681 | ss->set("IMAGEFLIPH", "imagefliph"); | ||
3317 | 2682 | undoManager->action(this, ss); | ||
3318 | 2683 | } | ||
3319 | 2684 | m_ImageIsFlippedH = !m_ImageIsFlippedH; | ||
3320 | 2685 | emit frameFlippedH(m_ImageIsFlippedH); | ||
3321 | 2686 | } | ||
3322 | 2687 | |||
3323 | 2688 | void PageItem::setImageFlippedV(bool flipped) | ||
3324 | 2689 | { | ||
3325 | 2690 | if (flipped != m_ImageIsFlippedV) | ||
3326 | 2691 | flipImageV(); | ||
3327 | 2692 | } | ||
3328 | 2693 | |||
3329 | 2694 | void PageItem::flipImageV() | ||
3330 | 2695 | { | ||
3331 | 2696 | if (UndoManager::undoEnabled()) | ||
3332 | 2697 | { | ||
3333 | 2698 | SimpleState *ss = new SimpleState(Um::FlipV, 0, Um::IFlipV); | ||
3334 | 2699 | ss->set("IMAGEFLIPV", "imageflipv"); | ||
3335 | 2700 | undoManager->action(this, ss); | ||
3336 | 2701 | } | ||
3337 | 2702 | m_ImageIsFlippedV = !m_ImageIsFlippedV; | ||
3338 | 2703 | emit frameFlippedV(m_ImageIsFlippedV); | ||
3339 | 2704 | } | ||
3340 | 2705 | |||
3341 | 2706 | void PageItem::setImageScalingMode(bool freeScale, bool keepRatio) | ||
3342 | 2707 | { | ||
3343 | 2708 | if (ScaleType == freeScale && AspectRatio == keepRatio) | ||
3344 | 2709 | return; | ||
3345 | 2710 | if (UndoManager::undoEnabled()) | ||
3346 | 2711 | { | ||
3347 | 2712 | QString from = ScaleType ? Um::FreeScaling : Um::FrameSize; | ||
3348 | 2713 | from += ", "; | ||
3349 | 2714 | from += AspectRatio ? Um::KeepRatio : Um::BreakRatio; | ||
3350 | 2715 | QString to = freeScale ? Um::FreeScaling : Um::FrameSize; | ||
3351 | 2716 | to += ", "; | ||
3352 | 2717 | to += keepRatio ? Um::KeepRatio : Um::BreakRatio; | ||
3353 | 2718 | SimpleState *ss = new SimpleState(Um::ImageScaling, QString(Um::FromTo).arg(from).arg(to), Um::IImageScaling); | ||
3354 | 2719 | ss->set("SCALE_MODE", "scaling_mode"); | ||
3355 | 2720 | if (freeScale != ScaleType) | ||
3356 | 2721 | { | ||
3357 | 2722 | ss->set("SCALE_TYPE", freeScale); | ||
3358 | 2723 | if (!freeScale) | ||
3359 | 2724 | { | ||
3360 | 2725 | //if switching from free scaling to frame size | ||
3361 | 2726 | //in undo must be offset and scale saved | ||
3362 | 2727 | ss->set("OLD_IMAGEXOFFSET", LocalX); | ||
3363 | 2728 | ss->set("OLD_IMAGEYOFFSET", LocalY); | ||
3364 | 2729 | ss->set("OLD_IMAGEXSCALE", LocalScX); | ||
3365 | 2730 | ss->set("OLD_IMAGEYSCALE", LocalScY); | ||
3366 | 2731 | } | ||
3367 | 2732 | } | ||
3368 | 2733 | if (keepRatio != AspectRatio) | ||
3369 | 2734 | ss->set("ASPECT_RATIO", keepRatio); | ||
3370 | 2735 | undoManager->action(this, ss); | ||
3371 | 2736 | } | ||
3372 | 2737 | ScaleType = freeScale; | ||
3373 | 2738 | AspectRatio = keepRatio; | ||
3374 | 2739 | AdjustPictScale(); | ||
3375 | 2740 | update(); | ||
3376 | 2741 | } | ||
3377 | 2742 | |||
3378 | 2743 | void PageItem::toggleLock() | ||
3379 | 2744 | { | ||
3380 | 2745 | if (UndoManager::undoEnabled()) | ||
3381 | 2746 | { | ||
3382 | 2747 | SimpleState *ss; | ||
3383 | 2748 | if (m_Locked) | ||
3384 | 2749 | ss = new SimpleState(Um::UnLock, 0, Um::IUnLock); | ||
3385 | 2750 | else | ||
3386 | 2751 | ss = new SimpleState(Um::Lock, 0, Um::ILock); | ||
3387 | 2752 | ss->set("LOCK", "lock"); | ||
3388 | 2753 | undoManager->action(this, ss); | ||
3389 | 2754 | } | ||
3390 | 2755 | m_Locked = !m_Locked; | ||
3391 | 2756 | emit frameLocked(m_Locked); | ||
3392 | 2757 | } | ||
3393 | 2758 | |||
3394 | 2759 | void PageItem::setLocked(bool isLocked) | ||
3395 | 2760 | { | ||
3396 | 2761 | if (isLocked != m_Locked) | ||
3397 | 2762 | toggleLock(); | ||
3398 | 2763 | } | ||
3399 | 2764 | |||
3400 | 2765 | void PageItem::setGroupsLastItem(PageItem* item) | ||
3401 | 2766 | { | ||
3402 | 2767 | if (UndoManager::undoEnabled()) | ||
3403 | 2768 | { | ||
3404 | 2769 | ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >("GroupsLastItem"); | ||
3405 | 2770 | is->set("GROUPS_LASTITEM", "groups_lastitem"); | ||
3406 | 2771 | is->setItem(std::pair<PageItem*, PageItem*>(this->groupsLastItem, item)); | ||
3407 | 2772 | undoManager->action(this, is); | ||
3408 | 2773 | } | ||
3409 | 2774 | groupsLastItem = item; | ||
3410 | 2775 | } | ||
3411 | 2776 | |||
3412 | 2777 | void PageItem::toggleSizeLock() | ||
3413 | 2778 | { | ||
3414 | 2779 | if (UndoManager::undoEnabled()) | ||
3415 | 2780 | { | ||
3416 | 2781 | SimpleState *ss; | ||
3417 | 2782 | if (m_SizeLocked) | ||
3418 | 2783 | ss = new SimpleState(Um::SizeUnLock, 0, Um::IUnLock); | ||
3419 | 2784 | else | ||
3420 | 2785 | ss = new SimpleState(Um::SizeLock, 0, Um::ILock); | ||
3421 | 2786 | ss->set("SIZE_LOCK", "size_lock"); | ||
3422 | 2787 | undoManager->action(this, ss); | ||
3423 | 2788 | } | ||
3424 | 2789 | m_SizeLocked = !m_SizeLocked; | ||
3425 | 2790 | emit frameSizeLocked(m_SizeLocked); | ||
3426 | 2791 | } | ||
3427 | 2792 | |||
3428 | 2793 | void PageItem::setSizeLocked(bool isLocked) | ||
3429 | 2794 | { | ||
3430 | 2795 | if (isLocked != m_SizeLocked) | ||
3431 | 2796 | toggleSizeLock(); | ||
3432 | 2797 | } | ||
3433 | 2798 | |||
3434 | 2799 | |||
3435 | 2800 | void PageItem::setPrintEnabled(bool toPrint) | ||
3436 | 2801 | { | ||
3437 | 2802 | if (toPrint != m_PrintEnabled) | ||
3438 | 2803 | togglePrintEnabled(); | ||
3439 | 2804 | } | ||
3440 | 2805 | |||
3441 | 2806 | void PageItem::togglePrintEnabled() | ||
3442 | 2807 | { | ||
3443 | 2808 | if (UndoManager::undoEnabled()) | ||
3444 | 2809 | { | ||
3445 | 2810 | SimpleState *ss; | ||
3446 | 2811 | if (m_PrintEnabled) | ||
3447 | 2812 | ss = new SimpleState(Um::DisablePrint, 0, Um::IDisablePrint); | ||
3448 | 2813 | else | ||
3449 | 2814 | ss = new SimpleState(Um::EnablePrint, 0, Um::IEnablePrint); | ||
3450 | 2815 | ss->set("PRINT_ENABLED", "print_enabled"); | ||
3451 | 2816 | undoManager->action(this, ss); | ||
3452 | 2817 | } | ||
3453 | 2818 | m_PrintEnabled=!m_PrintEnabled; | ||
3454 | 2819 | emit printEnabled(m_PrintEnabled); | ||
3455 | 2820 | } | ||
3456 | 2821 | |||
3457 | 2822 | void PageItem::setTextFlowMode(TextFlowMode mode) | ||
3458 | 2823 | { | ||
3459 | 2824 | if (textFlowModeVal == mode) | ||
3460 | 2825 | return; | ||
3461 | 2826 | if (UndoManager::undoEnabled()) | ||
3462 | 2827 | { | ||
3463 | 2828 | QString stateMessage; | ||
3464 | 2829 | if( mode == TextFlowUsesFrameShape ) | ||
3465 | 2830 | stateMessage = Um::ObjectFrame; | ||
3466 | 2831 | else if( mode == TextFlowUsesBoundingBox ) | ||
3467 | 2832 | stateMessage = Um::BoundingBox; | ||
3468 | 2833 | else if( mode == TextFlowUsesContourLine ) | ||
3469 | 2834 | stateMessage = Um::ContourLine; | ||
3470 | 2835 | else if( mode == TextFlowUsesImageClipping ) | ||
3471 | 2836 | stateMessage = Um::ImageClip; | ||
3472 | 2837 | else | ||
3473 | 2838 | stateMessage = Um::NoTextFlow; | ||
3474 | 2839 | SimpleState *ss = new SimpleState(stateMessage, "", Um::IFont); | ||
3475 | 2840 | ss->set("TEXTFLOW_OLDMODE", (int) textFlowModeVal); | ||
3476 | 2841 | ss->set("TEXTFLOW_NEWMODE", (int) mode); | ||
3477 | 2842 | undoManager->action(this, ss); | ||
3478 | 2843 | } | ||
3479 | 2844 | textFlowModeVal = mode; | ||
3480 | 2845 | |||
3481 | 2846 | checkTextFlowInteractions(); | ||
3482 | 2847 | } | ||
3483 | 2848 | |||
3484 | 2849 | void PageItem::checkTextFlowInteractions(bool allItems) | ||
3485 | 2850 | { | ||
3486 | 2851 | if(!m_Doc->isLoading()) | ||
3487 | 2852 | { | ||
3488 | 2853 | QRectF baseRect(getBoundingRect()); | ||
3489 | 2854 | QList<PageItem*>* items = OnMasterPage.isEmpty() ? &m_Doc->DocItems : &m_Doc->MasterItems; | ||
3490 | 2855 | for(int idx = (allItems ? items->count()-1 : ItemNr-1); idx >= 0 ; --idx) | ||
3491 | 2856 | { | ||
3492 | 2857 | if(idx != static_cast<int>(ItemNr)) // avoids itself | ||
3493 | 2858 | { | ||
3494 | 2859 | if(items->at(idx)->asTextFrame()) // do not bother with no text frames | ||
3495 | 2860 | { | ||
3496 | 2861 | QRectF uRect(items->at(idx)->getBoundingRect()); | ||
3497 | 2862 | if(baseRect.intersects(uRect)) | ||
3498 | 2863 | { | ||
3499 | 2864 | items->at(idx)->update(); | ||
3500 | 2865 | } | ||
3501 | 2866 | } | ||
3502 | 2867 | } | ||
3503 | 2868 | } | ||
3504 | 2869 | } | ||
3505 | 2870 | } | ||
3506 | 2871 | |||
3507 | 2872 | void PageItem::convertTo(ItemType newType) | ||
3508 | 2873 | { | ||
3509 | 2874 | if (m_ItemType == newType) | ||
3510 | 2875 | return; // nothing to do -> return | ||
3511 | 2876 | assert(newType != 1); //DEBUG CR 2005-02-06 | ||
3512 | 2877 | assert(newType != 3); //DEBUG CR 2005-02-06 | ||
3513 | 2878 | QString fromType = "", toType = ""; | ||
3514 | 2879 | switch (m_ItemType) | ||
3515 | 2880 | { | ||
3516 | 2881 | case ImageFrame: | ||
3517 | 2882 | if (asLatexFrame()) { | ||
3518 | 2883 | fromType = Um::LatexFrame; | ||
3519 | 2884 | } else { | ||
3520 | 2885 | fromType = Um::ImageFrame; | ||
3521 | 2886 | } | ||
3522 | 2887 | break; | ||
3523 | 2888 | case TextFrame: | ||
3524 | 2889 | fromType = Um::TextFrame; | ||
3525 | 2890 | break; | ||
3526 | 2891 | case Polygon: | ||
3527 | 2892 | fromType = Um::Polygon; | ||
3528 | 2893 | break; | ||
3529 | 2894 | default: | ||
3530 | 2895 | fromType = ""; | ||
3531 | 2896 | break; | ||
3532 | 2897 | } | ||
3533 | 2898 | switch (newType) | ||
3534 | 2899 | { | ||
3535 | 2900 | case ImageFrame: | ||
3536 | 2901 | toType = Um::ImageFrame; | ||
3537 | 2902 | setUPixmap(Um::IImageFrame); | ||
3538 | 2903 | break; | ||
3539 | 2904 | case LatexFrame: | ||
3540 | 2905 | toType = Um::LatexFrame; | ||
3541 | 2906 | setUPixmap(Um::ILatexFrame); | ||
3542 | 2907 | break; | ||
3543 | 2908 | case TextFrame: | ||
3544 | 2909 | toType = Um::TextFrame; | ||
3545 | 2910 | setUPixmap(Um::ITextFrame); | ||
3546 | 2911 | break; | ||
3547 | 2912 | case Polygon: | ||
3548 | 2913 | toType = Um::Polygon; | ||
3549 | 2914 | setUPixmap(Um::IPolygon); | ||
3550 | 2915 | break; | ||
3551 | 2916 | case PolyLine: | ||
3552 | 2917 | toType = Um::Polyline; | ||
3553 | 2918 | setUPixmap(Um::IPolyline); | ||
3554 | 2919 | break; | ||
3555 | 2920 | default: | ||
3556 | 2921 | toType = ""; | ||
3557 | 2922 | setUPixmap(NULL); | ||
3558 | 2923 | break; | ||
3559 | 2924 | } | ||
3560 | 2925 | /* | ||
3561 | 2926 | if (UndoManager::undoEnabled()) | ||
3562 | 2927 | { | ||
3563 | 2928 | SimpleState *ss = new SimpleState(Um::ConvertTo + " " + toType, | ||
3564 | 2929 | QString(Um::FromTo).arg(fromType).arg(toType)); | ||
3565 | 2930 | ss->set("CONVERT", "convert"); | ||
3566 | 2931 | ss->set("PAGEITEM", reinterpret_cast<int>(this)); | ||
3567 | 2932 | ss->set("OLD_TYPE", m_ItemType); | ||
3568 | 2933 | ss->set("NEW_TYPE", newType); | ||
3569 | 2934 | undoManager->action(this, ss); | ||
3570 | 2935 | } | ||
3571 | 2936 | */ | ||
3572 | 2937 | m_ItemType = newType; | ||
3573 | 2938 | emit frameType(m_ItemType); | ||
3574 | 2939 | } | ||
3575 | 2940 | |||
3576 | 2941 | void PageItem::setLayer(int layerId) | ||
3577 | 2942 | { | ||
3578 | 2943 | if (LayerNr == layerId) | ||
3579 | 2944 | return; | ||
3580 | 2945 | if (UndoManager::undoEnabled()) | ||
3581 | 2946 | { | ||
3582 | 2947 | SimpleState *ss = new SimpleState(Um::SendToLayer, | ||
3583 | 2948 | QString(Um::FromTo).arg(LayerNr).arg(layerId), | ||
3584 | 2949 | Um::ILayerAction); | ||
3585 | 2950 | ss->set("SEND_TO_LAYER", "send_to_layer"); | ||
3586 | 2951 | ss->set("OLD_LAYER", LayerNr); | ||
3587 | 2952 | ss->set("NEW_LAYER", layerId); | ||
3588 | 2953 | undoManager->action(this, ss); | ||
3589 | 2954 | } | ||
3590 | 2955 | LayerNr = layerId; | ||
3591 | 2956 | } | ||
3592 | 2957 | |||
3593 | 2958 | void PageItem::checkChanges(bool force) | ||
3594 | 2959 | { | ||
3595 | 2960 | bool spreadChanges(false); | ||
3596 | 2961 | // has the item been resized | ||
3597 | 2962 | if (force || ((oldWidth != Width || oldHeight != Height) && shouldCheck())) | ||
3598 | 2963 | { | ||
3599 | 2964 | resizeUndoAction(); | ||
3600 | 2965 | spreadChanges = (textFlowMode() != TextFlowDisabled ); | ||
3601 | 2966 | } | ||
3602 | 2967 | // has the item been rotated | ||
3603 | 2968 | if (force || ((oldRot != Rot) && (shouldCheck()))) | ||
3604 | 2969 | { | ||
3605 | 2970 | rotateUndoAction(); | ||
3606 | 2971 | spreadChanges = (textFlowMode() != TextFlowDisabled ); | ||
3607 | 2972 | } | ||
3608 | 2973 | // has the item been moved | ||
3609 | 2974 | if (force || ((oldXpos != Xpos || oldYpos != Ypos) && shouldCheck())) | ||
3610 | 2975 | { | ||
3611 | 2976 | moveUndoAction(); | ||
3612 | 2977 | spreadChanges = (textFlowMode() != TextFlowDisabled ); | ||
3613 | 2978 | } | ||
3614 | 2979 | // has the item's image been moved | ||
3615 | 2980 | if (force || ((oldLocalX != LocalX || oldLocalY != LocalY) && shouldCheck())) | ||
3616 | 2981 | changeImageOffsetUndoAction(); | ||
3617 | 2982 | // has the item's image been scaled | ||
3618 | 2983 | if (force || ((oldLocalScX != LocalScX || oldLocalScY != LocalScY) && shouldCheck())) | ||
3619 | 2984 | changeImageScaleUndoAction(); | ||
3620 | 2985 | |||
3621 | 2986 | if(spreadChanges) | ||
3622 | 2987 | { | ||
3623 | 2988 | checkTextFlowInteractions(); | ||
3624 | 2989 | } | ||
3625 | 2990 | } | ||
3626 | 2991 | |||
3627 | 2992 | bool PageItem::shouldCheck() | ||
3628 | 2993 | { | ||
3629 | 2994 | return ((!m_Doc->view()->mousePressed()) && | ||
3630 | 2995 | (!ScCore->primaryMainWindow()->arrowKeyDown()) && | ||
3631 | 2996 | (!ScCore->primaryMainWindow()->propertiesPalette->userActionOn())); | ||
3632 | 2997 | } | ||
3633 | 2998 | |||
3634 | 2999 | void PageItem::moveUndoAction() | ||
3635 | 3000 | { | ||
3636 | 3001 | if (oldXpos == Xpos && oldYpos == Ypos) | ||
3637 | 3002 | return; | ||
3638 | 3003 | if (UndoManager::undoEnabled()) | ||
3639 | 3004 | { | ||
3640 | 3005 | QString oldp; | ||
3641 | 3006 | QString newp; | ||
3642 | 3007 | if (oldOwnPage == -1) | ||
3643 | 3008 | oldp = Um::ScratchSpace; | ||
3644 | 3009 | else | ||
3645 | 3010 | oldp = QString(Um::PageNmbr).arg(m_Doc->FirstPnum + oldOwnPage); | ||
3646 | 3011 | if (OwnPage == -1) | ||
3647 | 3012 | newp = Um::ScratchSpace; | ||
3648 | 3013 | else | ||
3649 | 3014 | newp = QString(Um::PageNmbr).arg(m_Doc->FirstPnum + OwnPage); | ||
3650 | 3015 | SimpleState *ss = new SimpleState(Um::Move, | ||
3651 | 3016 | QString(Um::MoveFromTo).arg(oldXpos).arg(oldYpos).arg(oldp). | ||
3652 | 3017 | arg(Xpos).arg(Ypos).arg(newp), Um::IMove); | ||
3653 | 3018 | ss->set("OLD_XPOS", oldXpos); | ||
3654 | 3019 | ss->set("OLD_YPOS", oldYpos); | ||
3655 | 3020 | ss->set("NEW_XPOS", Xpos); | ||
3656 | 3021 | ss->set("NEW_YPOS", Ypos); | ||
3657 | 3022 | undoManager->action(this, ss); | ||
3658 | 3023 | } | ||
3659 | 3024 | oldXpos = Xpos; | ||
3660 | 3025 | oldYpos = Ypos; | ||
3661 | 3026 | oldOwnPage = OwnPage; | ||
3662 | 3027 | } | ||
3663 | 3028 | |||
3664 | 3029 | void PageItem::resizeUndoAction() | ||
3665 | 3030 | { | ||
3666 | 3031 | if (oldHeight == Height && oldWidth == Width) | ||
3667 | 3032 | return; | ||
3668 | 3033 | if (UndoManager::undoEnabled()) | ||
3669 | 3034 | { | ||
3670 | 3035 | SimpleState *ss = new SimpleState(Um::Resize, | ||
3671 | 3036 | QString(Um::ResizeFromTo).arg(oldWidth).arg(oldHeight).arg(Width).arg(Height), | ||
3672 | 3037 | Um::IResize); | ||
3673 | 3038 | ss->set("OLD_WIDTH", oldWidth); | ||
3674 | 3039 | ss->set("OLD_HEIGHT", oldHeight); | ||
3675 | 3040 | ss->set("NEW_WIDTH", Width); | ||
3676 | 3041 | ss->set("NEW_HEIGHT", Height); | ||
3677 | 3042 | ss->set("OLD_RXPOS", oldXpos); | ||
3678 | 3043 | ss->set("OLD_RYPOS", oldYpos); | ||
3679 | 3044 | ss->set("NEW_RXPOS", Xpos); | ||
3680 | 3045 | ss->set("NEW_RYPOS", Ypos); | ||
3681 | 3046 | ss->set("OLD_RROT", oldRot); | ||
3682 | 3047 | ss->set("NEW_RROT", Rot); | ||
3683 | 3048 | undoManager->action(this, ss); | ||
3684 | 3049 | } | ||
3685 | 3050 | oldXpos = Xpos; | ||
3686 | 3051 | oldYpos = Ypos; | ||
3687 | 3052 | oldHeight = Height; | ||
3688 | 3053 | oldWidth = Width; | ||
3689 | 3054 | oldOwnPage = OwnPage; | ||
3690 | 3055 | oldRot = Rot; | ||
3691 | 3056 | } | ||
3692 | 3057 | |||
3693 | 3058 | void PageItem::rotateUndoAction() | ||
3694 | 3059 | { | ||
3695 | 3060 | if (oldRot == Rot) | ||
3696 | 3061 | return; | ||
3697 | 3062 | if (UndoManager::undoEnabled()) | ||
3698 | 3063 | { | ||
3699 | 3064 | SimpleState *ss = new SimpleState(Um::Rotate, | ||
3700 | 3065 | QString(Um::FromTo).arg(oldRot).arg(Rot), | ||
3701 | 3066 | Um::IRotate); | ||
3702 | 3067 | ss->set("OLD_ROT", oldRot); | ||
3703 | 3068 | ss->set("NEW_ROT", Rot); | ||
3704 | 3069 | ss->set("OLD_RXPOS", oldXpos); | ||
3705 | 3070 | ss->set("OLD_RYPOS", oldYpos); | ||
3706 | 3071 | ss->set("NEW_RXPOS", Xpos); | ||
3707 | 3072 | ss->set("NEW_RYPOS", Ypos); | ||
3708 | 3073 | ss->set("OLD_RWIDTH", oldWidth); | ||
3709 | 3074 | ss->set("OLD_RHEIGHT", oldHeight); | ||
3710 | 3075 | ss->set("NEW_RWIDTH", Width); | ||
3711 | 3076 | ss->set("NEW_RHEIGHT", Height); | ||
3712 | 3077 | undoManager->action(this, ss); | ||
3713 | 3078 | } | ||
3714 | 3079 | oldRot = Rot; | ||
3715 | 3080 | oldXpos = Xpos; | ||
3716 | 3081 | oldYpos = Ypos; | ||
3717 | 3082 | oldOwnPage = OwnPage; | ||
3718 | 3083 | oldWidth = Width; | ||
3719 | 3084 | oldHeight = Height; | ||
3720 | 3085 | } | ||
3721 | 3086 | |||
3722 | 3087 | void PageItem::changeImageOffsetUndoAction() | ||
3723 | 3088 | { | ||
3724 | 3089 | if (oldLocalX == LocalX && oldLocalY == LocalY) | ||
3725 | 3090 | return; | ||
3726 | 3091 | if (UndoManager::undoEnabled()) | ||
3727 | 3092 | { | ||
3728 | 3093 | SimpleState *ss = new SimpleState(Um::ImageOffset, | ||
3729 | 3094 | QString(Um::ImageOffsetFromTo).arg(oldLocalX).arg(oldLocalY).arg(LocalX).arg(LocalY), Um::IMove); | ||
3730 | 3095 | ss->set("IMAGE_OFFSET", "image_offset"); | ||
3731 | 3096 | ss->set("OLD_IMAGEXOFFSET", oldLocalX); | ||
3732 | 3097 | ss->set("OLD_IMAGEYOFFSET", oldLocalY); | ||
3733 | 3098 | ss->set("NEW_IMAGEXOFFSET", LocalX); | ||
3734 | 3099 | ss->set("NEW_IMAGEYOFFSET", LocalY); | ||
3735 | 3100 | undoManager->action(this, ss); | ||
3736 | 3101 | } | ||
3737 | 3102 | oldLocalX = LocalX; | ||
3738 | 3103 | oldLocalY = LocalY; | ||
3739 | 3104 | } | ||
3740 | 3105 | |||
3741 | 3106 | void PageItem::changeImageScaleUndoAction() | ||
3742 | 3107 | { | ||
3743 | 3108 | //#9817: Hack for this rounding issue caused by conversion to text values. Undo needs fixing. | ||
3744 | 3109 | if ((ScCLocale::toDoubleC(ScCLocale::toQStringC(oldLocalScX)) == | ||
3745 | 3110 | ScCLocale::toDoubleC(ScCLocale::toQStringC(LocalScX))) | ||
3746 | 3111 | && (ScCLocale::toDoubleC(ScCLocale::toQStringC(oldLocalScY)) == | ||
3747 | 3112 | ScCLocale::toDoubleC(ScCLocale::toQStringC(LocalScY)))) | ||
3748 | 3113 | return; | ||
3749 | 3114 | if (UndoManager::undoEnabled()) | ||
3750 | 3115 | { | ||
3751 | 3116 | SimpleState *ss = new SimpleState(Um::ImageScale, | ||
3752 | 3117 | QString(Um::ImageScaleFromTo).arg(oldLocalScX).arg(oldLocalScY).arg(LocalScX).arg(LocalScY), Um::IMove); | ||
3753 | 3118 | ss->set("IMAGE_SCALE", "image_scale"); | ||
3754 | 3119 | ss->set("OLD_IMAGEXSCALE", oldLocalScX); | ||
3755 | 3120 | ss->set("OLD_IMAGEYSCALE", oldLocalScY); | ||
3756 | 3121 | ss->set("NEW_IMAGEXSCALE", LocalScX); | ||
3757 | 3122 | ss->set("NEW_IMAGEYSCALE", LocalScY); | ||
3758 | 3123 | undoManager->action(this, ss); | ||
3759 | 3124 | } | ||
3760 | 3125 | oldLocalScX = LocalScX; | ||
3761 | 3126 | oldLocalScY = LocalScY; | ||
3762 | 3127 | } | ||
3763 | 3128 | |||
3764 | 3129 | void PageItem::restore(UndoState *state, bool isUndo) | ||
3765 | 3130 | { | ||
3766 | 3131 | bool useRasterBackup = m_Doc->useRaster; | ||
3767 | 3132 | bool SnapGuidesBackup = m_Doc->SnapGuides; | ||
3768 | 3133 | m_Doc->useRaster = false; | ||
3769 | 3134 | m_Doc->SnapGuides = false; | ||
3770 | 3135 | SimpleState *ss = dynamic_cast<SimpleState*>(state); | ||
3771 | 3136 | bool oldMPMode=m_Doc->masterPageMode(); | ||
3772 | 3137 | m_Doc->setMasterPageMode(!OnMasterPage.isEmpty()); | ||
3773 | 3138 | Page *oldCurrentPage = m_Doc->currentPage(); | ||
3774 | 3139 | if (!OnMasterPage.isEmpty()) | ||
3775 | 3140 | { | ||
3776 | 3141 | oldCurrentPage = m_Doc->currentPage(); | ||
3777 | 3142 | m_Doc->setCurrentPage(m_Doc->MasterPages.at(m_Doc->MasterNames[OnMasterPage])); | ||
3778 | 3143 | } | ||
3779 | 3144 | if (ss) | ||
3780 | 3145 | { | ||
3781 | 3146 | if (ss->contains("OLD_XPOS")) | ||
3782 | 3147 | restoreMove(ss, isUndo); | ||
3783 | 3148 | else if (ss->contains("OLD_HEIGHT")) | ||
3784 | 3149 | restoreResize(ss, isUndo); | ||
3785 | 3150 | else if (ss->contains("OLD_ROT")) | ||
3786 | 3151 | restoreRotate(ss, isUndo); | ||
3787 | 3152 | else if (ss->contains("FILL")) | ||
3788 | 3153 | restoreFill(ss, isUndo); | ||
3789 | 3154 | else if (ss->contains("SHADE")) | ||
3790 | 3155 | restoreShade(ss, isUndo); | ||
3791 | 3156 | else if (ss->contains("LINE_COLOR")) | ||
3792 | 3157 | restoreLineColor(ss, isUndo); | ||
3793 | 3158 | else if (ss->contains("LINE_SHADE")) | ||
3794 | 3159 | restoreLineShade(ss, isUndo); | ||
3795 | 3160 | else if (ss->contains("IMAGEFLIPH")) | ||
3796 | 3161 | { | ||
3797 | 3162 | select(); | ||
3798 | 3163 | m_Doc->itemSelection_FlipH(); | ||
3799 | 3164 | } | ||
3800 | 3165 | else if (ss->contains("IMAGEFLIPV")) | ||
3801 | 3166 | { | ||
3802 | 3167 | select(); | ||
3803 | 3168 | m_Doc->itemSelection_FlipV(); | ||
3804 | 3169 | } | ||
3805 | 3170 | else if (ss->contains("LOCK")) | ||
3806 | 3171 | { | ||
3807 | 3172 | select(); | ||
3808 | 3173 | m_Doc->itemSelection_ToggleLock(); | ||
3809 | 3174 | } | ||
3810 | 3175 | else if (ss->contains("SIZE_LOCK")) | ||
3811 | 3176 | { | ||
3812 | 3177 | select(); | ||
3813 | 3178 | m_Doc->itemSelection_ToggleSizeLock(); | ||
3814 | 3179 | } | ||
3815 | 3180 | else if (ss->contains("PRINT_ENABLED")) | ||
3816 | 3181 | { | ||
3817 | 3182 | select(); | ||
3818 | 3183 | m_Doc->itemSelection_TogglePrintEnabled(); | ||
3819 | 3184 | } | ||
3820 | 3185 | else if (ss->contains("NEW_NAME")) | ||
3821 | 3186 | restoreName(ss, isUndo); | ||
3822 | 3187 | else if (ss->contains("TRANSPARENCY")) | ||
3823 | 3188 | restoreFillTP(ss, isUndo); | ||
3824 | 3189 | else if (ss->contains("LINE_TRANSPARENCY")) | ||
3825 | 3190 | restoreLineTP(ss, isUndo); | ||
3826 | 3191 | else if (ss->contains("LINE_STYLE")) | ||
3827 | 3192 | restoreLineStyle(ss, isUndo); | ||
3828 | 3193 | else if (ss->contains("LINE_END")) | ||
3829 | 3194 | restoreLineEnd(ss, isUndo); | ||
3830 | 3195 | else if (ss->contains("LINE_JOIN")) | ||
3831 | 3196 | restoreLineJoin(ss, isUndo); | ||
3832 | 3197 | else if (ss->contains("LINE_WIDTH")) | ||
3833 | 3198 | restoreLineWidth(ss, isUndo); | ||
3834 | 3199 | else if (ss->contains("CUSTOM_LINE_STYLE")) | ||
3835 | 3200 | restoreCustomLineStyle(ss, isUndo); | ||
3836 | 3201 | else if (ss->contains("START_ARROW")) | ||
3837 | 3202 | restoreArrow(ss, isUndo, true); | ||
3838 | 3203 | else if (ss->contains("END_ARROW")) | ||
3839 | 3204 | restoreArrow(ss, isUndo, false); | ||
3840 | 3205 | else if (ss->contains("PSTYLE")) | ||
3841 | 3206 | restorePStyle(ss, isUndo); | ||
3842 | 3207 | else if (ss->contains("CONVERT")) | ||
3843 | 3208 | restoreType(ss, isUndo); | ||
3844 | 3209 | else if (ss->contains("TEXTFLOW_OLDMODE")) | ||
3845 | 3210 | restoreTextFlowing(ss, isUndo); | ||
3846 | 3211 | else if (ss->contains("SCALE_MODE")) | ||
3847 | 3212 | restoreImageScaleMode(ss, isUndo); | ||
3848 | 3213 | else if (ss->contains("IMAGE_SCALE")) | ||
3849 | 3214 | restoreImageScaleChange(ss, isUndo); | ||
3850 | 3215 | else if (ss->contains("IMAGE_OFFSET")) | ||
3851 | 3216 | restoreImageOffsetChange(ss, isUndo); | ||
3852 | 3217 | else if (ss->contains("EDIT_CONTOUR")) | ||
3853 | 3218 | restorePoly(ss, isUndo, true); | ||
3854 | 3219 | else if (ss->contains("EDIT_SHAPE")) | ||
3855 | 3220 | restorePoly(ss, isUndo, false); | ||
3856 | 3221 | else if (ss->contains("RESET_CONTOUR")) | ||
3857 | 3222 | restoreContourLine(ss, isUndo); | ||
3858 | 3223 | else if (ss->contains("CHANGE_SHAPE_TYPE")) | ||
3859 | 3224 | restoreShapeType(ss, isUndo); | ||
3860 | 3225 | else if (ss->contains("MIRROR_PATH_H")) | ||
3861 | 3226 | { | ||
3862 | 3227 | bool editContour = m_Doc->nodeEdit.isContourLine; | ||
3863 | 3228 | m_Doc->nodeEdit.isContourLine = ss->getBool("IS_CONTOUR"); | ||
3864 | 3229 | select(); | ||
3865 | 3230 | m_Doc->MirrorPolyH(m_Doc->m_Selection->itemAt(0)); | ||
3866 | 3231 | m_Doc->nodeEdit.isContourLine = editContour; | ||
3867 | 3232 | } | ||
3868 | 3233 | else if (ss->contains("MIRROR_PATH_V")) | ||
3869 | 3234 | { | ||
3870 | 3235 | bool editContour = m_Doc->nodeEdit.isContourLine; | ||
3871 | 3236 | m_Doc->nodeEdit.isContourLine = ss->getBool("IS_CONTOUR"); | ||
3872 | 3237 | select(); | ||
3873 | 3238 | m_Doc->MirrorPolyV(m_Doc->m_Selection->itemAt(0)); | ||
3874 | 3239 | m_Doc->nodeEdit.isContourLine = editContour; | ||
3875 | 3240 | } | ||
3876 | 3241 | else if (ss->contains("SEND_TO_LAYER")) | ||
3877 | 3242 | restoreLayer(ss, isUndo); | ||
3878 | 3243 | else if (ss->contains("GET_IMAGE")) | ||
3879 | 3244 | restoreGetImage(ss, isUndo); | ||
3880 | 3245 | else if (ss->contains("GROUPS_LASTITEM")) | ||
3881 | 3246 | restoreGroupsLastItem(ss, isUndo); | ||
3882 | 3247 | else if (ss->contains("EDIT_SHAPE_OR_CONTOUR")) | ||
3883 | 3248 | restoreShapeContour(ss, isUndo); | ||
3884 | 3249 | else if (ss->contains("APPLY_IMAGE_EFFECTS")) | ||
3885 | 3250 | restoreImageEffects(ss, isUndo); | ||
3886 | 3251 | else if (ss->contains("STEXT")) | ||
3887 | 3252 | restoreEditText(ss, isUndo); | ||
3888 | 3253 | else if (ss->contains("CLEAR_IMAGE")) | ||
3889 | 3254 | restoreClearImage(ss,isUndo); | ||
3890 | 3255 | else if (ss->contains("LINK_TEXT_FRAME")) | ||
3891 | 3256 | restoreLinkTextFrame(ss,isUndo); | ||
3892 | 3257 | else if (ss->contains("UNLINK_TEXT_FRAME")) | ||
3893 | 3258 | restoreUnlinkTextFrame(ss,isUndo); | ||
3894 | 3259 | } | ||
3895 | 3260 | if (!OnMasterPage.isEmpty()) | ||
3896 | 3261 | m_Doc->setCurrentPage(oldCurrentPage); | ||
3897 | 3262 | m_Doc->setMasterPageMode(oldMPMode); | ||
3898 | 3263 | m_Doc->useRaster = useRasterBackup; | ||
3899 | 3264 | m_Doc->SnapGuides = SnapGuidesBackup; | ||
3900 | 3265 | } | ||
3901 | 3266 | |||
3902 | 3267 | void PageItem::restoreMove(SimpleState *state, bool isUndo) | ||
3903 | 3268 | { | ||
3904 | 3269 | double ox = state->getDouble("OLD_XPOS"); | ||
3905 | 3270 | double oy = state->getDouble("OLD_YPOS"); | ||
3906 | 3271 | double x = state->getDouble("NEW_XPOS"); | ||
3907 | 3272 | double y = state->getDouble("NEW_YPOS"); | ||
3908 | 3273 | double mx = ox - x; | ||
3909 | 3274 | double my = oy - y; | ||
3910 | 3275 | if (!isUndo) | ||
3911 | 3276 | { | ||
3912 | 3277 | mx = -mx; | ||
3913 | 3278 | my = -my; | ||
3914 | 3279 | } | ||
3915 | 3280 | m_Doc->MoveItem(mx, my, this, false); | ||
3916 | 3281 | oldXpos = Xpos; | ||
3917 | 3282 | oldYpos = Ypos; | ||
3918 | 3283 | oldOwnPage = OwnPage; | ||
3919 | 3284 | } | ||
3920 | 3285 | |||
3921 | 3286 | void PageItem::restoreResize(SimpleState *state, bool isUndo) | ||
3922 | 3287 | { | ||
3923 | 3288 | double ow = state->getDouble("OLD_WIDTH"); | ||
3924 | 3289 | double oh = state->getDouble("OLD_HEIGHT"); | ||
3925 | 3290 | double w = state->getDouble("NEW_WIDTH"); | ||
3926 | 3291 | double h = state->getDouble("NEW_HEIGHT"); | ||
3927 | 3292 | double ox = state->getDouble("OLD_RXPOS"); | ||
3928 | 3293 | double oy = state->getDouble("OLD_RYPOS"); | ||
3929 | 3294 | double x = state->getDouble("NEW_RXPOS"); | ||
3930 | 3295 | double y = state->getDouble("NEW_RYPOS"); | ||
3931 | 3296 | double ort = state->getDouble("OLD_RROT"); | ||
3932 | 3297 | double rt = state->getDouble("NEW_RROT"); | ||
3933 | 3298 | double mx = ox - x; | ||
3934 | 3299 | double my = oy - y; | ||
3935 | 3300 | int stateCode = state->transactionCode; | ||
3936 | 3301 | bool redraw = ((stateCode != 1) && (stateCode != 3)); | ||
3937 | 3302 | if (isUndo) | ||
3938 | 3303 | { | ||
3939 | 3304 | m_Doc->SizeItem(ow, oh, this, false, true, redraw); | ||
3940 | 3305 | m_Doc->MoveItem(mx, my, this, false); | ||
3941 | 3306 | m_Doc->RotateItem(ort, this); | ||
3942 | 3307 | } | ||
3943 | 3308 | else | ||
3944 | 3309 | { | ||
3945 | 3310 | mx = -mx; | ||
3946 | 3311 | my = -my; | ||
3947 | 3312 | m_Doc->SizeItem(w, h, this, false, true, redraw); | ||
3948 | 3313 | m_Doc->MoveItem(mx, my, this, false); | ||
3949 | 3314 | m_Doc->RotateItem(rt, this); | ||
3950 | 3315 | } | ||
3951 | 3316 | oldWidth = Width; | ||
3952 | 3317 | oldHeight = Height; | ||
3953 | 3318 | oldXpos = Xpos; | ||
3954 | 3319 | oldYpos = Ypos; | ||
3955 | 3320 | oldOwnPage = OwnPage; | ||
3956 | 3321 | oldRot = Rot; | ||
3957 | 3322 | } | ||
3958 | 3323 | |||
3959 | 3324 | void PageItem::restoreRotate(SimpleState *state, bool isUndo) | ||
3960 | 3325 | { | ||
3961 | 3326 | double ort = state->getDouble("OLD_ROT"); | ||
3962 | 3327 | double rt = state->getDouble("NEW_ROT"); | ||
3963 | 3328 | double ox = state->getDouble("OLD_RXPOS"); | ||
3964 | 3329 | double oy = state->getDouble("OLD_RYPOS"); | ||
3965 | 3330 | double x = state->getDouble("NEW_RXPOS"); | ||
3966 | 3331 | double y = state->getDouble("NEW_RYPOS"); | ||
3967 | 3332 | double ow = state->getDouble("OLD_RWIDTH"); | ||
3968 | 3333 | double oh = state->getDouble("OLD_RHEIGHT"); | ||
3969 | 3334 | double w = state->getDouble("NEW_RWIDTH"); | ||
3970 | 3335 | double h = state->getDouble("NEW_RHEIGHT"); | ||
3971 | 3336 | int stateCode = state->transactionCode; | ||
3972 | 3337 | bool redraw = ((stateCode != 1) && (stateCode != 3));; | ||
3973 | 3338 | //CB Commented out test code | ||
3974 | 3339 | //QRect oldR(getRedrawBounding(view->scale())); | ||
3975 | 3340 | //double mx = ox - x; | ||
3976 | 3341 | //double my = oy - y; | ||
3977 | 3342 | if (isUndo) | ||
3978 | 3343 | { | ||
3979 | 3344 | /*Rot=ort; | ||
3980 | 3345 | Xpos+=mx; | ||
3981 | 3346 | Ypos+=my; | ||
3982 | 3347 | Width=ow; | ||
3983 | 3348 | Height=oh;*/ | ||
3984 | 3349 | m_Doc->RotateItem(ort, this); | ||
3985 | 3350 | m_Doc->MoveItem(ox - Xpos, oy - Ypos, this, false); | ||
3986 | 3351 | m_Doc->SizeItem(ow, oh, this, false, true, redraw); | ||
3987 | 3352 | } | ||
3988 | 3353 | else | ||
3989 | 3354 | { | ||
3990 | 3355 | /*mx = -mx; | ||
3991 | 3356 | my = -my; | ||
3992 | 3357 | Rot=rt; | ||
3993 | 3358 | Xpos-=mx; | ||
3994 | 3359 | Ypos-=my; | ||
3995 | 3360 | Width=w; | ||
3996 | 3361 | Height=h; | ||
3997 | 3362 | */ | ||
3998 | 3363 | m_Doc->RotateItem(rt, this); | ||
3999 | 3364 | m_Doc->MoveItem(x - Xpos, y - Ypos, this, false); | ||
4000 | 3365 | m_Doc->SizeItem(w, h, this, false, true, redraw); | ||
4001 | 3366 | } | ||
4002 | 3367 | /* | ||
4003 | 3368 | m_Doc->setRedrawBounding(this); | ||
4004 | 3369 | QRect newR(getRedrawBounding(view->scale())); | ||
4005 | 3370 | view->updateContents(newR.unite(oldR)); | ||
4006 | 3371 | OwnPage = m_Doc->OnPage(this); | ||
4007 | 3372 | */ | ||
4008 | 3373 | oldRot = Rot; | ||
4009 | 3374 | oldXpos = Xpos; | ||
4010 | 3375 | oldYpos = Ypos; | ||
4011 | 3376 | oldOwnPage = OwnPage; | ||
4012 | 3377 | oldWidth = Width; | ||
4013 | 3378 | oldHeight = Height; | ||
4014 | 3379 | } | ||
4015 | 3380 | |||
4016 | 3381 | void PageItem::restoreFill(SimpleState *state, bool isUndo) | ||
4017 | 3382 | { | ||
4018 | 3383 | QString fill = state->get("OLD_FILL"); | ||
4019 | 3384 | if (!isUndo) | ||
4020 | 3385 | fill = state->get("NEW_FILL"); | ||
4021 | 3386 | select(); | ||
4022 | 3387 | m_Doc->itemSelection_SetItemBrush(fill); | ||
4023 | 3388 | } | ||
4024 | 3389 | |||
4025 | 3390 | void PageItem::restoreShade(SimpleState *state, bool isUndo) | ||
4026 | 3391 | { | ||
4027 | 3392 | int shade = state->getInt("OLD_SHADE"); | ||
4028 | 3393 | if (!isUndo) | ||
4029 | 3394 | shade = state->getInt("NEW_SHADE"); | ||
4030 | 3395 | select(); | ||
4031 | 3396 | m_Doc->itemSelection_SetItemBrushShade(shade); | ||
4032 | 3397 | } | ||
4033 | 3398 | |||
4034 | 3399 | void PageItem::restoreLineColor(SimpleState *state, bool isUndo) | ||
4035 | 3400 | { | ||
4036 | 3401 | QString fill = state->get("OLD_COLOR"); | ||
4037 | 3402 | if (!isUndo) | ||
4038 | 3403 | fill = state->get("NEW_COLOR"); | ||
4039 | 3404 | select(); | ||
4040 | 3405 | m_Doc->itemSelection_SetItemPen(fill); | ||
4041 | 3406 | } | ||
4042 | 3407 | |||
4043 | 3408 | void PageItem::restoreLineShade(SimpleState *state, bool isUndo) | ||
4044 | 3409 | { | ||
4045 | 3410 | int shade = state->getInt("OLD_SHADE"); | ||
4046 | 3411 | if (!isUndo) | ||
4047 | 3412 | shade = state->getInt("NEW_SHADE"); | ||
4048 | 3413 | select(); | ||
4049 | 3414 | m_Doc->itemSelection_SetItemPenShade(shade); | ||
4050 | 3415 | } | ||
4051 | 3416 | |||
4052 | 3417 | void PageItem::restoreFillTP(SimpleState *state, bool isUndo) | ||
4053 | 3418 | { | ||
4054 | 3419 | double tp = state->getDouble("OLD_TP"); | ||
4055 | 3420 | if (!isUndo) | ||
4056 | 3421 | tp = state->getDouble("NEW_TP"); | ||
4057 | 3422 | select(); | ||
4058 | 3423 | m_Doc->itemSelection_SetItemFillTransparency(tp); | ||
4059 | 3424 | } | ||
4060 | 3425 | |||
4061 | 3426 | void PageItem::restoreLineTP(SimpleState *state, bool isUndo) | ||
4062 | 3427 | { | ||
4063 | 3428 | double tp = state->getDouble("OLD_TP"); | ||
4064 | 3429 | if (!isUndo) | ||
4065 | 3430 | tp = state->getDouble("NEW_TP"); | ||
4066 | 3431 | select(); | ||
4067 | 3432 | m_Doc->itemSelection_SetItemLineTransparency(tp); | ||
4068 | 3433 | } | ||
4069 | 3434 | |||
4070 | 3435 | |||
4071 | 3436 | void PageItem::restoreLineStyle(SimpleState *state, bool isUndo) | ||
4072 | 3437 | { | ||
4073 | 3438 | Qt::PenStyle ps = static_cast<Qt::PenStyle>(state->getInt("OLD_STYLE")); | ||
4074 | 3439 | if (!isUndo) | ||
4075 | 3440 | ps = static_cast<Qt::PenStyle>(state->getInt("NEW_STYLE")); | ||
4076 | 3441 | select(); | ||
4077 | 3442 | m_Doc->itemSelection_SetLineArt(ps); | ||
4078 | 3443 | } | ||
4079 | 3444 | |||
4080 | 3445 | void PageItem::restoreLineEnd(SimpleState *state, bool isUndo) | ||
4081 | 3446 | { | ||
4082 | 3447 | Qt::PenCapStyle pcs = static_cast<Qt::PenCapStyle>(state->getInt("OLD_STYLE")); | ||
4083 | 3448 | if (!isUndo) | ||
4084 | 3449 | pcs = static_cast<Qt::PenCapStyle>(state->getInt("NEW_STYLE")); | ||
4085 | 3450 | select(); | ||
4086 | 3451 | m_Doc->itemSelection_SetLineEnd(pcs); | ||
4087 | 3452 | } | ||
4088 | 3453 | |||
4089 | 3454 | void PageItem::restoreLineJoin(SimpleState *state, bool isUndo) | ||
4090 | 3455 | { | ||
4091 | 3456 | Qt::PenJoinStyle pjs = static_cast<Qt::PenJoinStyle>(state->getInt("OLD_STYLE")); | ||
4092 | 3457 | if (!isUndo) | ||
4093 | 3458 | pjs = static_cast<Qt::PenJoinStyle>(state->getInt("NEW_STYLE")); | ||
4094 | 3459 | select(); | ||
4095 | 3460 | m_Doc->itemSelection_SetLineJoin(pjs); | ||
4096 | 3461 | } | ||
4097 | 3462 | |||
4098 | 3463 | void PageItem::restoreLineWidth(SimpleState *state, bool isUndo) | ||
4099 | 3464 | { | ||
4100 | 3465 | double w = state->getDouble("OLD_WIDTH"); | ||
4101 | 3466 | if (!isUndo) | ||
4102 | 3467 | w = state->getDouble("NEW_WIDTH"); | ||
4103 | 3468 | select(); | ||
4104 | 3469 | m_Doc->itemSelection_SetLineWidth(w); | ||
4105 | 3470 | } | ||
4106 | 3471 | |||
4107 | 3472 | void PageItem::restoreCustomLineStyle(SimpleState *state, bool isUndo) | ||
4108 | 3473 | { | ||
4109 | 3474 | QString style = state->get("OLD_STYLE"); | ||
4110 | 3475 | if (!isUndo) | ||
4111 | 3476 | style = state->get("NEW_STYLE"); | ||
4112 | 3477 | setCustomLineStyle(style); | ||
4113 | 3478 | } | ||
4114 | 3479 | |||
4115 | 3480 | void PageItem::restoreName(SimpleState *state, bool isUndo) | ||
4116 | 3481 | { | ||
4117 | 3482 | QString name = state->get("OLD_NAME"); | ||
4118 | 3483 | if (!isUndo) | ||
4119 | 3484 | name = state->get("NEW_NAME"); | ||
4120 | 3485 | setItemName(name); | ||
4121 | 3486 | } | ||
4122 | 3487 | |||
4123 | 3488 | void PageItem::restoreArrow(SimpleState *state, bool isUndo, bool isStart) | ||
4124 | 3489 | { | ||
4125 | 3490 | int i = state->getInt("OLD_INDEX"); | ||
4126 | 3491 | if (!isUndo) | ||
4127 | 3492 | i = state->getInt("NEW_INDEX"); | ||
4128 | 3493 | if (isStart) | ||
4129 | 3494 | setStartArrowIndex(i); | ||
4130 | 3495 | else | ||
4131 | 3496 | setEndArrowIndex(i); | ||
4132 | 3497 | } | ||
4133 | 3498 | |||
4134 | 3499 | |||
4135 | 3500 | void PageItem::restorePStyle(SimpleState *state, bool isUndo) | ||
4136 | 3501 | { | ||
4137 | 3502 | int styleid = state->getInt("OLD_STYLE"); | ||
4138 | 3503 | if (!isUndo) | ||
4139 | 3504 | styleid = state->getInt("NEW_STYLE"); | ||
4140 | 3505 | //will be done later with other text-undo: | ||
4141 | 3506 | // m_Doc->chAbStyle(this, styleid); | ||
4142 | 3507 | } | ||
4143 | 3508 | |||
4144 | 3509 | |||
4145 | 3510 | // FIXME: This must go into class ScribusDoc! | ||
4146 | 3511 | // For now we'll just make it independent of 'this' -- AV | ||
4147 | 3512 | void PageItem::restoreType(SimpleState *state, bool isUndo) | ||
4148 | 3513 | { | ||
4149 | 3514 | // well, probably not the best way to handle pointers... | ||
4150 | 3515 | PageItem * item = reinterpret_cast<PageItem *>(state->getInt("PAGEITEM")); | ||
4151 | 3516 | int type = state->getInt("OLD_TYPE"); | ||
4152 | 3517 | if (!isUndo) | ||
4153 | 3518 | type = state->getInt("NEW_TYPE"); | ||
4154 | 3519 | ScribusView* view = m_Doc->view(); | ||
4155 | 3520 | view->Deselect(false); | ||
4156 | 3521 | view->SelectItem(item, false); | ||
4157 | 3522 | switch (type) { | ||
4158 | 3523 | case ImageFrame: view->ToPicFrame(); break; | ||
4159 | 3524 | case TextFrame: view->ToTextFrame(); break; | ||
4160 | 3525 | case Polygon: view->ToPolyFrame(); break; | ||
4161 | 3526 | case PolyLine: view->ToBezierFrame(); break; | ||
4162 | 3527 | } | ||
4163 | 3528 | view->requestMode(modeNormal); | ||
4164 | 3529 | } | ||
4165 | 3530 | |||
4166 | 3531 | void PageItem::restoreTextFlowing(SimpleState *state, bool isUndo) | ||
4167 | 3532 | { | ||
4168 | 3533 | TextFlowMode oldMode = (TextFlowMode) state->getInt("TEXTFLOW_OLDMODE"); | ||
4169 | 3534 | TextFlowMode newMode = (TextFlowMode) state->getInt("TEXTFLOW_NEWMODE"); | ||
4170 | 3535 | if (isUndo) | ||
4171 | 3536 | textFlowModeVal = oldMode; | ||
4172 | 3537 | else | ||
4173 | 3538 | textFlowModeVal = newMode; | ||
4174 | 3539 | |||
4175 | 3540 | QList<PageItem*> pList; | ||
4176 | 3541 | for(int idx = ItemNr-1; idx >= 0 ; --idx) | ||
4177 | 3542 | { | ||
4178 | 3543 | pList << m_Doc->Items->at(idx); | ||
4179 | 3544 | } | ||
4180 | 3545 | |||
4181 | 3546 | QRectF baseRect(getBoundingRect()); | ||
4182 | 3547 | for(int idx(0); idx < pList.count(); ++idx) | ||
4183 | 3548 | { | ||
4184 | 3549 | QRectF uRect(pList.at(idx)->getBoundingRect()); | ||
4185 | 3550 | if(baseRect.intersects(uRect)) | ||
4186 | 3551 | pList.at(idx)->update(); | ||
4187 | 3552 | } | ||
4188 | 3553 | } | ||
4189 | 3554 | |||
4190 | 3555 | void PageItem::restoreImageScaleMode(SimpleState *state, bool isUndo) | ||
4191 | 3556 | { | ||
4192 | 3557 | bool type=ScaleType; | ||
4193 | 3558 | if (state->contains("SCALE_TYPE")) | ||
4194 | 3559 | { | ||
4195 | 3560 | if (isUndo) | ||
4196 | 3561 | type = !state->getBool("SCALE_TYPE"); | ||
4197 | 3562 | else | ||
4198 | 3563 | type = state->getBool("SCALE_TYPE"); | ||
4199 | 3564 | //if restoring free scaling | ||
4200 | 3565 | //old offset and scale ratio must be restored | ||
4201 | 3566 | if (type) | ||
4202 | 3567 | { | ||
4203 | 3568 | double oscx = state->getDouble("OLD_IMAGEXSCALE"); | ||
4204 | 3569 | double oscy = state->getDouble("OLD_IMAGEYSCALE"); | ||
4205 | 3570 | double ox = state->getDouble("OLD_IMAGEXOFFSET"); | ||
4206 | 3571 | double oy = state->getDouble("OLD_IMAGEYOFFSET"); | ||
4207 | 3572 | Selection tempSelection(this, false); | ||
4208 | 3573 | tempSelection.addItem(this, true); | ||
4209 | 3574 | m_Doc->itemSelection_SetImageScale(oscx, oscy, &tempSelection); | ||
4210 | 3575 | m_Doc->itemSelection_SetImageOffset(ox, oy, &tempSelection); | ||
4211 | 3576 | } | ||
4212 | 3577 | |||
4213 | 3578 | } | ||
4214 | 3579 | |||
4215 | 3580 | bool ratio=AspectRatio; | ||
4216 | 3581 | if (state->contains("ASPECT_RATIO")) | ||
4217 | 3582 | { | ||
4218 | 3583 | if (isUndo) | ||
4219 | 3584 | ratio = !state->getBool("ASPECT_RATIO"); | ||
4220 | 3585 | else | ||
4221 | 3586 | ratio = state->getBool("ASPECT_RATIO"); | ||
4222 | 3587 | } | ||
4223 | 3588 | |||
4224 | 3589 | setImageScalingMode(type, ratio); | ||
4225 | 3590 | } | ||
4226 | 3591 | |||
4227 | 3592 | void PageItem::restoreImageScaleChange(SimpleState *state, bool isUndo) | ||
4228 | 3593 | { | ||
4229 | 3594 | double oscx = state->getDouble("OLD_IMAGEXSCALE"); | ||
4230 | 3595 | double oscy = state->getDouble("OLD_IMAGEYSCALE"); | ||
4231 | 3596 | double scx = state->getDouble("NEW_IMAGEXSCALE"); | ||
4232 | 3597 | double scy = state->getDouble("NEW_IMAGEYSCALE"); | ||
4233 | 3598 | Selection tempSelection(this, false); | ||
4234 | 3599 | tempSelection.addItem(this, true); | ||
4235 | 3600 | if (!isUndo) | ||
4236 | 3601 | m_Doc->itemSelection_SetImageScale(scx, scy, &tempSelection); | ||
4237 | 3602 | else | ||
4238 | 3603 | m_Doc->itemSelection_SetImageScale(oscx, oscy, &tempSelection); | ||
4239 | 3604 | } | ||
4240 | 3605 | |||
4241 | 3606 | void PageItem::restoreImageOffsetChange(SimpleState *state, bool isUndo) | ||
4242 | 3607 | { | ||
4243 | 3608 | double ox = state->getDouble("OLD_IMAGEXOFFSET"); | ||
4244 | 3609 | double oy = state->getDouble("OLD_IMAGEYOFFSET"); | ||
4245 | 3610 | double x = state->getDouble("NEW_IMAGEXOFFSET"); | ||
4246 | 3611 | double y = state->getDouble("NEW_IMAGEYOFFSET"); | ||
4247 | 3612 | Selection tempSelection(this, false); | ||
4248 | 3613 | tempSelection.addItem(this, true); | ||
4249 | 3614 | if (!isUndo) | ||
4250 | 3615 | m_Doc->itemSelection_SetImageOffset(x, y, &tempSelection); | ||
4251 | 3616 | else | ||
4252 | 3617 | m_Doc->itemSelection_SetImageOffset(ox, oy, &tempSelection); | ||
4253 | 3618 | } | ||
4254 | 3619 | |||
4255 | 3620 | void PageItem::restoreClearImage(UndoState *state, bool isUndo) | ||
4256 | 3621 | { | ||
4257 | 3622 | if (!isImageFrame()) | ||
4258 | 3623 | return; | ||
4259 | 3624 | if (isUndo) | ||
4260 | 3625 | { | ||
4261 | 3626 | ItemState<ScImageEffectList> *is = dynamic_cast<ItemState<ScImageEffectList>*>(state); | ||
4262 | 3627 | Pfile = is->get("CI_PFILE"); | ||
4263 | 3628 | loadImage(Pfile, false); | ||
4264 | 3629 | effectsInUse = is->getItem(); | ||
4265 | 3630 | setImageFlippedH(is->getBool("CI_FLIPPH")); | ||
4266 | 3631 | setImageFlippedV(is->getBool("CI_FLIPPV")); | ||
4267 | 3632 | setImageScalingMode(is->getBool("CI_SCALING"),is->getBool("CI_ASPECT")); | ||
4268 | 3633 | setImageXYOffset(is->getDouble("CI_XOFF"), is->getDouble("CI_YOFF")); | ||
4269 | 3634 | setImageXYScale(is->getDouble("CI_XSCALE"), is->getDouble("CI_YSCALE")); | ||
4270 | 3635 | setFillTransparency(is->getDouble("CI_FILLT")); | ||
4271 | 3636 | setLineTransparency(is->getDouble("CI_LINET")); | ||
4272 | 3637 | select(); | ||
4273 | 3638 | m_Doc->updatePic(); | ||
4274 | 3639 | } | ||
4275 | 3640 | else | ||
4276 | 3641 | asImageFrame()->clearContents(); | ||
4277 | 3642 | } | ||
4278 | 3643 | |||
4279 | 3644 | void PageItem::restoreLinkTextFrame(UndoState *state, bool isUndo) | ||
4280 | 3645 | { | ||
4281 | 3646 | if (!isTextFrame()) | ||
4282 | 3647 | return; | ||
4283 | 3648 | if (isUndo) | ||
4284 | 3649 | { | ||
4285 | 3650 | unlink(); | ||
4286 | 3651 | } | ||
4287 | 3652 | else | ||
4288 | 3653 | { | ||
4289 | 3654 | ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(state); | ||
4290 | 3655 | asTextFrame()->link(is->getItem().second->asTextFrame()); | ||
4291 | 3656 | } | ||
4292 | 3657 | } | ||
4293 | 3658 | |||
4294 | 3659 | void PageItem::restoreUnlinkTextFrame(UndoState *state, bool isUndo) | ||
4295 | 3660 | { | ||
4296 | 3661 | if (!isTextFrame()) | ||
4297 | 3662 | return; | ||
4298 | 3663 | if (isUndo) | ||
4299 | 3664 | { | ||
4300 | 3665 | ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(state); | ||
4301 | 3666 | asTextFrame()->link(is->getItem().second->asTextFrame()); | ||
4302 | 3667 | } | ||
4303 | 3668 | else | ||
4304 | 3669 | { | ||
4305 | 3670 | unlink(); | ||
4306 | 3671 | } | ||
4307 | 3672 | } | ||
4308 | 3673 | |||
4309 | 3674 | |||
4310 | 3675 | void PageItem::restorePoly(SimpleState *state, bool isUndo, bool isContour) | ||
4311 | 3676 | { | ||
4312 | 3677 | int mode = state->getInt("MODE"); | ||
4313 | 3678 | int rot = state->getInt("ROT"); | ||
4314 | 3679 | ScribusView* view = m_Doc->view(); | ||
4315 | 3680 | double scaling = state->getDouble("SCALING"); | ||
4316 | 3681 | bool editContour = m_Doc->nodeEdit.isContourLine; | ||
4317 | 3682 | m_Doc->nodeEdit.isContourLine = isContour; | ||
4318 | 3683 | select(); | ||
4319 | 3684 | if (isUndo) | ||
4320 | 3685 | { | ||
4321 | 3686 | if (mode % 2 != 0 && mode != 0) | ||
4322 | 3687 | --mode; | ||
4323 | 3688 | else | ||
4324 | 3689 | ++mode; | ||
4325 | 3690 | if (mode == 2) | ||
4326 | 3691 | scaling = (1.0 - (100.0 / (100.0 + scaling))) * 100.0; | ||
4327 | 3692 | else if (mode == 3) | ||
4328 | 3693 | scaling = ((100.0 / (100.0 - scaling)) - 1.0) * 100.0; | ||
4329 | 3694 | } | ||
4330 | 3695 | view->TransformPoly(mode, rot, scaling); | ||
4331 | 3696 | m_Doc->nodeEdit.isContourLine = editContour; | ||
4332 | 3697 | } | ||
4333 | 3698 | |||
4334 | 3699 | void PageItem::restoreContourLine(SimpleState *state, bool isUndo) | ||
4335 | 3700 | { | ||
4336 | 3701 | ItemState<FPointArray> *is = dynamic_cast<ItemState<FPointArray>*>(state); | ||
4337 | 3702 | if (is) | ||
4338 | 3703 | { | ||
4339 | 3704 | if (isUndo) | ||
4340 | 3705 | ContourLine = is->getItem(); | ||
4341 | 3706 | else | ||
4342 | 3707 | ContourLine = PoLine.copy(); | ||
4343 | 3708 | ClipEdited = true; | ||
4344 | 3709 | } | ||
4345 | 3710 | } | ||
4346 | 3711 | |||
4347 | 3712 | void PageItem::restoreShapeType(SimpleState *state, bool isUndo) | ||
4348 | 3713 | { | ||
4349 | 3714 | // Store shape info in this form: | ||
4350 | 3715 | // CHANGE_SHAPE_TYPE - ID of the undo operation | ||
4351 | 3716 | // OLD_FRAME_TYPE - original frame type | ||
4352 | 3717 | // NEW_FRAME_TYPE - change of frame type | ||
4353 | 3718 | // binary QPair<FPointArray, FPointArray> - .first original shape, .second new shape | ||
4354 | 3719 | ItemState<QPair<FPointArray,FPointArray> > *is = dynamic_cast<ItemState<QPair<FPointArray,FPointArray> >*>(state); | ||
4355 | 3720 | if (is) | ||
4356 | 3721 | { | ||
4357 | 3722 | if (isUndo) | ||
4358 | 3723 | { | ||
4359 | 3724 | this->FrameType = is->getInt("OLD_FRAME_TYPE"); | ||
4360 | 3725 | this->PoLine = is->getItem().first; | ||
4361 | 3726 | } | ||
4362 | 3727 | else | ||
4363 | 3728 | { | ||
4364 | 3729 | this->FrameType = is->getInt("NEW_FRAME_TYPE"); | ||
4365 | 3730 | this->PoLine = is->getItem().second; | ||
4366 | 3731 | } | ||
4367 | 3732 | ClipEdited = true; | ||
4368 | 3733 | } | ||
4369 | 3734 | } | ||
4370 | 3735 | |||
4371 | 3736 | void PageItem::restoreLayer(SimpleState *state, bool isUndo) | ||
4372 | 3737 | { | ||
4373 | 3738 | ScribusView* view = m_Doc->view(); | ||
4374 | 3739 | setLayer(isUndo ? state->getInt("OLD_LAYER") : state->getInt("NEW_LAYER")); | ||
4375 | 3740 | view->Deselect(true); | ||
4376 | 3741 | m_Doc->regionsChanged()->update(QRectF()); | ||
4377 | 3742 | } | ||
4378 | 3743 | |||
4379 | 3744 | void PageItem::restoreGetImage(UndoState *state, bool isUndo) | ||
4380 | 3745 | { | ||
4381 | 3746 | ItemState<ScImageEffectList> *is = dynamic_cast<ItemState<ScImageEffectList>*>(state); | ||
4382 | 3747 | QString fn = is->get("OLD_IMAGE_PATH"); | ||
4383 | 3748 | if (!isUndo) | ||
4384 | 3749 | fn = is->get("NEW_IMAGE_PATH"); | ||
4385 | 3750 | if (fn.isEmpty()) | ||
4386 | 3751 | { | ||
4387 | 3752 | Selection tempSelection(this, false); | ||
4388 | 3753 | tempSelection.addItem(this, true); | ||
4389 | 3754 | m_Doc->itemSelection_ClearItem(&tempSelection); | ||
4390 | 3755 | } | ||
4391 | 3756 | else | ||
4392 | 3757 | { | ||
4393 | 3758 | loadImage(fn, false); | ||
4394 | 3759 | if (isUndo) | ||
4395 | 3760 | { | ||
4396 | 3761 | //restore old image settings | ||
4397 | 3762 | effectsInUse = is->getItem(); | ||
4398 | 3763 | setImageFlippedH(is->getBool("FLIPPH")); | ||
4399 | 3764 | setImageFlippedV(is->getBool("FLIPPV")); | ||
4400 | 3765 | setImageScalingMode(is->getBool("SCALING"), is->getBool("ASPECT")); | ||
4401 | 3766 | setImageXYOffset(is->getDouble("XOFF"), is->getDouble("YOFF")); | ||
4402 | 3767 | setImageXYScale(is->getDouble("XSCALE"), is->getDouble("YSCALE")); | ||
4403 | 3768 | setFillTransparency(is->getDouble("FILLT")); | ||
4404 | 3769 | setLineTransparency(is->getDouble("LINET")); | ||
4405 | 3770 | } | ||
4406 | 3771 | select(); | ||
4407 | 3772 | m_Doc->updatePic(); | ||
4408 | 3773 | } | ||
4409 | 3774 | } | ||
4410 | 3775 | |||
4411 | 3776 | void PageItem::restoreGroupsLastItem(SimpleState *state, bool isUndo) | ||
4412 | 3777 | { | ||
4413 | 3778 | ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> > *>(state); | ||
4414 | 3779 | if (is) | ||
4415 | 3780 | { | ||
4416 | 3781 | if (isUndo) | ||
4417 | 3782 | this->groupsLastItem = is->getItem().first; | ||
4418 | 3783 | else | ||
4419 | 3784 | this->groupsLastItem = is->getItem().second; | ||
4420 | 3785 | } | ||
4421 | 3786 | } | ||
4422 | 3787 | |||
4423 | 3788 | void PageItem::restoreShapeContour(UndoState *state, bool isUndo) | ||
4424 | 3789 | { | ||
4425 | 3790 | ItemState<QPair<FPointArray,FPointArray> > *istate = | ||
4426 | 3791 | dynamic_cast<ItemState<QPair<FPointArray,FPointArray> >*>(state); | ||
4427 | 3792 | if (istate) | ||
4428 | 3793 | { | ||
4429 | 3794 | FPointArray oldClip = istate->getItem().first; | ||
4430 | 3795 | FPointArray newClip = istate->getItem().second; | ||
4431 | 3796 | bool isContour = istate->getBool("IS_CONTOUR"); | ||
4432 | 3797 | double oldX = istate->getDouble("OLD_X"); | ||
4433 | 3798 | double oldY = istate->getDouble("OLD_Y"); | ||
4434 | 3799 | double newX = istate->getDouble("NEW_X"); | ||
4435 | 3800 | double newY = istate->getDouble("NEW_Y"); | ||
4436 | 3801 | double mx = oldX - newX; | ||
4437 | 3802 | double my = oldY - newY; | ||
4438 | 3803 | |||
4439 | 3804 | if (isUndo) | ||
4440 | 3805 | { | ||
4441 | 3806 | if (isContour) | ||
4442 | 3807 | ContourLine = oldClip; | ||
4443 | 3808 | else | ||
4444 | 3809 | PoLine = oldClip; | ||
4445 | 3810 | } | ||
4446 | 3811 | else | ||
4447 | 3812 | { | ||
4448 | 3813 | mx = -mx; | ||
4449 | 3814 | my = -my; | ||
4450 | 3815 | if (isContour) | ||
4451 | 3816 | ContourLine = newClip; | ||
4452 | 3817 | else | ||
4453 | 3818 | PoLine = newClip; | ||
4454 | 3819 | } | ||
4455 | 3820 | m_Doc->AdjustItemSize(this); | ||
4456 | 3821 | m_Doc->MoveItem(mx, my, this, false); | ||
4457 | 3822 | m_Doc->regionsChanged()->update(QRectF()); | ||
4458 | 3823 | } | ||
4459 | 3824 | |||
4460 | 3825 | } | ||
4461 | 3826 | |||
4462 | 3827 | void PageItem::restoreImageEffects(UndoState *state, bool isUndo) | ||
4463 | 3828 | { | ||
4464 | 3829 | ItemState<QPair<ScImageEffectList, ScImageEffectList> > *istate = | ||
4465 | 3830 | dynamic_cast<ItemState<QPair<ScImageEffectList,ScImageEffectList> >*>(state); | ||
4466 | 3831 | if (istate) | ||
4467 | 3832 | { | ||
4468 | 3833 | if (isUndo) | ||
4469 | 3834 | effectsInUse = istate->getItem().first; | ||
4470 | 3835 | else | ||
4471 | 3836 | effectsInUse = istate->getItem().second; | ||
4472 | 3837 | |||
4473 | 3838 | select(); | ||
4474 | 3839 | m_Doc->updatePic(); | ||
4475 | 3840 | } | ||
4476 | 3841 | } | ||
4477 | 3842 | |||
4478 | 3843 | void PageItem::restoreEditText(SimpleState *state, bool isUndo) | ||
4479 | 3844 | { | ||
4480 | 3845 | if (!isTextFrame()) | ||
4481 | 3846 | return; | ||
4482 | 3847 | itemText.deselectAll(); | ||
4483 | 3848 | HasSel = false; | ||
4484 | 3849 | EditAct action = (EditAct) state->getInt("STEXT"); | ||
4485 | 3850 | if (action == PARAMFULL || action == PARAMSEL) | ||
4486 | 3851 | { | ||
4487 | 3852 | QString buffer; | ||
4488 | 3853 | if (isUndo) | ||
4489 | 3854 | buffer.append(state->get("STEXT_OLD")); | ||
4490 | 3855 | else | ||
4491 | 3856 | buffer.append(state->get("STEXT_NEW")); | ||
4492 | 3857 | if (!buffer.isEmpty()) | ||
4493 | 3858 | { | ||
4494 | 3859 | Serializer dig(*m_Doc); | ||
4495 | 3860 | dig.store<ScribusDoc>("<scribusdoc>", m_Doc); | ||
4496 | 3861 | StoryText::desaxeRules("/", dig, "SCRIBUSTEXT"); | ||
4497 | 3862 | dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>()); | ||
4498 | 3863 | dig.parseMemory(buffer.toStdString().c_str(), buffer.length()); | ||
4499 | 3864 | StoryText* story = dig.result<StoryText>(); | ||
4500 | 3865 | if (action == PARAMFULL) | ||
4501 | 3866 | { | ||
4502 | 3867 | itemText.selectAll(); | ||
4503 | 3868 | itemText.clear(); | ||
4504 | 3869 | itemText.append(*story); | ||
4505 | 3870 | } | ||
4506 | 3871 | else if (action == PARAMSEL) | ||
4507 | 3872 | { | ||
4508 | 3873 | itemText.deselectAll(); | ||
4509 | 3874 | int SelStart = state->getInt("STEXT_SELSTART"); | ||
4510 | 3875 | itemText.select(SelStart,state->getInt("STEXT_SELLEN")); | ||
4511 | 3876 | asTextFrame()->deleteSelectedTextFromFrame(); | ||
4512 | 3877 | int ItemLength = itemText.length(); | ||
4513 | 3878 | itemText.insert(SelStart, *story); | ||
4514 | 3879 | // If we have inserted at end of text we have to restore trailing style | ||
4515 | 3880 | if (ItemLength == SelStart && story->length() > 0 && story->text(-1) != SpecialChars::PARSEP) | ||
4516 | 3881 | { | ||
4517 | 3882 | itemText.setStyle(-1, story->paragraphStyle(story->length())); | ||
4518 | 3883 | } | ||
4519 | 3884 | itemText.select(SelStart, story->length()); | ||
4520 | 3885 | HasSel = true; | ||
4521 | 3886 | } | ||
4522 | 3887 | CPos = itemText.endOfSelection(); | ||
4523 | 3888 | delete story; | ||
4524 | 3889 | } | ||
4525 | 3890 | else { qDebug() << "UNDO buffer EMPTY";} | ||
4526 | 3891 | } | ||
4527 | 3892 | else if (action == REPSAX) | ||
4528 | 3893 | { | ||
4529 | 3894 | QString buffout, buffin; //buffout is deleted, buffin is inserted | ||
4530 | 3895 | int pos = state->getInt("STEXT_CPOS"); | ||
4531 | 3896 | if (isUndo) | ||
4532 | 3897 | { | ||
4533 | 3898 | buffin.append(state->get("STEXT_OLD")); | ||
4534 | 3899 | buffout.append(state->get("STEXT_NEW")); | ||
4535 | 3900 | } | ||
4536 | 3901 | else | ||
4537 | 3902 | { | ||
4538 | 3903 | buffin.append(state->get("STEXT_NEW")); | ||
4539 | 3904 | buffout.append(state->get("STEXT_OLD")); | ||
4540 | 3905 | } | ||
4541 | 3906 | |||
4542 | 3907 | Serializer dig(*m_Doc); | ||
4543 | 3908 | dig.store<ScribusDoc>("<scribusdoc>", m_Doc); | ||
4544 | 3909 | StoryText::desaxeRules("/", dig, "SCRIBUSTEXT"); | ||
4545 | 3910 | dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>()); | ||
4546 | 3911 | dig.parseMemory(buffout.toStdString().c_str(), buffout.length()); | ||
4547 | 3912 | StoryText* story = dig.result<StoryText>(); | ||
4548 | 3913 | itemText.select(pos,story->length()); | ||
4549 | 3914 | asTextFrame()->deleteSelectedTextFromFrame(); | ||
4550 | 3915 | |||
4551 | 3916 | Serializer dig2(*m_Doc); | ||
4552 | 3917 | dig2.store<ScribusDoc>("<scribusdoc>", m_Doc); | ||
4553 | 3918 | StoryText::desaxeRules("/", dig2, "SCRIBUSTEXT"); | ||
4554 | 3919 | dig2.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>()); | ||
4555 | 3920 | dig2.parseMemory(buffin.toStdString().c_str(), buffin.length()); | ||
4556 | 3921 | story = dig2.result<StoryText>(); | ||
4557 | 3922 | itemText.insert(pos,*story); | ||
4558 | 3923 | itemText.select(pos, story->length()); | ||
4559 | 3924 | HasSel = true; | ||
4560 | 3925 | CPos = pos + story->length(); | ||
4561 | 3926 | delete story; | ||
4562 | 3927 | } | ||
4563 | 3928 | else if (action == INSSAX || action == DELSAX) | ||
4564 | 3929 | { | ||
4565 | 3930 | QString str = state->get("STEXT_STR"); | ||
4566 | 3931 | if (str.isEmpty()) | ||
4567 | 3932 | str = itemTextSaxed; | ||
4568 | 3933 | int pos = state->getInt("STEXT_CPOS"); | ||
4569 | 3934 | Serializer dig(*m_Doc); | ||
4570 | 3935 | dig.store<ScribusDoc>("<scribusdoc>", m_Doc); | ||
4571 | 3936 | StoryText::desaxeRules("/", dig, "SCRIBUSTEXT"); | ||
4572 | 3937 | dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>()); | ||
4573 | 3938 | dig.parseMemory(str.toStdString().c_str(), str.length()); | ||
4574 | 3939 | StoryText* story = dig.result<StoryText>(); | ||
4575 | 3940 | if ((action == INSSAX && isUndo) || (action == DELSAX && !isUndo)) | ||
4576 | 3941 | { | ||
4577 | 3942 | //undo for INSSAX, redo for DELSAX | ||
4578 | 3943 | itemText.select(pos, story->length()); | ||
4579 | 3944 | asTextFrame()->deleteSelectedTextFromFrame(); | ||
4580 | 3945 | } | ||
4581 | 3946 | else | ||
4582 | 3947 | { | ||
4583 | 3948 | //undo for DELSAX, redo for INSSAX | ||
4584 | 3949 | itemText.insert(pos, *story); | ||
4585 | 3950 | CPos = pos + story->length(); | ||
4586 | 3951 | } | ||
4587 | 3952 | delete story; | ||
4588 | 3953 | } | ||
4589 | 3954 | else if (action == INS) | ||
4590 | 3955 | { | ||
4591 | 3956 | QString str = state->get("STEXT_STR"); | ||
4592 | 3957 | int pos = state->getInt("STEXT_CPOS"); | ||
4593 | 3958 | if (isUndo) | ||
4594 | 3959 | { | ||
4595 | 3960 | itemText.select(pos, str.length()); | ||
4596 | 3961 | asTextFrame()->deleteSelectedTextFromFrame(); | ||
4597 | 3962 | } | ||
4598 | 3963 | else | ||
4599 | 3964 | { | ||
4600 | 3965 | itemText.insertChars(pos, str, true); | ||
4601 | 3966 | CPos = pos + str.length(); | ||
4602 | 3967 | } | ||
4603 | 3968 | } | ||
4604 | 3969 | // after Undo or Redo new actions should create new undoStates | ||
4605 | 3970 | asTextFrame()->lastUndoAction = NOACTION; | ||
4606 | 3971 | |||
4607 | 3972 | m_Doc->scMW()->setTBvals(this); | ||
4608 | 3973 | update(); | ||
4609 | 3974 | } | ||
4610 | 3975 | |||
4611 | 3976 | QString PageItem::getItemTextSaxed(EditActPlace undoItem) | ||
4612 | 3977 | { | ||
4613 | 3978 | if (!isTextFrame()) return ""; | ||
4614 | 3979 | StoryText iT(m_Doc); | ||
4615 | 3980 | iT.setDefaultStyle(itemText.defaultStyle()); | ||
4616 | 3981 | if (undoItem == FRAME) | ||
4617 | 3982 | iT.insert(0, itemText); | ||
4618 | 3983 | else | ||
4619 | 3984 | { | ||
4620 | 3985 | int StartOldSel = -1, LenOldSel = -1; | ||
4621 | 3986 | if (undoItem == PARAGRAPH) | ||
4622 | 3987 | { | ||
4623 | 3988 | LenOldSel = 0; | ||
4624 | 3989 | if (HasSel) | ||
4625 | 3990 | { | ||
4626 | 3991 | StartOldSel = itemText.startOfSelection(); | ||
4627 | 3992 | LenOldSel = itemText.lengthOfSelection(); | ||
4628 | 3993 | } | ||
4629 | 3994 | asTextFrame()->expandParaSelection(true); | ||
4630 | 3995 | } | ||
4631 | 3996 | else if (undoItem == CHAR || (undoItem == SELECTION && !HasSel)) | ||
4632 | 3997 | { | ||
4633 | 3998 | LenOldSel = itemText.lengthOfSelection(); | ||
4634 | 3999 | if (LenOldSel > 0) | ||
4635 | 4000 | StartOldSel = itemText.startOfSelection(); | ||
4636 | 4001 | if (CPos >= itemText.length()) | ||
4637 | 4002 | return ""; | ||
4638 | 4003 | itemText.select(CPos,1); | ||
4639 | 4004 | HasSel = true; | ||
4640 | 4005 | } | ||
4641 | 4006 | //is SELECTION | ||
4642 | 4007 | iT.insert(0, itemText, HasSel); | ||
4643 | 4008 | if (LenOldSel > 0) //restoring old selection if undoItem was PARAPGRAPH | ||
4644 | 4009 | { | ||
4645 | 4010 | itemText.select(StartOldSel, LenOldSel); | ||
4646 | 4011 | HasSel = true; | ||
4647 | 4012 | } | ||
4648 | 4013 | else if (LenOldSel == 0) | ||
4649 | 4014 | { | ||
4650 | 4015 | itemText.deselectAll(); | ||
4651 | 4016 | HasSel = false; | ||
4652 | 4017 | } | ||
4653 | 4018 | } | ||
4654 | 4019 | //saxing text | ||
4655 | 4020 | std::ostringstream xmlString; | ||
4656 | 4021 | SaxXML xmlStream(xmlString); | ||
4657 | 4022 | xmlStream.beginDoc(); | ||
4658 | 4023 | iT.saxx(xmlStream, "SCRIBUSTEXT"); | ||
4659 | 4024 | xmlStream.endDoc(); | ||
4660 | 4025 | std::string xml(xmlString.str()); | ||
4661 | 4026 | return QString(xml.c_str()); | ||
4662 | 4027 | } | ||
4663 | 4028 | |||
4664 | 4029 | QString PageItem::getItemTextSaxed(int selStart, int selLength) | ||
4665 | 4030 | { | ||
4666 | 4031 | if (selStart < 0 || selLength < 0) | ||
4667 | 4032 | return QString(); | ||
4668 | 4033 | |||
4669 | 4034 | StoryText it(m_Doc); | ||
4670 | 4035 | it.setDefaultStyle(itemText.defaultStyle()); | ||
4671 | 4036 | |||
4672 | 4037 | int oldSelStart = -1, oldSelLength = -1; | ||
4673 | 4038 | oldSelStart = itemText.startOfSelection(); | ||
4674 | 4039 | oldSelLength = itemText.lengthOfSelection(); | ||
4675 | 4040 | |||
4676 | 4041 | itemText.select(selStart, selLength); | ||
4677 | 4042 | it.insert(0, itemText, (selLength > 0)); | ||
4678 | 4043 | |||
4679 | 4044 | if (oldSelLength > 0) //restoring old selection if undoItem was PARAPGRAPH | ||
4680 | 4045 | { | ||
4681 | 4046 | itemText.select(oldSelStart, oldSelLength); | ||
4682 | 4047 | HasSel = true; | ||
4683 | 4048 | } | ||
4684 | 4049 | else if (oldSelLength == 0) | ||
4685 | 4050 | { | ||
4686 | 4051 | itemText.deselectAll(); | ||
4687 | 4052 | HasSel = false; | ||
4688 | 4053 | } | ||
4689 | 4054 | |||
4690 | 4055 | //saxing text | ||
4691 | 4056 | std::ostringstream xmlString; | ||
4692 | 4057 | SaxXML xmlStream(xmlString); | ||
4693 | 4058 | xmlStream.beginDoc(); | ||
4694 | 4059 | it.saxx(xmlStream, "SCRIBUSTEXT"); | ||
4695 | 4060 | xmlStream.endDoc(); | ||
4696 | 4061 | std::string xml(xmlString.str()); | ||
4697 | 4062 | return QString(xml.c_str()); | ||
4698 | 4063 | } | ||
4699 | 4064 | |||
4700 | 4065 | QString PageItem::getTextSaxed(QString str) | ||
4701 | 4066 | { | ||
4702 | 4067 | StoryText iT(m_Doc); | ||
4703 | 4068 | iT.setDefaultStyle(itemText.defaultStyle()); | ||
4704 | 4069 | iT.insertChars(0,str,true); | ||
4705 | 4070 | std::ostringstream xmlString; | ||
4706 | 4071 | SaxXML xmlStream(xmlString); | ||
4707 | 4072 | xmlStream.beginDoc(); | ||
4708 | 4073 | iT.saxx(xmlStream, "SCRIBUSTEXT"); | ||
4709 | 4074 | xmlStream.endDoc(); | ||
4710 | 4075 | std::string xml(xmlString.str()); | ||
4711 | 4076 | return QString(xml.c_str()); | ||
4712 | 4077 | } | ||
4713 | 4078 | |||
4714 | 4079 | void PageItem::select() | ||
4715 | 4080 | { | ||
4716 | 4081 | if (m_Doc->m_Selection->count() == 1 && m_Doc->m_Selection->itemAt()->isTextFrame()) | ||
4717 | 4082 | m_Doc->m_Selection->itemAt()->asTextFrame()->lastUndoAction = PageItem::NOACTION; | ||
4718 | 4083 | m_Doc->view()->Deselect(false); | ||
4719 | 4084 | //CB #2969 add this true parm to addItem so we dont connectToGUI, the rest of view->SelectItem isnt needed anyway | ||
4720 | 4085 | m_Doc->m_Selection->addItem(this, true); | ||
4721 | 4086 | } | ||
4722 | 4087 | |||
4723 | 4088 | ObjAttrVector* PageItem::getObjectAttributes() | ||
4724 | 4089 | { | ||
4725 | 4090 | return &pageItemAttributes; | ||
4726 | 4091 | } | ||
4727 | 4092 | |||
4728 | 4093 | ObjectAttribute PageItem::getObjectAttribute(QString attributeName) const | ||
4729 | 4094 | { | ||
4730 | 4095 | int countFound=0; | ||
4731 | 4096 | ObjAttrVector::const_iterator foundIt = pageItemAttributes.begin(); | ||
4732 | 4097 | for(ObjAttrVector::const_iterator objAttrIt = pageItemAttributes.begin() ; objAttrIt != pageItemAttributes.end(); ++objAttrIt ) | ||
4733 | 4098 | { | ||
4734 | 4099 | if ((*objAttrIt).name==attributeName) | ||
4735 | 4100 | { | ||
4736 | 4101 | ++countFound; | ||
4737 | 4102 | foundIt=objAttrIt; | ||
4738 | 4103 | } | ||
4739 | 4104 | } | ||
4740 | 4105 | ObjectAttribute returnAttribute; | ||
4741 | 4106 | if(countFound==1) | ||
4742 | 4107 | returnAttribute=(*foundIt); | ||
4743 | 4108 | else | ||
4744 | 4109 | returnAttribute.name=QString::null; | ||
4745 | 4110 | return returnAttribute; | ||
4746 | 4111 | } | ||
4747 | 4112 | |||
4748 | 4113 | |||
4749 | 4114 | void PageItem::setObjectAttributes(ObjAttrVector* map) | ||
4750 | 4115 | { | ||
4751 | 4116 | pageItemAttributes=*map; | ||
4752 | 4117 | } | ||
4753 | 4118 | |||
4754 | 4119 | QString PageItem::generateUniqueCopyName(const QString originalName) const | ||
4755 | 4120 | { | ||
4756 | 4121 | if (!m_Doc->itemNameExists(originalName)) | ||
4757 | 4122 | return originalName; | ||
4758 | 4123 | |||
4759 | 4124 | // Start embellishing the name until we get an acceptable unique name | ||
4760 | 4125 | // first we prefix `Copy of' if it's not already there | ||
4761 | 4126 | QString newname(originalName); | ||
4762 | 4127 | if (!originalName.startsWith( tr("Copy of"))) | ||
4763 | 4128 | newname.prepend( tr("Copy of")+" "); | ||
4764 | 4129 | |||
4765 | 4130 | // See if the name prefixed by "Copy of " is free | ||
4766 | 4131 | if (m_Doc->itemNameExists(newname)) | ||
4767 | 4132 | { | ||
4768 | 4133 | // Search the string for (number) at the end and capture | ||
4769 | 4134 | // both the number and the text leading up to it sans brackets. | ||
4770 | 4135 | // Copy of fred (5) | ||
4771 | 4136 | // ^^^^^^^^^^^^ ^ (where ^ means captured) | ||
4772 | 4137 | static QRegExp rx("^(.*)\\s+\\((\\d+)\\)$"); | ||
4773 | 4138 | int numMatches = rx.lastIndexIn(newname); | ||
4774 | 4139 | // Add a (number) suffix to the end of the name. We start at the | ||
4775 | 4140 | // old suffix's value if there was one, or at 2 if there was not. | ||
4776 | 4141 | int suffixnum = 2; | ||
4777 | 4142 | QString prefix(newname); | ||
4778 | 4143 | if (numMatches != -1) | ||
4779 | 4144 | { | ||
4780 | 4145 | // Already had a suffix; use the name w/o suffix for prefix and | ||
4781 | 4146 | // grab the old suffix value as a starting point. | ||
4782 | 4147 | QStringList matches = rx.capturedTexts(); | ||
4783 | 4148 | prefix = matches[1]; | ||
4784 | 4149 | suffixnum = matches[2].toInt(); | ||
4785 | 4150 | } | ||
4786 | 4151 | // Keep on incrementing the suffix 'till we find a free name | ||
4787 | 4152 | do | ||
4788 | 4153 | { | ||
4789 | 4154 | newname = prefix + " (" + QString::number(suffixnum) + ")"; | ||
4790 | 4155 | suffixnum ++; | ||
4791 | 4156 | } | ||
4792 | 4157 | while (m_Doc->itemNameExists(newname)); | ||
4793 | 4158 | } | ||
4794 | 4159 | // Unnecessary assert, previous code ensure condition is always true - JG | ||
4795 | 4160 | // assert(!m_Doc->itemNameExists(newname)); | ||
4796 | 4161 | return newname; | ||
4797 | 4162 | } | ||
4798 | 4163 | |||
4799 | 4164 | void PageItem::setTagged(bool tag) | ||
4800 | 4165 | { | ||
4801 | 4166 | tagged=tag; | ||
4802 | 4167 | } | ||
4803 | 4168 | |||
4804 | 4169 | void PageItem::replaceNamedResources(ResourceCollection& newNames) | ||
4805 | 4170 | { | ||
4806 | 4171 | QMap<QString,QString>::ConstIterator it; | ||
4807 | 4172 | |||
4808 | 4173 | it = newNames.colors().find(fillColor()); | ||
4809 | 4174 | if (it != newNames.colors().end()) | ||
4810 | 4175 | setFillColor(*it); | ||
4811 | 4176 | |||
4812 | 4177 | it = newNames.colors().find(lineColor()); | ||
4813 | 4178 | if (it != newNames.colors().end()) | ||
4814 | 4179 | setLineColor(*it); | ||
4815 | 4180 | |||
4816 | 4181 | QList<VColorStop*> cstops = fill_gradient.colorStops(); | ||
4817 | 4182 | for (uint cst = 0; cst < fill_gradient.Stops(); ++cst) | ||
4818 | 4183 | { | ||
4819 | 4184 | it = newNames.colors().find(cstops.at(cst)->name); | ||
4820 | 4185 | if (it != newNames.colors().end()) | ||
4821 | 4186 | { | ||
4822 | 4187 | if (*it != CommonStrings::None) | ||
4823 | 4188 | cstops.at(cst)->name = *it; | ||
4824 | 4189 | } | ||
4825 | 4190 | } | ||
4826 | 4191 | if (effectsInUse.count() != 0) | ||
4827 | 4192 | { | ||
4828 | 4193 | QString col1 = CommonStrings::None; | ||
4829 | 4194 | QString col2 = CommonStrings::None; | ||
4830 | 4195 | QString col3 = CommonStrings::None; | ||
4831 | 4196 | QString col4 = CommonStrings::None; | ||
4832 | 4197 | for (int a = 0; a < effectsInUse.count(); ++a) | ||
4833 | 4198 | { | ||
4834 | 4199 | QString tmpstr = effectsInUse.at(a).effectParameters; | ||
4835 | 4200 | QString tmpstr2 = ""; | ||
4836 | 4201 | ScTextStream fp(&tmpstr, QIODevice::ReadOnly); | ||
4837 | 4202 | switch (effectsInUse.at(a).effectCode) | ||
4838 | 4203 | { | ||
4839 | 4204 | case ScImage::EF_QUADTONE: | ||
4840 | 4205 | col1 = fp.readLine(); | ||
4841 | 4206 | col2 = fp.readLine(); | ||
4842 | 4207 | col3 = fp.readLine(); | ||
4843 | 4208 | col4 = fp.readLine(); | ||
4844 | 4209 | it = newNames.colors().find(col1); | ||
4845 | 4210 | if (it != newNames.colors().end()) | ||
4846 | 4211 | { | ||
4847 | 4212 | if (*it != CommonStrings::None) | ||
4848 | 4213 | tmpstr2 += *it + "\n"; | ||
4849 | 4214 | else | ||
4850 | 4215 | tmpstr2 += col1 + "\n"; | ||
4851 | 4216 | } | ||
4852 | 4217 | else | ||
4853 | 4218 | tmpstr2 += col1 + "\n"; | ||
4854 | 4219 | it = newNames.colors().find(col2); | ||
4855 | 4220 | if (it != newNames.colors().end()) | ||
4856 | 4221 | { | ||
4857 | 4222 | if (*it != CommonStrings::None) | ||
4858 | 4223 | tmpstr2 += *it + "\n"; | ||
4859 | 4224 | else | ||
4860 | 4225 | tmpstr2 += col2 + "\n"; | ||
4861 | 4226 | } | ||
4862 | 4227 | else | ||
4863 | 4228 | tmpstr2 += col2 + "\n"; | ||
4864 | 4229 | it = newNames.colors().find(col3); | ||
4865 | 4230 | if (it != newNames.colors().end()) | ||
4866 | 4231 | { | ||
4867 | 4232 | if (*it != CommonStrings::None) | ||
4868 | 4233 | tmpstr2 += *it + "\n"; | ||
4869 | 4234 | else | ||
4870 | 4235 | tmpstr2 += col3 + "\n"; | ||
4871 | 4236 | } | ||
4872 | 4237 | else | ||
4873 | 4238 | tmpstr2 += col3 + "\n"; | ||
4874 | 4239 | it = newNames.colors().find(col4); | ||
4875 | 4240 | if (it != newNames.colors().end()) | ||
4876 | 4241 | { | ||
4877 | 4242 | if (*it != CommonStrings::None) | ||
4878 | 4243 | tmpstr2 += *it + "\n"; | ||
4879 | 4244 | else | ||
4880 | 4245 | tmpstr2 += col4 + "\n"; | ||
4881 | 4246 | } | ||
4882 | 4247 | else | ||
4883 | 4248 | tmpstr2 += col4 + "\n"; | ||
4884 | 4249 | tmpstr2 += fp.readAll(); | ||
4885 | 4250 | break; | ||
4886 | 4251 | case ScImage::EF_TRITONE: | ||
4887 | 4252 | col1 = fp.readLine(); | ||
4888 | 4253 | col2 = fp.readLine(); | ||
4889 | 4254 | col3 = fp.readLine(); | ||
4890 | 4255 | it = newNames.colors().find(col1); | ||
4891 | 4256 | if (it != newNames.colors().end()) | ||
4892 | 4257 | { | ||
4893 | 4258 | if (*it != CommonStrings::None) | ||
4894 | 4259 | tmpstr2 += *it + "\n"; | ||
4895 | 4260 | else | ||
4896 | 4261 | tmpstr2 += col1 + "\n"; | ||
4897 | 4262 | } | ||
4898 | 4263 | else | ||
4899 | 4264 | tmpstr2 += col1 + "\n"; | ||
4900 | 4265 | it = newNames.colors().find(col2); | ||
4901 | 4266 | if (it != newNames.colors().end()) | ||
4902 | 4267 | { | ||
4903 | 4268 | if (*it != CommonStrings::None) | ||
4904 | 4269 | tmpstr2 += *it + "\n"; | ||
4905 | 4270 | else | ||
4906 | 4271 | tmpstr2 += col2 + "\n"; | ||
4907 | 4272 | } | ||
4908 | 4273 | else | ||
4909 | 4274 | tmpstr2 += col2 + "\n"; | ||
4910 | 4275 | it = newNames.colors().find(col3); | ||
4911 | 4276 | if (it != newNames.colors().end()) | ||
4912 | 4277 | { | ||
4913 | 4278 | if (*it != CommonStrings::None) | ||
4914 | 4279 | tmpstr2 += *it + "\n"; | ||
4915 | 4280 | else | ||
4916 | 4281 | tmpstr2 += col3 + "\n"; | ||
4917 | 4282 | } | ||
4918 | 4283 | else | ||
4919 | 4284 | tmpstr2 += col3 + "\n"; | ||
4920 | 4285 | tmpstr2 += fp.readAll(); | ||
4921 | 4286 | break; | ||
4922 | 4287 | case ScImage::EF_DUOTONE: | ||
4923 | 4288 | col1 = fp.readLine(); | ||
4924 | 4289 | col2 = fp.readLine(); | ||
4925 | 4290 | it = newNames.colors().find(col1); | ||
4926 | 4291 | if (it != newNames.colors().end()) | ||
4927 | 4292 | { | ||
4928 | 4293 | if (*it != CommonStrings::None) | ||
4929 | 4294 | tmpstr2 += *it + "\n"; | ||
4930 | 4295 | else | ||
4931 | 4296 | tmpstr2 += col1 + "\n"; | ||
4932 | 4297 | } | ||
4933 | 4298 | else | ||
4934 | 4299 | tmpstr2 += col1 + "\n"; | ||
4935 | 4300 | it = newNames.colors().find(col2); | ||
4936 | 4301 | if (it != newNames.colors().end()) | ||
4937 | 4302 | { | ||
4938 | 4303 | if (*it != CommonStrings::None) | ||
4939 | 4304 | tmpstr2 += *it + "\n"; | ||
4940 | 4305 | else | ||
4941 | 4306 | tmpstr2 += col2 + "\n"; | ||
4942 | 4307 | } | ||
4943 | 4308 | else | ||
4944 | 4309 | tmpstr2 += col2 + "\n"; | ||
4945 | 4310 | tmpstr2 += fp.readAll(); | ||
4946 | 4311 | break; | ||
4947 | 4312 | case ScImage::EF_COLORIZE: | ||
4948 | 4313 | col1 = fp.readLine(); | ||
4949 | 4314 | it = newNames.colors().find(col1); | ||
4950 | 4315 | if (it != newNames.colors().end()) | ||
4951 | 4316 | { | ||
4952 | 4317 | if (*it != CommonStrings::None) | ||
4953 | 4318 | tmpstr2 += *it + "\n" + fp.readAll(); | ||
4954 | 4319 | else | ||
4955 | 4320 | tmpstr2 += col1 + "\n" + fp.readAll(); | ||
4956 | 4321 | } | ||
4957 | 4322 | else | ||
4958 | 4323 | tmpstr2 += col1 + "\n" + fp.readAll(); | ||
4959 | 4324 | break; | ||
4960 | 4325 | default: | ||
4961 | 4326 | tmpstr2 = tmpstr; | ||
4962 | 4327 | break; | ||
4963 | 4328 | } | ||
4964 | 4329 | effectsInUse[a].effectParameters = tmpstr2; | ||
4965 | 4330 | } | ||
4966 | 4331 | } | ||
4967 | 4332 | |||
4968 | 4333 | it = newNames.patterns().find(pattern()); | ||
4969 | 4334 | if (it != newNames.patterns().end()) | ||
4970 | 4335 | setPattern(*it); | ||
4971 | 4336 | |||
4972 | 4337 | it = newNames.lineStyles().find(customLineStyle()); | ||
4973 | 4338 | if (it != newNames.lineStyles().end()) | ||
4974 | 4339 | setCustomLineStyle(*it); | ||
4975 | 4340 | |||
4976 | 4341 | if (prevInChain() == NULL) | ||
4977 | 4342 | itemText.replaceNamedResources(newNames); | ||
4978 | 4343 | } | ||
4979 | 4344 | |||
4980 | 4345 | |||
4981 | 4346 | void PageItem::getNamedResources(ResourceCollection& lists) const | ||
4982 | 4347 | { | ||
4983 | 4348 | lists.collectColor(lineColor()); | ||
4984 | 4349 | if (GrType == 0) | ||
4985 | 4350 | lists.collectColor(fillColor()); | ||
4986 | 4351 | else if (GrType < 8) | ||
4987 | 4352 | { | ||
4988 | 4353 | QList<VColorStop*> cstops = fill_gradient.colorStops(); | ||
4989 | 4354 | for (uint cst = 0; cst < fill_gradient.Stops(); ++cst) | ||
4990 | 4355 | { | ||
4991 | 4356 | lists.collectColor(cstops.at(cst)->name); | ||
4992 | 4357 | } | ||
4993 | 4358 | } | ||
4994 | 4359 | if (effectsInUse.count() != 0) | ||
4995 | 4360 | { | ||
4996 | 4361 | for (int a = 0; a < effectsInUse.count(); ++a) | ||
4997 | 4362 | { | ||
4998 | 4363 | QString tmpstr = effectsInUse.at(a).effectParameters; | ||
4999 | 4364 | ScTextStream fp(&tmpstr, QIODevice::ReadOnly); | ||
5000 | 4365 | switch (effectsInUse.at(a).effectCode) |
The diff has been truncated for viewing.
1.4.0.dfsg+r17300-1 has been merged already.