~ubuntu-branches/debian/sid/scribus/sid

« back to all changes in this revision

Viewing changes to .pc/qreal_double.patch/scribus/pageitem.cpp

  • Committer: Package Import Robot
  • Author(s): Mattia Rizzolo
  • Date: 2013-12-21 16:13:37 UTC
  • Revision ID: package-import@ubuntu.com-20131221161337-6pseqv3sa41puz12
Tags: 1.4.2.dfsg+r18267-1.1
* Non-maintainer upload.
* debian/patch/qreal_double.patch: Avoid qreal/double clashes on ARM
  (imported from Ubuntu). (Closes: #707882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
 
3
to the COPYING file provided with the program. Following this notice may exist
 
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
 
5
for which a new license (GPL+exception) is in place.
 
6
*/
 
7
/***************************************************************************
 
8
                          pageitem.cpp  -  description
 
9
                             -------------------
 
10
    begin                : Sat Apr 7 2001
 
11
    copyright            : (C) 2001 by Franz Schmid
 
12
    email                : Franz.Schmid@altmuehlnet.de
 
13
 ***************************************************************************/
 
14
 
 
15
/***************************************************************************
 
16
 *                                                                         *
 
17
 *   This program is free software; you can redistribute it and/or modify  *
 
18
 *   it under the terms of the GNU General Public License as published by  *
 
19
 *   the Free Software Foundation; either version 2 of the License, or     *
 
20
 *   (at your option) any later version.                                   *
 
21
 *                                                                         *
 
22
 ***************************************************************************/
 
23
 
 
24
#include "pageitem.h"
 
25
#include <QPainter>
 
26
#include <QPen>
 
27
#include <QFont>
 
28
#include <QRegion>
 
29
#include <QPoint>
 
30
#include <QFileInfo>
 
31
#include <qdrawutil.h>
 
32
#include <QRegExp>
 
33
#include <QMessageBox>
 
34
#include <QPolygon>
 
35
#include <cassert>
 
36
#include <QDebug>
 
37
#include <iostream>
 
38
#include <sstream>
 
39
#include <string>
 
40
 
 
41
#include "canvas.h"
 
42
#include "cmsettings.h"
 
43
#include "colorblind.h"
 
44
#include "commonstrings.h"
 
45
#include "cpalette.h"
 
46
#include "guidemanager.h"
 
47
#include "page.h"
 
48
#include "pageitem_latexframe.h"
 
49
#include "pageitem_textframe.h"
 
50
#include "prefsmanager.h"
 
51
#include "propertiespalette.h"
 
52
#include "resourcecollection.h"
 
53
#include "scclocale.h"
 
54
#include "sccolorengine.h"
 
55
#include "scconfig.h"
 
56
#include "scpainter.h"
 
57
#include "scpaths.h"
 
58
#include "scpattern.h"
 
59
#include "scribus.h"
 
60
#include "scribusapp.h"
 
61
#include "scribuscore.h"
 
62
#include "scribusdoc.h"
 
63
#include "scribusstructs.h"
 
64
#include "scribuswin.h"
 
65
#include "sctextstream.h"
 
66
#include "serializer.h"
 
67
#include "selection.h"
 
68
#include "sclimits.h"
 
69
#include "text/nlsconfig.h"
 
70
#include "desaxe/saxXML.h"
 
71
#include "undomanager.h"
 
72
#include "undostate.h"
 
73
#include "util.h"
 
74
#include "util_formats.h"
 
75
#include "util_math.h"
 
76
#include "util_text.h"
 
77
#include "util_file.h"
 
78
#ifdef HAVE_CAIRO
 
79
        #include <cairo.h>
 
80
#endif
 
81
 
 
82
using namespace std;
 
83
 
 
84
PageItem::PageItem(const PageItem & other)
 
85
        : QObject(other.parent()),
 
86
         UndoObject(other), SingleObservable<PageItem>(other.m_Doc->itemsChanged()),
 
87
 
 
88
// 200 attributes! That is madness, or to quote some famous people from Kriquet:
 
89
// "THAT ALL HAS TO GO!"
 
90
        gXpos(other.gXpos),
 
91
        gYpos(other.gYpos),
 
92
        gWidth(other.gWidth),
 
93
        gHeight(other.gHeight),
 
94
        GrType(other.GrType),
 
95
        GrStartX(other.GrStartX),
 
96
        GrStartY(other.GrStartY),
 
97
        GrEndX(other.GrEndX),
 
98
        GrEndY(other.GrEndY),
 
99
        Cols(other.Cols),
 
100
        ColGap(other.ColGap),
 
101
        PLineArt(other.PLineArt),
 
102
        PLineEnd(other.PLineEnd),
 
103
        PLineJoin(other.PLineJoin),
 
104
        NamedLStyle(other.NamedLStyle),
 
105
        Clip(other.Clip),
 
106
        PoLine(other.PoLine),
 
107
        ContourLine(other.ContourLine),
 
108
        imageClip(other.imageClip),
 
109
        Segments(other.Segments),
 
110
        effectsInUse(other.effectsInUse),
 
111
        PoShow(other.PoShow),
 
112
        BaseOffs(other.BaseOffs),
 
113
        textPathType(other.textPathType),
 
114
        textPathFlipped(other.textPathFlipped),
 
115
        ClipEdited(other.ClipEdited),
 
116
        FrameType(other.FrameType),
 
117
        ItemNr(other.ItemNr),
 
118
        Frame(other.Frame),
 
119
        OwnPage(other.OwnPage),
 
120
        oldOwnPage(other.oldOwnPage),
 
121
        pixm(other.pixm),
 
122
        Pfile(other.Pfile),
 
123
        Pfile2(other.Pfile2),
 
124
        Pfile3(other.Pfile3),
 
125
        IProfile(other.IProfile),
 
126
        UseEmbedded(other.UseEmbedded),
 
127
        EmProfile(other.EmProfile),
 
128
        IRender(other.IRender),
 
129
 
 
130
        PictureIsAvailable(other.PictureIsAvailable),
 
131
        OrigW(other.OrigW),
 
132
        OrigH(other.OrigH),
 
133
        BBoxX(other.BBoxX),
 
134
        BBoxH(other.BBoxH),
 
135
        CurX(other.CurX),
 
136
        CurY(other.CurY),
 
137
        itemText(other.itemText),
 
138
        isBookmark(other.isBookmark),
 
139
        HasSel(other.HasSel),
 
140
//      Tinput(other.Tinput),
 
141
        isAutoText(other.isAutoText),
 
142
        BackBox(NULL),  // otherwise other.BackBox->NextBox would be inconsistent
 
143
        NextBox(NULL),  // otherwise other.NextBox->BackBox would be inconsistent
 
144
        firstChar(0),   // since this box is unlinked now
 
145
        MaxChars(0),   // since the layout is invalid now
 
146
        inPdfArticle(other.inPdfArticle),
 
147
        isRaster(other.isRaster),
 
148
        OldB(other.OldB),
 
149
        OldH(other.OldH),
 
150
        OldB2(other.OldB2),
 
151
        OldH2(other.OldH2),
 
152
        Sizing(other.Sizing),
 
153
        toPixmap(other.toPixmap),
 
154
        LayerNr(other.LayerNr),
 
155
        ScaleType(other.ScaleType),
 
156
        AspectRatio(other.AspectRatio),
 
157
        Groups(other.Groups),
 
158
        DashValues(other.DashValues),
 
159
        DashOffset(other.DashOffset),
 
160
        fill_gradient(other.fill_gradient),
 
161
        fillRule(other.fillRule),
 
162
        doOverprint(other.doOverprint),
 
163
        LeftLink(other.LeftLink),
 
164
        RightLink(other.RightLink),
 
165
        TopLink(other.TopLink),
 
166
        BottomLink(other.BottomLink),
 
167
        LeftLinkID(other.LeftLinkID),
 
168
        RightLinkID(other.RightLinkID),
 
169
        TopLinkID(other.TopLinkID),
 
170
        BottomLinkID(other.BottomLinkID),
 
171
        LeftLine(other.LeftLine),
 
172
        RightLine(other.RightLine),
 
173
        TopLine(other.TopLine),
 
174
        BottomLine(other.BottomLine),
 
175
        isTableItem(other.isTableItem),
 
176
        isSingleSel(other.isSingleSel),
 
177
        isGroupControl(other.isGroupControl),
 
178
        groupsLastItem(other.groupsLastItem),
 
179
        BoundingX(other.BoundingX),
 
180
        BoundingY(other.BoundingY),
 
181
        BoundingW(other.BoundingW),
 
182
        BoundingH(other.BoundingH),
 
183
        ChangedMasterItem(other.ChangedMasterItem),
 
184
        OnMasterPage(other.OnMasterPage),
 
185
        isEmbedded(other.isEmbedded),
 
186
 
 
187
        // protected
 
188
        undoManager(other.undoManager),
 
189
        m_ItemType(other.m_ItemType),
 
190
        AnName(other.AnName),
 
191
        patternVal(other.patternVal),
 
192
        patternScaleX(other.patternScaleX),
 
193
        patternScaleY(other.patternScaleY),
 
194
        patternOffsetX(other.patternOffsetX),
 
195
        patternOffsetY(other.patternOffsetY),
 
196
        patternRotation(other.patternRotation),
 
197
        fillColorVal(other.fillColorVal),
 
198
        lineColorVal(other.lineColorVal),
 
199
        lineShadeVal(other.lineShadeVal),
 
200
        fillShadeVal(other.fillShadeVal),
 
201
        fillTransparencyVal(other.fillTransparencyVal),
 
202
        lineTransparencyVal(other.lineTransparencyVal),
 
203
        fillBlendmodeVal(other.fillBlendmodeVal),
 
204
        lineBlendmodeVal(other.lineBlendmodeVal),
 
205
        m_ImageIsFlippedH(other.m_ImageIsFlippedH),
 
206
        m_ImageIsFlippedV(other.m_ImageIsFlippedV),
 
207
        m_Locked(other.m_Locked),
 
208
        m_SizeLocked(other.m_SizeLocked),
 
209
        textFlowModeVal(other.textFlowModeVal),
 
210
        pageItemAttributes(other.pageItemAttributes),
 
211
        m_PrintEnabled(other.m_PrintEnabled),
 
212
        tagged(other.tagged),
 
213
        fillQColor(other.fillQColor),
 
214
        strokeQColor(other.strokeQColor),
 
215
        Xpos(other.Xpos),
 
216
        Ypos(other.Ypos),
 
217
        Width(other.Width),
 
218
        Height(other.Height),
 
219
        Rot(other.Rot),
 
220
        Select(other.Select),
 
221
        LocalScX(other.LocalScX),
 
222
        LocalScY(other.LocalScY),
 
223
        LocalX(other.LocalX),
 
224
        LocalY(other.LocalY),
 
225
        Reverse(other.Reverse),
 
226
        m_startArrowIndex(other.m_startArrowIndex),
 
227
        m_endArrowIndex(other.m_endArrowIndex),
 
228
        Extra(other.Extra),
 
229
        TExtra(other.TExtra),
 
230
        BExtra(other.BExtra),
 
231
        RExtra(other.RExtra),
 
232
        firstLineOffsetP(other.firstLineOffsetP),
 
233
        RadRect(other.RadRect),
 
234
        oldXpos(other.oldXpos),
 
235
        oldYpos(other.oldYpos),
 
236
        oldWidth(other.oldWidth),
 
237
        oldHeight(other.oldHeight),
 
238
        oldRot(other.oldRot),
 
239
        oldLocalScX(other.oldLocalScX),
 
240
        oldLocalScY(other.oldLocalScY),
 
241
        oldLocalX(other.oldLocalX),
 
242
        oldLocalY(other.oldLocalY),
 
243
        m_Doc(other.m_Doc),
 
244
        m_isAnnotation(other.m_isAnnotation),
 
245
        m_annotation(other.m_annotation),
 
246
        PicArt(other.PicArt),
 
247
        m_lineWidth(other.m_lineWidth),
 
248
        Oldm_lineWidth(other.Oldm_lineWidth)
 
249
{
 
250
        QString tmp;
 
251
        m_Doc->TotalItems++;
 
252
        AnName += tmp.setNum(m_Doc->TotalItems);
 
253
        uniqueNr = m_Doc->TotalItems;
 
254
        invalid = true;
 
255
        if (other.isInlineImage)
 
256
        {
 
257
                QFileInfo inlFi(Pfile);
 
258
                QString ext = inlFi.suffix();
 
259
                tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_XXXXXX." + ext);
 
260
                tempImageFile->open();
 
261
                QString fileName = getLongPathName(tempImageFile->fileName());
 
262
                tempImageFile->close();
 
263
                copyFile(Pfile, fileName);
 
264
                Pfile = fileName;
 
265
                isInlineImage = true;
 
266
        }
 
267
        else
 
268
        {
 
269
                tempImageFile = NULL;
 
270
                isInlineImage = false;
 
271
        }
 
272
}
 
273
 
 
274
 
 
275
PageItem::PageItem(ScribusDoc *pa, ItemType newType, double x, double y, double w, double h, double w2, QString fill, QString outline)
 
276
        // Initialize superclass(es)
 
277
        : QObject(pa), SingleObservable<PageItem>(pa->itemsChanged()),
 
278
        // Initialize member variables
 
279
        itemText(pa),
 
280
        undoManager(UndoManager::instance()),
 
281
        lineShadeVal(100),
 
282
        fillShadeVal(100),
 
283
        fillTransparencyVal(0.0),
 
284
        lineTransparencyVal(0.0),
 
285
        fillBlendmodeVal(0),
 
286
        lineBlendmodeVal(0),
 
287
        m_ImageIsFlippedH(0),
 
288
        m_ImageIsFlippedV(0),
 
289
        m_Locked(false),
 
290
        m_SizeLocked(false),
 
291
        textFlowModeVal(TextFlowDisabled)
 
292
{
 
293
        m_Doc = pa;
 
294
        QString tmp;
 
295
        BackBox = 0;
 
296
        NextBox = 0;
 
297
        oldXpos = Xpos = x;
 
298
        oldYpos = Ypos = y;
 
299
        //CB Surely we can remove some of these?
 
300
        OldB2 = OldB = oldWidth = Width = w;
 
301
        OldH2 = OldH = oldHeight = Height = h;
 
302
        BoundingX = x;
 
303
        BoundingY = y;
 
304
        BoundingW = w;
 
305
        BoundingH = h;
 
306
        m_ItemType = newType;
 
307
        oldRot = Rot = 0;
 
308
        fillColorVal = fill;
 
309
        lineColorVal = m_ItemType == PageItem::TextFrame ? fill : outline;
 
310
        gXpos = gYpos = 0;
 
311
        gWidth = gHeight = 0;
 
312
        GrType = 0;
 
313
        GrStartX = 0;
 
314
        GrStartY = 0;
 
315
        GrEndX = w;
 
316
        GrEndY = 0;
 
317
        patternVal = "";
 
318
        patternScaleX = 100;
 
319
        patternScaleY = 100;
 
320
        patternOffsetX = 0;
 
321
        patternOffsetY = 0;
 
322
        patternRotation = 0;
 
323
        m_lineWidth = w2;
 
324
        Oldm_lineWidth = w2;
 
325
        PLineArt = Qt::PenStyle(m_Doc->toolSettings.dLineArt);
 
326
        PLineEnd = Qt::FlatCap;
 
327
        PLineJoin = Qt::MiterJoin;
 
328
        Select = false;
 
329
        ClipEdited = false;
 
330
        FrameType = 0;
 
331
        CurX = 0;
 
332
        CurY = 0;
 
333
        oldCPos = 0;
 
334
        Extra = 0;
 
335
        TExtra = 0;
 
336
        BExtra = 0;
 
337
        RExtra = 0;
 
338
        firstChar = 0;
 
339
        MaxChars = 0;
 
340
        Pfile = "";
 
341
        pixm = ScImage();
 
342
        pixm.imgInfo.lowResType = m_Doc->toolSettings.lowResType;
 
343
        Pfile2 = "";
 
344
        Pfile3 = "";
 
345
        oldLocalScX = LocalScX = 1;
 
346
        oldLocalScY = LocalScY = 1;
 
347
        OrigW = 0;
 
348
        OrigH = 0;
 
349
        oldLocalX = LocalX = 0;
 
350
        oldLocalY = LocalY = 0;
 
351
        BBoxX = 0;
 
352
        BBoxH = 0;
 
353
        RadRect = 0;
 
354
        if ((m_ItemType == TextFrame) || (m_ItemType == ImageFrame) || (m_ItemType == PathText))
 
355
                // TODO: Frame should become a read-only calculated property
 
356
                Frame = true;
 
357
        else
 
358
                Frame = false;
 
359
        switch (m_ItemType)
 
360
        {
 
361
                case Polygon:
 
362
                        Clip.setPoints(4, static_cast<int>(w/2), 0, static_cast<int>(w), static_cast<int>(h/2),
 
363
                                                                static_cast<int>(w/2), static_cast<int>(h), 0,static_cast<int>(h/2));
 
364
                        break;
 
365
                default:
 
366
                        Clip.setPoints(4, 0,0, static_cast<int>(w),0, static_cast<int>(w), static_cast<int>(h), 0,static_cast<int>(h));
 
367
                        break;
 
368
        }
 
369
        PoLine.resize(0);
 
370
        ContourLine.resize(0);
 
371
        imageClip.resize(0);
 
372
        Segments.clear();
 
373
        PoShow = false;
 
374
        BaseOffs = 0;
 
375
        textPathType = 0;
 
376
        textPathFlipped = false;
 
377
        OwnPage = m_Doc->currentPage()->pageNr();
 
378
        oldOwnPage = OwnPage;
 
379
        savedOwnPage = OwnPage;
 
380
        PicArt = true;
 
381
        PictureIsAvailable = false;
 
382
        m_PrintEnabled = true;
 
383
        isBookmark = false;
 
384
        m_isAnnotation = false;
 
385
        
 
386
        switch (m_ItemType)
 
387
        {
 
388
        case ImageFrame:
 
389
        case LatexFrame:
 
390
                //We can't determine if this is a latex frame here
 
391
                // because c++'s typeinfos are still saying it's 
 
392
                // a plain pageitem
 
393
                // This is fixed in the PageItem_LatexFrame constructor
 
394
                AnName = tr("Image");
 
395
                setUPixmap(Um::IImageFrame);
 
396
                break;
 
397
        case TextFrame:
 
398
                AnName = tr("Text");
 
399
                setUPixmap(Um::ITextFrame);
 
400
                break;
 
401
        case Line:
 
402
                AnName = tr("Line");
 
403
                setUPixmap(Um::ILine);
 
404
                break;
 
405
        case Polygon:
 
406
                AnName = tr("Polygon");
 
407
                setUPixmap(Um::IPolygon);
 
408
                break;
 
409
        case PolyLine:
 
410
                AnName = tr("Polyline");
 
411
                setUPixmap(Um::IPolyline);
 
412
                break;
 
413
        case PathText:
 
414
                AnName = tr("PathText");
 
415
                setUPixmap(Um::IPathText);
 
416
                break;
 
417
        default:
 
418
                AnName = "Item";
 
419
                break;
 
420
        }
 
421
        m_Doc->TotalItems++;
 
422
        AnName += tmp.setNum(m_Doc->TotalItems); // +" "+QDateTime::currentDateTime().toString();
 
423
        uniqueNr = m_Doc->TotalItems;
 
424
        AutoName = true;
 
425
        setUName(AnName);
 
426
        m_annotation.setBorderColor(outline);
 
427
        HasSel = false;
 
428
//      Tinput = false;
 
429
        isAutoText = false;
 
430
        inPdfArticle = false;
 
431
        isRaster = false;
 
432
        Sizing = false;
 
433
        toPixmap = false;
 
434
        UseEmbedded = true;
 
435
        IRender = Intent_Relative_Colorimetric;
 
436
        EmProfile = "";
 
437
        Groups.clear();
 
438
        LayerNr = m_Doc->activeLayer();
 
439
        ScaleType = true;
 
440
        AspectRatio = true;
 
441
        Reverse = false;
 
442
        NamedLStyle = "";
 
443
        DashValues.clear();
 
444
        DashOffset = 0;
 
445
        fillRule = true;
 
446
        doOverprint = false;
 
447
        fill_gradient = VGradient(VGradient::linear);
 
448
        fill_gradient.clearStops();
 
449
        if (fillColorVal != CommonStrings::None)
 
450
        {
 
451
                const ScColor& col = m_Doc->PageColors[fillColorVal];
 
452
                QColor qcol = ScColorEngine::getRGBColor(col, m_Doc);
 
453
                fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, fillColorVal, 100);
 
454
                fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, fillColorVal, 100);
 
455
        }
 
456
        else
 
457
        {
 
458
                if (m_Doc->toolSettings.dBrush != CommonStrings::None)
 
459
                {
 
460
                        const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dBrush];
 
461
                        QColor qcol = ScColorEngine::getRGBColor(col, m_Doc);
 
462
                        fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
 
463
                        fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
 
464
                }
 
465
                else
 
466
                {
 
467
                        if (lineColorVal != CommonStrings::None)
 
468
                        {
 
469
                                const ScColor& col = m_Doc->PageColors[lineColorVal];
 
470
                                QColor qcol = ScColorEngine::getRGBColor(col, m_Doc);
 
471
                                fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, lineColorVal, 100);
 
472
                                fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, lineColorVal, 100);
 
473
                        }
 
474
                        else
 
475
                        {
 
476
                                if (m_Doc->toolSettings.dPen != CommonStrings::None)
 
477
                                {
 
478
                                        const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dPen];
 
479
                                        QColor qcol = ScColorEngine::getRGBColor(col, m_Doc);
 
480
                                        fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
 
481
                                        fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
 
482
                                }
 
483
                                else if (m_Doc->PageColors.contains("Black"))
 
484
                                {
 
485
                                        const ScColor& col = m_Doc->PageColors["Black"];
 
486
                                        QColor qcol = ScColorEngine::getRGBColor(col, m_Doc);
 
487
                                        fill_gradient.addStop(qcol, 0.0, 0.5, 1.0, "Black", 100);
 
488
                                        fill_gradient.addStop(qcol, 1.0, 0.5, 1.0, "Black", 100);
 
489
                                }
 
490
                        }
 
491
                }
 
492
        }
 
493
        firstLineOffsetP = FLOPRealGlyphHeight;
 
494
        Cols = m_Doc->toolSettings.dCols;
 
495
        ColGap = m_Doc->toolSettings.dGap;
 
496
        LeftLink = 0;
 
497
        RightLink = 0;
 
498
        TopLink = 0;
 
499
        BottomLink = 0;
 
500
        LeftLinkID = 0;
 
501
        RightLinkID = 0;
 
502
        TopLinkID = 0;
 
503
        BottomLinkID = 0;
 
504
        LeftLine = 0;
 
505
        RightLine = false;
 
506
        TopLine = false;
 
507
        BottomLine = false;
 
508
        isTableItem = false;
 
509
        isSingleSel = false;
 
510
        Dirty = false;
 
511
        invalid = true;
 
512
        isGroupControl = false;
 
513
        groupsLastItem = 0;
 
514
        ChangedMasterItem = false;
 
515
        isEmbedded = false;
 
516
        OnMasterPage = m_Doc->currentPage()->pageName();
 
517
        m_startArrowIndex = m_Doc->toolSettings.dStartArrow;
 
518
        m_endArrowIndex = m_Doc->toolSettings.dEndArrow;
 
519
        effectsInUse.clear();
 
520
        //Page Item Attributes
 
521
        pageItemAttributes.clear();
 
522
        for(ObjAttrVector::Iterator objAttrIt = m_Doc->docItemAttributes.begin() ; objAttrIt != m_Doc->docItemAttributes.end(); ++objAttrIt )
 
523
        {
 
524
                if (((*objAttrIt).autoaddto=="textframes" && m_ItemType==TextFrame) ||
 
525
                        ((*objAttrIt).autoaddto=="imageframes" && m_ItemType==ImageFrame)
 
526
                        )
 
527
                        pageItemAttributes.append(*objAttrIt);
 
528
        }
 
529
        tempImageFile = NULL;
 
530
        isInlineImage = false;
 
531
}
 
532
 
 
533
void PageItem::setXPos(const double newXPos, bool drawingOnly)
 
534
{
 
535
        Xpos = newXPos;
 
536
        if (drawingOnly || m_Doc->isLoading())
 
537
                return;
 
538
        checkChanges();
 
539
        emit position(Xpos, Ypos);
 
540
}
 
541
 
 
542
void PageItem::setYPos(const double newYPos, bool drawingOnly)
 
543
{
 
544
        Ypos = newYPos;
 
545
        if (drawingOnly || m_Doc->isLoading())
 
546
                return;
 
547
        checkChanges();
 
548
        emit position(Xpos, Ypos);
 
549
}
 
550
 
 
551
void PageItem::setXYPos(const double newXPos, const double newYPos, bool drawingOnly)
 
552
{
 
553
        Xpos = newXPos;
 
554
        Ypos = newYPos;
 
555
        if (drawingOnly || m_Doc->isLoading())
 
556
                return;
 
557
        checkChanges();
 
558
        emit position(Xpos, Ypos);
 
559
}
 
560
 
 
561
void PageItem::moveBy(const double dX, const double dY, bool drawingOnly)
 
562
{
 
563
        if (dX==0.0 && dY==0.0)
 
564
                return;
 
565
        invalid = true;
 
566
        if (dX!=0.0)
 
567
                Xpos+=dX;
 
568
        if (dY!=0.0)
 
569
                Ypos+=dY;
 
570
        if (drawingOnly || m_Doc->isLoading())
 
571
                return;
 
572
        checkChanges();
 
573
        emit position(Xpos, Ypos);
 
574
}
 
575
 
 
576
void PageItem::setWidth(const double newWidth)
 
577
{
 
578
        Width = newWidth;
 
579
        updateConstants();
 
580
        checkChanges();
 
581
        emit widthAndHeight(Width, Height);
 
582
}
 
583
 
 
584
void PageItem::setHeight(const double newHeight)
 
585
{
 
586
        Height = newHeight;
 
587
        updateConstants();
 
588
        checkChanges();
 
589
        emit widthAndHeight(Width, Height);
 
590
}
 
591
 
 
592
void PageItem::setWidthHeight(const double newWidth, const double newHeight, bool drawingOnly)
 
593
{
 
594
        Width = newWidth;
 
595
        Height = newHeight;
 
596
        updateConstants();
 
597
        if (drawingOnly)
 
598
                return;
 
599
        checkChanges();
 
600
        emit widthAndHeight(Width, Height);
 
601
}
 
602
 
 
603
void PageItem::setWidthHeight(const double newWidth, const double newHeight)
 
604
{
 
605
        Width = newWidth;
 
606
        Height = newHeight;
 
607
        updateConstants();
 
608
        checkChanges();
 
609
        emit widthAndHeight(Width, Height);
 
610
}
 
611
 
 
612
void PageItem::resizeBy(const double dH, const double dW)
 
613
{
 
614
        if (dH==0.0 && dW==0.0)
 
615
                return;
 
616
        if (dH!=0.0)
 
617
                Width+=dH;
 
618
        if (dW!=0.0)
 
619
                Height+=dW;
 
620
        updateConstants();
 
621
        checkChanges();
 
622
        emit widthAndHeight(Width, Height);
 
623
}
 
624
 
 
625
void PageItem::setRotation(const double newRotation, bool drawingOnly)
 
626
{
 
627
        Rot=newRotation;
 
628
        checkChanges();
 
629
        if (drawingOnly || m_Doc->isLoading())
 
630
                return;
 
631
        emit rotation(Rot);
 
632
}
 
633
 
 
634
void PageItem::rotateBy(const double dR)
 
635
{
 
636
        if (dR==0.0)
 
637
                return;
 
638
        Rot+=dR;
 
639
        checkChanges();
 
640
        emit rotation(Rot);
 
641
}
 
642
 
 
643
void PageItem::setSelected(const bool toSelect)
 
644
{
 
645
        Select=toSelect;
 
646
}
 
647
 
 
648
void PageItem::setImageXScale(const double newImageXScale)
 
649
{
 
650
        LocalScX=newImageXScale;
 
651
        checkChanges();
 
652
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
653
}
 
654
 
 
655
void PageItem::setImageYScale(const double newImageYScale)
 
656
{
 
657
        LocalScY=newImageYScale;
 
658
        checkChanges();
 
659
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
660
}
 
661
 
 
662
void PageItem::setImageXYScale(const double newImageXScale, const double newImageYScale)
 
663
{
 
664
        LocalScX=newImageXScale;
 
665
        LocalScY=newImageYScale;
 
666
        checkChanges();
 
667
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
668
}
 
669
 
 
670
void PageItem::setImageXOffset(const double newImageXOffset)
 
671
{
 
672
        LocalX=newImageXOffset;
 
673
        checkChanges();
 
674
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
675
}
 
676
 
 
677
void PageItem::setImageYOffset(const double newImageYOffset)
 
678
{
 
679
        LocalY=newImageYOffset;
 
680
        checkChanges();
 
681
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
682
}
 
683
 
 
684
void PageItem::setImageXYOffset(const double newImageXOffset, const double newImageYOffset)
 
685
{
 
686
        LocalX=newImageXOffset;
 
687
        LocalY=newImageYOffset;
 
688
        checkChanges();
 
689
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
690
}
 
691
 
 
692
void PageItem::moveImageXYOffsetBy(const double dX, const double dY)
 
693
{
 
694
        if (dX==0.0 && dY==0.0)
 
695
                return;
 
696
        if (dX != 0.0)
 
697
                LocalX += dX;
 
698
        if (dY != 0.0)
 
699
                LocalY += dY;
 
700
        checkChanges();
 
701
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
702
}
 
703
 
 
704
void PageItem::setReversed(bool newReversed)
 
705
{
 
706
        if (Reverse == newReversed)
 
707
                return;
 
708
        if (UndoManager::undoEnabled())
 
709
        {
 
710
                SimpleState *ss = new SimpleState(Um::FlipH, 0, Um::IFlipH);
 
711
                ss->set("REVERSE_TEXT", newReversed);
 
712
                undoManager->action(this, ss);
 
713
        }
 
714
        Reverse = newReversed;
 
715
}
 
716
 
 
717
//return frame where is text end
 
718
PageItem * PageItem::frameTextEnd()
 
719
{
 
720
        PageItem * LastBox = this;
 
721
        if (frameOverflows() && NextBox)
 
722
        { // text ending in some next frame
 
723
                LastBox = NextBox;
 
724
                while (LastBox != 0 && !LastBox->frameDisplays(itemText.length()-1))
 
725
                        LastBox = LastBox->nextInChain();
 
726
        }
 
727
        else if (frameUnderflows() && BackBox)
 
728
        { //text ending in some previous frame
 
729
                LastBox = BackBox;
 
730
                while (LastBox != 0 && !LastBox->frameDisplays(itemText.length()-1))
 
731
                        LastBox = LastBox->prevInChain();
 
732
        }
 
733
        return LastBox;
 
734
}
 
735
 
 
736
/// returns true if text overflows
 
737
bool PageItem::frameOverflows() const
 
738
{
 
739
#ifndef NLS_PROTO
 
740
        // Fix #6991 : "Text overflow" warning when there is a text underflow in fact
 
741
        /*return NextBox == NULL && itemText.length() > static_cast<int>(MaxChars);*/
 
742
        return ( NextBox == NULL )
 
743
               && ( static_cast<int> ( firstChar ) < itemText.length() )
 
744
                   // Fix #7766 : scribus.textOverflows() returns 0 if there is no place for the overflow mark
 
745
               /*&& ( firstChar < MaxChars )*/
 
746
                   && ( firstChar <= MaxChars )
 
747
               && ( itemText.length() > static_cast<int> ( MaxChars ) );
 
748
#else
 
749
        return false; // FIXME:NLS
 
750
#endif
 
751
}
 
752
 
 
753
/// returns true if text is ending before that frame
 
754
bool PageItem::frameUnderflows() const
 
755
{
 
756
        if (BackBox == NULL)
 
757
                return false;
 
758
        //FIX ME - I have found that condition if frame is empty
 
759
        //and has been linked with previous frame
 
760
        //if you will find any better solution - fix that function
 
761
        return (firstInFrame() > lastInFrame());
 
762
}
 
763
 
 
764
int PageItem::firstInFrame() const
 
765
{
 
766
        return firstChar;
 
767
}
 
768
int PageItem::lastInFrame() const
 
769
{
 
770
#ifndef NLS_PROTO
 
771
        return qMin(signed(MaxChars), itemText.length()) - 1;
 
772
#else
 
773
        return itemText.length() - 1;
 
774
#endif
 
775
}
 
776
 
 
777
bool PageItem::testLinkCandidate(PageItem* nxt)
 
778
{
 
779
        if (this->nextInChain() )
 
780
                return false;
 
781
        if (nxt->prevInChain() )
 
782
                return false;
 
783
        for (PageItem* ff=nxt; ff; ff=ff->nextInChain())
 
784
        {
 
785
                if (ff == this) return false;
 
786
        }
 
787
        return true;
 
788
}
 
789
 
 
790
void PageItem::link(PageItem* nxt)
 
791
{
 
792
        assert( !nextInChain() );
 
793
        assert( !nxt->prevInChain() );
 
794
        for (PageItem* ff=nxt; ff; ff=ff->nextInChain())
 
795
        {
 
796
                assert (ff != this);
 
797
        }
 
798
        // Append only if necessary to avoid the
 
799
        // charstyle: access at end of text warning
 
800
        if (nxt->itemText.length() > 0)
 
801
                itemText.append(nxt->itemText);
 
802
        NextBox = nxt;
 
803
        nxt->BackBox = this;
 
804
        // update AutoText
 
805
        if (isAutoText)
 
806
        {
 
807
                PageItem* after = nxt;
 
808
                while (after)
 
809
                {
 
810
                        after->isAutoText = true;
 
811
                        m_Doc->LastAuto = after;
 
812
                        after = after->NextBox;
 
813
                }
 
814
        }
 
815
        else if (nxt->isAutoText)
 
816
        {
 
817
                PageItem* before = this;
 
818
                while (before)
 
819
                {
 
820
                        before->isAutoText = true;
 
821
                        m_Doc->FirstAuto = before;
 
822
                        before = before->BackBox;
 
823
                }
 
824
        }
 
825
        invalid = true;
 
826
        while (nxt)
 
827
        {
 
828
                nxt->itemText = itemText;
 
829
                nxt->invalid = true;
 
830
                nxt->firstChar = 0;
 
831
                nxt = nxt->NextBox;
 
832
        }
 
833
        if (UndoManager::undoEnabled())
 
834
        {
 
835
                ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >(UndoManager::LinkTextFrame);
 
836
                is->set("LINK_TEXT_FRAME", "linkTextFrame");
 
837
                is->setItem(std::pair<PageItem*, PageItem*>(this, NextBox));
 
838
                undoManager->action(this, is);
 
839
        }
 
840
}
 
841
 
 
842
void PageItem::unlink()
 
843
{
 
844
        if( NextBox )
 
845
        {
 
846
                PageItem *undoNextBox=NextBox;
 
847
                // make sure lastInFrame is valid
 
848
                layout();
 
849
                /*
 
850
                //<< CB #6332: Stop the StoryText cut and break and act like other publishing apps
 
851
                // move following text to new StoryText
 
852
                itemText.select(lastInFrame()+1, itemText.length()-lastInFrame()-1);
 
853
                */
 
854
                StoryText follow(m_Doc);
 
855
                /*
 
856
                follow.setDefaultStyle(itemText.defaultStyle());
 
857
                follow.insert(0, itemText, true);
 
858
                // remove following text from this chain
 
859
                itemText.removeSelection();
 
860
                //>> 
 
861
                */
 
862
                // update auto pointers
 
863
                if (isAutoText)
 
864
                {
 
865
                        PageItem* before = this;
 
866
                        while (before) 
 
867
                        {
 
868
                                before->isAutoText = false;
 
869
                                before = before->BackBox;
 
870
                        }
 
871
                        m_Doc->FirstAuto = NextBox;
 
872
                }
 
873
                // link following frames to new text
 
874
                NextBox->firstChar = 0;
 
875
                NextBox->BackBox = NULL;
 
876
                while (NextBox) {
 
877
                        NextBox->itemText = follow;
 
878
                        NextBox->invalid = true;
 
879
                        NextBox->firstChar = 0;
 
880
                        NextBox = NextBox->NextBox;
 
881
                }
 
882
                // NextBox == NULL now
 
883
                NextBox = NULL;
 
884
                if (UndoManager::undoEnabled())
 
885
                {
 
886
                        ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >(UndoManager::UnlinkTextFrame);
 
887
                        is->set("UNLINK_TEXT_FRAME", "unlinkTextFrame");
 
888
                        is->setItem(std::pair<PageItem*, PageItem*>(this, undoNextBox));
 
889
                        undoManager->action(this, is);
 
890
                }
 
891
        }
 
892
}
 
893
 
 
894
 
 
895
void PageItem::dropLinks()
 
896
{
 
897
        // update auto pointers
 
898
        if (isAutoText && NextBox == 0)
 
899
        {
 
900
                m_Doc->LastAuto = BackBox;
 
901
        }
 
902
        if (isAutoText && BackBox == 0)
 
903
        {
 
904
                m_Doc->FirstAuto = NextBox;
 
905
        }
 
906
        isAutoText = false;
 
907
 
 
908
        // leave text in remaining chain
 
909
        PageItem* before = BackBox;
 
910
        PageItem* after = NextBox;
 
911
        if (after != 0 || before != 0)
 
912
        {
 
913
                itemText = StoryText(m_Doc);
 
914
                if (before)
 
915
                        before->NextBox = after;
 
916
                if (after) 
 
917
                {
 
918
                        after->BackBox = before;
 
919
                        while (after)
 
920
                        { 
 
921
                                after->invalid = true;
 
922
                                after->firstChar = 0;
 
923
                                after = after->NextBox;
 
924
                        }
 
925
                }
 
926
                // JG we should set BackBox and NextBox to NULL at a point
 
927
                BackBox = NextBox = NULL;
 
928
        }
 
929
}
 
930
 
 
931
/// tests if a character is displayed by this frame
 
932
bool PageItem::frameDisplays(int textpos) const
 
933
{
 
934
#ifndef NLS_PROTO
 
935
        return 0 <= textpos && textpos < signed(MaxChars) &&  textpos < itemText.length();
 
936
#else
 
937
        return true; // FIXME:NLS
 
938
#endif
 
939
}
 
940
 
 
941
 
 
942
/// returns the style at the current charpos
 
943
const ParagraphStyle& PageItem::currentStyle() const
 
944
{
 
945
        if (frameDisplays(itemText.cursorPosition()))
 
946
                return itemText.paragraphStyle();
 
947
        else
 
948
                return itemText.defaultStyle();
 
949
}
 
950
 
 
951
/// returns the style at the current charpos for changing
 
952
ParagraphStyle& PageItem::changeCurrentStyle()
 
953
{
 
954
        if (frameDisplays(itemText.cursorPosition()))
 
955
                return const_cast<ParagraphStyle&>(itemText.paragraphStyle());
 
956
        else
 
957
                return const_cast<ParagraphStyle&>(itemText.defaultStyle());
 
958
}
 
959
 
 
960
/// returns the style at the current charpos
 
961
const CharStyle& PageItem::currentCharStyle() const
 
962
{
 
963
        if (frameDisplays(itemText.cursorPosition()))
 
964
                return itemText.charStyle();
 
965
        else
 
966
                return itemText.defaultStyle().charStyle();
 
967
}
 
968
 
 
969
void PageItem::setTextToFrameDistLeft(double newLeft)
 
970
{
 
971
        Extra=newLeft;
 
972
        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 
973
}
 
974
 
 
975
void PageItem::setTextToFrameDistRight(double newRight)
 
976
{
 
977
        RExtra=newRight;
 
978
        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 
979
}
 
980
 
 
981
void PageItem::setTextToFrameDistTop(double newTop)
 
982
{
 
983
        TExtra=newTop;
 
984
        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 
985
}
 
986
 
 
987
void PageItem::setTextToFrameDistBottom(double newBottom)
 
988
{
 
989
        BExtra=newBottom;
 
990
        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 
991
}
 
992
 
 
993
void PageItem::setTextToFrameDist(double newLeft, double newRight, double newTop, double newBottom)
 
994
{
 
995
        Extra=newLeft;
 
996
        RExtra=newRight;
 
997
        TExtra=newTop;
 
998
        BExtra=newBottom;
 
999
        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 
1000
}
 
1001
 
 
1002
double PageItem::gridOffset() const { return m_Doc->typographicSettings.offsetBaseGrid; }
 
1003
double PageItem::gridDistance() const { return m_Doc->typographicSettings.valueBaseGrid; }
 
1004
 
 
1005
void PageItem::setGridOffset(double) { } // FIXME
 
1006
void PageItem::setGridDistance(double) { } // FIXME
 
1007
void PageItem::setColumns(int n) 
 
1008
{
 
1009
        Cols = qMax(1, n); //FIXME: undo
 
1010
}
 
1011
void PageItem::setColumnGap(double gap)
 
1012
{
 
1013
        ColGap = gap; //FIXME: undo
 
1014
}
 
1015
 
 
1016
void PageItem::setCornerRadius(double newRadius)
 
1017
{
 
1018
        RadRect=newRadius;
 
1019
        emit cornerRadius(RadRect);
 
1020
}
 
1021
 
 
1022
 
 
1023
 
 
1024
 
 
1025
 
 
1026
 
 
1027
 
 
1028
 
 
1029
 
 
1030
/** Paints the item.
 
1031
    CHANGE: cullingArea is in doc coordinates!
 
1032
 */
 
1033
void PageItem::DrawObj(ScPainter *p, QRectF cullingArea)
 
1034
{
 
1035
//      qDebug << "PageItem::DrawObj";
 
1036
        double sc;
 
1037
        if (!m_Doc->DoDrawing)
 
1038
        {
 
1039
//              Tinput = false;
 
1040
                return;
 
1041
        }
 
1042
        if (cullingArea.isNull())
 
1043
        {
 
1044
                cullingArea = QRectF(QPointF(m_Doc->minCanvasCoordinate.x(), m_Doc->minCanvasCoordinate.y()), 
 
1045
                                                         QPointF(m_Doc->maxCanvasCoordinate.x(), m_Doc->maxCanvasCoordinate.y())).toAlignedRect();
 
1046
        }
 
1047
        
 
1048
        DrawObj_Pre(p, sc);
 
1049
        if (m_Doc->layerOutline(LayerNr))
 
1050
        {
 
1051
                if ((itemType()==TextFrame || itemType()==ImageFrame || itemType()==PathText || itemType()==Line || itemType()==PolyLine) && (!isGroupControl))
 
1052
                        DrawObj_Item(p, cullingArea, sc);
 
1053
        }
 
1054
        else
 
1055
        {
 
1056
                if (!isGroupControl)
 
1057
                        DrawObj_Item(p, cullingArea, sc);
 
1058
        }
 
1059
        DrawObj_Post(p);
 
1060
}
 
1061
 
 
1062
void PageItem::DrawObj_Pre(ScPainter *p, double &sc)
 
1063
{
 
1064
        ScribusView* view = m_Doc->view();
 
1065
        sc = view->scale();
 
1066
        p->save();
 
1067
        if (!isEmbedded)
 
1068
                p->translate(Xpos, Ypos);
 
1069
        p->rotate(Rot);
 
1070
        if (m_Doc->layerOutline(LayerNr))
 
1071
        {
 
1072
                p->setPen(m_Doc->layerMarker(LayerNr), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1073
                p->setFillMode(ScPainter::None);
 
1074
                p->setBrushOpacity(1.0);
 
1075
                p->setPenOpacity(1.0);
 
1076
        }
 
1077
        else
 
1078
        {
 
1079
                if (!isGroupControl)
 
1080
                {
 
1081
                        if (fillBlendmode() != 0)
 
1082
                                p->beginLayer(1.0 - fillTransparency(), fillBlendmode());
 
1083
 
 
1084
                        p->setLineWidth(m_lineWidth);
 
1085
                        if (GrType != 0)
 
1086
                        {
 
1087
                                if (GrType == 8)
 
1088
                                {
 
1089
                                        if ((patternVal.isEmpty()) || (!m_Doc->docPatterns.contains(patternVal)))
 
1090
                                        {
 
1091
                                                p->fill_gradient = VGradient(VGradient::linear);
 
1092
                                                if (fillColor() != CommonStrings::None)
 
1093
                                                {
 
1094
                                                        p->setBrush(fillQColor);
 
1095
                                                        p->setFillMode(ScPainter::Solid);
 
1096
                                                }
 
1097
                                                else
 
1098
                                                        p->setFillMode(ScPainter::None);
 
1099
                                                if ((!patternVal.isEmpty()) && (!m_Doc->docPatterns.contains(patternVal)))
 
1100
                                                {
 
1101
                                                        GrType = 0;
 
1102
                                                        patternVal = "";
 
1103
                                                }
 
1104
                                        }
 
1105
                                        else
 
1106
                                        {
 
1107
                                                p->setPattern(&m_Doc->docPatterns[patternVal], patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
 
1108
                                                p->setFillMode(ScPainter::Pattern);
 
1109
                                        }
 
1110
                                }
 
1111
                                else
 
1112
                                {
 
1113
                                        if (fill_gradient.Stops() < 2) // fall back to solid filling if there are not enough colorstops in the gradient.
 
1114
                                        {
 
1115
                                                if (fillColor() != CommonStrings::None)
 
1116
                                                {
 
1117
                                                        p->setBrush(fillQColor);
 
1118
                                                        p->setFillMode(ScPainter::Solid);
 
1119
                                                }
 
1120
                                                else
 
1121
                                                        p->setFillMode(ScPainter::None);
 
1122
                                        }
 
1123
                                        else
 
1124
                                        {
 
1125
                                                p->setFillMode(ScPainter::Gradient);
 
1126
                                                p->fill_gradient = fill_gradient;
 
1127
                                                QMatrix grm;
 
1128
                                                grm.rotate(Rot);
 
1129
                                                FPointArray gra;
 
1130
                                                switch (GrType)
 
1131
                                                {
 
1132
                                                        case 1:
 
1133
                                                        case 2:
 
1134
                                                        case 3:
 
1135
                                                        case 4:
 
1136
                                                        case 6:
 
1137
                                                                p->setGradient(VGradient::linear, FPoint(GrStartX, GrStartY), FPoint(GrEndX, GrEndY));
 
1138
                                                                break;
 
1139
                                                        case 5:
 
1140
                                                        case 7:
 
1141
                                                                gra.setPoints(2, GrStartX, GrStartY, GrEndX, GrEndY);
 
1142
                                                                p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
 
1143
                                                                break;
 
1144
                                                }
 
1145
                                        }
 
1146
                                }
 
1147
                        }
 
1148
                        else
 
1149
                        {
 
1150
                                p->fill_gradient = VGradient(VGradient::linear);
 
1151
                                if (fillColor() != CommonStrings::None)
 
1152
                                {
 
1153
                                        p->setBrush(fillQColor);
 
1154
                                        p->setFillMode(ScPainter::Solid);
 
1155
                                }
 
1156
                                else
 
1157
                                        p->setFillMode(ScPainter::None);
 
1158
                        }
 
1159
                        if (lineColor() != CommonStrings::None)
 
1160
                        {
 
1161
//                              if ((m_lineWidth == 0) && ! asLine())
 
1162
//                                      p->setLineWidth(0);
 
1163
//                              else
 
1164
//                              {
 
1165
                                        p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin);
 
1166
                                        if (DashValues.count() != 0)
 
1167
                                                p->setDash(DashValues, DashOffset);
 
1168
//                              }
 
1169
                        }
 
1170
                        else
 
1171
                                p->setLineWidth(0);
 
1172
                        if (fillBlendmode() == 0)
 
1173
                                p->setBrushOpacity(1.0 - fillTransparency());
 
1174
                        if (lineBlendmode() == 0)
 
1175
                                p->setPenOpacity(1.0 - lineTransparency());
 
1176
                        p->setFillRule(fillRule);
 
1177
                }
 
1178
        }
 
1179
}
 
1180
 
 
1181
void PageItem::DrawObj_Post(ScPainter *p)
 
1182
{
 
1183
        bool doStroke=true;
 
1184
        ScribusView* view = m_Doc->view();
 
1185
        if (!isGroupControl)
 
1186
        {
 
1187
                if (m_Doc->layerOutline(LayerNr))
 
1188
                {
 
1189
                        if (itemType()!=Line)
 
1190
                        {
 
1191
                                p->setPen(m_Doc->layerMarker(LayerNr), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1192
                                p->setFillMode(ScPainter::None);
 
1193
                                p->setBrushOpacity(1.0);
 
1194
                                p->setPenOpacity(1.0);
 
1195
                                if (itemType()==PolyLine)
 
1196
                                        p->setupPolygon(&PoLine, false);
 
1197
                                else if (itemType() == PathText)
 
1198
                                {
 
1199
                                        if (PoShow)
 
1200
                                                p->setupPolygon(&PoLine, false);
 
1201
                                        else
 
1202
                                                doStroke = false;
 
1203
                                }
 
1204
                                else
 
1205
                                        p->setupPolygon(&PoLine);
 
1206
                                if (doStroke)
 
1207
                                        p->strokePath();
 
1208
                                if (itemType()==ImageFrame)
 
1209
                                {
 
1210
                                        if (imageClip.size() != 0)
 
1211
                                        {
 
1212
                                                p->setupPolygon(&imageClip);
 
1213
                                                p->strokePath();
 
1214
                                        }
 
1215
                                }
 
1216
                        }
 
1217
                }
 
1218
                else
 
1219
                {
 
1220
                        if (fillBlendmode() != 0)
 
1221
                                p->endLayer();
 
1222
                        if (itemType()==PathText || itemType()==PolyLine || itemType()==Line)
 
1223
                                doStroke=false;
 
1224
                        if ((doStroke) && (!m_Doc->RePos))
 
1225
                        {
 
1226
                                if (lineBlendmode() != 0)
 
1227
                                        p->beginLayer(1.0 - lineTransparency(), lineBlendmode());
 
1228
//                              if (lineColor() != CommonStrings::None)
 
1229
//                              {
 
1230
//                                      p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin);
 
1231
//                                      if (DashValues.count() != 0)
 
1232
//                                              p->setDash(DashValues, DashOffset);
 
1233
//                              }
 
1234
//                              else
 
1235
//                                      p->setLineWidth(0);
 
1236
                                if (!isTableItem)
 
1237
                                {
 
1238
                                        if ((itemType() == LatexFrame) || (itemType() == ImageFrame))
 
1239
                                                p->setupPolygon(&PoLine);
 
1240
                                        if (NamedLStyle.isEmpty())
 
1241
                                        {
 
1242
                                                if (lineColor() != CommonStrings::None)
 
1243
                                                {
 
1244
                                                        p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin);
 
1245
                                                        if (DashValues.count() != 0)
 
1246
                                                                p->setDash(DashValues, DashOffset);
 
1247
                                                        p->strokePath();
 
1248
                                                }
 
1249
                                        }
 
1250
                                        else
 
1251
                                        {
 
1252
                                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
1253
                                                QColor tmp;
 
1254
                                                for (int it = ml.size()-1; it > -1; it--)
 
1255
                                                {
 
1256
                                                        struct SingleLine& sl = ml[it];
 
1257
                                                        // Qt4 if ((!sl.Color != CommonStrings::None) && (sl.Width != 0))
 
1258
                                                        if (sl.Color != CommonStrings::None) // && (sl.Width != 0))
 
1259
                                                        {
 
1260
                                                                SetQColor(&tmp, sl.Color, sl.Shade);
 
1261
                                                                p->setPen(tmp, sl.Width, static_cast<Qt::PenStyle>(sl.Dash), static_cast<Qt::PenCapStyle>(sl.LineEnd), static_cast<Qt::PenJoinStyle>(sl.LineJoin));
 
1262
                                                                p->strokePath();
 
1263
                                                        }
 
1264
                                                }
 
1265
                                        }
 
1266
                                }
 
1267
                                if (lineBlendmode() != 0)
 
1268
                                        p->endLayer();
 
1269
                        }
 
1270
                }
 
1271
        }
 
1272
        if ((!isEmbedded) && (!m_Doc->RePos))
 
1273
        {
 
1274
                double aestheticFactor(3.33);
 
1275
                double scpInv = 1.0 / (view->scale() * aestheticFactor);
 
1276
                if (!isGroupControl)
 
1277
                {
 
1278
                        if ((Frame) && (m_Doc->guidesSettings.framesShown) && ((itemType() == ImageFrame) || (itemType() == LatexFrame) || (itemType() == PathText)))
 
1279
                        {
 
1280
                                p->setPen(PrefsManager::instance()->appPrefs.DFrameNormColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1281
                                if ((isBookmark) || (m_isAnnotation))
 
1282
                                        p->setPen(PrefsManager::instance()->appPrefs.DFrameAnnotationColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1283
                                if ((BackBox != 0) || (NextBox != 0))
 
1284
                                        p->setPen(PrefsManager::instance()->appPrefs.DFrameLinkColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1285
                                if (m_Locked)
 
1286
                                        p->setPen(PrefsManager::instance()->appPrefs.DFrameLockColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1287
                                p->setFillMode(0);
 
1288
                                if (itemType()==PathText)
 
1289
                                {
 
1290
                                        if (Clip.count() != 0)
 
1291
                                        {
 
1292
                                                FPointArray tclip;
 
1293
                                                FPoint np = FPoint(Clip.point(0));
 
1294
                                                tclip.resize(2);
 
1295
                                                tclip.setPoint(0, np);
 
1296
                                                tclip.setPoint(1, np);
 
1297
                                                for (int a = 1; a < Clip.size(); ++a)
 
1298
                                                {
 
1299
                                                        np = FPoint(Clip.point(a));
 
1300
                                                        tclip.putPoints(tclip.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y());
 
1301
                                                }
 
1302
                                                np = FPoint(Clip.point(0));
 
1303
                                                tclip.putPoints(tclip.size(), 2, np.x(), np.y(), np.x(), np.y());
 
1304
                                                p->setupPolygon(&tclip);
 
1305
                                        }
 
1306
                                }
 
1307
                                else
 
1308
// Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows
 
1309
#ifdef HAVE_CAIRO
 
1310
        #if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0)))
 
1311
                                        p->setupPolygon(&PoLine, false);
 
1312
        #else
 
1313
                                        p->setupPolygon(&PoLine);
 
1314
        #endif
 
1315
#else
 
1316
                                        p->setupPolygon(&PoLine);
 
1317
#endif
 
1318
                                p->strokePath();
 
1319
                        }
 
1320
                }
 
1321
                if ((m_Doc->guidesSettings.framesShown) && textFlowUsesContourLine() && (ContourLine.size() != 0))
 
1322
                {
 
1323
                        p->setPen(Qt::darkGray, scpInv, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
 
1324
// Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows
 
1325
#ifdef HAVE_CAIRO
 
1326
        #if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0)))
 
1327
                        p->setupPolygon(&ContourLine, false);
 
1328
        #else
 
1329
                        p->setupPolygon(&ContourLine);
 
1330
        #endif
 
1331
#else
 
1332
                        p->setupPolygon(&ContourLine);
 
1333
#endif
 
1334
                        p->strokePath();
 
1335
                }
 
1336
                if ((m_Doc->guidesSettings.layerMarkersShown) && (m_Doc->layerCount() > 1) && (!m_Doc->layerOutline(LayerNr)) && ((isGroupControl) || (Groups.count() == 0)) && (!view->m_canvas->isPreviewMode()))
 
1337
                {
 
1338
                        p->setPen(Qt::black, 0.5 / m_Doc->view()->scale(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1339
                        p->setPenOpacity(1.0);
 
1340
                        p->setBrush(m_Doc->layerMarker(LayerNr));
 
1341
                        p->setBrushOpacity(1.0);
 
1342
                        p->setFillMode(ScPainter::Solid);
 
1343
                        double ofwh = 10;
 
1344
                        double ofx = Width - ofwh/2;
 
1345
                        double ofy = Height - ofwh*3;
 
1346
                        p->drawRect(ofx, ofy, ofwh, ofwh);
 
1347
                }
 
1348
                //CB disabled for now
 
1349
                //if (m_Doc->m_Selection->findItem(this)!=-1)
 
1350
                //      drawLockedMarker(p);
 
1351
        }
 
1352
//      Tinput = false;
 
1353
        FrameOnly = false;
 
1354
        p->restore();
 
1355
}
 
1356
 
 
1357
void PageItem::DrawObj_Embedded(ScPainter *p, QRectF cullingArea, const CharStyle& style, PageItem* cembedded)
 
1358
{
 
1359
        if (!cembedded)
 
1360
                return;
 
1361
        if (!m_Doc->DoDrawing)
 
1362
                return;
 
1363
        QList<PageItem*> emG;
 
1364
        QStack<PageItem*> groupStack;
 
1365
        groupStack.clear();
 
1366
        emG.clear();
 
1367
        emG.append(cembedded);
 
1368
        if (cembedded->Groups.count() != 0)
 
1369
        {
 
1370
                for (int ga=0; ga<m_Doc->FrameItems.count(); ++ga)
 
1371
                {
 
1372
                        if (m_Doc->FrameItems.at(ga)->Groups.count() != 0)
 
1373
                        {
 
1374
                                if (m_Doc->FrameItems.at(ga)->Groups.top() == cembedded->Groups.top())
 
1375
                                {
 
1376
                                        if (m_Doc->FrameItems.at(ga)->ItemNr != cembedded->ItemNr)
 
1377
                                        {
 
1378
                                                if (!emG.contains(m_Doc->FrameItems.at(ga)))
 
1379
                                                        emG.append(m_Doc->FrameItems.at(ga));
 
1380
                                        }
 
1381
                                }
 
1382
                        }
 
1383
                }
 
1384
        }
 
1385
        for (int em = 0; em < emG.count(); ++em)
 
1386
        {
 
1387
                PageItem* embedded = emG.at(em);
 
1388
                if (embedded->isGroupControl)
 
1389
                {
 
1390
                        p->save();
 
1391
                        FPointArray cl = embedded->PoLine.copy();
 
1392
                        QMatrix mm;
 
1393
                        mm.translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0)));
 
1394
                        if (style.baselineOffset() != 0)
 
1395
                                mm.translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0));
 
1396
                        mm.scale(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
 
1397
                        mm.rotate(embedded->rotation());
 
1398
                        cl.map( mm );
 
1399
                        p->beginLayer(1.0 - embedded->fillTransparency(), embedded->fillBlendmode(), &cl);
 
1400
                        groupStack.push(embedded->groupsLastItem);
 
1401
                        continue;
 
1402
                }
 
1403
                p->save();
 
1404
                double x = embedded->xPos();
 
1405
                double y = embedded->yPos();
 
1406
                embedded->Xpos = embedded->gXpos;
 
1407
                embedded->Ypos = (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos;
 
1408
                p->translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0)));
 
1409
                if (style.baselineOffset() != 0)
 
1410
                {
 
1411
                        p->translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0));
 
1412
                        embedded->Ypos -= embedded->gHeight * (style.baselineOffset() / 1000.0);
 
1413
                }
 
1414
                p->scale(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
 
1415
                embedded->Dirty = Dirty;
 
1416
                embedded->invalid = true;
 
1417
                double sc;
 
1418
                double pws = embedded->m_lineWidth;
 
1419
                embedded->DrawObj_Pre(p, sc);
 
1420
                switch(embedded->itemType())
 
1421
                {
 
1422
                        case ImageFrame:
 
1423
                        case TextFrame:
 
1424
                        case LatexFrame:
 
1425
                        case Polygon:
 
1426
                        case PathText:
 
1427
                                embedded->DrawObj_Item(p, cullingArea, sc);
 
1428
                                break;
 
1429
                        case Line:
 
1430
                        case PolyLine:
 
1431
                                embedded->m_lineWidth = pws * qMin(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
 
1432
                                embedded->DrawObj_Item(p, cullingArea, sc);
 
1433
                                break;
 
1434
                        default:
 
1435
                                break;
 
1436
                }
 
1437
                embedded->m_lineWidth = pws * qMin(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
 
1438
                embedded->DrawObj_Post(p);
 
1439
                embedded->Xpos = x;
 
1440
                embedded->Ypos = y;
 
1441
                p->restore();
 
1442
                if (groupStack.count() != 0)
 
1443
                {
 
1444
                        while (embedded == groupStack.top())
 
1445
                        {
 
1446
                                p->endLayer();
 
1447
                                p->restore();
 
1448
                                groupStack.pop();
 
1449
                                if (groupStack.count() == 0)
 
1450
                                        break;
 
1451
                        }
 
1452
                }
 
1453
                embedded->m_lineWidth = pws;
 
1454
        }
 
1455
        for (int em = 0; em < emG.count(); ++em)
 
1456
        {
 
1457
                PageItem* embedded = emG.at(em);
 
1458
                if (!embedded->isTableItem)
 
1459
                        continue;
 
1460
                p->save();
 
1461
                double x = embedded->xPos();
 
1462
                double y = embedded->yPos();
 
1463
                embedded->Xpos = embedded->gXpos;
 
1464
                embedded->Ypos = (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos;
 
1465
                p->translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0)));
 
1466
                if (style.baselineOffset() != 0)
 
1467
                {
 
1468
                        p->translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0));
 
1469
                        embedded->Ypos -= embedded->gHeight * (style.baselineOffset() / 1000.0);
 
1470
                }
 
1471
                p->scale(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
 
1472
                p->rotate(embedded->rotation());
 
1473
                double pws = embedded->m_lineWidth;
 
1474
                embedded->m_lineWidth = pws * qMin(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
 
1475
                if ((embedded->lineColor() != CommonStrings::None) && (embedded->lineWidth() != 0.0))
 
1476
                {
 
1477
                        QColor tmp;
 
1478
                        embedded->SetQColor(&tmp, embedded->lineColor(), embedded->lineShade());
 
1479
                        if ((embedded->TopLine) || (embedded->RightLine) || (embedded->BottomLine) || (embedded->LeftLine))
 
1480
                        {
 
1481
                                p->setPen(tmp, embedded->lineWidth(), embedded->PLineArt, Qt::SquareCap, embedded->PLineJoin);
 
1482
                                if (embedded->TopLine)
 
1483
                                        p->drawLine(FPoint(0.0, 0.0), FPoint(embedded->width(), 0.0));
 
1484
                                if (embedded->RightLine)
 
1485
                                        p->drawLine(FPoint(embedded->width(), 0.0), FPoint(embedded->width(), embedded->height()));
 
1486
                                if (embedded->BottomLine)
 
1487
                                        p->drawLine(FPoint(embedded->width(), embedded->height()), FPoint(0.0, embedded->height()));
 
1488
                                if (embedded->LeftLine)
 
1489
                                        p->drawLine(FPoint(0.0, embedded->height()), FPoint(0.0, 0.0));
 
1490
                        }
 
1491
                }
 
1492
                embedded->m_lineWidth = pws;
 
1493
                embedded->Xpos = x;
 
1494
                embedded->Ypos = y;
 
1495
                p->restore();
 
1496
        }
 
1497
}
 
1498
 
 
1499
 
 
1500
void PageItem::paintObj(QPainter *p)
 
1501
{
 
1502
        if ((!m_Doc->DoDrawing) || (m_Doc->RePos))
 
1503
        {
 
1504
                FrameOnly = false;
 
1505
                return;
 
1506
        }
 
1507
        double sc = m_Doc->view()->scale();
 
1508
        double handleSize = 6.0 / sc;
 
1509
        double halfSize = 3.0 / sc;
 
1510
        if ((!FrameOnly) && (!m_Doc->RePos))
 
1511
        {
 
1512
                if (!m_Doc->m_Selection->isEmpty())
 
1513
                {
 
1514
//                              qDebug() << "Item: " << ItemNr << "W: " << Width << "H: " << Height;
 
1515
                        if (Groups.count() == 0)
 
1516
                        {
 
1517
                                //Locked line colour selection
 
1518
                                if (m_Locked)
 
1519
                                        p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameLockColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
 
1520
                                else
 
1521
                                        p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
 
1522
                                p->setBrush(Qt::NoBrush);
 
1523
                                double lw2 = 1.0 / sc;
 
1524
                                double lw = 1.0 / sc;
 
1525
                                Qt::PenCapStyle le = Qt::FlatCap;
 
1526
                                if (NamedLStyle.isEmpty())
 
1527
                                {
 
1528
                                        lw2 = (m_lineWidth / 2.0)  / sc;
 
1529
                                        lw = qMax(m_lineWidth, 1.0)  / sc;
 
1530
                                        le = PLineEnd;
 
1531
                                }
 
1532
                                else
 
1533
                                {
 
1534
                                        multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
1535
                                        lw2 = (ml[ml.size()-1].Width / 2.0) / sc;
 
1536
                                        lw = qMax(ml[ml.size()-1].Width, 1.0) / sc;
 
1537
                                        le = static_cast<Qt::PenCapStyle>(ml[ml.size()-1].LineEnd);
 
1538
                                }
 
1539
                                //Draw our frame outline
 
1540
                                if (asLine())
 
1541
                                {
 
1542
                                        if (le != Qt::FlatCap)
 
1543
                                                p->drawRect(QRectF(-lw2, -lw2, Width+lw, lw));
 
1544
                                        else
 
1545
                                                p->drawRect(QRectF(-1 / sc, -lw2, Width, lw));
 
1546
                                }
 
1547
                                else
 
1548
                                        p->drawRect(QRectF(0, 0, Width, Height));
 
1549
//                              p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
 
1550
                                p->setBrush(PrefsManager::instance()->appPrefs.DFrameColor);
 
1551
                                p->setPen(Qt::NoPen);
 
1552
                                if ((!m_Locked) && (!m_SizeLocked))
 
1553
                                {
 
1554
                                        if (! asLine())
 
1555
                                        {
 
1556
                                                p->drawRect(QRectF(0.0, 0.0, handleSize, handleSize));
 
1557
                                                p->drawRect(QRectF(Width - handleSize, Height - handleSize, handleSize, handleSize));
 
1558
                                                p->drawRect(QRectF(Width - handleSize, 0.0, handleSize, handleSize));
 
1559
                                                p->drawRect(QRectF(0.0, Height - handleSize, handleSize, handleSize));
 
1560
                                                if (Width > 6)
 
1561
                                                {
 
1562
                                                        p->drawRect(QRectF(Width / 2.0 - halfSize, Height - handleSize, handleSize, handleSize));
 
1563
                                                        p->drawRect(QRectF(Width / 2.0 - halfSize, 0.0, handleSize, handleSize));
 
1564
                                                }
 
1565
                                                if (Height > 6)
 
1566
                                                {
 
1567
                                                        p->drawRect(QRectF(Width - handleSize, Height / 2.0 - halfSize, handleSize, handleSize));
 
1568
                                                        p->drawRect(QRectF(0.0, Height / 2.0 - halfSize, handleSize, handleSize));
 
1569
                                                }
 
1570
                                        }
 
1571
                                        else
 
1572
                                        {
 
1573
                                                p->drawRect(QRectF(-halfSize, -halfSize, handleSize, handleSize));
 
1574
                                                p->drawRect(QRectF(Width + halfSize, -halfSize, -handleSize, handleSize));
 
1575
                                        }
 
1576
                                }
 
1577
                        }
 
1578
                        else
 
1579
                        {
 
1580
                                p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameGroupColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
 
1581
                                p->setBrush(Qt::NoBrush);
 
1582
                                p->drawRect(QRectF(0.0, 0.0, Width, Height));
 
1583
                                if (m_Doc->m_Selection->count() == 1)
 
1584
                                {
 
1585
                                        p->setPen(Qt::NoPen);
 
1586
//                                      p->setPen(QPen(PrefsManager::instance()->appPrefs.DFrameGroupColor, 1.0 / sc, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
 
1587
                                        p->setBrush(PrefsManager::instance()->appPrefs.DFrameGroupColor);
 
1588
                                        p->drawRect(QRectF(0.0, 0.0, handleSize, handleSize));
 
1589
                                        p->drawRect(QRectF(Width - handleSize, Height - handleSize, handleSize, handleSize));
 
1590
                                        p->drawRect(QRectF(Width - handleSize, 0.0, handleSize, handleSize));
 
1591
                                        p->drawRect(QRectF(0.0, Height - handleSize, handleSize, handleSize));
 
1592
                                        if (Width > 6)
 
1593
                                        {
 
1594
                                                p->drawRect(QRectF(Width / 2.0 - halfSize, Height - handleSize, handleSize, handleSize));
 
1595
                                                p->drawRect(QRectF(Width / 2.0 - halfSize, 0.0, handleSize, handleSize));
 
1596
                                        }
 
1597
                                        if (Height > 6)
 
1598
                                        {
 
1599
                                                p->drawRect(QRectF(Width - handleSize, Height / 2.0 - halfSize, handleSize, handleSize));
 
1600
                                                p->drawRect(QRectF(0.0, Height / 2.0 - halfSize, handleSize, handleSize));
 
1601
                                        }
 
1602
                                }
 
1603
                        }
 
1604
                }
 
1605
        }
 
1606
        FrameOnly = false;
 
1607
}
 
1608
 
 
1609
QImage PageItem::DrawObj_toImage()
 
1610
{
 
1611
        QList<PageItem*> emG;
 
1612
        emG.clear();
 
1613
        double minx =  std::numeric_limits<double>::max();
 
1614
        double miny =  std::numeric_limits<double>::max();
 
1615
        double maxx = -std::numeric_limits<double>::max();
 
1616
        double maxy = -std::numeric_limits<double>::max();
 
1617
        if (Groups.count() != 0)
 
1618
        {
 
1619
                for (int ga=0; ga<m_Doc->Items->count(); ++ga)
 
1620
                {
 
1621
                        if (m_Doc->Items->at(ga)->Groups.count() != 0)
 
1622
                        {
 
1623
                                if (m_Doc->Items->at(ga)->Groups.top() == Groups.top())
 
1624
                                {
 
1625
                                        if (!emG.contains(m_Doc->Items->at(ga)))
 
1626
                                        {
 
1627
                                                emG.append(m_Doc->Items->at(ga));
 
1628
                                                PageItem *currItem = m_Doc->Items->at(ga);
 
1629
                                                double x1, x2, y1, y2;
 
1630
                                                currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
 
1631
                                                minx = qMin(minx, x1);
 
1632
                                                miny = qMin(miny, y1);
 
1633
                                                maxx = qMax(maxx, x2);
 
1634
                                                maxy = qMax(maxy, y2);
 
1635
                                        }
 
1636
                                }
 
1637
                        }
 
1638
                }
 
1639
                for (int em = 0; em < emG.count(); ++em)
 
1640
                {
 
1641
                        PageItem* currItem = emG.at(em);
 
1642
                        currItem->gXpos = currItem->xPos() - minx;
 
1643
                        currItem->gYpos = currItem->yPos() - miny;
 
1644
                        currItem->gWidth = maxx - minx;
 
1645
                        currItem->gHeight = maxy - miny;
 
1646
                }
 
1647
        }
 
1648
        else
 
1649
        {
 
1650
                double x1, x2, y1, y2;
 
1651
                getVisualBoundingRect(&x1, &y1, &x2, &y2);
 
1652
                minx = qMin(minx, x1);
 
1653
                miny = qMin(miny, y1);
 
1654
                maxx = qMax(maxx, x2);
 
1655
                maxy = qMax(maxy, y2);
 
1656
                gXpos = xPos() - minx;
 
1657
                gYpos = yPos() - miny;
 
1658
                gWidth = maxx - minx;
 
1659
                gHeight = maxy - miny;
 
1660
                emG.append(this);
 
1661
        }
 
1662
        return DrawObj_toImage(emG);
 
1663
}
 
1664
 
 
1665
QImage PageItem::DrawObj_toImage(QList<PageItem*> &emG)
 
1666
{
 
1667
        QImage retImg = QImage(qRound(gWidth), qRound(gHeight), QImage::Format_ARGB32);
 
1668
//      retImg.fill( qRgba(255, 255, 255, 0) );
 
1669
        retImg.fill( qRgba(0, 0, 0, 0) );
 
1670
        ScPainter *painter = new ScPainter(&retImg, retImg.width(), retImg.height(), 1, 0);
 
1671
//      painter->setZoomFactor(1.0);
 
1672
        painter->setZoomFactor(qMax(qRound(gWidth) / gWidth, qRound(gHeight) / gHeight));
 
1673
        QStack<PageItem*> groupStack;
 
1674
        for (int em = 0; em < emG.count(); ++em)
 
1675
        {
 
1676
                PageItem* embedded = emG.at(em);
 
1677
                if (embedded->isGroupControl)
 
1678
                {
 
1679
                        painter->save();
 
1680
                        FPointArray cl = embedded->PoLine.copy();
 
1681
                        QMatrix mm;
 
1682
                        mm.translate(embedded->gXpos, embedded->gYpos);
 
1683
                        mm.rotate(embedded->rotation());
 
1684
                        cl.map( mm );
 
1685
                        painter->beginLayer(1.0 - embedded->fillTransparency(), embedded->fillBlendmode(), &cl);
 
1686
                        groupStack.push(embedded->groupsLastItem);
 
1687
                        continue;
 
1688
                }
 
1689
                painter->save();
 
1690
//              qDebug()<<embedded<<embedded->xPos()<<embedded->yPos()<<embedded->gXpos<<embedded->gYpos;
 
1691
//              double x = embedded->xPos();
 
1692
//              double y = embedded->yPos();
 
1693
//              embedded->Xpos = embedded->gXpos;
 
1694
//              embedded->Ypos = embedded->gYpos;
 
1695
                // Seems to work without all this coordinates mess. To monitor tho
 
1696
                painter->translate(embedded->gXpos, embedded->gYpos);
 
1697
                embedded->isEmbedded = true;
 
1698
                embedded->invalid = true;
 
1699
                embedded->DrawObj(painter, QRectF());
 
1700
//              embedded->Xpos = x;
 
1701
//              embedded->Ypos = y;
 
1702
                embedded->isEmbedded = false;
 
1703
                painter->restore();
 
1704
                if (groupStack.count() != 0)
 
1705
                {
 
1706
                        while (embedded == groupStack.top())
 
1707
                        {
 
1708
                                painter->endLayer();
 
1709
                                painter->restore();
 
1710
                                groupStack.pop();
 
1711
                                if (groupStack.count() == 0)
 
1712
                                        break;
 
1713
                        }
 
1714
                }
 
1715
        }
 
1716
        for (int em = 0; em < emG.count(); ++em)
 
1717
        {
 
1718
                PageItem* embedded = emG.at(em);
 
1719
                if (!embedded->isTableItem)
 
1720
                        continue;
 
1721
                painter->save();
 
1722
//              double x = embedded->xPos();
 
1723
//              double y = embedded->yPos();
 
1724
//              embedded->Xpos = embedded->gXpos;
 
1725
//              embedded->Ypos = embedded->gYpos;
 
1726
                painter->translate(embedded->gXpos, embedded->gYpos);
 
1727
                painter->rotate(embedded->rotation());
 
1728
                embedded->isEmbedded = true;
 
1729
                embedded->invalid = true;
 
1730
                if ((embedded->lineColor() != CommonStrings::None) && (embedded->lineWidth() != 0.0))
 
1731
                {
 
1732
                        QColor tmp;
 
1733
                        embedded->SetQColor(&tmp, embedded->lineColor(), embedded->lineShade());
 
1734
                        if ((embedded->TopLine) || (embedded->RightLine) || (embedded->BottomLine) || (embedded->LeftLine))
 
1735
                        {
 
1736
                                painter->setPen(tmp, embedded->lineWidth(), embedded->PLineArt, Qt::SquareCap, embedded->PLineJoin);
 
1737
                                if (embedded->TopLine)
 
1738
                                        painter->drawLine(FPoint(0.0, 0.0), FPoint(embedded->width(), 0.0));
 
1739
                                if (embedded->RightLine)
 
1740
                                        painter->drawLine(FPoint(embedded->width(), 0.0), FPoint(embedded->width(), embedded->height()));
 
1741
                                if (embedded->BottomLine)
 
1742
                                        painter->drawLine(FPoint(embedded->width(), embedded->height()), FPoint(0.0, embedded->height()));
 
1743
                                if (embedded->LeftLine)
 
1744
                                        painter->drawLine(FPoint(0.0, embedded->height()), FPoint(0.0, 0.0));
 
1745
                        }
 
1746
                }
 
1747
                embedded->isEmbedded = false;
 
1748
//              embedded->Xpos = x;
 
1749
//              embedded->Ypos = y;
 
1750
                painter->restore();
 
1751
        }
 
1752
        painter->end();
 
1753
        delete painter;
 
1754
        return retImg;
 
1755
}
 
1756
 
 
1757
QString PageItem::ExpandToken(uint base)
 
1758
{
 
1759
        uint zae = 0;
 
1760
        QChar ch = itemText.text(base);
 
1761
        QString chstr = ch;
 
1762
        if (ch == SpecialChars::PAGENUMBER)
 
1763
        {
 
1764
                // compatibility mode: ignore subsequent pagenumber chars
 
1765
                if (base > 0 && itemText.text(base-1) == SpecialChars::PAGENUMBER)
 
1766
                        return "";
 
1767
                if ((!m_Doc->masterPageMode()) && (OwnPage != -1))
 
1768
                {
 
1769
                        QString out("%1");
 
1770
                        //CB Section numbering
 
1771
                        chstr = out.arg(m_Doc->getSectionPageNumberForPageIndex(OwnPage), -(int)zae);
 
1772
                }
 
1773
                else
 
1774
                        return "#";
 
1775
        }
 
1776
        else if (ch == SpecialChars::PAGECOUNT)
 
1777
        {
 
1778
                if (!m_Doc->masterPageMode())
 
1779
                {
 
1780
                        QString out("%1");
 
1781
                        int key = m_Doc->getSectionKeyForPageIndex(OwnPage);
 
1782
                        if (key == -1)
 
1783
                                return "%";
 
1784
                        chstr = out.arg(getStringFromSequence(m_Doc->sections[key].type, m_Doc->sections[key].toindex - m_Doc->sections[key].fromindex + 1));
 
1785
                }
 
1786
                else
 
1787
                        return "%";
 
1788
        }
 
1789
        return chstr;
 
1790
}
 
1791
 
 
1792
void PageItem::SetQColor(QColor *tmp, QString farbe, double shad)
 
1793
{
 
1794
        const ScColor& col = m_Doc->PageColors[farbe];
 
1795
        *tmp = ScColorEngine::getShadeColorProof(col, m_Doc, shad);
 
1796
        if ((m_Doc->view()) && (m_Doc->view()->m_canvas->usePreviewVisual()))
 
1797
        {
 
1798
                VisionDefectColor defect;
 
1799
                *tmp = defect.convertDefect(*tmp, m_Doc->view()->m_canvas->previewVisual());
 
1800
        }
 
1801
}
 
1802
 
 
1803
/**
 
1804
    layout glyphs translates the chars into a number of glyphs, applying the Charstyle
 
1805
    'style'. The following fields are set in layout: glyph, more, scaleH, scaleV, xoffset, yoffset, xadvance.
 
1806
    If the DropCap-bit in style.effects is set and yadvance is > 0, scaleH/V, x/yoffset and xadvance
 
1807
    are modified to scale the glyphs to this height.
 
1808
    Otherwise yadvance is set to the max ascender of all generated glyphs.
 
1809
    It scales according to smallcaps and
 
1810
    sets xadvance to the advance width without kerning. If more than one glyph
 
1811
    is generated, kerning is included in all but the last xadvance.
 
1812
*/
 
1813
double PageItem::layoutGlyphs(const CharStyle& style, const QString& chars, GlyphLayout& layout)
 
1814
{
 
1815
        double retval = 0.0;
 
1816
        double asce = style.font().ascent(style.fontSize() / 10.0);
 
1817
        int chst = style.effects() & 1919;
 
1818
/*      if (chars[0] == SpecialChars::ZWSPACE ||
 
1819
                chars[0] == SpecialChars::ZWNBSPACE ||
 
1820
                chars[0] == SpecialChars::NBSPACE ||
 
1821
                chars[0] == SpecialChars::NBHYPHEN ||
 
1822
                chars[0] == SpecialChars::SHYPHEN ||
 
1823
                chars[0] == SpecialChars::PARSEP ||
 
1824
                chars[0] == SpecialChars::COLBREAK ||
 
1825
                chars[0] == SpecialChars::LINEBREAK ||
 
1826
                chars[0] == SpecialChars::FRAMEBREAK ||
 
1827
                chars[0] == SpecialChars::TAB)
 
1828
        {
 
1829
                layout.glyph = ScFace::CONTROL_GLYPHS + chars[0].unicode();
 
1830
        }
 
1831
        else */
 
1832
        {
 
1833
                layout.glyph = style.font().char2CMap(chars[0].unicode());
 
1834
        }
 
1835
        
 
1836
        double tracking = 0.0;
 
1837
        if ( (style.effects() & ScStyle_StartOfLine) == 0)
 
1838
                tracking = style.fontSize() * style.tracking() / 10000.0;
 
1839
 
 
1840
        layout.xoffset = tracking;
 
1841
        layout.yoffset = 0;
 
1842
        if (chst != ScStyle_Default)
 
1843
        {
 
1844
                if (chst & ScStyle_Superscript)
 
1845
                {
 
1846
                        retval -= asce * m_Doc->typographicSettings.valueSuperScript / 100.0;
 
1847
                        layout.yoffset -= asce * m_Doc->typographicSettings.valueSuperScript / 100.0;
 
1848
                        layout.scaleV = layout.scaleH = qMax(m_Doc->typographicSettings.scalingSuperScript / 100.0, 10.0 / style.fontSize());
 
1849
                }
 
1850
                else if (chst & ScStyle_Subscript)
 
1851
                {
 
1852
                        retval += asce * m_Doc->typographicSettings.valueSubScript / 100.0;
 
1853
                        layout.yoffset += asce * m_Doc->typographicSettings.valueSubScript / 100.0;
 
1854
                        layout.scaleV = layout.scaleH = qMax(m_Doc->typographicSettings.scalingSubScript / 100.0, 10.0 / style.fontSize());
 
1855
                }
 
1856
                else {
 
1857
                        layout.scaleV = layout.scaleH = 1.0;
 
1858
                }
 
1859
                layout.scaleH *= style.scaleH() / 1000.0;
 
1860
                layout.scaleV *= style.scaleV() / 1000.0;
 
1861
                if (chst & ScStyle_AllCaps)
 
1862
                {
 
1863
                        layout.glyph = style.font().char2CMap(chars[0].toUpper().unicode());
 
1864
                }
 
1865
                if (chst & ScStyle_SmallCaps)
 
1866
                {
 
1867
                        double smallcapsScale = m_Doc->typographicSettings.valueSmallCaps / 100.0;
 
1868
                        QChar uc = chars[0].toUpper();
 
1869
                        if (uc != chars[0])
 
1870
                        {
 
1871
                                layout.glyph = style.font().char2CMap(chars[0].toUpper().unicode());
 
1872
                                layout.scaleV *= smallcapsScale;
 
1873
                                layout.scaleH *= smallcapsScale;
 
1874
                        }
 
1875
                }
 
1876
        }
 
1877
        else {
 
1878
                layout.scaleH = style.scaleH() / 1000.0;
 
1879
                layout.scaleV = style.scaleV() / 1000.0;
 
1880
        }       
 
1881
        
 
1882
/*      if (layout.glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBSPACE.unicode())) {
 
1883
                uint replGlyph = style.font().char2CMap(QChar(' '));
 
1884
                layout.xadvance = style.font().glyphWidth(replGlyph, style.fontSize() / 10) * layout.scaleH;
 
1885
                layout.yadvance = style.font().glyphBBox(replGlyph, style.fontSize() / 10).ascent * layout.scaleV;
 
1886
        }
 
1887
        else if (layout.glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBHYPHEN.unicode())) {
 
1888
                uint replGlyph = style.font().char2CMap(QChar('-'));
 
1889
                layout.xadvance = style.font().glyphWidth(replGlyph, style.fontSize() / 10) * layout.scaleH;
 
1890
                layout.yadvance = style.font().glyphBBox(replGlyph, style.fontSize() / 10).ascent * layout.scaleV;
 
1891
        }
 
1892
        else if (layout.glyph >= ScFace::CONTROL_GLYPHS) {
 
1893
                layout.xadvance = 0;
 
1894
                layout.yadvance = 0;
 
1895
        }
 
1896
        else */
 
1897
        {
 
1898
                layout.xadvance = style.font().glyphWidth(layout.glyph, style.fontSize() / 10) * layout.scaleH;
 
1899
                layout.yadvance = style.font().glyphBBox(layout.glyph, style.fontSize() / 10).ascent * layout.scaleV;
 
1900
        }
 
1901
        if (layout.xadvance > 0)
 
1902
                layout.xadvance += tracking;
 
1903
 
 
1904
        if (chars.length() > 1) {
 
1905
                layout.grow();
 
1906
                layoutGlyphs(style, chars.mid(1), *layout.more);
 
1907
                layout.xadvance += style.font().glyphKerning(layout.glyph, layout.more->glyph, style.fontSize() / 10) * layout.scaleH;
 
1908
                if (layout.more->yadvance > layout.yadvance)
 
1909
                        layout.yadvance = layout.more->yadvance;
 
1910
        }
 
1911
        else {
 
1912
                layout.shrink();
 
1913
        }
 
1914
        return retval;
 
1915
}
 
1916
 
 
1917
void PageItem::drawGlyphs(ScPainter *p, const CharStyle& style, GlyphLayout& glyphs)
 
1918
{
 
1919
        uint glyph = glyphs.glyph;
 
1920
        if ((m_Doc->guidesSettings.showControls) && 
 
1921
                (glyph == style.font().char2CMap(QChar(' ')) || glyph >=  ScFace::CONTROL_GLYPHS))
 
1922
        {
 
1923
                bool stroke = false;
 
1924
                if (glyph >=  ScFace::CONTROL_GLYPHS)
 
1925
                        glyph -= ScFace::CONTROL_GLYPHS;
 
1926
                else
 
1927
                        glyph = 32;
 
1928
                QMatrix chma, chma4, chma5;
 
1929
                FPointArray points;
 
1930
                if (glyph == SpecialChars::TAB.unicode())
 
1931
                {
 
1932
                        points = m_Doc->symTab.copy();
 
1933
                        chma4.translate(glyphs.xoffset + glyphs.xadvance - ((style.fontSize() / 10.0) * glyphs.scaleH * 0.7), glyphs.yoffset - ((style.fontSize() / 10.0) * glyphs.scaleV * 0.5));
 
1934
                }
 
1935
                else if (glyph == SpecialChars::COLBREAK.unicode())
 
1936
                {
 
1937
                        points = m_Doc->symNewCol.copy();
 
1938
                        chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.6));
 
1939
                }
 
1940
                else if (glyph == SpecialChars::FRAMEBREAK.unicode())
 
1941
                {
 
1942
                        points = m_Doc->symNewFrame.copy();
 
1943
                        chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.6));
 
1944
                }
 
1945
                else if (glyph == SpecialChars::PARSEP.unicode())
 
1946
                {
 
1947
                        points = m_Doc->symReturn.copy();
 
1948
                        chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.8));
 
1949
                }
 
1950
                else if (glyph == SpecialChars::LINEBREAK.unicode())
 
1951
                {
 
1952
                        points = m_Doc->symNewLine.copy();
 
1953
                        chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.4));
 
1954
                }
 
1955
                else if (glyph == SpecialChars::NBSPACE.unicode() ||
 
1956
                                 glyph == 32)
 
1957
                {
 
1958
                        stroke = (glyph == 32);
 
1959
                        points = m_Doc->symNonBreak.copy();
 
1960
                        chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.4));
 
1961
                }
 
1962
                else if (glyph == SpecialChars::NBHYPHEN.unicode())
 
1963
                {
 
1964
                        points = style.font().glyphOutline(style.font().char2CMap(QChar('-')), style.fontSize() / 100);
 
1965
                        chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV));
 
1966
                }
 
1967
                else if (glyph == SpecialChars::SHYPHEN.unicode())
 
1968
                {
 
1969
                        points.resize(0);
 
1970
                        points.addQuadPoint(0, -10, 0, -10, 0, -6, 0, -6);
 
1971
                        stroke = true;
 
1972
                }
 
1973
                else // ???
 
1974
                {
 
1975
                        points.resize(0);
 
1976
                        points.addQuadPoint(0, -10, 0, -10, 0, -9, 0, -9);                      
 
1977
                        points.addQuadPoint(0, -9, 0, -9, 1, -9, 1, -9);                        
 
1978
                        points.addQuadPoint(1, -9, 1, -9, 1, -10, 1, -10);                      
 
1979
                        points.addQuadPoint(1, -10, 1, -10, 0, -10, 0, -10);                    
 
1980
                }
 
1981
                chma.scale(glyphs.scaleH * style.fontSize() / 100.0, glyphs.scaleV * style.fontSize() / 100.0);
 
1982
                points.map(chma * chma4);
 
1983
                p->setupPolygon(&points, true);
 
1984
                QColor oldBrush = p->brush();
 
1985
                p->setBrush( (style.effects() & ScStyle_SuppressSpace) ? Qt::green
 
1986
                                        : PrefsManager::instance()->appPrefs.DControlCharColor);
 
1987
                if (stroke)
 
1988
                {
 
1989
                        QColor tmp = p->pen();
 
1990
                        p->setPen(p->brush(), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1991
                        p->setLineWidth(style.fontSize() * glyphs.scaleV / 200.0);
 
1992
                        p->strokePath();
 
1993
                        p->setPen(tmp, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
1994
                }
 
1995
                else
 
1996
                {
 
1997
                        p->setFillMode(1);
 
1998
                        p->fillPath();
 
1999
                }
 
2000
                p->setBrush(oldBrush);
 
2001
                if (glyphs.more)
 
2002
                {
 
2003
                        p->translate(glyphs.xadvance, 0);
 
2004
                        drawGlyphs(p, style, *glyphs.more);
 
2005
                }                       
 
2006
                return;
 
2007
        }
 
2008
        else if (glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBSPACE.unicode()) ||
 
2009
                         glyph == (ScFace::CONTROL_GLYPHS + 32)) 
 
2010
                glyph = style.font().char2CMap(QChar(' '));
 
2011
        else if (glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBHYPHEN.unicode()))
 
2012
                glyph = style.font().char2CMap(QChar('-'));
 
2013
        
 
2014
        if (glyph >= ScFace::CONTROL_GLYPHS || (style.effects() & ScStyle_SuppressSpace)) {
 
2015
//              qDebug("drawGlyphs: skipping %d", glyph);
 
2016
                // all those are empty
 
2017
                if (glyphs.more)
 
2018
                {
 
2019
                        p->translate(glyphs.xadvance, 0);
 
2020
                        drawGlyphs(p, style, *glyphs.more);
 
2021
                }                       
 
2022
                return;
 
2023
        }
 
2024
//      if (style.font().canRender(QChar(glyph)))
 
2025
        {
 
2026
                FPointArray gly = style.font().glyphOutline(glyph);
 
2027
                // Do underlining first so you can get typographically correct
 
2028
                // underlines when drawing a white outline
 
2029
                if (((style.effects() & ScStyle_Underline) || ((style.effects() & ScStyle_UnderlineWords) && glyph != style.font().char2CMap(QChar(' ')))) && (style.strokeColor() != CommonStrings::None))
 
2030
                {
 
2031
                        double st, lw;
 
2032
                        if ((style.underlineOffset() != -1) || (style.underlineWidth() != -1))
 
2033
                        {
 
2034
                                if (style.underlineOffset() != -1)
 
2035
                                        st = (style.underlineOffset() / 1000.0) * (style.font().descent(style.fontSize() / 10.0));
 
2036
                                else
 
2037
                                        st = style.font().underlinePos(style.fontSize() / 10.0);
 
2038
                                if (style.underlineWidth() != -1)
 
2039
                                        lw = (style.underlineWidth() / 1000.0) * (style.fontSize() / 10.0);
 
2040
                                else
 
2041
                                lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), qreal(1.0));
 
2042
                        }
 
2043
                        else
 
2044
                        {
 
2045
                                st = style.font().underlinePos(style.fontSize() / 10.0);
 
2046
                                lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), qreal(1.0));
 
2047
                        }
 
2048
                        if (style.baselineOffset() != 0)
 
2049
                                st += (style.fontSize() / 10.0) * glyphs.scaleV * (style.baselineOffset() / 1000.0);
 
2050
                        QColor tmpC = p->pen();
 
2051
                        p->setPen(p->brush());
 
2052
                        p->setLineWidth(lw);
 
2053
                        if (style.effects() & ScStyle_Subscript)
 
2054
                                p->drawLine(FPoint(glyphs.xoffset, glyphs.yoffset - st), FPoint(glyphs.xoffset + glyphs.xadvance, glyphs.yoffset - st));
 
2055
                        else
 
2056
                                p->drawLine(FPoint(glyphs.xoffset, -st), FPoint(glyphs.xoffset + glyphs.xadvance, -st));
 
2057
                        p->setPen(tmpC);
 
2058
                }
 
2059
                if (gly.size() > 3)
 
2060
                {
 
2061
                        if (glyph == 0)
 
2062
                        {
 
2063
//                              qDebug() << QString("glyph 0: (%1,%2) * %3 %4 + %5").arg(glyphs.xoffset).arg(glyphs.yoffset).arg(glyphs.scaleH).arg(glyphs.scaleV).arg(glyphs.xadvance));
 
2064
                        }
 
2065
                        p->save();
 
2066
                        p->translate(glyphs.xoffset, glyphs.yoffset - ((style.fontSize() / 10.0) * glyphs.scaleV));
 
2067
                        if (Reverse)
 
2068
                        {
 
2069
                                p->scale(-1, 1);
 
2070
                                p->translate(-glyphs.xadvance, 0);
 
2071
                        }
 
2072
                        if (style.baselineOffset() != 0)
 
2073
                                p->translate(0, -(style.fontSize() / 10.0) * (style.baselineOffset() / 1000.0));
 
2074
                        double glxSc = glyphs.scaleH * style.fontSize() / 100.00;
 
2075
                        double glySc = glyphs.scaleV * style.fontSize() / 100.0;
 
2076
                        p->scale(glxSc, glySc);
 
2077
//                      p->setFillMode(1);
 
2078
                        bool fr = p->fillRule();
 
2079
                        p->setFillRule(false);
 
2080
//                      double  a = gly.point(0).x();
 
2081
//                      double  b = gly.point(0).y();
 
2082
//                      double  c = gly.point(3).x();
 
2083
//                      double  d = gly.point(3).y();
 
2084
//                      qDebug() << QString("drawglyphs: %1 (%2,%3) (%4,%5) scaled %6,%7 trans %8,%9")
 
2085
//                                 .arg(gly.size()).arg(a).arg(b).arg(c).arg(d)
 
2086
//                                 .arg(p->worldMatrix().m11()).arg(p->worldMatrix().m22()).arg(p->worldMatrix().dx()).arg(p->worldMatrix().dy());
 
2087
                        p->setupPolygon(&gly, true);
 
2088
                        if (m_Doc->layerOutline(LayerNr))
 
2089
                        {
 
2090
                                p->save();
 
2091
                                p->setPen(m_Doc->layerMarker(LayerNr), 0.5, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
2092
                                p->setFillMode(ScPainter::None);
 
2093
                                p->setBrushOpacity(1.0);
 
2094
                                p->setPenOpacity(1.0);
 
2095
                                p->strokePath();
 
2096
                                p->restore();
 
2097
                                p->setFillRule(fr);
 
2098
                                p->restore();
 
2099
                                if (glyphs.more)
 
2100
                                {
 
2101
                                        p->translate(glyphs.xadvance, 0);
 
2102
                                        drawGlyphs(p, style, *glyphs.more);
 
2103
                                }
 
2104
                                return;
 
2105
                        }
 
2106
                        if (glyph == 0)
 
2107
                        {
 
2108
                                p->setPen(PrefsManager::instance()->appPrefs.DControlCharColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
2109
                                p->setLineWidth(style.fontSize() * glyphs.scaleV * style.outlineWidth() * 2 / 10000.0);
 
2110
                                p->strokePath();
 
2111
                        }
 
2112
                        else if ((style.font().isStroked()) && (style.strokeColor() != CommonStrings::None) && ((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) != 0))
 
2113
                        {
 
2114
                                QColor tmp = p->brush();
 
2115
                                p->setPen(tmp, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
2116
                                p->setLineWidth(style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0);
 
2117
                                p->strokePath();
 
2118
                        }
 
2119
                        else
 
2120
                        {
 
2121
                                if ((style.effects() & ScStyle_Shadowed) && (style.strokeColor() != CommonStrings::None))
 
2122
                                {
 
2123
                                        p->save();
 
2124
                                        p->translate((style.fontSize() * glyphs.scaleH * style.shadowXOffset() / 10000.0) / glxSc, -(style.fontSize() * glyphs.scaleV * style.shadowYOffset() / 10000.0) / glySc);
 
2125
                                        QColor tmp = p->brush();
 
2126
                                        p->setBrush(p->pen());
 
2127
                                        p->setupPolygon(&gly, true);
 
2128
                                        p->fillPath();
 
2129
                                        p->setBrush(tmp);
 
2130
                                        p->restore();
 
2131
                                        p->setupPolygon(&gly, true);
 
2132
                                }
 
2133
                                if (style.fillColor() != CommonStrings::None)
 
2134
                                        p->fillPath();
 
2135
                                if ((style.effects() & ScStyle_Outline) && (style.strokeColor() != CommonStrings::None) && ((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) != 0))
 
2136
                                {
 
2137
                                        p->setLineWidth((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) / glySc);
 
2138
                                        p->strokePath();
 
2139
                                }
 
2140
                        }
 
2141
                        p->setFillRule(fr);
 
2142
                        p->restore();
 
2143
                }
 
2144
                else {
 
2145
//                      qDebug() << "drawGlyphs: empty glyph" << glyph;
 
2146
                }
 
2147
                if ((style.effects() & ScStyle_Strikethrough) && (style.strokeColor() != CommonStrings::None))
 
2148
                {
 
2149
                        double st, lw;
 
2150
                        if ((style.strikethruOffset() != -1) || (style.strikethruWidth() != -1))
 
2151
                        {
 
2152
                                if (style.strikethruOffset() != -1)
 
2153
                                        st = (style.strikethruOffset() / 1000.0) * (style.font().ascent(style.fontSize() / 10.0));
 
2154
                                else
 
2155
                                        st = style.font().strikeoutPos(style.fontSize() / 10.0);
 
2156
                                if (style.strikethruWidth() != -1)
 
2157
                                        lw = (style.strikethruWidth() / 1000.0) * (style.fontSize() / 10.0);
 
2158
                                else
 
2159
                                lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), qreal(1.0));
 
2160
                        }
 
2161
                        else
 
2162
                        {
 
2163
                                st = style.font().strikeoutPos(style.fontSize() / 10.0);
 
2164
                                lw = qMax(style.font().strokeWidth(style.fontSize() / 10.0), qreal(1.0));
 
2165
                        }
 
2166
                        if (style.baselineOffset() != 0)
 
2167
                                st += (style.fontSize() / 10.0) * glyphs.scaleV * (style.baselineOffset() / 1000.0);
 
2168
                        p->setPen(p->brush());
 
2169
                        p->setLineWidth(lw);
 
2170
                        p->drawLine(FPoint(glyphs.xoffset, glyphs.yoffset - st), FPoint(glyphs.xoffset + glyphs.xadvance, glyphs.yoffset - st));
 
2171
                }
 
2172
        }
 
2173
/*      else
 
2174
        {
 
2175
                p->setLineWidth(1);
 
2176
                p->setPen(red);
 
2177
                p->setBrush(red);
 
2178
                p->setFillMode(1);
 
2179
                p->drawRect(glyphs.xoffset, glyphs.yoffset - (style.fontSize() / 10.0) * glyphs.scaleV , (style.fontSize() / 10.0) * glyphs.scaleH, (style.fontSize() / 10.0) * glyphs.scaleV);
 
2180
        }
 
2181
        */      
 
2182
        if (glyphs.more)
 
2183
        {
 
2184
                p->translate(glyphs.xadvance, 0);
 
2185
                drawGlyphs(p, style, *glyphs.more);
 
2186
        }
 
2187
}
 
2188
 
 
2189
void PageItem::DrawPolyL(QPainter *p, QPolygon pts)
 
2190
{
 
2191
        if (Segments.count() != 0)
 
2192
        {
 
2193
                QList<uint>::Iterator it2end=Segments.end();
 
2194
                uint FirstVal = 0;
 
2195
                for (QList<uint>::Iterator it2 = Segments.begin(); it2 != it2end; ++it2)
 
2196
                {
 
2197
                                p->drawPolygon(pts.constData() + FirstVal, (*it2)-FirstVal);
 
2198
                        FirstVal = (*it2);
 
2199
                }
 
2200
                p->drawPolygon(pts.constData() + FirstVal, pts.size() - FirstVal);
 
2201
        }
 
2202
        else
 
2203
                p->drawPolygon(pts);
 
2204
/*
 
2205
        QColor tmp;
 
2206
        if (Segments.count() != 0)
 
2207
        {
 
2208
                QList<uint>::Iterator it2end=Segments.end();
 
2209
                uint FirstVal = 0;
 
2210
                for (QList<uint>::Iterator it2 = Segments.begin(); it2 != it2end; ++it2)
 
2211
                {
 
2212
                        if (NamedLStyle.isEmpty())
 
2213
                        {
 
2214
                                if (lineColor() != CommonStrings::None)
 
2215
                                        p->setPen(QPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin));
 
2216
                                p->drawPolygon(pts.constData() + FirstVal, (*it2)-FirstVal);
 
2217
                        }
 
2218
                        else
 
2219
                        {
 
2220
                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
2221
                                for (int it = ml.size()-1; it > -1; it--)
 
2222
                                {
 
2223
                                        SetQColor(&tmp, ml[it].Color, ml[it].Shade);
 
2224
                                        p->setPen(QPen(tmp,
 
2225
                                                                         qMax(static_cast<int>(ml[it].Width), 1),
 
2226
                                                                         static_cast<Qt::PenStyle>(ml[it].Dash),
 
2227
                                                                         static_cast<Qt::PenCapStyle>(ml[it].LineEnd),
 
2228
                                                                         static_cast<Qt::PenJoinStyle>(ml[it].LineJoin)));
 
2229
                                        p->drawPolygon(pts.constData() + FirstVal, (*it2)-FirstVal);
 
2230
                                }
 
2231
                        }
 
2232
                        FirstVal = (*it2);
 
2233
                }
 
2234
                if (NamedLStyle.isEmpty())
 
2235
                {
 
2236
                        if (lineColor() != CommonStrings::None)
 
2237
                                p->setPen(QPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin));
 
2238
                        p->drawPolygon(pts.constData() + FirstVal, pts.size() - FirstVal);
 
2239
                }
 
2240
                else
 
2241
                {
 
2242
                        multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
2243
                        for (int it = ml.size()-1; it > -1; it--)
 
2244
                        {
 
2245
                                SetQColor(&tmp, ml[it].Color, ml[it].Shade);
 
2246
                                p->setPen(QPen(tmp,
 
2247
                                                                 qMax(static_cast<int>(ml[it].Width), 1),
 
2248
                                                                 static_cast<Qt::PenStyle>(ml[it].Dash),
 
2249
                                                                 static_cast<Qt::PenCapStyle>(ml[it].LineEnd),
 
2250
                                                                 static_cast<Qt::PenJoinStyle>(ml[it].LineJoin)));
 
2251
                                p->drawPolygon(pts.constData() + FirstVal, pts.size() - FirstVal);
 
2252
                        }
 
2253
                }
 
2254
        }
 
2255
        else
 
2256
        {
 
2257
                if (NamedLStyle.isEmpty())
 
2258
                {
 
2259
                        if (lineColor() != CommonStrings::None)
 
2260
                                p->setPen(QPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin));
 
2261
                        p->drawPolygon(pts);
 
2262
                }
 
2263
                else
 
2264
                {
 
2265
                        multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
2266
                        for (int it = ml.size()-1; it > -1; it--)
 
2267
                        {
 
2268
                                SetQColor(&tmp, ml[it].Color, ml[it].Shade);
 
2269
                                p->setPen(QPen(tmp,
 
2270
                                                                 qMax(static_cast<int>(ml[it].Width), 1),
 
2271
                                                                 static_cast<Qt::PenStyle>(ml[it].Dash),
 
2272
                                                                 static_cast<Qt::PenCapStyle>(ml[it].LineEnd),
 
2273
                                                                 static_cast<Qt::PenJoinStyle>(ml[it].LineJoin)));
 
2274
                                p->drawPolygon(pts);
 
2275
                        }
 
2276
                }
 
2277
        } */
 
2278
}
 
2279
 
 
2280
void PageItem::setItemName(const QString& newName)
 
2281
{
 
2282
        if (AnName == newName)
 
2283
                return; // nothing to do -> return
 
2284
        if (newName.isEmpty())
 
2285
                return;
 
2286
        QString oldName = AnName;
 
2287
        AnName = generateUniqueCopyName(newName);
 
2288
        AutoName = false;
 
2289
        if (UndoManager::undoEnabled())
 
2290
        {
 
2291
                SimpleState *ss = new SimpleState(Um::Rename, QString(Um::FromTo).arg(AnName).arg(newName));
 
2292
                ss->set("OLD_NAME", oldName);
 
2293
                ss->set("NEW_NAME", newName);
 
2294
                undoManager->action(this, ss);
 
2295
        }
 
2296
        setUName(AnName); // set the name for the UndoObject too
 
2297
}
 
2298
 
 
2299
void PageItem::setPattern(const QString &newPattern)
 
2300
{
 
2301
        if (patternVal != newPattern)
 
2302
                patternVal = newPattern;
 
2303
}
 
2304
 
 
2305
void PageItem::gradientVector(double& startX, double& startY, double& endX, double& endY) const
 
2306
{
 
2307
        startX = GrStartX;
 
2308
        startY = GrStartY;
 
2309
        endX   = GrEndX;
 
2310
        endY   = GrEndY;
 
2311
}
 
2312
 
 
2313
void PageItem::setGradientVector(double startX, double startY, double endX, double endY)
 
2314
{
 
2315
        GrStartX = startX;
 
2316
        GrStartY = startY;
 
2317
        GrEndX   = endX;
 
2318
        GrEndY   = endY;
 
2319
}
 
2320
 
 
2321
void PageItem::setPatternTransform(double scaleX, double scaleY, double offsetX, double offsetY, double rotation)
 
2322
{
 
2323
        patternScaleX = scaleX;
 
2324
        patternScaleY = scaleY;
 
2325
        patternOffsetX = offsetX;
 
2326
        patternOffsetY = offsetY;
 
2327
        patternRotation = rotation;
 
2328
}
 
2329
 
 
2330
void  PageItem::patternTransform(double &scaleX, double &scaleY, double &offsetX, double &offsetY, double &rotation) const
 
2331
{
 
2332
         scaleX = patternScaleX;
 
2333
         scaleY = patternScaleY;
 
2334
         offsetX = patternOffsetX;
 
2335
         offsetY = patternOffsetY;
 
2336
         rotation = patternRotation;
 
2337
}
 
2338
 
 
2339
void PageItem::setFillColor(const QString &newColor)
 
2340
{
 
2341
        QString tmp = newColor;
 
2342
        if (tmp != CommonStrings::None)
 
2343
        {
 
2344
                if (!m_Doc->PageColors.contains(newColor))
 
2345
                {
 
2346
                        switch(itemType())
 
2347
                        {
 
2348
                                case ImageFrame:
 
2349
                                case LatexFrame:
 
2350
                                        tmp = m_Doc->toolSettings.dBrushPict;
 
2351
                                case TextFrame:
 
2352
                                case PathText:
 
2353
                                        tmp = m_Doc->toolSettings.dTextBackGround;
 
2354
                                        break;
 
2355
                                case Line:
 
2356
                                case PolyLine:
 
2357
                                case Polygon:
 
2358
                                        tmp = m_Doc->toolSettings.dBrush;
 
2359
                                        break;
 
2360
                                default:
 
2361
                                        break;
 
2362
                        }
 
2363
                }
 
2364
        }
 
2365
        if (fillColorVal == tmp)
 
2366
        {
 
2367
                setFillQColor();
 
2368
                return;
 
2369
        }
 
2370
        if (UndoManager::undoEnabled())
 
2371
        {
 
2372
                SimpleState *ss = new SimpleState(Um::SetFill,
 
2373
                                                                                  QString(Um::ColorFromTo).arg(fillColorVal).arg(tmp),
 
2374
                                          Um::IFill);
 
2375
                ss->set("FILL", "fill");
 
2376
                ss->set("OLD_FILL", fillColorVal);
 
2377
                ss->set("NEW_FILL", tmp);
 
2378
                undoManager->action(this, ss);
 
2379
        }
 
2380
        fillColorVal = tmp;
 
2381
        if (GrType == 0)
 
2382
        {
 
2383
                fill_gradient = VGradient(VGradient::linear);
 
2384
                fill_gradient.clearStops();
 
2385
                if (fillColorVal != CommonStrings::None)
 
2386
                {
 
2387
                        const ScColor& col = m_Doc->PageColors[fillColorVal];
 
2388
                        fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, fillColorVal, 100);
 
2389
                        fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, fillColorVal, 100);
 
2390
                }
 
2391
        }
 
2392
        setFillQColor();
 
2393
//CB unused in 135      emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
 
2394
}
 
2395
 
 
2396
void PageItem::setFillShade(double newShade)
 
2397
{
 
2398
        if (fillShadeVal == newShade)
 
2399
        {
 
2400
                setFillQColor();
 
2401
                return;
 
2402
        }
 
2403
        if (UndoManager::undoEnabled())
 
2404
        {
 
2405
                SimpleState *ss = new SimpleState(Um::SetShade,
 
2406
                                                                                  QString(Um::FromTo).arg(fillShadeVal).arg(newShade),
 
2407
                                                                                  Um::IShade);
 
2408
                ss->set("SHADE", "shade");
 
2409
                ss->set("OLD_SHADE", fillShadeVal);
 
2410
                ss->set("NEW_SHADE", newShade);
 
2411
                undoManager->action(this, ss);
 
2412
        }
 
2413
        fillShadeVal = newShade;
 
2414
        setFillQColor();
 
2415
//CB unused in 135      emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
 
2416
}
 
2417
 
 
2418
void PageItem::setFillTransparency(double newTransparency)
 
2419
{
 
2420
        if (fillTransparencyVal == newTransparency)
 
2421
                return; // nothing to do -> return
 
2422
        if (UndoManager::undoEnabled())
 
2423
        {
 
2424
                SimpleState *ss = new SimpleState(Um::Transparency,
 
2425
                                                                                  QString(Um::FromTo).arg(fillTransparencyVal).arg(newTransparency),
 
2426
                                                                                  Um::ITransparency);
 
2427
                ss->set("TRANSPARENCY", "transparency");
 
2428
                ss->set("OLD_TP", fillTransparencyVal);
 
2429
                ss->set("NEW_TP", newTransparency);
 
2430
                undoManager->action(this, ss);
 
2431
        }
 
2432
        fillTransparencyVal = newTransparency;
 
2433
}
 
2434
 
 
2435
void PageItem::setFillBlendmode(int newBlendmode)
 
2436
{
 
2437
        if (fillBlendmodeVal == newBlendmode)
 
2438
                return; // nothing to do -> return
 
2439
        fillBlendmodeVal = newBlendmode;
 
2440
}
 
2441
 
 
2442
void PageItem::setLineColor(const QString &newColor)
 
2443
{
 
2444
        QString tmp = newColor;
 
2445
        if (tmp != CommonStrings::None)
 
2446
        {
 
2447
                if (!m_Doc->PageColors.contains(newColor))
 
2448
                {
 
2449
                        switch(itemType())
 
2450
                        {
 
2451
                                case TextFrame:
 
2452
                                case PathText:
 
2453
                                        tmp = m_Doc->toolSettings.dTextLineColor;
 
2454
                                        break;
 
2455
                                case Line:
 
2456
                                        tmp = m_Doc->toolSettings.dPenLine;
 
2457
                                        break;
 
2458
                                case PolyLine:
 
2459
                                case Polygon:
 
2460
                                case ImageFrame:
 
2461
                                case LatexFrame:
 
2462
                                        tmp = m_Doc->toolSettings.dPen;
 
2463
                                        break;
 
2464
                                default:
 
2465
                                        break;
 
2466
                        }
 
2467
                }
 
2468
        }
 
2469
        if (lineColorVal == tmp)
 
2470
        {
 
2471
                setLineQColor();
 
2472
                return;
 
2473
        }
 
2474
        if (UndoManager::undoEnabled())
 
2475
        {
 
2476
                SimpleState *ss = new SimpleState(Um::SetLineColor,
 
2477
                                                                                  QString(Um::ColorFromTo).arg(lineColorVal).arg(tmp),
 
2478
                                                                                  Um::IFill);
 
2479
                ss->set("LINE_COLOR", "line_color");
 
2480
                ss->set("OLD_COLOR", lineColorVal);
 
2481
                ss->set("NEW_COLOR", tmp);
 
2482
                undoManager->action(this, ss);
 
2483
        }
 
2484
        lineColorVal = tmp;
 
2485
        setLineQColor();
 
2486
//CB unused in 135      emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
 
2487
}
 
2488
 
 
2489
void PageItem::setLineShade(double newShade)
 
2490
{
 
2491
        if (lineShadeVal == newShade)
 
2492
        {
 
2493
                setLineQColor();
 
2494
                return;
 
2495
        }
 
2496
        if (UndoManager::undoEnabled())
 
2497
        {
 
2498
                SimpleState *ss = new SimpleState(Um::SetLineShade,
 
2499
                                                                                  QString(Um::FromTo).arg(lineShadeVal).arg(newShade),
 
2500
                                                                                  Um::IShade);
 
2501
                ss->set("LINE_SHADE", "line_shade");
 
2502
                ss->set("OLD_SHADE", lineShadeVal);
 
2503
                ss->set("NEW_SHADE", newShade);
 
2504
                undoManager->action(this, ss);
 
2505
        }
 
2506
        lineShadeVal = newShade;
 
2507
        setLineQColor();
 
2508
//CB unused in 135      emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
 
2509
}
 
2510
 
 
2511
void PageItem::setLineQColor()
 
2512
{
 
2513
        if (lineColorVal != CommonStrings::None)
 
2514
        {
 
2515
                if (!m_Doc->PageColors.contains(lineColorVal))
 
2516
                {
 
2517
                        switch(itemType())
 
2518
                        {
 
2519
                                case TextFrame:
 
2520
                                case PathText:
 
2521
                                        lineColorVal = m_Doc->toolSettings.dTextLineColor;
 
2522
                                        break;
 
2523
                                case Line:
 
2524
                                        lineColorVal = m_Doc->toolSettings.dPenLine;
 
2525
                                        break;
 
2526
                                case PolyLine:
 
2527
                                case Polygon:
 
2528
                                case ImageFrame:
 
2529
                                case LatexFrame:
 
2530
                                        lineColorVal = m_Doc->toolSettings.dPen;
 
2531
                                        break;
 
2532
                                default:
 
2533
                                        break;
 
2534
                        }
 
2535
                }
 
2536
                if (!m_Doc->PageColors.contains(lineColorVal))
 
2537
                        lineColorVal = m_Doc->toolSettings.dPen;
 
2538
                const ScColor& col = m_Doc->PageColors[lineColorVal];
 
2539
                strokeQColor = ScColorEngine::getShadeColorProof(col, m_Doc, lineShadeVal);
 
2540
        }
 
2541
        if ((m_Doc->view()) && (m_Doc->view()->m_canvas->usePreviewVisual()))
 
2542
        {
 
2543
                VisionDefectColor defect;
 
2544
                strokeQColor = defect.convertDefect(strokeQColor, m_Doc->view()->m_canvas->previewVisual());
 
2545
        }
 
2546
}
 
2547
 
 
2548
void PageItem::setFillQColor()
 
2549
{
 
2550
        if (fillColorVal != CommonStrings::None)
 
2551
        {
 
2552
                if (!m_Doc->PageColors.contains(fillColorVal))
 
2553
                {
 
2554
                        switch(itemType())
 
2555
                        {
 
2556
                                case ImageFrame:
 
2557
                                case LatexFrame:
 
2558
                                        fillColorVal = m_Doc->toolSettings.dBrushPict;
 
2559
                                case TextFrame:
 
2560
                                case PathText:
 
2561
                                        fillColorVal = m_Doc->toolSettings.dTextBackGround;
 
2562
                                        break;
 
2563
                                case Line:
 
2564
                                case PolyLine:
 
2565
                                case Polygon:
 
2566
                                        fillColorVal = m_Doc->toolSettings.dBrush;
 
2567
                                        break;
 
2568
                                default:
 
2569
                                        break;
 
2570
                        }
 
2571
                }
 
2572
                const ScColor& col = m_Doc->PageColors[fillColorVal];
 
2573
                fillQColor = ScColorEngine::getShadeColorProof(col, m_Doc, fillShadeVal);
 
2574
        }
 
2575
        if ((m_Doc->view()) && (m_Doc->view()->m_canvas->usePreviewVisual()))
 
2576
        {
 
2577
                VisionDefectColor defect;
 
2578
                fillQColor = defect.convertDefect(fillQColor, m_Doc->view()->m_canvas->previewVisual());
 
2579
        }
 
2580
}
 
2581
 
 
2582
void PageItem::setLineTransparency(double newTransparency)
 
2583
{
 
2584
        if (lineTransparencyVal == newTransparency)
 
2585
                return; // nothing to do -> return
 
2586
        if (UndoManager::undoEnabled())
 
2587
        {
 
2588
                SimpleState *ss = new SimpleState(Um::LineTransparency,
 
2589
                                                                                  QString(Um::FromTo).arg(lineTransparencyVal).arg(newTransparency),
 
2590
                                                                                  Um::ITransparency);
 
2591
                ss->set("LINE_TRANSPARENCY", "transparency");
 
2592
                ss->set("OLD_TP", lineTransparencyVal);
 
2593
                ss->set("NEW_TP", newTransparency);
 
2594
                undoManager->action(this, ss);
 
2595
        }
 
2596
        lineTransparencyVal = newTransparency;
 
2597
}
 
2598
 
 
2599
void PageItem::setLineBlendmode(int newBlendmode)
 
2600
{
 
2601
        if (lineBlendmodeVal == newBlendmode)
 
2602
                return; // nothing to do -> return
 
2603
        lineBlendmodeVal = newBlendmode;
 
2604
}
 
2605
 
 
2606
void PageItem::setLineStyle(Qt::PenStyle newStyle)
 
2607
{
 
2608
        if (PLineArt == newStyle)
 
2609
                return; // nothing to do -> return
 
2610
        if (UndoManager::undoEnabled())
 
2611
        {
 
2612
                SimpleState *ss = new SimpleState(Um::LineStyle,"",Um::ILineStyle);
 
2613
                ss->set("LINE_STYLE", "line_style");
 
2614
                ss->set("OLD_STYLE", static_cast<int>(PLineArt));
 
2615
                ss->set("NEW_STYLE", static_cast<int>(newStyle));
 
2616
                undoManager->action(this, ss);
 
2617
        }
 
2618
        PLineArt = newStyle;
 
2619
}
 
2620
 
 
2621
void PageItem::setLineWidth(double newWidth)
 
2622
{
 
2623
        if (m_lineWidth == newWidth)
 
2624
                return; // nothing to do -> return
 
2625
        if (UndoManager::undoEnabled())
 
2626
        {
 
2627
                SimpleState *ss = new SimpleState(Um::LineWidth,
 
2628
                                                QString(Um::FromTo).arg(m_lineWidth).arg(newWidth),Um::ILineStyle);
 
2629
                ss->set("LINE_WIDTH", "line_width");
 
2630
                ss->set("OLD_WIDTH", m_lineWidth);
 
2631
                ss->set("NEW_WIDTH", newWidth);
 
2632
                undoManager->action(this, ss);
 
2633
        }
 
2634
        Oldm_lineWidth=m_lineWidth;
 
2635
        m_lineWidth = newWidth;
 
2636
}
 
2637
 
 
2638
void PageItem::setLineEnd(Qt::PenCapStyle newStyle)
 
2639
{
 
2640
        if (PLineEnd == newStyle)
 
2641
                return; // nothing to do -> return
 
2642
        if (UndoManager::undoEnabled())
 
2643
        {
 
2644
                SimpleState *ss = new SimpleState(Um::LineEnd,"",Um::ILineStyle);
 
2645
                ss->set("LINE_END", "line_end");
 
2646
                ss->set("OLD_STYLE", static_cast<int>(PLineEnd));
 
2647
                ss->set("NEW_STYLE", static_cast<int>(newStyle));
 
2648
                undoManager->action(this, ss);
 
2649
        }
 
2650
        PLineEnd = newStyle;
 
2651
}
 
2652
 
 
2653
void PageItem::setLineJoin(Qt::PenJoinStyle newStyle)
 
2654
{
 
2655
        if (PLineJoin == newStyle)
 
2656
                return; // nothing to do -> return
 
2657
        if (UndoManager::undoEnabled())
 
2658
        {
 
2659
                SimpleState *ss = new SimpleState(Um::LineJoin,"",Um::ILineStyle);
 
2660
                ss->set("LINE_JOIN", "line_join");
 
2661
                ss->set("OLD_STYLE", static_cast<int>(PLineJoin));
 
2662
                ss->set("NEW_STYLE", static_cast<int>(newStyle));
 
2663
                undoManager->action(this, ss);
 
2664
        }
 
2665
        PLineJoin = newStyle;
 
2666
}
 
2667
 
 
2668
void PageItem::setCustomLineStyle(const QString& newStyle)
 
2669
{
 
2670
        if (NamedLStyle == newStyle)
 
2671
                return; // nothing to do -> return
 
2672
        if (UndoManager::undoEnabled())
 
2673
        {
 
2674
                QString oldStyle = NamedLStyle.isEmpty() ? Um::NoStyle : NamedLStyle;
 
2675
                QString nStyle   = newStyle.isEmpty() ? Um::NoStyle : newStyle;
 
2676
                QString action   = newStyle.isEmpty() ? Um::NoLineStyle : Um::CustomLineStyle;
 
2677
                SimpleState *ss = new SimpleState(action,
 
2678
                                QString(Um::FromTo).arg(oldStyle).arg(nStyle),Um::ILineStyle);
 
2679
                ss->set("CUSTOM_LINE_STYLE", "customlinestyle");
 
2680
                ss->set("OLD_STYLE", NamedLStyle);
 
2681
                ss->set("NEW_STYLE", newStyle);
 
2682
                undoManager->action(this, ss);
 
2683
        }
 
2684
        NamedLStyle = newStyle;
 
2685
}
 
2686
 
 
2687
void PageItem::setStartArrowIndex(int newIndex)
 
2688
{
 
2689
        if (m_startArrowIndex == newIndex)
 
2690
                return; // nothing to do -> return
 
2691
        if (UndoManager::undoEnabled())
 
2692
        {
 
2693
                SimpleState *ss = new SimpleState(Um::StartArrow,"",Um::IArrow);
 
2694
                ss->set("START_ARROW", "startarrow");
 
2695
                ss->set("OLD_INDEX", m_startArrowIndex);
 
2696
                ss->set("NEW_INDEX", newIndex);
 
2697
                undoManager->action(this, ss);
 
2698
        }
 
2699
        m_startArrowIndex = newIndex;
 
2700
}
 
2701
 
 
2702
void PageItem::setEndArrowIndex(int newIndex)
 
2703
{
 
2704
        if (m_endArrowIndex == newIndex)
 
2705
                return; // nothing to do -> return
 
2706
        if (UndoManager::undoEnabled())
 
2707
        {
 
2708
                SimpleState *ss = new SimpleState(Um::EndArrow,"",Um::IArrow);
 
2709
                ss->set("END_ARROW", "endarrow");
 
2710
                ss->set("OLD_INDEX", m_endArrowIndex);
 
2711
                ss->set("NEW_INDEX", newIndex);
 
2712
                undoManager->action(this, ss);
 
2713
        }
 
2714
        m_endArrowIndex = newIndex;
 
2715
}
 
2716
 
 
2717
void PageItem::setImageFlippedH(bool flipped)
 
2718
{
 
2719
        if (flipped != m_ImageIsFlippedH)
 
2720
                flipImageH();
 
2721
}
 
2722
 
 
2723
void PageItem::flipImageH()
 
2724
{
 
2725
        if (UndoManager::undoEnabled())
 
2726
        {
 
2727
                SimpleState *ss = new SimpleState(Um::FlipH, 0, Um::IFlipH);
 
2728
                ss->set("IMAGEFLIPH", "imagefliph");
 
2729
                undoManager->action(this, ss);
 
2730
        }
 
2731
        m_ImageIsFlippedH = !m_ImageIsFlippedH;
 
2732
        emit frameFlippedH(m_ImageIsFlippedH);
 
2733
}
 
2734
 
 
2735
void PageItem::setImageFlippedV(bool flipped)
 
2736
{
 
2737
        if (flipped != m_ImageIsFlippedV)
 
2738
                flipImageV();
 
2739
}
 
2740
 
 
2741
void PageItem::flipImageV()
 
2742
{
 
2743
        if (UndoManager::undoEnabled())
 
2744
        {
 
2745
                SimpleState *ss = new SimpleState(Um::FlipV, 0, Um::IFlipV);
 
2746
                ss->set("IMAGEFLIPV", "imageflipv");
 
2747
                undoManager->action(this, ss);
 
2748
        }
 
2749
        m_ImageIsFlippedV = !m_ImageIsFlippedV;
 
2750
        emit frameFlippedV(m_ImageIsFlippedV);
 
2751
}
 
2752
 
 
2753
void PageItem::setImageScalingMode(bool freeScale, bool keepRatio)
 
2754
{
 
2755
        if (ScaleType == freeScale && AspectRatio == keepRatio)
 
2756
                return;
 
2757
        if (UndoManager::undoEnabled())
 
2758
        {
 
2759
                QString from = ScaleType ? Um::FreeScaling : Um::FrameSize;
 
2760
                from += ", ";
 
2761
                from += AspectRatio ? Um::KeepRatio : Um::BreakRatio;
 
2762
                QString to = freeScale ? Um::FreeScaling : Um::FrameSize;
 
2763
                to += ", ";
 
2764
                to += keepRatio ? Um::KeepRatio : Um::BreakRatio;
 
2765
                SimpleState *ss = new SimpleState(Um::ImageScaling, QString(Um::FromTo).arg(from).arg(to), Um::IImageScaling);
 
2766
                ss->set("SCALE_MODE", "scaling_mode");
 
2767
                if (freeScale != ScaleType)
 
2768
                {
 
2769
                        ss->set("SCALE_TYPE", freeScale);
 
2770
                        ss->set("OLD_IMAGEXOFFSET", LocalX);
 
2771
                        ss->set("OLD_IMAGEYOFFSET", LocalY);
 
2772
                        ss->set("OLD_IMAGEXSCALE", LocalScX);
 
2773
                        ss->set("OLD_IMAGEYSCALE", LocalScY);
 
2774
                }
 
2775
                if (keepRatio != AspectRatio)
 
2776
                        ss->set("ASPECT_RATIO", keepRatio);
 
2777
                undoManager->action(this, ss);
 
2778
        }
 
2779
        ScaleType = freeScale;
 
2780
        AspectRatio = keepRatio;
 
2781
        AdjustPictScale();
 
2782
        update();
 
2783
}
 
2784
 
 
2785
void PageItem::toggleLock()
 
2786
{
 
2787
        if (UndoManager::undoEnabled())
 
2788
        {
 
2789
                SimpleState *ss;
 
2790
                if (m_Locked)
 
2791
                        ss = new SimpleState(Um::UnLock, 0, Um::IUnLock);
 
2792
                else
 
2793
                        ss = new SimpleState(Um::Lock, 0, Um::ILock);
 
2794
                ss->set("LOCK", "lock");
 
2795
                undoManager->action(this, ss);
 
2796
        }
 
2797
        m_Locked = !m_Locked;
 
2798
        emit frameLocked(m_Locked);
 
2799
}
 
2800
 
 
2801
void PageItem::setLocked(bool isLocked)
 
2802
{
 
2803
        if (isLocked != m_Locked)
 
2804
                toggleLock();
 
2805
}
 
2806
 
 
2807
void PageItem::setGroupsLastItem(PageItem* item)
 
2808
{
 
2809
        if (UndoManager::undoEnabled())
 
2810
        {
 
2811
                ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >("GroupsLastItem");
 
2812
                is->set("GROUPS_LASTITEM", "groups_lastitem");
 
2813
                is->setItem(std::pair<PageItem*, PageItem*>(this->groupsLastItem, item));
 
2814
                undoManager->action(this, is);
 
2815
        }
 
2816
        groupsLastItem = item;
 
2817
}
 
2818
 
 
2819
void PageItem::toggleSizeLock()
 
2820
{
 
2821
        if (UndoManager::undoEnabled())
 
2822
        {
 
2823
                SimpleState *ss;
 
2824
                if (m_SizeLocked)
 
2825
                        ss = new SimpleState(Um::SizeUnLock, 0, Um::IUnLock);
 
2826
                else
 
2827
                        ss = new SimpleState(Um::SizeLock, 0, Um::ILock);
 
2828
                ss->set("SIZE_LOCK", "size_lock");
 
2829
                undoManager->action(this, ss);
 
2830
        }
 
2831
        m_SizeLocked = !m_SizeLocked;
 
2832
        emit frameSizeLocked(m_SizeLocked);
 
2833
}
 
2834
 
 
2835
void PageItem::setSizeLocked(bool isLocked)
 
2836
{
 
2837
        if (isLocked != m_SizeLocked)
 
2838
                toggleSizeLock();
 
2839
}
 
2840
 
 
2841
 
 
2842
void PageItem::setPrintEnabled(bool toPrint)
 
2843
{
 
2844
        if (toPrint != m_PrintEnabled)
 
2845
                togglePrintEnabled();
 
2846
}
 
2847
 
 
2848
void PageItem::togglePrintEnabled()
 
2849
{
 
2850
        if (UndoManager::undoEnabled())
 
2851
        {
 
2852
                SimpleState *ss;
 
2853
                if (m_PrintEnabled)
 
2854
                        ss = new SimpleState(Um::DisablePrint, 0, Um::IDisablePrint);
 
2855
                else
 
2856
                        ss = new SimpleState(Um::EnablePrint, 0, Um::IEnablePrint);
 
2857
                ss->set("PRINT_ENABLED", "print_enabled");
 
2858
                undoManager->action(this, ss);
 
2859
        }
 
2860
        m_PrintEnabled=!m_PrintEnabled;
 
2861
        emit printEnabled(m_PrintEnabled);
 
2862
}
 
2863
 
 
2864
void PageItem::setTextFlowMode(TextFlowMode mode)
 
2865
{
 
2866
        if (textFlowModeVal == mode)
 
2867
                return;
 
2868
        if (UndoManager::undoEnabled())
 
2869
        {
 
2870
                QString stateMessage;
 
2871
                if( mode == TextFlowUsesFrameShape )
 
2872
                        stateMessage = Um::ObjectFrame;
 
2873
                else if( mode == TextFlowUsesBoundingBox )
 
2874
                        stateMessage = Um::BoundingBox;
 
2875
                else if( mode == TextFlowUsesContourLine )
 
2876
                        stateMessage = Um::ContourLine;
 
2877
                else if( mode == TextFlowUsesImageClipping )
 
2878
                        stateMessage = Um::ImageClip;
 
2879
                else
 
2880
                        stateMessage = Um::NoTextFlow;
 
2881
                SimpleState *ss = new SimpleState(stateMessage, "", Um::IFont);
 
2882
                ss->set("TEXTFLOW_OLDMODE", (int) textFlowModeVal);
 
2883
                ss->set("TEXTFLOW_NEWMODE", (int) mode);
 
2884
                undoManager->action(this, ss);
 
2885
        }
 
2886
        textFlowModeVal = mode;
 
2887
        
 
2888
        checkTextFlowInteractions();
 
2889
}
 
2890
 
 
2891
void PageItem::checkTextFlowInteractions(bool allItems)
 
2892
{       
 
2893
        if(!m_Doc->isLoading())
 
2894
        {
 
2895
                QRectF baseRect(getBoundingRect());
 
2896
                QList<PageItem*>* items = OnMasterPage.isEmpty() ? &m_Doc->DocItems : &m_Doc->MasterItems;
 
2897
                for(int idx = (allItems ? items->count()-1 : ItemNr-1); idx >= 0 ; --idx)
 
2898
                {
 
2899
                        if(idx != static_cast<int>(ItemNr)) // avoids itself
 
2900
                        {
 
2901
                                if(items->at(idx)->asTextFrame()) // do not bother with no text frames
 
2902
                                {
 
2903
                                        QRectF uRect(items->at(idx)->getBoundingRect());
 
2904
                                        if(baseRect.intersects(uRect))
 
2905
                                        {
 
2906
                                                items->at(idx)->update();
 
2907
                                        }
 
2908
                                }
 
2909
                        }
 
2910
                }
 
2911
        }
 
2912
}
 
2913
 
 
2914
void PageItem::convertTo(ItemType newType)
 
2915
{
 
2916
        if (m_ItemType == newType)
 
2917
                return; // nothing to do -> return
 
2918
        assert(newType != 1);   //DEBUG CR 2005-02-06
 
2919
        assert(newType != 3);   //DEBUG CR 2005-02-06
 
2920
        QString fromType = "", toType = "";
 
2921
        switch (m_ItemType)
 
2922
        {
 
2923
                case ImageFrame:
 
2924
                        if (asLatexFrame()) {
 
2925
                                fromType = Um::LatexFrame;
 
2926
                        } else {
 
2927
                                fromType = Um::ImageFrame;
 
2928
                        }
 
2929
                        break;
 
2930
                case TextFrame:
 
2931
                        fromType = Um::TextFrame;
 
2932
                        break;
 
2933
                case Polygon:
 
2934
                        fromType = Um::Polygon;
 
2935
                        break;
 
2936
                default:
 
2937
                        fromType = "";
 
2938
                        break;
 
2939
        }
 
2940
        switch (newType)
 
2941
        {
 
2942
                case ImageFrame:
 
2943
                        toType = Um::ImageFrame;
 
2944
                        setUPixmap(Um::IImageFrame);
 
2945
                        break;
 
2946
                case LatexFrame:
 
2947
                        toType = Um::LatexFrame;
 
2948
                        setUPixmap(Um::ILatexFrame);
 
2949
                        break;
 
2950
                case TextFrame:
 
2951
                        toType = Um::TextFrame;
 
2952
                        setUPixmap(Um::ITextFrame);
 
2953
                        break;
 
2954
                case Polygon:
 
2955
                        toType = Um::Polygon;
 
2956
                        setUPixmap(Um::IPolygon);
 
2957
                        break;
 
2958
                case PolyLine:
 
2959
                        toType = Um::Polyline;
 
2960
                        setUPixmap(Um::IPolyline);
 
2961
                        break;
 
2962
                default:
 
2963
                        toType = "";
 
2964
                        setUPixmap(NULL);
 
2965
                        break;
 
2966
        }
 
2967
        /*
 
2968
        if (UndoManager::undoEnabled())
 
2969
        {
 
2970
                SimpleState *ss = new SimpleState(Um::ConvertTo + " " + toType,
 
2971
                                                                                  QString(Um::FromTo).arg(fromType).arg(toType));
 
2972
                ss->set("CONVERT", "convert");
 
2973
                ss->set("PAGEITEM", reinterpret_cast<int>(this));
 
2974
                ss->set("OLD_TYPE", m_ItemType);
 
2975
                ss->set("NEW_TYPE", newType);
 
2976
                undoManager->action(this, ss);
 
2977
        }
 
2978
        */
 
2979
        m_ItemType = newType;
 
2980
        emit frameType(m_ItemType);
 
2981
}
 
2982
 
 
2983
void PageItem::setLayer(int layerId)
 
2984
{
 
2985
        if (LayerNr == layerId)
 
2986
                return;
 
2987
        if (UndoManager::undoEnabled())
 
2988
        {
 
2989
                SimpleState *ss = new SimpleState(Um::SendToLayer,
 
2990
                                                                                  QString(Um::FromTo).arg(LayerNr).arg(layerId),
 
2991
                                                                                  Um::ILayerAction);
 
2992
                ss->set("SEND_TO_LAYER", "send_to_layer");
 
2993
                ss->set("OLD_LAYER", LayerNr);
 
2994
                ss->set("NEW_LAYER", layerId);
 
2995
                undoManager->action(this, ss);
 
2996
        }
 
2997
        LayerNr = layerId;
 
2998
}
 
2999
 
 
3000
void PageItem::checkChanges(bool force)
 
3001
{
 
3002
        bool spreadChanges(false);
 
3003
        // has the item been resized
 
3004
        if (force || ((oldWidth != Width || oldHeight != Height) && shouldCheck()))
 
3005
        {
 
3006
                resizeUndoAction();
 
3007
                spreadChanges = (textFlowMode() != TextFlowDisabled );
 
3008
        }
 
3009
        // has the item been rotated
 
3010
        if (force || ((oldRot != Rot) && (shouldCheck())))
 
3011
        {
 
3012
                rotateUndoAction();
 
3013
                spreadChanges = (textFlowMode() != TextFlowDisabled );
 
3014
        }
 
3015
        // has the item been moved
 
3016
        if (force || ((oldXpos != Xpos || oldYpos != Ypos) && shouldCheck()))
 
3017
        {
 
3018
                moveUndoAction();
 
3019
                spreadChanges = (textFlowMode() != TextFlowDisabled );
 
3020
        }
 
3021
        // has the item's image been moved
 
3022
        if (force || ((oldLocalX != LocalX || oldLocalY != LocalY) && shouldCheck()))
 
3023
                changeImageOffsetUndoAction();
 
3024
        // has the item's image been scaled
 
3025
        if (force || ((oldLocalScX != LocalScX || oldLocalScY != LocalScY) && shouldCheck()))
 
3026
                changeImageScaleUndoAction();
 
3027
        
 
3028
        if(spreadChanges)
 
3029
        {
 
3030
                checkTextFlowInteractions();
 
3031
        }
 
3032
}
 
3033
 
 
3034
bool PageItem::shouldCheck()
 
3035
{
 
3036
        return ((!m_Doc->view()->mousePressed()) &&
 
3037
                        (!ScCore->primaryMainWindow()->arrowKeyDown()) &&
 
3038
                        (!ScCore->primaryMainWindow()->propertiesPalette->userActionOn()));
 
3039
}
 
3040
 
 
3041
void PageItem::moveUndoAction()
 
3042
{
 
3043
        if (oldXpos == Xpos && oldYpos == Ypos)
 
3044
                return;
 
3045
        if (UndoManager::undoEnabled())
 
3046
        {
 
3047
                QString oldp;
 
3048
                QString newp;
 
3049
                if (oldOwnPage == -1)
 
3050
                        oldp = Um::ScratchSpace;
 
3051
                else
 
3052
                        oldp = QString(Um::PageNmbr).arg(m_Doc->FirstPnum + oldOwnPage);
 
3053
                if (OwnPage == -1)
 
3054
                        newp = Um::ScratchSpace;
 
3055
                else
 
3056
                        newp = QString(Um::PageNmbr).arg(m_Doc->FirstPnum + OwnPage);
 
3057
                SimpleState *ss = new SimpleState(Um::Move,
 
3058
                                          QString(Um::MoveFromTo).arg(oldXpos).arg(oldYpos).arg(oldp).
 
3059
                                                                  arg(Xpos).arg(Ypos).arg(newp), Um::IMove);
 
3060
                ss->set("OLD_XPOS", oldXpos);
 
3061
                ss->set("OLD_YPOS", oldYpos);
 
3062
                ss->set("NEW_XPOS", Xpos);
 
3063
                ss->set("NEW_YPOS", Ypos);
 
3064
                undoManager->action(this, ss);
 
3065
        }
 
3066
        oldXpos = Xpos;
 
3067
        oldYpos = Ypos;
 
3068
        oldOwnPage = OwnPage;
 
3069
}
 
3070
 
 
3071
void PageItem::resizeUndoAction()
 
3072
{
 
3073
        if (oldHeight == Height && oldWidth == Width)
 
3074
                return;
 
3075
        if (UndoManager::undoEnabled())
 
3076
        {
 
3077
                SimpleState *ss = new SimpleState(Um::Resize,
 
3078
                           QString(Um::ResizeFromTo).arg(oldWidth).arg(oldHeight).arg(Width).arg(Height),
 
3079
                                          Um::IResize);
 
3080
                ss->set("OLD_WIDTH", oldWidth);
 
3081
                ss->set("OLD_HEIGHT", oldHeight);
 
3082
                ss->set("NEW_WIDTH", Width);
 
3083
                ss->set("NEW_HEIGHT", Height);
 
3084
                ss->set("OLD_RXPOS", oldXpos);
 
3085
                ss->set("OLD_RYPOS", oldYpos);
 
3086
                ss->set("NEW_RXPOS", Xpos);
 
3087
                ss->set("NEW_RYPOS", Ypos);
 
3088
                ss->set("OLD_RROT", oldRot);
 
3089
                ss->set("NEW_RROT", Rot);
 
3090
                undoManager->action(this, ss);
 
3091
        }
 
3092
        oldXpos = Xpos;
 
3093
        oldYpos = Ypos;
 
3094
        oldHeight = Height;
 
3095
        oldWidth = Width;
 
3096
        oldOwnPage = OwnPage;
 
3097
        oldRot = Rot;
 
3098
}
 
3099
 
 
3100
void PageItem::rotateUndoAction()
 
3101
{
 
3102
        if (oldRot == Rot)
 
3103
                return;
 
3104
        if (UndoManager::undoEnabled())
 
3105
        {
 
3106
                SimpleState *ss = new SimpleState(Um::Rotate,
 
3107
                                          QString(Um::FromTo).arg(oldRot).arg(Rot),
 
3108
                                          Um::IRotate);
 
3109
                ss->set("OLD_ROT", oldRot);
 
3110
                ss->set("NEW_ROT", Rot);
 
3111
                ss->set("OLD_RXPOS", oldXpos);
 
3112
                ss->set("OLD_RYPOS", oldYpos);
 
3113
                ss->set("NEW_RXPOS", Xpos);
 
3114
                ss->set("NEW_RYPOS", Ypos);
 
3115
                ss->set("OLD_RWIDTH", oldWidth);
 
3116
                ss->set("OLD_RHEIGHT", oldHeight);
 
3117
                ss->set("NEW_RWIDTH", Width);
 
3118
                ss->set("NEW_RHEIGHT", Height);
 
3119
                undoManager->action(this, ss);
 
3120
        }
 
3121
        oldRot = Rot;
 
3122
        oldXpos = Xpos;
 
3123
        oldYpos = Ypos;
 
3124
        oldOwnPage = OwnPage;
 
3125
        oldWidth = Width;
 
3126
        oldHeight = Height;
 
3127
}
 
3128
 
 
3129
void PageItem::changeImageOffsetUndoAction()
 
3130
{
 
3131
        if (oldLocalX == LocalX && oldLocalY == LocalY)
 
3132
                return;
 
3133
        if (UndoManager::undoEnabled())
 
3134
        {
 
3135
                SimpleState *ss = new SimpleState(Um::ImageOffset,
 
3136
                        QString(Um::ImageOffsetFromTo).arg(oldLocalX).arg(oldLocalY).arg(LocalX).arg(LocalY), Um::IMove);
 
3137
                ss->set("IMAGE_OFFSET", "image_offset");
 
3138
                ss->set("OLD_IMAGEXOFFSET", oldLocalX);
 
3139
                ss->set("OLD_IMAGEYOFFSET", oldLocalY);
 
3140
                ss->set("NEW_IMAGEXOFFSET", LocalX);
 
3141
                ss->set("NEW_IMAGEYOFFSET", LocalY);
 
3142
                undoManager->action(this, ss);
 
3143
        }
 
3144
        oldLocalX = LocalX;
 
3145
        oldLocalY = LocalY;
 
3146
}
 
3147
 
 
3148
void PageItem::changeImageScaleUndoAction()
 
3149
{
 
3150
        //#9817: Hack for this rounding issue caused by conversion to text values. Undo needs fixing.
 
3151
        if ((ScCLocale::toDoubleC(ScCLocale::toQStringC(oldLocalScX)) ==
 
3152
                ScCLocale::toDoubleC(ScCLocale::toQStringC(LocalScX)))
 
3153
                && (ScCLocale::toDoubleC(ScCLocale::toQStringC(oldLocalScY)) ==
 
3154
                ScCLocale::toDoubleC(ScCLocale::toQStringC(LocalScY))))
 
3155
                return;
 
3156
        if (UndoManager::undoEnabled())
 
3157
        {
 
3158
                SimpleState *ss = new SimpleState(Um::ImageScale,
 
3159
                        QString(Um::ImageScaleFromTo).arg(oldLocalScX).arg(oldLocalScY).arg(LocalScX).arg(LocalScY), Um::IMove);
 
3160
                ss->set("IMAGE_SCALE", "image_scale");
 
3161
                ss->set("OLD_IMAGEXSCALE", oldLocalScX);
 
3162
                ss->set("OLD_IMAGEYSCALE", oldLocalScY);
 
3163
                ss->set("NEW_IMAGEXSCALE", LocalScX);
 
3164
                ss->set("NEW_IMAGEYSCALE", LocalScY);
 
3165
                undoManager->action(this, ss);
 
3166
        }
 
3167
        oldLocalScX = LocalScX;
 
3168
        oldLocalScY = LocalScY;
 
3169
}
 
3170
 
 
3171
void PageItem::restore(UndoState *state, bool isUndo)
 
3172
{
 
3173
        bool useRasterBackup = m_Doc->useRaster;
 
3174
        bool SnapGuidesBackup = m_Doc->SnapGuides;
 
3175
        m_Doc->useRaster = false;
 
3176
        m_Doc->SnapGuides = false;
 
3177
        SimpleState *ss = dynamic_cast<SimpleState*>(state);
 
3178
        bool oldMPMode=m_Doc->masterPageMode();
 
3179
        m_Doc->setMasterPageMode(!OnMasterPage.isEmpty());
 
3180
        Page *oldCurrentPage = m_Doc->currentPage();
 
3181
        if (!OnMasterPage.isEmpty())
 
3182
        {
 
3183
                oldCurrentPage = m_Doc->currentPage();
 
3184
                m_Doc->setCurrentPage(m_Doc->MasterPages.at(m_Doc->MasterNames[OnMasterPage]));
 
3185
        }
 
3186
        if (ss)
 
3187
        {
 
3188
                if (ss->contains("OLD_XPOS"))
 
3189
                        restoreMove(ss, isUndo);
 
3190
                else if (ss->contains("OLD_HEIGHT"))
 
3191
                        restoreResize(ss, isUndo);
 
3192
                else if (ss->contains("OLD_ROT"))
 
3193
                        restoreRotate(ss, isUndo);
 
3194
                else if (ss->contains("FILL"))
 
3195
                        restoreFill(ss, isUndo);
 
3196
                else if (ss->contains("SHADE"))
 
3197
                        restoreShade(ss, isUndo);
 
3198
                else if (ss->contains("LINE_COLOR"))
 
3199
                        restoreLineColor(ss, isUndo);
 
3200
                else if (ss->contains("LINE_SHADE"))
 
3201
                        restoreLineShade(ss, isUndo);
 
3202
                else if (ss->contains("IMAGEFLIPH"))
 
3203
                {
 
3204
                        select();
 
3205
                        m_Doc->itemSelection_FlipH();
 
3206
                }
 
3207
                else if (ss->contains("IMAGEFLIPV"))
 
3208
                {
 
3209
                        select();
 
3210
                        m_Doc->itemSelection_FlipV();
 
3211
                }
 
3212
                else if (ss->contains("LOCK"))
 
3213
                {
 
3214
                        select();
 
3215
                        m_Doc->itemSelection_ToggleLock();
 
3216
                }
 
3217
                else if (ss->contains("SIZE_LOCK"))
 
3218
                {
 
3219
                        select();
 
3220
                        m_Doc->itemSelection_ToggleSizeLock();
 
3221
                }
 
3222
                else if (ss->contains("PRINT_ENABLED"))
 
3223
                {
 
3224
                        select();
 
3225
                        m_Doc->itemSelection_TogglePrintEnabled();
 
3226
                }
 
3227
                else if (ss->contains("NEW_NAME"))
 
3228
                        restoreName(ss, isUndo);
 
3229
                else if (ss->contains("TRANSPARENCY"))
 
3230
                        restoreFillTP(ss, isUndo);
 
3231
                else if (ss->contains("LINE_TRANSPARENCY"))
 
3232
                        restoreLineTP(ss, isUndo);
 
3233
                else if (ss->contains("LINE_STYLE"))
 
3234
                        restoreLineStyle(ss, isUndo);
 
3235
                else if (ss->contains("LINE_END"))
 
3236
                        restoreLineEnd(ss, isUndo);
 
3237
                else if (ss->contains("LINE_JOIN"))
 
3238
                        restoreLineJoin(ss, isUndo);
 
3239
                else if (ss->contains("LINE_WIDTH"))
 
3240
                        restoreLineWidth(ss, isUndo);
 
3241
                else if (ss->contains("CUSTOM_LINE_STYLE"))
 
3242
                        restoreCustomLineStyle(ss, isUndo);
 
3243
                else if (ss->contains("START_ARROW"))
 
3244
                        restoreArrow(ss, isUndo, true);
 
3245
                else if (ss->contains("END_ARROW"))
 
3246
                        restoreArrow(ss, isUndo, false);
 
3247
                else if (ss->contains("PSTYLE"))
 
3248
                        restorePStyle(ss, isUndo);
 
3249
                else if (ss->contains("CONVERT"))
 
3250
                        restoreType(ss, isUndo);
 
3251
                else if (ss->contains("TEXTFLOW_OLDMODE"))
 
3252
                        restoreTextFlowing(ss, isUndo);
 
3253
                else if (ss->contains("SCALE_MODE"))
 
3254
                        restoreImageScaleMode(ss, isUndo);
 
3255
                else if (ss->contains("IMAGE_SCALE"))
 
3256
                        restoreImageScaleChange(ss, isUndo);
 
3257
                else if (ss->contains("IMAGE_OFFSET"))
 
3258
                        restoreImageOffsetChange(ss, isUndo);   
 
3259
                else if (ss->contains("EDIT_CONTOUR"))
 
3260
                        restorePoly(ss, isUndo, true);
 
3261
                else if (ss->contains("EDIT_SHAPE"))
 
3262
                        restorePoly(ss, isUndo, false);
 
3263
                else if (ss->contains("RESET_CONTOUR"))
 
3264
                        restoreContourLine(ss, isUndo);
 
3265
                else if (ss->contains("CHANGE_SHAPE_TYPE"))
 
3266
                        restoreShapeType(ss, isUndo);
 
3267
                else if (ss->contains("MIRROR_PATH_H"))
 
3268
                {
 
3269
                        bool editContour = m_Doc->nodeEdit.isContourLine;
 
3270
                        m_Doc->nodeEdit.isContourLine = ss->getBool("IS_CONTOUR");
 
3271
                        select();
 
3272
                        m_Doc->MirrorPolyH(m_Doc->m_Selection->itemAt(0));
 
3273
                        m_Doc->nodeEdit.isContourLine = editContour;
 
3274
                }
 
3275
                else if (ss->contains("MIRROR_PATH_V"))
 
3276
                {
 
3277
                        bool editContour = m_Doc->nodeEdit.isContourLine;
 
3278
                        m_Doc->nodeEdit.isContourLine = ss->getBool("IS_CONTOUR");
 
3279
                        select();
 
3280
                        m_Doc->MirrorPolyV(m_Doc->m_Selection->itemAt(0));
 
3281
                        m_Doc->nodeEdit.isContourLine = editContour;
 
3282
                }
 
3283
                else if (ss->contains("SEND_TO_LAYER"))
 
3284
                        restoreLayer(ss, isUndo);
 
3285
                else if (ss->contains("GET_IMAGE"))
 
3286
                        restoreGetImage(ss, isUndo);
 
3287
                else if (ss->contains("GROUPS_LASTITEM"))
 
3288
                        restoreGroupsLastItem(ss, isUndo);
 
3289
                else if (ss->contains("EDIT_SHAPE_OR_CONTOUR"))
 
3290
                        restoreShapeContour(ss, isUndo);
 
3291
                else if (ss->contains("APPLY_IMAGE_EFFECTS"))
 
3292
                        restoreImageEffects(ss, isUndo);
 
3293
                else if (ss->contains("STEXT"))
 
3294
                        restoreEditText(ss, isUndo);
 
3295
                else if (ss->contains("CLEAR_IMAGE"))
 
3296
                        restoreClearImage(ss,isUndo);
 
3297
                else if (ss->contains("LINK_TEXT_FRAME"))
 
3298
                        restoreLinkTextFrame(ss,isUndo);
 
3299
                else if (ss->contains("UNLINK_TEXT_FRAME"))
 
3300
                        restoreUnlinkTextFrame(ss, isUndo);
 
3301
                else if (ss->contains("REVERSE_TEXT"))
 
3302
                        restoreReverseText(ss, isUndo);
 
3303
                else if (ss->contains("PATH_OPERATION"))
 
3304
                        restorePathOperation(ss, isUndo);
 
3305
        }
 
3306
        if (!OnMasterPage.isEmpty())
 
3307
                m_Doc->setCurrentPage(oldCurrentPage);
 
3308
        m_Doc->setMasterPageMode(oldMPMode);
 
3309
        m_Doc->useRaster = useRasterBackup;
 
3310
        m_Doc->SnapGuides = SnapGuidesBackup;
 
3311
}
 
3312
 
 
3313
void PageItem::restoreMove(SimpleState *state, bool isUndo)
 
3314
{
 
3315
        double ox = state->getDouble("OLD_XPOS");
 
3316
        double oy = state->getDouble("OLD_YPOS");
 
3317
        double  x = state->getDouble("NEW_XPOS");
 
3318
        double  y = state->getDouble("NEW_YPOS");
 
3319
        double mx = ox - x;
 
3320
        double my = oy - y;
 
3321
        if (!isUndo)
 
3322
        {
 
3323
                mx = -mx;
 
3324
                my = -my;
 
3325
        }
 
3326
        m_Doc->MoveItem(mx, my, this, false);
 
3327
        oldXpos = Xpos;
 
3328
        oldYpos = Ypos;
 
3329
        oldOwnPage = OwnPage;
 
3330
}
 
3331
 
 
3332
void PageItem::restoreResize(SimpleState *state, bool isUndo)
 
3333
{
 
3334
        double  ow = state->getDouble("OLD_WIDTH");
 
3335
        double  oh = state->getDouble("OLD_HEIGHT");
 
3336
        double   w = state->getDouble("NEW_WIDTH");
 
3337
        double   h = state->getDouble("NEW_HEIGHT");
 
3338
        double  ox = state->getDouble("OLD_RXPOS");
 
3339
        double  oy = state->getDouble("OLD_RYPOS");
 
3340
        double   x = state->getDouble("NEW_RXPOS");
 
3341
        double   y = state->getDouble("NEW_RYPOS");
 
3342
        double ort = state->getDouble("OLD_RROT");
 
3343
        double  rt = state->getDouble("NEW_RROT");
 
3344
        double  mx = ox - x;
 
3345
        double  my = oy - y;
 
3346
        int  stateCode = state->transactionCode;
 
3347
        bool redraw = ((stateCode != 1) && (stateCode != 3));
 
3348
        if (isUndo)
 
3349
        {
 
3350
                m_Doc->SizeItem(ow, oh, this, false, true, redraw);
 
3351
                m_Doc->MoveItem(mx, my, this, false);
 
3352
                m_Doc->RotateItem(ort, this);
 
3353
        }
 
3354
        else
 
3355
        {
 
3356
                mx = -mx;
 
3357
                my = -my;
 
3358
                m_Doc->SizeItem(w, h, this, false, true, redraw);
 
3359
                m_Doc->MoveItem(mx, my, this, false);
 
3360
                m_Doc->RotateItem(rt, this);
 
3361
        }
 
3362
        oldWidth = Width;
 
3363
        oldHeight = Height;
 
3364
        oldXpos = Xpos;
 
3365
        oldYpos = Ypos;
 
3366
        oldOwnPage = OwnPage;
 
3367
        oldRot = Rot;
 
3368
}
 
3369
 
 
3370
void PageItem::restoreRotate(SimpleState *state, bool isUndo)
 
3371
{
 
3372
        double ort = state->getDouble("OLD_ROT");
 
3373
        double  rt = state->getDouble("NEW_ROT");
 
3374
        double  ox = state->getDouble("OLD_RXPOS");
 
3375
        double  oy = state->getDouble("OLD_RYPOS");
 
3376
        double   x = state->getDouble("NEW_RXPOS");
 
3377
        double   y = state->getDouble("NEW_RYPOS");
 
3378
        double  ow = state->getDouble("OLD_RWIDTH");
 
3379
        double  oh = state->getDouble("OLD_RHEIGHT");
 
3380
        double   w = state->getDouble("NEW_RWIDTH");
 
3381
        double   h = state->getDouble("NEW_RHEIGHT");
 
3382
        int  stateCode = state->transactionCode;
 
3383
        bool redraw = ((stateCode != 1) && (stateCode != 3));;
 
3384
        //CB Commented out test code
 
3385
        //QRect oldR(getRedrawBounding(view->scale()));
 
3386
        //double mx = ox - x;
 
3387
        //double my = oy - y;
 
3388
        if (isUndo)
 
3389
        {
 
3390
                /*Rot=ort;
 
3391
                Xpos+=mx;
 
3392
                Ypos+=my;
 
3393
                Width=ow;
 
3394
                Height=oh;*/
 
3395
                m_Doc->RotateItem(ort, this);
 
3396
                m_Doc->MoveItem(ox - Xpos, oy - Ypos, this, false);
 
3397
                m_Doc->SizeItem(ow, oh, this, false, true, redraw);
 
3398
        }
 
3399
        else
 
3400
        {
 
3401
                /*mx = -mx;
 
3402
                my = -my;
 
3403
                Rot=rt;
 
3404
                Xpos-=mx;
 
3405
                Ypos-=my;
 
3406
                Width=w;
 
3407
                Height=h;
 
3408
                */
 
3409
                m_Doc->RotateItem(rt, this);
 
3410
                m_Doc->MoveItem(x - Xpos, y - Ypos, this, false);
 
3411
                m_Doc->SizeItem(w, h, this, false, true, redraw);
 
3412
        }
 
3413
        /*
 
3414
        m_Doc->setRedrawBounding(this);
 
3415
        QRect newR(getRedrawBounding(view->scale()));
 
3416
        view->updateContents(newR.unite(oldR));
 
3417
        OwnPage = m_Doc->OnPage(this);
 
3418
        */
 
3419
        oldRot = Rot;
 
3420
        oldXpos = Xpos;
 
3421
        oldYpos = Ypos;
 
3422
        oldOwnPage = OwnPage;
 
3423
        oldWidth = Width;
 
3424
        oldHeight = Height;
 
3425
}
 
3426
 
 
3427
void PageItem::restoreFill(SimpleState *state, bool isUndo)
 
3428
{
 
3429
        QString fill = state->get("OLD_FILL");
 
3430
        if (!isUndo)
 
3431
                fill = state->get("NEW_FILL");
 
3432
        select();
 
3433
        m_Doc->itemSelection_SetItemBrush(fill);
 
3434
}
 
3435
 
 
3436
void PageItem::restoreShade(SimpleState *state, bool isUndo)
 
3437
{
 
3438
        int shade = state->getInt("OLD_SHADE");
 
3439
        if (!isUndo)
 
3440
                shade = state->getInt("NEW_SHADE");
 
3441
        select();
 
3442
        m_Doc->itemSelection_SetItemBrushShade(shade);
 
3443
}
 
3444
 
 
3445
void PageItem::restoreLineColor(SimpleState *state, bool isUndo)
 
3446
{
 
3447
        QString fill = state->get("OLD_COLOR");
 
3448
        if (!isUndo)
 
3449
                fill = state->get("NEW_COLOR");
 
3450
        select();
 
3451
        m_Doc->itemSelection_SetItemPen(fill);
 
3452
}
 
3453
 
 
3454
void PageItem::restoreLineShade(SimpleState *state, bool isUndo)
 
3455
{
 
3456
        int shade = state->getInt("OLD_SHADE");
 
3457
        if (!isUndo)
 
3458
                shade = state->getInt("NEW_SHADE");
 
3459
        select();
 
3460
        m_Doc->itemSelection_SetItemPenShade(shade);
 
3461
}
 
3462
 
 
3463
void PageItem::restoreFillTP(SimpleState *state, bool isUndo)
 
3464
{
 
3465
        double tp = state->getDouble("OLD_TP");
 
3466
        if (!isUndo)
 
3467
                tp = state->getDouble("NEW_TP");
 
3468
        select();
 
3469
        m_Doc->itemSelection_SetItemFillTransparency(tp);
 
3470
}
 
3471
 
 
3472
void PageItem::restoreLineTP(SimpleState *state, bool isUndo)
 
3473
{
 
3474
        double tp = state->getDouble("OLD_TP");
 
3475
        if (!isUndo)
 
3476
                tp = state->getDouble("NEW_TP");
 
3477
        select();
 
3478
        m_Doc->itemSelection_SetItemLineTransparency(tp);
 
3479
}
 
3480
 
 
3481
 
 
3482
void PageItem::restoreLineStyle(SimpleState *state, bool isUndo)
 
3483
{
 
3484
        Qt::PenStyle ps = static_cast<Qt::PenStyle>(state->getInt("OLD_STYLE"));
 
3485
        if (!isUndo)
 
3486
                ps = static_cast<Qt::PenStyle>(state->getInt("NEW_STYLE"));
 
3487
        select();
 
3488
        m_Doc->itemSelection_SetLineArt(ps);
 
3489
}
 
3490
 
 
3491
void PageItem::restoreLineEnd(SimpleState *state, bool isUndo)
 
3492
{
 
3493
        Qt::PenCapStyle pcs = static_cast<Qt::PenCapStyle>(state->getInt("OLD_STYLE"));
 
3494
        if (!isUndo)
 
3495
                pcs = static_cast<Qt::PenCapStyle>(state->getInt("NEW_STYLE"));
 
3496
        select();
 
3497
        m_Doc->itemSelection_SetLineEnd(pcs);
 
3498
}
 
3499
 
 
3500
void PageItem::restoreLineJoin(SimpleState *state, bool isUndo)
 
3501
{
 
3502
        Qt::PenJoinStyle pjs = static_cast<Qt::PenJoinStyle>(state->getInt("OLD_STYLE"));
 
3503
        if (!isUndo)
 
3504
                pjs = static_cast<Qt::PenJoinStyle>(state->getInt("NEW_STYLE"));
 
3505
        select();
 
3506
        m_Doc->itemSelection_SetLineJoin(pjs);
 
3507
}
 
3508
 
 
3509
void PageItem::restoreLineWidth(SimpleState *state, bool isUndo)
 
3510
{
 
3511
        double w = state->getDouble("OLD_WIDTH");
 
3512
        if (!isUndo)
 
3513
                w = state->getDouble("NEW_WIDTH");
 
3514
        select();
 
3515
        m_Doc->itemSelection_SetLineWidth(w);
 
3516
}
 
3517
 
 
3518
void PageItem::restoreCustomLineStyle(SimpleState *state, bool isUndo)
 
3519
{
 
3520
        QString style = state->get("OLD_STYLE");
 
3521
        if (!isUndo)
 
3522
                style = state->get("NEW_STYLE");
 
3523
        setCustomLineStyle(style);
 
3524
}
 
3525
 
 
3526
void PageItem::restoreName(SimpleState *state, bool isUndo)
 
3527
{
 
3528
        QString name = state->get("OLD_NAME");
 
3529
        if (!isUndo)
 
3530
                name = state->get("NEW_NAME");
 
3531
        setItemName(name);
 
3532
}
 
3533
 
 
3534
void PageItem::restoreArrow(SimpleState *state, bool isUndo, bool isStart)
 
3535
{
 
3536
        int i = state->getInt("OLD_INDEX");
 
3537
        if (!isUndo)
 
3538
                i = state->getInt("NEW_INDEX");
 
3539
        if (isStart)
 
3540
                setStartArrowIndex(i);
 
3541
        else
 
3542
                setEndArrowIndex(i);
 
3543
}
 
3544
 
 
3545
 
 
3546
void PageItem::restorePStyle(SimpleState *state, bool isUndo)
 
3547
{
 
3548
        int styleid = state->getInt("OLD_STYLE");
 
3549
        if (!isUndo)
 
3550
                styleid = state->getInt("NEW_STYLE");
 
3551
        //will be done later with other text-undo:
 
3552
        //      m_Doc->chAbStyle(this, styleid);
 
3553
}
 
3554
 
 
3555
 
 
3556
// FIXME: This must go into class ScribusDoc!
 
3557
// For now we'll just make it independent of 'this' -- AV
 
3558
void PageItem::restoreType(SimpleState *state, bool isUndo)
 
3559
{
 
3560
        // well, probably not the best way to handle pointers...
 
3561
        PageItem * item = reinterpret_cast<PageItem *>(state->getInt("PAGEITEM"));
 
3562
        int type = state->getInt("OLD_TYPE");
 
3563
        if (!isUndo)
 
3564
                type = state->getInt("NEW_TYPE");
 
3565
        ScribusView* view = m_Doc->view();
 
3566
        view->Deselect(false);
 
3567
        view->SelectItem(item, false);
 
3568
        switch (type) {
 
3569
                case ImageFrame: view->ToPicFrame(); break;
 
3570
                case TextFrame: view->ToTextFrame(); break;
 
3571
                case Polygon: view->ToPolyFrame(); break;
 
3572
                case PolyLine: view->ToBezierFrame(); break;
 
3573
        }
 
3574
        view->requestMode(modeNormal);
 
3575
}
 
3576
 
 
3577
void PageItem::restoreTextFlowing(SimpleState *state, bool isUndo)
 
3578
{
 
3579
        TextFlowMode oldMode = (TextFlowMode) state->getInt("TEXTFLOW_OLDMODE");
 
3580
        TextFlowMode newMode = (TextFlowMode) state->getInt("TEXTFLOW_NEWMODE");
 
3581
        if (isUndo)
 
3582
                textFlowModeVal = oldMode;
 
3583
        else
 
3584
                textFlowModeVal = newMode;
 
3585
        
 
3586
        QList<PageItem*> pList;
 
3587
        for(int idx = ItemNr-1; idx >= 0 ; --idx)
 
3588
        {
 
3589
                pList << m_Doc->Items->at(idx);
 
3590
        }
 
3591
                
 
3592
        QRectF baseRect(getBoundingRect());
 
3593
        for(int idx(0); idx < pList.count(); ++idx)
 
3594
        {
 
3595
                QRectF uRect(pList.at(idx)->getBoundingRect());
 
3596
                if(baseRect.intersects(uRect))
 
3597
                        pList.at(idx)->update();
 
3598
        }
 
3599
}
 
3600
 
 
3601
void PageItem::restoreImageScaleMode(SimpleState *state, bool isUndo)
 
3602
{
 
3603
        bool type=ScaleType;
 
3604
        if (state->contains("SCALE_TYPE"))
 
3605
        {
 
3606
                if (isUndo)
 
3607
                        type = !state->getBool("SCALE_TYPE");
 
3608
                else
 
3609
                        type = state->getBool("SCALE_TYPE");
 
3610
                //if restoring free scaling
 
3611
                //old offset and scale ratio must be restored
 
3612
                if (type)
 
3613
                {
 
3614
                        double oscx = state->getDouble("OLD_IMAGEXSCALE");
 
3615
                        double oscy = state->getDouble("OLD_IMAGEYSCALE");
 
3616
                        double ox = state->getDouble("OLD_IMAGEXOFFSET");
 
3617
                        double oy = state->getDouble("OLD_IMAGEYOFFSET");
 
3618
                        Selection tempSelection(this, false);
 
3619
                        tempSelection.addItem(this, true);
 
3620
                        m_Doc->itemSelection_SetImageScale(oscx, oscy, &tempSelection);
 
3621
                        m_Doc->itemSelection_SetImageOffset(ox, oy, &tempSelection);
 
3622
                }
 
3623
 
 
3624
        }
 
3625
 
 
3626
        bool ratio=AspectRatio;
 
3627
        if (state->contains("ASPECT_RATIO"))
 
3628
        {
 
3629
                if (isUndo)
 
3630
                        ratio = !state->getBool("ASPECT_RATIO");
 
3631
                else
 
3632
                        ratio = state->getBool("ASPECT_RATIO");
 
3633
        }
 
3634
 
 
3635
        setImageScalingMode(type, ratio);
 
3636
}
 
3637
 
 
3638
void PageItem::restoreImageScaleChange(SimpleState *state, bool isUndo)
 
3639
{
 
3640
        double oscx = state->getDouble("OLD_IMAGEXSCALE");
 
3641
        double oscy = state->getDouble("OLD_IMAGEYSCALE");
 
3642
        double  scx = state->getDouble("NEW_IMAGEXSCALE");
 
3643
        double  scy = state->getDouble("NEW_IMAGEYSCALE");
 
3644
        Selection tempSelection(this, false);
 
3645
        tempSelection.addItem(this, true);
 
3646
        if (!isUndo)
 
3647
                m_Doc->itemSelection_SetImageScale(scx, scy, &tempSelection);
 
3648
        else
 
3649
                m_Doc->itemSelection_SetImageScale(oscx, oscy, &tempSelection);
 
3650
}
 
3651
 
 
3652
void PageItem::restoreImageOffsetChange(SimpleState *state, bool isUndo)
 
3653
{
 
3654
        double ox = state->getDouble("OLD_IMAGEXOFFSET");
 
3655
        double oy = state->getDouble("OLD_IMAGEYOFFSET");
 
3656
        double  x = state->getDouble("NEW_IMAGEXOFFSET");
 
3657
        double  y = state->getDouble("NEW_IMAGEYOFFSET");
 
3658
        Selection tempSelection(this, false);
 
3659
        tempSelection.addItem(this, true);
 
3660
        if (!isUndo)
 
3661
                m_Doc->itemSelection_SetImageOffset(x, y, &tempSelection);
 
3662
        else
 
3663
                m_Doc->itemSelection_SetImageOffset(ox, oy, &tempSelection);
 
3664
}
 
3665
 
 
3666
void PageItem::restoreClearImage(UndoState *state, bool isUndo)
 
3667
{
 
3668
        if (!isImageFrame())
 
3669
                return;
 
3670
        if (isUndo)
 
3671
        {
 
3672
                ItemState<ScImageEffectList> *is = dynamic_cast<ItemState<ScImageEffectList>*>(state);
 
3673
                Pfile = is->get("CI_PFILE");
 
3674
                loadImage(Pfile, false);
 
3675
                effectsInUse = is->getItem();
 
3676
                setImageFlippedH(is->getBool("CI_FLIPPH"));
 
3677
                setImageFlippedV(is->getBool("CI_FLIPPV"));
 
3678
                setImageScalingMode(is->getBool("CI_SCALING"),is->getBool("CI_ASPECT"));
 
3679
                setImageXYOffset(is->getDouble("CI_XOFF"), is->getDouble("CI_YOFF"));
 
3680
                setImageXYScale(is->getDouble("CI_XSCALE"), is->getDouble("CI_YSCALE"));
 
3681
                setFillTransparency(is->getDouble("CI_FILLT"));
 
3682
                setLineTransparency(is->getDouble("CI_LINET"));
 
3683
                select();
 
3684
                m_Doc->updatePic();
 
3685
        }
 
3686
        else
 
3687
                asImageFrame()->clearContents();
 
3688
}
 
3689
 
 
3690
void PageItem::restoreLinkTextFrame(UndoState *state, bool isUndo)
 
3691
{
 
3692
        if (!isTextFrame())
 
3693
                return;
 
3694
        if (isUndo)
 
3695
        {
 
3696
                unlink();
 
3697
        }
 
3698
        else
 
3699
        {
 
3700
                ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(state);
 
3701
                asTextFrame()->link(is->getItem().second->asTextFrame());
 
3702
        }
 
3703
}
 
3704
 
 
3705
void PageItem::restoreUnlinkTextFrame(UndoState *state, bool isUndo)
 
3706
{
 
3707
        if (!isTextFrame())
 
3708
                return;
 
3709
        if (isUndo)
 
3710
        {
 
3711
                ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(state);
 
3712
                asTextFrame()->link(is->getItem().second->asTextFrame());
 
3713
        }
 
3714
        else
 
3715
        {
 
3716
                unlink();
 
3717
        }
 
3718
}
 
3719
 
 
3720
void PageItem::restoreReverseText(UndoState *state, bool /*isUndo*/)
 
3721
{
 
3722
        if (!isTextFrame())
 
3723
                return;
 
3724
        Reverse = !Reverse;
 
3725
}
 
3726
 
 
3727
void PageItem::restorePathOperation(UndoState *state, bool isUndo)
 
3728
{//PATH_OPERATION
 
3729
        ItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >*is = dynamic_cast<ItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >*>(state);
 
3730
        if (is)
 
3731
        {
 
3732
                if (isUndo)
 
3733
                {
 
3734
                        this->ClipEdited=is->getBool("PATH_OP_OLD_CLIPEDITED");
 
3735
                        this->Frame=is->getBool("PATH_OP_OLD_FRAME");
 
3736
                        this->FrameType=is->getInt("PATH_OP_OLD_FRAMETYPE");
 
3737
                        this->OldB2=is->getDouble("PATH_OP_OLD_OLDB2");
 
3738
                        this->OldH2=is->getDouble("PATH_OP_OLD_OLDH2");
 
3739
                        QPair<FPointArray, FPointArray> oldLines=is->getItem().first;
 
3740
                        this->PoLine = oldLines.first;
 
3741
                        this->ContourLine = oldLines.second;
 
3742
                }
 
3743
                else
 
3744
                {
 
3745
                        this->ClipEdited=is->getBool("PATH_OP_NEW_CLIPEDITED");
 
3746
                        this->Frame=is->getBool("PATH_OP_NEW_FRAME");
 
3747
                        this->FrameType=is->getInt("PATH_OP_NEW_FRAMETYPE");
 
3748
                        this->OldB2=is->getDouble("PATH_OP_NEW_OLDB2");
 
3749
                        this->OldH2=is->getDouble("PATH_OP_NEW_OLDH2");
 
3750
                        QPair<FPointArray, FPointArray> newLines=is->getItem().second;
 
3751
                        this->PoLine = newLines.first;
 
3752
                        this->ContourLine = newLines.second;
 
3753
                }
 
3754
                this->updateClip();
 
3755
        }
 
3756
}
 
3757
 
 
3758
void PageItem::restorePoly(SimpleState *state, bool isUndo, bool isContour)
 
3759
{
 
3760
        int mode    = state->getInt("MODE");
 
3761
        int rot     = state->getInt("ROT");
 
3762
        ScribusView* view = m_Doc->view();
 
3763
        double scaling = state->getDouble("SCALING");
 
3764
        bool editContour = m_Doc->nodeEdit.isContourLine;
 
3765
        m_Doc->nodeEdit.isContourLine = isContour;
 
3766
        select();
 
3767
        if (isUndo)
 
3768
        {
 
3769
                if (mode % 2 != 0 && mode != 0)
 
3770
                        --mode;
 
3771
                else
 
3772
                        ++mode;
 
3773
                if (mode == 2)
 
3774
                        scaling = (1.0 - (100.0 / (100.0 + scaling))) * 100.0;
 
3775
                else if (mode == 3)
 
3776
                        scaling = ((100.0 / (100.0 - scaling)) - 1.0) * 100.0;
 
3777
        }
 
3778
        view->TransformPoly(mode, rot, scaling);
 
3779
        m_Doc->nodeEdit.isContourLine = editContour;
 
3780
}
 
3781
 
 
3782
void PageItem::restoreContourLine(SimpleState *state, bool isUndo)
 
3783
{
 
3784
        ItemState<FPointArray> *is = dynamic_cast<ItemState<FPointArray>*>(state);
 
3785
        if (is)
 
3786
        {
 
3787
                if (isUndo)
 
3788
                        ContourLine = is->getItem();
 
3789
                else
 
3790
                        ContourLine = PoLine.copy();
 
3791
                ClipEdited = true;
 
3792
        }
 
3793
}
 
3794
 
 
3795
void PageItem::restoreShapeType(SimpleState *state, bool isUndo)
 
3796
{
 
3797
        // Store shape info in this form:
 
3798
        // CHANGE_SHAPE_TYPE - ID of the undo operation
 
3799
        // OLD_FRAME_TYPE - original frame type
 
3800
        // NEW_FRAME_TYPE - change of frame type
 
3801
        // binary QPair<FPointArray, FPointArray> - .first original shape, .second new shape
 
3802
        ItemState<QPair<FPointArray,FPointArray> > *is = dynamic_cast<ItemState<QPair<FPointArray,FPointArray> >*>(state);
 
3803
        if (is)
 
3804
        {
 
3805
                if (isUndo)
 
3806
                {
 
3807
                        this->FrameType = is->getInt("OLD_FRAME_TYPE");
 
3808
                        this->PoLine = is->getItem().first;
 
3809
                }
 
3810
                else
 
3811
                {
 
3812
                        this->FrameType = is->getInt("NEW_FRAME_TYPE");
 
3813
                        this->PoLine = is->getItem().second;
 
3814
                }
 
3815
                ClipEdited = true;
 
3816
        }
 
3817
}
 
3818
 
 
3819
void PageItem::restoreLayer(SimpleState *state, bool isUndo)
 
3820
{
 
3821
        ScribusView* view = m_Doc->view();
 
3822
        setLayer(isUndo ? state->getInt("OLD_LAYER") : state->getInt("NEW_LAYER"));
 
3823
        view->Deselect(true);
 
3824
        m_Doc->regionsChanged()->update(QRectF());
 
3825
}
 
3826
 
 
3827
void PageItem::restoreGetImage(UndoState *state, bool isUndo)
 
3828
{
 
3829
        ItemState<ScImageEffectList> *is = dynamic_cast<ItemState<ScImageEffectList>*>(state);
 
3830
        QString fn = is->get("OLD_IMAGE_PATH");
 
3831
        if (!isUndo)
 
3832
                fn = is->get("NEW_IMAGE_PATH");
 
3833
        if (fn.isEmpty())
 
3834
        {
 
3835
                Selection tempSelection(this, false);
 
3836
                tempSelection.addItem(this, true);
 
3837
                m_Doc->itemSelection_ClearItem(&tempSelection);
 
3838
        }
 
3839
        else
 
3840
        {
 
3841
                loadImage(fn, false);
 
3842
                if (isUndo)
 
3843
                {
 
3844
                        //restore old image settings
 
3845
                        effectsInUse = is->getItem();
 
3846
                        setImageFlippedH(is->getBool("FLIPPH"));
 
3847
                        setImageFlippedV(is->getBool("FLIPPV"));
 
3848
                        setImageScalingMode(is->getBool("SCALING"), is->getBool("ASPECT"));
 
3849
                        setImageXYOffset(is->getDouble("XOFF"), is->getDouble("YOFF"));
 
3850
                        setImageXYScale(is->getDouble("XSCALE"), is->getDouble("YSCALE"));
 
3851
                        setFillTransparency(is->getDouble("FILLT"));
 
3852
                        setLineTransparency(is->getDouble("LINET"));
 
3853
                }
 
3854
                select();
 
3855
                m_Doc->updatePic();
 
3856
        }
 
3857
}
 
3858
 
 
3859
void PageItem::restoreGroupsLastItem(SimpleState *state, bool isUndo)
 
3860
{
 
3861
        ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> > *>(state);
 
3862
        if (is)
 
3863
        {
 
3864
                if (isUndo)
 
3865
                        this->groupsLastItem = is->getItem().first;
 
3866
                else
 
3867
                        this->groupsLastItem = is->getItem().second;
 
3868
        }
 
3869
}
 
3870
 
 
3871
void PageItem::restoreShapeContour(UndoState *state, bool isUndo)
 
3872
{
 
3873
        ItemState<QPair<FPointArray,FPointArray> > *istate =
 
3874
                        dynamic_cast<ItemState<QPair<FPointArray,FPointArray> >*>(state);
 
3875
        if (istate)
 
3876
        {
 
3877
                FPointArray oldClip = istate->getItem().first;
 
3878
                FPointArray newClip = istate->getItem().second;
 
3879
                bool isContour = istate->getBool("IS_CONTOUR");
 
3880
                double oldX = istate->getDouble("OLD_X");
 
3881
                double oldY = istate->getDouble("OLD_Y");
 
3882
                double newX = istate->getDouble("NEW_X");
 
3883
                double newY = istate->getDouble("NEW_Y");
 
3884
                double mx = oldX - newX;
 
3885
                double my = oldY - newY;
 
3886
 
 
3887
                if (isUndo)
 
3888
                {
 
3889
                        if (isContour)
 
3890
                                ContourLine = oldClip;
 
3891
                        else
 
3892
                                PoLine = oldClip;
 
3893
                }
 
3894
                else
 
3895
                {
 
3896
                        mx = -mx;
 
3897
                        my = -my;
 
3898
                        if (isContour)
 
3899
                                ContourLine = newClip;
 
3900
                        else
 
3901
                                PoLine = newClip;
 
3902
                }
 
3903
                m_Doc->AdjustItemSize(this);
 
3904
                m_Doc->MoveItem(mx, my, this, false);
 
3905
                m_Doc->regionsChanged()->update(QRectF());
 
3906
        }
 
3907
 
 
3908
}
 
3909
 
 
3910
void PageItem::restoreImageEffects(UndoState *state, bool isUndo)
 
3911
{
 
3912
        ItemState<QPair<ScImageEffectList, ScImageEffectList> > *istate =
 
3913
        dynamic_cast<ItemState<QPair<ScImageEffectList,ScImageEffectList> >*>(state);
 
3914
        if (istate)
 
3915
        {
 
3916
                if (isUndo)
 
3917
                        effectsInUse = istate->getItem().first;
 
3918
                else
 
3919
                        effectsInUse = istate->getItem().second;
 
3920
 
 
3921
                select();
 
3922
                m_Doc->updatePic();
 
3923
        }
 
3924
}
 
3925
 
 
3926
void PageItem::restoreEditText(SimpleState *state, bool isUndo)
 
3927
{
 
3928
        if (!isTextFrame())
 
3929
                return;
 
3930
        itemText.deselectAll();
 
3931
        HasSel = false;
 
3932
        EditAct action = (EditAct) state->getInt("STEXT");
 
3933
        if (action == PARAMFULL || action == PARAMSEL)
 
3934
        {
 
3935
                QString buffer;
 
3936
                if (isUndo)
 
3937
                        buffer.append(state->get("STEXT_OLD"));
 
3938
                else
 
3939
                        buffer.append(state->get("STEXT_NEW"));
 
3940
                if (!buffer.isEmpty())
 
3941
                {
 
3942
                        Serializer dig(*m_Doc);
 
3943
                        dig.store<ScribusDoc>("<scribusdoc>", m_Doc);
 
3944
                        StoryText::desaxeRules("/", dig, "SCRIBUSTEXT");
 
3945
                        dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
 
3946
                        dig.parseMemory(buffer.toStdString().c_str(), buffer.length());
 
3947
                        StoryText* story = dig.result<StoryText>();
 
3948
                        if (action == PARAMFULL)
 
3949
                        {
 
3950
                                itemText.selectAll();
 
3951
                                itemText.clear();
 
3952
                                itemText.append(*story);
 
3953
                        }
 
3954
                        else if (action == PARAMSEL)
 
3955
                        {
 
3956
                                itemText.deselectAll();
 
3957
                                int SelStart = state->getInt("STEXT_SELSTART");
 
3958
                                itemText.select(SelStart,state->getInt("STEXT_SELLEN"));
 
3959
                                asTextFrame()->deleteSelectedTextFromFrame();
 
3960
                                int ItemLength = itemText.length();
 
3961
                                itemText.insert(SelStart, *story);
 
3962
                                // If we have inserted at end of text we have to restore trailing style
 
3963
                                if (ItemLength == SelStart && story->length() > 0 && story->text(-1) != SpecialChars::PARSEP)
 
3964
                                {
 
3965
                                        itemText.setStyle(-1, story->paragraphStyle(story->length()));
 
3966
                                }
 
3967
                                itemText.select(SelStart, story->length());
 
3968
                                HasSel = true;
 
3969
                        }
 
3970
                        itemText.setCursorPosition( itemText.endOfSelection() );
 
3971
                        delete story;
 
3972
                }
 
3973
                else { qDebug() << "UNDO buffer EMPTY";}
 
3974
        }
 
3975
        else if (action == REPSAX)
 
3976
        {
 
3977
                QString buffout, buffin;  //buffout is deleted, buffin is inserted
 
3978
                int pos = state->getInt("STEXT_CPOS");
 
3979
                if (isUndo)
 
3980
                {
 
3981
                        buffin.append(state->get("STEXT_OLD"));
 
3982
                        buffout.append(state->get("STEXT_NEW"));
 
3983
                }
 
3984
                else
 
3985
                {
 
3986
                        buffin.append(state->get("STEXT_NEW"));
 
3987
                        buffout.append(state->get("STEXT_OLD"));
 
3988
                }
 
3989
 
 
3990
                Serializer dig(*m_Doc);
 
3991
                dig.store<ScribusDoc>("<scribusdoc>", m_Doc);
 
3992
                StoryText::desaxeRules("/", dig, "SCRIBUSTEXT");
 
3993
                dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
 
3994
                dig.parseMemory(buffout.toStdString().c_str(), buffout.length());
 
3995
                StoryText* story = dig.result<StoryText>();
 
3996
                itemText.select(pos,story->length());
 
3997
                asTextFrame()->deleteSelectedTextFromFrame();
 
3998
 
 
3999
                Serializer dig2(*m_Doc);
 
4000
                dig2.store<ScribusDoc>("<scribusdoc>", m_Doc);
 
4001
                StoryText::desaxeRules("/", dig2, "SCRIBUSTEXT");
 
4002
                dig2.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
 
4003
                dig2.parseMemory(buffin.toStdString().c_str(), buffin.length());
 
4004
                story = dig2.result<StoryText>();
 
4005
                itemText.insert(pos,*story);
 
4006
                itemText.select(pos, story->length());
 
4007
                HasSel = true;
 
4008
                delete story;
 
4009
        }
 
4010
        else if (action == INSSAX || action == DELSAX)
 
4011
        {
 
4012
                QString str = state->get("STEXT_STR");
 
4013
                if (str.isEmpty())
 
4014
                        str = itemTextSaxed;
 
4015
                int pos = state->getInt("STEXT_CPOS");
 
4016
                Serializer dig(*m_Doc);
 
4017
                dig.store<ScribusDoc>("<scribusdoc>", m_Doc);
 
4018
                StoryText::desaxeRules("/", dig, "SCRIBUSTEXT");
 
4019
                dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
 
4020
                dig.parseMemory(str.toStdString().c_str(), str.length());
 
4021
                StoryText* story = dig.result<StoryText>();
 
4022
                if ((action == INSSAX && isUndo) || (action == DELSAX && !isUndo))
 
4023
                {
 
4024
                        //undo for INSSAX, redo for DELSAX
 
4025
                        itemText.select(pos, story->length());
 
4026
                        asTextFrame()->deleteSelectedTextFromFrame();
 
4027
                }
 
4028
                else
 
4029
                {
 
4030
                        //undo for DELSAX, redo for INSSAX
 
4031
                        itemText.insert(pos, *story);
 
4032
                }
 
4033
                delete story;
 
4034
        }
 
4035
        else if (action == INS)
 
4036
        {
 
4037
                QString str = state->get("STEXT_STR");
 
4038
                int pos = state->getInt("STEXT_CPOS");
 
4039
                if (isUndo)
 
4040
                {
 
4041
                        itemText.select(pos, str.length());
 
4042
                        asTextFrame()->deleteSelectedTextFromFrame();
 
4043
                }
 
4044
                else
 
4045
                {
 
4046
                        itemText.insertChars(pos, str, true);
 
4047
                }
 
4048
        }
 
4049
        // after Undo or Redo new actions should create new undoStates
 
4050
        asTextFrame()->lastUndoAction = NOACTION;
 
4051
 
 
4052
        m_Doc->scMW()->setTBvals(this);
 
4053
        update();
 
4054
}
 
4055
 
 
4056
QString PageItem::getItemTextSaxed(EditActPlace undoItem)
 
4057
{
 
4058
        if (!isTextFrame()) return "";
 
4059
        StoryText iT(m_Doc);
 
4060
        iT.setDefaultStyle(itemText.defaultStyle());
 
4061
        if (undoItem == FRAME)
 
4062
                iT.insert(0, itemText);
 
4063
        else
 
4064
        {
 
4065
                int StartOldSel = 0, LenOldSel = 0;
 
4066
                if (HasSel)
 
4067
                {
 
4068
                        StartOldSel = itemText.startOfSelection();
 
4069
                        LenOldSel = itemText.lengthOfSelection();
 
4070
                }
 
4071
                if (undoItem == PARAGRAPH)
 
4072
                        asTextFrame()->expandParaSelection(true);
 
4073
                else if (undoItem == CHAR || !HasSel)
 
4074
                {
 
4075
                        if (itemText.cursorPosition() >= itemText.length())
 
4076
                                return  "";
 
4077
                        itemText.select(itemText.cursorPosition(), 1);
 
4078
                }
 
4079
                //is SELECTION
 
4080
                iT.insert(0, itemText, true);
 
4081
                itemText.deselectAll();
 
4082
                if (LenOldSel > 0) //restoring old selection if undoItem was PARAPGRAPH
 
4083
                        itemText.select(StartOldSel, LenOldSel);
 
4084
        }
 
4085
        //saxing text
 
4086
        std::ostringstream xmlString;
 
4087
        SaxXML xmlStream(xmlString);
 
4088
        xmlStream.beginDoc();
 
4089
        iT.saxx(xmlStream, "SCRIBUSTEXT");
 
4090
        xmlStream.endDoc();
 
4091
        std::string xml(xmlString.str());
 
4092
        return QString(xml.c_str());
 
4093
}
 
4094
 
 
4095
QString PageItem::getItemTextSaxed(int selStart, int selLength)
 
4096
{
 
4097
        if (selStart < 0 || selLength < 0)
 
4098
                return QString();
 
4099
        
 
4100
        StoryText it(m_Doc);
 
4101
        it.setDefaultStyle(itemText.defaultStyle());
 
4102
 
 
4103
        itemText.select(selStart, selLength);
 
4104
        it.insert(0, itemText, (selLength > 0));
 
4105
 
 
4106
        //saxing text
 
4107
        std::ostringstream xmlString;
 
4108
        SaxXML xmlStream(xmlString);
 
4109
        xmlStream.beginDoc();
 
4110
        it.saxx(xmlStream, "SCRIBUSTEXT");
 
4111
        xmlStream.endDoc();
 
4112
        std::string xml(xmlString.str());
 
4113
        return QString(xml.c_str());
 
4114
}
 
4115
 
 
4116
QString PageItem::getTextSaxed(QString str)
 
4117
{
 
4118
        StoryText iT(m_Doc);
 
4119
        iT.setDefaultStyle(itemText.defaultStyle());
 
4120
        iT.insertChars(0,str,true);
 
4121
        std::ostringstream xmlString;
 
4122
        SaxXML xmlStream(xmlString);
 
4123
        xmlStream.beginDoc();
 
4124
        iT.saxx(xmlStream, "SCRIBUSTEXT");
 
4125
        xmlStream.endDoc();
 
4126
        std::string xml(xmlString.str());
 
4127
        return QString(xml.c_str());
 
4128
}
 
4129
 
 
4130
void PageItem::select()
 
4131
{
 
4132
        if (m_Doc->m_Selection->count() == 1 && m_Doc->m_Selection->itemAt()->isTextFrame())
 
4133
                m_Doc->m_Selection->itemAt()->asTextFrame()->lastUndoAction = PageItem::NOACTION;
 
4134
        m_Doc->view()->Deselect(false);
 
4135
        //CB #2969 add this true parm to addItem so we dont connectToGUI, the rest of view->SelectItem isnt needed anyway
 
4136
        m_Doc->m_Selection->addItem(this, true);
 
4137
}
 
4138
 
 
4139
ObjAttrVector* PageItem::getObjectAttributes()
 
4140
{
 
4141
        return &pageItemAttributes;
 
4142
}
 
4143
 
 
4144
QList<ObjectAttribute> PageItem::getObjectAttributes(QString attributeName) const
 
4145
{
 
4146
        QList<ObjectAttribute> attributes;
 
4147
        for(ObjAttrVector::const_iterator objAttrIt = pageItemAttributes.begin() ; objAttrIt != pageItemAttributes.end(); ++objAttrIt )
 
4148
        {
 
4149
                if (objAttrIt->name == attributeName)
 
4150
                {
 
4151
                        attributes.append(*objAttrIt);
 
4152
                }
 
4153
        }
 
4154
        return attributes;
 
4155
}
 
4156
 
 
4157
ObjectAttribute PageItem::getObjectAttribute(QString attributeName) const
 
4158
{
 
4159
        int countFound = 0;
 
4160
        ObjAttrVector::const_iterator foundIt = pageItemAttributes.begin();
 
4161
        for(ObjAttrVector::const_iterator objAttrIt = pageItemAttributes.begin(); objAttrIt != pageItemAttributes.end(); ++objAttrIt )
 
4162
        {
 
4163
                if (objAttrIt->name == attributeName)
 
4164
                {
 
4165
                        ++countFound;
 
4166
                        foundIt = objAttrIt;
 
4167
                }
 
4168
        }
 
4169
        ObjectAttribute returnAttribute;
 
4170
        if(countFound == 1)
 
4171
                returnAttribute = (*foundIt);
 
4172
        else
 
4173
                returnAttribute.name = QString::null;
 
4174
        return returnAttribute;
 
4175
}
 
4176
 
 
4177
 
 
4178
void PageItem::setObjectAttributes(ObjAttrVector* map)
 
4179
{
 
4180
        pageItemAttributes=*map;
 
4181
}
 
4182
 
 
4183
QString PageItem::generateUniqueCopyName(const QString originalName) const
 
4184
{
 
4185
        if (!m_Doc->itemNameExists(originalName))
 
4186
                return originalName;
 
4187
 
 
4188
        // Start embellishing the name until we get an acceptable unique name
 
4189
        // first we prefix `Copy of' if it's not already there
 
4190
        QString newname(originalName);
 
4191
        if (!originalName.startsWith( tr("Copy of")))
 
4192
                newname.prepend( tr("Copy of")+" ");
 
4193
 
 
4194
        // See if the name prefixed by "Copy of " is free
 
4195
        if (m_Doc->itemNameExists(newname))
 
4196
        {
 
4197
                // Search the string for (number) at the end and capture
 
4198
                // both the number and the text leading up to it sans brackets.
 
4199
                //     Copy of fred (5)
 
4200
                //     ^^^^^^^^^^^^  ^   (where ^ means captured)
 
4201
                static QRegExp rx("^(.*)\\s+\\((\\d+)\\)$");
 
4202
                int numMatches = rx.lastIndexIn(newname);
 
4203
                // Add a (number) suffix to the end of the name. We start at the
 
4204
                // old suffix's value if there was one, or at 2 if there was not.
 
4205
                int suffixnum = 2;
 
4206
                QString prefix(newname);
 
4207
                if (numMatches != -1)
 
4208
                {
 
4209
                        // Already had a suffix; use the name w/o suffix for prefix and
 
4210
                        // grab the old suffix value as a starting point.
 
4211
                        QStringList matches = rx.capturedTexts();
 
4212
                        prefix = matches[1];
 
4213
                        suffixnum = matches[2].toInt();
 
4214
                }
 
4215
                // Keep on incrementing the suffix 'till we find a free name
 
4216
                do
 
4217
                {
 
4218
                        newname = prefix + " (" + QString::number(suffixnum) + ")";
 
4219
                        suffixnum ++;
 
4220
                }
 
4221
                while (m_Doc->itemNameExists(newname));
 
4222
        }
 
4223
        // Unnecessary assert, previous code ensure condition is always true - JG
 
4224
        // assert(!m_Doc->itemNameExists(newname));
 
4225
        return newname;
 
4226
}
 
4227
 
 
4228
void PageItem::setTagged(bool tag)
 
4229
{
 
4230
        tagged=tag;
 
4231
}
 
4232
 
 
4233
void PageItem::replaceNamedResources(ResourceCollection& newNames) 
 
4234
{
 
4235
        QMap<QString,QString>::ConstIterator it;
 
4236
 
 
4237
        it = newNames.colors().find(fillColor());
 
4238
        if (it != newNames.colors().end())
 
4239
                setFillColor(*it);
 
4240
 
 
4241
        it = newNames.colors().find(lineColor());
 
4242
        if (it != newNames.colors().end())
 
4243
                setLineColor(*it);
 
4244
 
 
4245
        QList<VColorStop*> cstops = fill_gradient.colorStops();
 
4246
        for (uint cst = 0; cst < fill_gradient.Stops(); ++cst)
 
4247
        {
 
4248
                it = newNames.colors().find(cstops.at(cst)->name);
 
4249
                if (it != newNames.colors().end())
 
4250
                {
 
4251
                        if (*it != CommonStrings::None)
 
4252
                                cstops.at(cst)->name = *it;
 
4253
                }
 
4254
        }
 
4255
        if (effectsInUse.count() != 0)
 
4256
        {
 
4257
                QString col1 = CommonStrings::None;
 
4258
                QString col2 = CommonStrings::None;
 
4259
                QString col3 = CommonStrings::None;
 
4260
                QString col4 = CommonStrings::None;
 
4261
                for (int a = 0; a < effectsInUse.count(); ++a)
 
4262
                {
 
4263
                        QString tmpstr = effectsInUse.at(a).effectParameters;
 
4264
                        QString tmpstr2 = "";
 
4265
                        ScTextStream fp(&tmpstr, QIODevice::ReadOnly);
 
4266
                        switch (effectsInUse.at(a).effectCode)
 
4267
                        {
 
4268
                                case ScImage::EF_QUADTONE:
 
4269
                                        col1 = fp.readLine();
 
4270
                                        col2 = fp.readLine();
 
4271
                                        col3 = fp.readLine();
 
4272
                                        col4 = fp.readLine();
 
4273
                                        it = newNames.colors().find(col1);
 
4274
                                        if (it != newNames.colors().end())
 
4275
                                        {
 
4276
                                                if (*it != CommonStrings::None)
 
4277
                                                        tmpstr2 += *it + "\n";
 
4278
                                                else
 
4279
                                                        tmpstr2 += col1 + "\n";
 
4280
                                        }
 
4281
                                        else
 
4282
                                                tmpstr2 += col1 + "\n";
 
4283
                                        it = newNames.colors().find(col2);
 
4284
                                        if (it != newNames.colors().end())
 
4285
                                        {
 
4286
                                                if (*it != CommonStrings::None)
 
4287
                                                        tmpstr2 += *it + "\n";
 
4288
                                                else
 
4289
                                                        tmpstr2 += col2 + "\n";
 
4290
                                        }
 
4291
                                        else
 
4292
                                                tmpstr2 += col2 + "\n";
 
4293
                                        it = newNames.colors().find(col3);
 
4294
                                        if (it != newNames.colors().end())
 
4295
                                        {
 
4296
                                                if (*it != CommonStrings::None)
 
4297
                                                        tmpstr2 += *it + "\n";
 
4298
                                                else
 
4299
                                                        tmpstr2 += col3 + "\n";
 
4300
                                        }
 
4301
                                        else
 
4302
                                                tmpstr2 += col3 + "\n";
 
4303
                                        it = newNames.colors().find(col4);
 
4304
                                        if (it != newNames.colors().end())
 
4305
                                        {
 
4306
                                                if (*it != CommonStrings::None)
 
4307
                                                        tmpstr2 += *it + "\n";
 
4308
                                                else
 
4309
                                                        tmpstr2 += col4 + "\n";
 
4310
                                        }
 
4311
                                        else
 
4312
                                                tmpstr2 += col4 + "\n";
 
4313
                                        tmpstr2 += fp.readAll();
 
4314
                                        break;
 
4315
                                case ScImage::EF_TRITONE:
 
4316
                                        col1 = fp.readLine();
 
4317
                                        col2 = fp.readLine();
 
4318
                                        col3 = fp.readLine();
 
4319
                                        it = newNames.colors().find(col1);
 
4320
                                        if (it != newNames.colors().end())
 
4321
                                        {
 
4322
                                                if (*it != CommonStrings::None)
 
4323
                                                        tmpstr2 += *it + "\n";
 
4324
                                                else
 
4325
                                                        tmpstr2 += col1 + "\n";
 
4326
                                        }
 
4327
                                        else
 
4328
                                                tmpstr2 += col1 + "\n";
 
4329
                                        it = newNames.colors().find(col2);
 
4330
                                        if (it != newNames.colors().end())
 
4331
                                        {
 
4332
                                                if (*it != CommonStrings::None)
 
4333
                                                        tmpstr2 += *it + "\n";
 
4334
                                                else
 
4335
                                                        tmpstr2 += col2 + "\n";
 
4336
                                        }
 
4337
                                        else
 
4338
                                                tmpstr2 += col2 + "\n";
 
4339
                                        it = newNames.colors().find(col3);
 
4340
                                        if (it != newNames.colors().end())
 
4341
                                        {
 
4342
                                                if (*it != CommonStrings::None)
 
4343
                                                        tmpstr2 += *it + "\n";
 
4344
                                                else
 
4345
                                                        tmpstr2 += col3 + "\n";
 
4346
                                        }
 
4347
                                        else
 
4348
                                                tmpstr2 += col3 + "\n";
 
4349
                                        tmpstr2 += fp.readAll();
 
4350
                                        break;
 
4351
                                case ScImage::EF_DUOTONE:
 
4352
                                        col1 = fp.readLine();
 
4353
                                        col2 = fp.readLine();
 
4354
                                        it = newNames.colors().find(col1);
 
4355
                                        if (it != newNames.colors().end())
 
4356
                                        {
 
4357
                                                if (*it != CommonStrings::None)
 
4358
                                                        tmpstr2 += *it + "\n";
 
4359
                                                else
 
4360
                                                        tmpstr2 += col1 + "\n";
 
4361
                                        }
 
4362
                                        else
 
4363
                                                tmpstr2 += col1 + "\n";
 
4364
                                        it = newNames.colors().find(col2);
 
4365
                                        if (it != newNames.colors().end())
 
4366
                                        {
 
4367
                                                if (*it != CommonStrings::None)
 
4368
                                                        tmpstr2 += *it + "\n";
 
4369
                                                else
 
4370
                                                        tmpstr2 += col2 + "\n";
 
4371
                                        }
 
4372
                                        else
 
4373
                                                tmpstr2 += col2 + "\n";
 
4374
                                        tmpstr2 += fp.readAll();
 
4375
                                        break;
 
4376
                                case ScImage::EF_COLORIZE:
 
4377
                                        col1 = fp.readLine();
 
4378
                                        it = newNames.colors().find(col1);
 
4379
                                        if (it != newNames.colors().end())
 
4380
                                        {
 
4381
                                                if (*it != CommonStrings::None)
 
4382
                                                        tmpstr2 += *it + "\n" + fp.readAll();
 
4383
                                                else
 
4384
                                                        tmpstr2 += col1 + "\n" + fp.readAll();
 
4385
                                        }
 
4386
                                        else
 
4387
                                                tmpstr2 += col1 + "\n" + fp.readAll();
 
4388
                                        break;
 
4389
                                default:
 
4390
                                        tmpstr2 = tmpstr;
 
4391
                                        break;
 
4392
                        }
 
4393
                        effectsInUse[a].effectParameters = tmpstr2;
 
4394
                }
 
4395
        }
 
4396
        
 
4397
        it = newNames.patterns().find(pattern());
 
4398
        if (it != newNames.patterns().end())
 
4399
                setPattern(*it);
 
4400
 
 
4401
        it = newNames.lineStyles().find(customLineStyle());
 
4402
        if (it != newNames.lineStyles().end())
 
4403
                setCustomLineStyle(*it);
 
4404
 
 
4405
        if (prevInChain() == NULL)
 
4406
                itemText.replaceNamedResources(newNames);
 
4407
}
 
4408
 
 
4409
 
 
4410
void PageItem::getNamedResources(ResourceCollection& lists) const
 
4411
{
 
4412
        lists.collectColor(lineColor());
 
4413
        if (GrType == 0)
 
4414
                lists.collectColor(fillColor());
 
4415
        else if (GrType < 8)
 
4416
        {
 
4417
                QList<VColorStop*> cstops = fill_gradient.colorStops();
 
4418
                for (uint cst = 0; cst < fill_gradient.Stops(); ++cst)
 
4419
                {
 
4420
                        lists.collectColor(cstops.at(cst)->name);
 
4421
                }
 
4422
        }
 
4423
        if (effectsInUse.count() != 0)
 
4424
        {
 
4425
                for (int a = 0; a < effectsInUse.count(); ++a)
 
4426
                {
 
4427
                        QString tmpstr = effectsInUse.at(a).effectParameters;
 
4428
                        ScTextStream fp(&tmpstr, QIODevice::ReadOnly);
 
4429
                        switch (effectsInUse.at(a).effectCode)
 
4430
                        {
 
4431
                                case ScImage::EF_QUADTONE:
 
4432
                                        lists.collectColor(fp.readLine());
 
4433
                                case ScImage::EF_TRITONE:
 
4434
                                        lists.collectColor(fp.readLine());
 
4435
                                case ScImage::EF_DUOTONE:
 
4436
                                        lists.collectColor(fp.readLine());
 
4437
                                case ScImage::EF_COLORIZE:
 
4438
                                        lists.collectColor(fp.readLine());
 
4439
                                        break;
 
4440
                                default:
 
4441
                                        break;
 
4442
                        }
 
4443
                }
 
4444
        }
 
4445
        lists.collectPattern(pattern());
 
4446
        lists.collectLineStyle(customLineStyle());
 
4447
        if (prevInChain() == NULL)
 
4448
                itemText.getNamedResources(lists);
 
4449
}
 
4450
 
 
4451
void PageItem::copyToCopyPasteBuffer(struct CopyPasteBuffer *Buffer)
 
4452
{
 
4453
        Buffer->PType = realItemType();
 
4454
        Buffer->Xpos = Xpos;
 
4455
        Buffer->Ypos = Ypos;
 
4456
        Buffer->Width = Width;
 
4457
        Buffer->Height = Height;
 
4458
        Buffer->RadRect = RadRect;
 
4459
        Buffer->FrameType = FrameType;
 
4460
        Buffer->ClipEdited = ClipEdited;
 
4461
        Buffer->Pwidth = m_lineWidth;
 
4462
        Buffer->Pcolor = fillColor();
 
4463
        Buffer->Pcolor2 = lineColor();
 
4464
        Buffer->Shade = fillShade();
 
4465
        Buffer->Shade2 = lineShade();
 
4466
        Buffer->FillRule = fillRule;
 
4467
        Buffer->GrColor = "";
 
4468
        Buffer->GrColor2 = "";
 
4469
        Buffer->GrShade = 100;
 
4470
        Buffer->GrShade2 = 100;
 
4471
        Buffer->fill_gradient = fill_gradient;
 
4472
        Buffer->GrType = GrType;
 
4473
        Buffer->GrStartX = GrStartX;
 
4474
        Buffer->GrStartY = GrStartY;
 
4475
        Buffer->GrEndX = GrEndX;
 
4476
        Buffer->GrEndY = GrEndY;
 
4477
        Buffer->Rot = Rot;
 
4478
        Buffer->PLineArt = PLineArt;
 
4479
        Buffer->PLineEnd = PLineEnd;
 
4480
        Buffer->PLineJoin = PLineJoin;
 
4481
        Buffer->LocalScX = LocalScX;
 
4482
        Buffer->LocalScY = LocalScY;
 
4483
        Buffer->LocalX = LocalX;
 
4484
        Buffer->LocalY = LocalY;
 
4485
        Buffer->PicArt = PicArt;
 
4486
        Buffer->flippedH = imageFlippedH();
 
4487
        Buffer->flippedV = imageFlippedV();
 
4488
/*      Buffer->BBoxX = BBoxX;
 
4489
        Buffer->BBoxH = BBoxH; */
 
4490
        Buffer->isPrintable = printEnabled();
 
4491
        Buffer->isBookmark = isBookmark;
 
4492
//      Buffer->BMnr = BMnr;
 
4493
        Buffer->m_isAnnotation = m_isAnnotation;
 
4494
        Buffer->m_annotation = m_annotation;
 
4495
        Buffer->Extra = Extra;
 
4496
        Buffer->TExtra = TExtra;
 
4497
        Buffer->BExtra = BExtra;
 
4498
        Buffer->RExtra = RExtra;
 
4499
        Buffer->firstLineOffsetP = firstLineOffsetP;
 
4500
        Buffer->Pfile = Pfile;
 
4501
        Buffer->Pfile2 = Pfile2;
 
4502
        Buffer->Pfile3 = Pfile3;
 
4503
        QString Text = "";
 
4504
        uint itemTextCount=itemText.length();
 
4505
        if (itemTextCount != 0)
 
4506
        {
 
4507
                for (uint a=0; a<itemTextCount; ++a)
 
4508
                {
 
4509
                        if( (itemText.text(a) == '\n') || (itemText.text(a) == '\r'))
 
4510
                                Text += QString(QChar(5))+"\t";
 
4511
                        else if(itemText.text(a) == '\t')
 
4512
                                Text += QString(QChar(4))+"\t";
 
4513
                        else
 
4514
                                Text += itemText.text(a,1)+"\t";
 
4515
                        Text += itemText.charStyle(a).font().scName()+"\t";
 
4516
                        Text += QString::number(itemText.charStyle(a).fontSize() / 10.0)+"\t";
 
4517
                        Text += itemText.charStyle(a).fillColor()+"\t";
 
4518
                        Text += QString::number(itemText.charStyle(a).tracking())+"\t";
 
4519
                        Text += QString::number(itemText.charStyle(a).fillShade())+'\t';
 
4520
                        Text += QString::number(itemText.charStyle(a).effects())+'\t';
 
4521
                        Text += QString::number(findParagraphStyle(m_Doc, itemText.paragraphStyle(a)))+'\t';
 
4522
                        Text += itemText.charStyle(a).strokeColor()+"\t";
 
4523
                        Text += QString::number(itemText.charStyle(a).strokeShade())+'\t';
 
4524
                        Text += QString::number(itemText.charStyle(a).scaleH())+'\t';
 
4525
                        Text += QString::number(itemText.charStyle(a).scaleV())+'\t';
 
4526
                        Text += QString::number(itemText.charStyle(a).baselineOffset())+'\t';
 
4527
                        Text += QString::number(itemText.charStyle(a).shadowXOffset())+'\t';
 
4528
                        Text += QString::number(itemText.charStyle(a).shadowYOffset())+'\t';
 
4529
                        Text += QString::number(itemText.charStyle(a).outlineWidth())+'\t';
 
4530
                        Text += QString::number(itemText.charStyle(a).underlineOffset())+'\t';
 
4531
                        Text += QString::number(itemText.charStyle(a).underlineWidth())+'\t';
 
4532
                        Text += QString::number(itemText.charStyle(a).strikethruOffset())+'\t';
 
4533
                        Text += QString::number(itemText.charStyle(a).strikethruWidth())+'\n';
 
4534
                }
 
4535
        }
 
4536
        if (asLatexFrame()) {
 
4537
                Buffer->itemText = asLatexFrame()->formula();
 
4538
        } else {
 
4539
                Buffer->itemText = Text;
 
4540
        }
 
4541
        Buffer->Clip = Clip;
 
4542
        Buffer->PoLine = PoLine.copy();
 
4543
        Buffer->ContourLine = ContourLine.copy();
 
4544
        //Buffer->UseContour = textFlowUsesContourLine();
 
4545
        Buffer->DashValues = DashValues;
 
4546
        Buffer->DashOffset = DashOffset;
 
4547
        Buffer->PoShow = PoShow;
 
4548
        Buffer->BaseOffs = BaseOffs;
 
4549
        Buffer->textPathFlipped = textPathFlipped;
 
4550
        Buffer->textPathType = textPathType;
 
4551
        Buffer->TextflowMode = textFlowMode();
 
4552
        Buffer->Groups = Groups;
 
4553
        Buffer->IProfile = IProfile;
 
4554
        Buffer->IRender = IRender;
 
4555
        Buffer->UseEmbedded = UseEmbedded;
 
4556
        Buffer->EmProfile = EmProfile;
 
4557
        Buffer->LayerNr = LayerNr;
 
4558
        Buffer->ScaleType = ScaleType;
 
4559
        Buffer->AspectRatio = AspectRatio;
 
4560
        Buffer->Locked = locked();
 
4561
        Buffer->LockRes = sizeLocked();
 
4562
        Buffer->Transparency = fillTransparency();
 
4563
        Buffer->TranspStroke = lineTransparency();
 
4564
        Buffer->TransBlend = fillBlendmode();
 
4565
        Buffer->TransBlendS = lineBlendmode();
 
4566
        Buffer->Reverse = Reverse;
 
4567
        Buffer->NamedLStyle = NamedLStyle;
 
4568
        Buffer->Cols = Cols;
 
4569
        Buffer->ColGap = ColGap;
 
4570
        Buffer->isTableItem = isTableItem;
 
4571
        Buffer->TopLine = TopLine;
 
4572
        Buffer->LeftLine = LeftLine;
 
4573
        Buffer->RightLine = RightLine;
 
4574
        Buffer->BottomLine = BottomLine;
 
4575
        if (isTableItem)
 
4576
        {
 
4577
                if (TopLink != 0)
 
4578
                        Buffer->TopLinkID = TopLink->ItemNr;
 
4579
                else
 
4580
                        Buffer->TopLinkID = -1;
 
4581
                if (LeftLink != 0)
 
4582
                        Buffer->LeftLinkID = LeftLink->ItemNr;
 
4583
                else
 
4584
                        Buffer->LeftLinkID = -1;
 
4585
                if (RightLink != 0)
 
4586
                        Buffer->RightLinkID = RightLink->ItemNr;
 
4587
                else
 
4588
                        Buffer->RightLinkID = -1;
 
4589
                if (BottomLink != 0)
 
4590
                        Buffer->BottomLinkID = BottomLink->ItemNr;
 
4591
                else
 
4592
                        Buffer->BottomLinkID = -1;
 
4593
        }
 
4594
        Buffer->startArrowIndex = m_startArrowIndex;
 
4595
        Buffer->endArrowIndex = m_endArrowIndex;
 
4596
}
 
4597
 
 
4598
 
 
4599
//Moved from View
 
4600
void PageItem::SetFrameShape(int count, double *vals)
 
4601
{
 
4602
        PoLine.resize(0);
 
4603
        for (int a = 0; a < count-3; a += 4)
 
4604
        {
 
4605
                if (vals[a] < 0)
 
4606
                {
 
4607
                        PoLine.setMarker();
 
4608
                        continue;
 
4609
                }
 
4610
                double x1 = Width * vals[a] / 100.0;
 
4611
                double y1 = Height * vals[a+1] / 100.0;
 
4612
                double x2 = Width * vals[a+2] / 100.0;
 
4613
                double y2 = Height * vals[a+3] / 100.0;
 
4614
                PoLine.addPoint(x1, y1);
 
4615
                PoLine.addPoint(x2, y2);
 
4616
        }
 
4617
        Clip = FlattenPath(PoLine, Segments);
 
4618
        ClipEdited = true;
 
4619
}
 
4620
 
 
4621
void PageItem::SetRectFrame()
 
4622
{
 
4623
        static double rect[] = {  0.0,   0.0,   0.0,   0.0,
 
4624
                                                        100.0,   0.0, 100.0,   0.0,
 
4625
                                                        100.0,   0.0, 100.0,   0.0,
 
4626
                                                        100.0, 100.0, 100.0, 100.0,
 
4627
                                                        100.0, 100.0, 100.0, 100.0,
 
4628
                                                          0.0, 100.0,   0.0, 100.0,
 
4629
                                                          0.0, 100.0,   0.0, 100.0,
 
4630
                                                          0.0,   0.0,   0.0,   0.0};
 
4631
        SetFrameShape(32, rect);
 
4632
        ClipEdited = false;
 
4633
        FrameType = 0;
 
4634
}
 
4635
 
 
4636
void PageItem::SetOvalFrame()
 
4637
{
 
4638
        static double rect[] = {   100.0,  50.0, 100.0,       77.615235,
 
4639
                                                                50.0, 100.0,  77.615235, 100.0,
 
4640
                                                                50.0, 100.0,  22.385765, 100.0,
 
4641
                                                                 0.0,  50.0,   0.0,       77.615235,
 
4642
                                                                 0.0,  50.0,   0.0,       22.385765,
 
4643
                                                                50.0,   0.0,  22.385765,   0.0,
 
4644
                                                                50.0,   0.0,  77.615235,   0.0,
 
4645
                                                           100.0,  50.0, 100.0,       22.385765};
 
4646
        SetFrameShape(32, rect);
 
4647
        FrameType = 1;
 
4648
        ClipEdited = false;
 
4649
}
 
4650
 
 
4651
void PageItem::SetFrameRound()
 
4652
{
 
4653
        setCornerRadius(qMin(RadRect, qMin(Width,Height)/2));
 
4654
        PoLine.resize(0);
 
4655
        double rr = fabs(RadRect);
 
4656
        double bezierFactor=0.552284749; //Bezier Control Point Factor: 8/3*(sin(45)-0.5)
 
4657
        double rrxBezierFactor=rr*bezierFactor;
 
4658
        double Width_rr=Width-rr;
 
4659
        double Height_rr=Height-rr;
 
4660
        if (RadRect > 0)
 
4661
        {
 
4662
                PoLine.addQuadPoint(rr, 0, rr, 0, Width_rr, 0, Width_rr, 0);
 
4663
                PoLine.addQuadPoint(Width_rr, 0, Width_rr+rrxBezierFactor, 0, Width, rr, Width, rr-rrxBezierFactor);
 
4664
                PoLine.addQuadPoint(Width, rr, Width, rr, Width, Height_rr, Width, Height_rr);
 
4665
                PoLine.addQuadPoint(Width, Height_rr, Width, Height_rr+rrxBezierFactor, Width_rr, Height, Width_rr+rrxBezierFactor, Height);
 
4666
                PoLine.addQuadPoint(Width_rr, Height, Width_rr, Height, rr, Height, rr, Height);
 
4667
                PoLine.addQuadPoint(rr, Height, rr-rrxBezierFactor, Height, 0, Height_rr, 0, Height_rr+rrxBezierFactor);
 
4668
                PoLine.addQuadPoint(0, Height_rr, 0, Height_rr, 0, rr, 0, rr);
 
4669
                PoLine.addQuadPoint(0, rr, 0, rr-rrxBezierFactor, rr, 0, rr-rrxBezierFactor, 0);
 
4670
        }
 
4671
        else
 
4672
        {
 
4673
                PoLine.addQuadPoint(rr, 0, rr, 0, Width_rr, 0, Width_rr, 0);
 
4674
                PoLine.addQuadPoint(Width_rr, 0, Width_rr, rrxBezierFactor, Width, rr, Width-rrxBezierFactor, rr);
 
4675
                PoLine.addQuadPoint(Width, rr, Width, rr, Width, Height_rr, Width, Height_rr);
 
4676
                PoLine.addQuadPoint(Width, Height_rr, Width-rrxBezierFactor, Height_rr, Width_rr, Height, Width_rr, Height-rrxBezierFactor);
 
4677
                PoLine.addQuadPoint(Width_rr, Height, Width_rr, Height, rr, Height, rr, Height);
 
4678
                PoLine.addQuadPoint(rr, Height, rr, Height-rrxBezierFactor, 0, Height_rr, rrxBezierFactor, Height_rr);
 
4679
                PoLine.addQuadPoint(0, Height_rr, 0, Height_rr, 0, rr, 0, rr);
 
4680
                PoLine.addQuadPoint(0, rr, rrxBezierFactor, rr, rr, 0, rr, rr*bezierFactor);
 
4681
        }
 
4682
        Clip = FlattenPath(PoLine, Segments);
 
4683
        ClipEdited = false;
 
4684
        FrameType = 2;
 
4685
}
 
4686
 
 
4687
 
 
4688
 
 
4689
void PageItem::getTransform(QMatrix& mat) const
 
4690
{
 
4691
        mat.translate(Xpos, Ypos);
 
4692
        mat.rotate(Rot);
 
4693
}
 
4694
 
 
4695
QMatrix PageItem::getTransform() const
 
4696
{
 
4697
        QMatrix result;
 
4698
        getTransform(result);
 
4699
        return result;
 
4700
}
 
4701
 
 
4702
QRectF PageItem::getBoundingRect() const
 
4703
{
 
4704
        double x,y,x2,y2;
 
4705
        getBoundingRect(&x, &y, &x2, &y2);
 
4706
        return QRectF(x,y,x2-x,y2-y);
 
4707
}
 
4708
 
 
4709
QRectF PageItem::getCurrentBoundingRect(double moreSpace) const
 
4710
{
 
4711
        double x = BoundingX - moreSpace / 2.0;
 
4712
        double y = BoundingY - moreSpace / 2.0;
 
4713
        double w = BoundingW + moreSpace;
 
4714
        double h = BoundingH + moreSpace;
 
4715
        QRectF ret = QRectF(x, y, w, h);
 
4716
        return ret;
 
4717
}
 
4718
 
 
4719
QRectF PageItem::getVisualBoundingRect() const
 
4720
{
 
4721
        double x,y,x2,y2;
 
4722
        getVisualBoundingRect(&x, &y, &x2, &y2);
 
4723
        return QRectF(x,y,x2-x,y2-y);
 
4724
}
 
4725
 
 
4726
void PageItem::getBoundingRect(double *x1, double *y1, double *x2, double *y2) const
 
4727
{
 
4728
        double minx =  std::numeric_limits<double>::max();
 
4729
        double miny =  std::numeric_limits<double>::max();
 
4730
        double maxx = -std::numeric_limits<double>::max();
 
4731
        double maxy = -std::numeric_limits<double>::max();
 
4732
        if (Rot != 0)
 
4733
        {
 
4734
                FPointArray pb;
 
4735
                pb.resize(0);
 
4736
                pb.addPoint(FPoint(Xpos, Ypos));
 
4737
                pb.addPoint(FPoint(Width,    0.0, Xpos, Ypos, Rot, 1.0, 1.0));
 
4738
                pb.addPoint(FPoint(Width, Height, Xpos, Ypos, Rot, 1.0, 1.0));
 
4739
                pb.addPoint(FPoint(  0.0, Height, Xpos, Ypos, Rot, 1.0, 1.0));
 
4740
                for (uint pc = 0; pc < 4; ++pc)
 
4741
                {
 
4742
                        minx = qMin(minx, pb.point(pc).x());
 
4743
                        miny = qMin(miny, pb.point(pc).y());
 
4744
                        maxx = qMax(maxx, pb.point(pc).x());
 
4745
                        maxy = qMax(maxy, pb.point(pc).y());
 
4746
                }
 
4747
                *x1 = minx;
 
4748
                *y1 = miny;
 
4749
                *x2 = maxx;
 
4750
                *y2 = maxy;
 
4751
        }
 
4752
        else
 
4753
        {
 
4754
                *x1 = Xpos;
 
4755
                *y1 = Ypos;
 
4756
                *x2 = Xpos + qMax(Width, m_lineWidth);
 
4757
                *y2 = Ypos + qMax(Height, m_lineWidth);
 
4758
        }
 
4759
        QRectF totalRect = QRectF(QPointF(*x1, *y1), QPointF(*x2, *y2));
 
4760
        if (m_startArrowIndex != 0)
 
4761
        {
 
4762
                QMatrix arrowTrans;
 
4763
                FPointArray arrow = m_Doc->arrowStyles.at(m_startArrowIndex-1).points.copy();
 
4764
                arrowTrans.translate(Xpos, Ypos);
 
4765
                arrowTrans.rotate(Rot);
 
4766
                if (itemType() == Line)
 
4767
                {
 
4768
                        arrowTrans.translate(0, 0);
 
4769
                        if (NamedLStyle.isEmpty())
 
4770
                        {
 
4771
                                if (m_lineWidth != 0.0)
 
4772
                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
4773
                        }
 
4774
                        else
 
4775
                        {
 
4776
                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4777
                                if (ml[ml.size()-1].Width != 0.0)
 
4778
                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
4779
                        }
 
4780
                        arrowTrans.scale(-1,1);
 
4781
                        arrow.map(arrowTrans);
 
4782
                }
 
4783
                else
 
4784
                {
 
4785
                        FPoint Start = PoLine.point(0);
 
4786
                        for (uint xx = 1; xx < PoLine.size(); xx += 2)
 
4787
                        {
 
4788
                                FPoint Vector = PoLine.point(xx);
 
4789
                                if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
 
4790
                                {
 
4791
                                        arrowTrans.translate(Start.x(), Start.y());
 
4792
                                        arrowTrans.rotate(atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI));
 
4793
                                        if (NamedLStyle.isEmpty())
 
4794
                                        {
 
4795
                                                if (m_lineWidth != 0.0)
 
4796
                                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
4797
                                        }
 
4798
                                        else
 
4799
                                        {
 
4800
                                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4801
                                                if (ml[ml.size()-1].Width != 0.0)
 
4802
                                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
4803
                                        }
 
4804
                                        arrow.map(arrowTrans);
 
4805
                                        break;
 
4806
                                }
 
4807
                        }
 
4808
                }
 
4809
                FPoint minAr = getMinClipF(&arrow);
 
4810
                FPoint maxAr = getMaxClipF(&arrow);
 
4811
                totalRect = totalRect.united(QRectF(QPointF(minAr.x(), minAr.y()), QPointF(maxAr.x(), maxAr.y())));
 
4812
        }
 
4813
        if (m_endArrowIndex != 0)
 
4814
        {
 
4815
                QMatrix arrowTrans;
 
4816
                FPointArray arrow = m_Doc->arrowStyles.at(m_endArrowIndex-1).points.copy();
 
4817
                arrowTrans.translate(Xpos, Ypos);
 
4818
                arrowTrans.rotate(Rot);
 
4819
                if (itemType() == Line)
 
4820
                {
 
4821
                        arrowTrans.translate(Width, 0);
 
4822
                        if (NamedLStyle.isEmpty())
 
4823
                        {
 
4824
                                if (m_lineWidth != 0.0)
 
4825
                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
4826
                        }
 
4827
                        else
 
4828
                        {
 
4829
                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4830
                                if (ml[ml.size()-1].Width != 0.0)
 
4831
                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
4832
                        }
 
4833
                        arrow.map(arrowTrans);
 
4834
                }
 
4835
                else
 
4836
                {
 
4837
                        FPoint End = PoLine.point(PoLine.size()-2);
 
4838
                        for (uint xx = PoLine.size()-1; xx > 0; xx -= 2)
 
4839
                        {
 
4840
                                FPoint Vector = PoLine.point(xx);
 
4841
                                if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
 
4842
                                {
 
4843
                                        arrowTrans.translate(End.x(), End.y());
 
4844
                                        arrowTrans.rotate(atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI));
 
4845
                                        if (NamedLStyle.isEmpty())
 
4846
                                        {
 
4847
                                                if (m_lineWidth != 0.0)
 
4848
                                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
4849
                                        }
 
4850
                                        else
 
4851
                                        {
 
4852
                                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4853
                                                if (ml[ml.size()-1].Width != 0.0)
 
4854
                                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
4855
                                        }
 
4856
                                        arrow.map(arrowTrans);
 
4857
                                        break;
 
4858
                                }
 
4859
                        }
 
4860
                }
 
4861
                FPoint minAr = getMinClipF(&arrow);
 
4862
                FPoint maxAr = getMaxClipF(&arrow);
 
4863
                totalRect = totalRect.united(QRectF(QPointF(minAr.x(), minAr.y()), QPointF(maxAr.x(), maxAr.y())));
 
4864
        }
 
4865
 
 
4866
        qreal rx1, ry1, rx2, ry2;
 
4867
        totalRect.getCoords(&rx1, &ry1, &rx2, &ry2);
 
4868
        *x1 = rx1; *y1 = ry1;
 
4869
        *x2 = rx2; *y2 = ry2;
 
4870
}
 
4871
 
 
4872
void PageItem::getVisualBoundingRect(double * x1, double * y1, double * x2, double * y2) const
 
4873
{
 
4874
        double minx =  std::numeric_limits<double>::max();
 
4875
        double miny =  std::numeric_limits<double>::max();
 
4876
        double maxx = -std::numeric_limits<double>::max();
 
4877
        double maxy = -std::numeric_limits<double>::max();
 
4878
        double extraSpace = 0.0;
 
4879
        if (NamedLStyle.isEmpty())
 
4880
        {
 
4881
                if (lineColor() != CommonStrings::None)
 
4882
                {
 
4883
                        if ((itemType() == Line) && (PLineEnd == Qt::FlatCap))
 
4884
                                extraSpace = 0.0;
 
4885
                        else
 
4886
                                extraSpace = m_lineWidth / 2.0;
 
4887
                }
 
4888
        }
 
4889
        else
 
4890
        {
 
4891
                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4892
                struct SingleLine& sl = ml[ml.size()-1];
 
4893
                if ((sl.Color != CommonStrings::None) && (sl.Width != 0))
 
4894
                        extraSpace = sl.Width / 2.0;
 
4895
        }
 
4896
        if (Rot != 0)
 
4897
        {
 
4898
                FPointArray pb;
 
4899
                pb.resize(0);
 
4900
                pb.addPoint(FPoint(-extraSpace,                 -extraSpace,                    xPos(), yPos(), Rot, 1.0, 1.0));
 
4901
                pb.addPoint(FPoint(visualWidth()-extraSpace,    -extraSpace,                    xPos(), yPos(), Rot, 1.0, 1.0));
 
4902
                pb.addPoint(FPoint(visualWidth()-extraSpace,    visualHeight()-extraSpace,      xPos(), yPos(), Rot, 1.0, 1.0));
 
4903
                pb.addPoint(FPoint(-extraSpace,                 visualHeight()-extraSpace,      xPos(), yPos(), Rot, 1.0, 1.0));
 
4904
                for (uint pc = 0; pc < 4; ++pc)
 
4905
                {
 
4906
                        minx = qMin(minx, pb.point(pc).x());
 
4907
                        miny = qMin(miny, pb.point(pc).y());
 
4908
                        maxx = qMax(maxx, pb.point(pc).x());
 
4909
                        maxy = qMax(maxy, pb.point(pc).y());
 
4910
                }
 
4911
                *x1 = minx;
 
4912
                *y1 = miny;
 
4913
                *x2 = maxx;
 
4914
                *y2 = maxy;
 
4915
        }
 
4916
        else
 
4917
        {
 
4918
                *x1 = visualXPos();
 
4919
                *y1 = visualYPos();
 
4920
                *x2 = *x1 + qMax(visualWidth(), extraSpace);
 
4921
                *y2 = *y1 + qMax(visualHeight(), extraSpace);
 
4922
        }
 
4923
        QRectF totalRect = QRectF(QPointF(*x1, *y1), QPointF(*x2, *y2));
 
4924
        if (m_startArrowIndex != 0)
 
4925
        {
 
4926
                QMatrix arrowTrans;
 
4927
                FPointArray arrow = m_Doc->arrowStyles.at(m_startArrowIndex-1).points.copy();
 
4928
                arrowTrans.translate(Xpos, Ypos);
 
4929
                arrowTrans.rotate(Rot);
 
4930
                if (itemType() == Line)
 
4931
                {
 
4932
                        arrowTrans.translate(0, 0);
 
4933
                        if (NamedLStyle.isEmpty())
 
4934
                        {
 
4935
                                if (m_lineWidth != 0.0)
 
4936
                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
4937
                        }
 
4938
                        else
 
4939
                        {
 
4940
                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4941
                                if (ml[ml.size()-1].Width != 0.0)
 
4942
                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
4943
                        }
 
4944
                        arrowTrans.scale(-1,1);
 
4945
                        arrow.map(arrowTrans);
 
4946
                }
 
4947
                else
 
4948
                {
 
4949
                        FPoint Start = PoLine.point(0);
 
4950
                        for (uint xx = 1; xx < PoLine.size(); xx += 2)
 
4951
                        {
 
4952
                                FPoint Vector = PoLine.point(xx);
 
4953
                                if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
 
4954
                                {
 
4955
                                        arrowTrans.translate(Start.x(), Start.y());
 
4956
                                        arrowTrans.rotate(atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI));
 
4957
                                        if (NamedLStyle.isEmpty())
 
4958
                                        {
 
4959
                                                if (m_lineWidth != 0.0)
 
4960
                                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
4961
                                        }
 
4962
                                        else
 
4963
                                        {
 
4964
                                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4965
                                                if (ml[ml.size()-1].Width != 0.0)
 
4966
                                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
4967
                                        }
 
4968
                                        arrow.map(arrowTrans);
 
4969
                                        break;
 
4970
                                }
 
4971
                        }
 
4972
                }
 
4973
                FPoint minAr = getMinClipF(&arrow);
 
4974
                FPoint maxAr = getMaxClipF(&arrow);
 
4975
                totalRect = totalRect.united(QRectF(QPointF(minAr.x(), minAr.y()), QPointF(maxAr.x(), maxAr.y())));
 
4976
        }
 
4977
        if (m_endArrowIndex != 0)
 
4978
        {
 
4979
                QMatrix arrowTrans;
 
4980
                FPointArray arrow = m_Doc->arrowStyles.at(m_endArrowIndex-1).points.copy();
 
4981
                arrowTrans.translate(Xpos, Ypos);
 
4982
                arrowTrans.rotate(Rot);
 
4983
                if (itemType() == Line)
 
4984
                {
 
4985
                        arrowTrans.translate(Width, 0);
 
4986
                        if (NamedLStyle.isEmpty())
 
4987
                        {
 
4988
                                if (m_lineWidth != 0.0)
 
4989
                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
4990
                        }
 
4991
                        else
 
4992
                        {
 
4993
                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
4994
                                if (ml[ml.size()-1].Width != 0.0)
 
4995
                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
4996
                        }
 
4997
                        arrow.map(arrowTrans);
 
4998
                }
 
4999
                else
 
5000
                {
 
5001
                        FPoint End = PoLine.point(PoLine.size()-2);
 
5002
                        for (uint xx = PoLine.size()-1; xx > 0; xx -= 2)
 
5003
                        {
 
5004
                                FPoint Vector = PoLine.point(xx);
 
5005
                                if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
 
5006
                                {
 
5007
                                        arrowTrans.translate(End.x(), End.y());
 
5008
                                        arrowTrans.rotate(atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI));
 
5009
                                        if (NamedLStyle.isEmpty())
 
5010
                                        {
 
5011
                                                if (m_lineWidth != 0.0)
 
5012
                                                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
5013
                                        }
 
5014
                                        else
 
5015
                                        {
 
5016
                                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
5017
                                                if (ml[ml.size()-1].Width != 0.0)
 
5018
                                                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
5019
                                        }
 
5020
                                        arrow.map(arrowTrans);
 
5021
                                        break;
 
5022
                                }
 
5023
                        }
 
5024
                }
 
5025
                FPoint minAr = getMinClipF(&arrow);
 
5026
                FPoint maxAr = getMaxClipF(&arrow);
 
5027
                totalRect = totalRect.united(QRectF(QPointF(minAr.x(), minAr.y()), QPointF(maxAr.x(), maxAr.y())));
 
5028
        }
 
5029
 
 
5030
        qreal rx1, ry1, rx2, ry2;
 
5031
        totalRect.getCoords(&rx1, &ry1, &rx2, &ry2);
 
5032
        *x1 = rx1; *y1 = ry1;
 
5033
        *x2 = rx2; *y2 = ry2;
 
5034
}
 
5035
 
 
5036
double PageItem::visualXPos() const
 
5037
{
 
5038
        double extraSpace = 0.0;
 
5039
        if (!isLine())
 
5040
        {
 
5041
                if (NamedLStyle.isEmpty())
 
5042
                {
 
5043
                        if (lineColor() != CommonStrings::None)
 
5044
                                extraSpace = m_lineWidth / 2.0;
 
5045
                }
 
5046
                else
 
5047
                {
 
5048
                        multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
5049
                        struct SingleLine& sl = ml[ml.size()-1];
 
5050
                        if ((sl.Color != CommonStrings::None) && (sl.Width != 0))
 
5051
                                extraSpace = sl.Width / 2.0;
 
5052
                }
 
5053
        }
 
5054
        return Xpos - extraSpace;
 
5055
}
 
5056
 
 
5057
double PageItem::visualYPos() const
 
5058
{
 
5059
        double extraSpace = 0.0;
 
5060
        if (NamedLStyle.isEmpty())
 
5061
        {
 
5062
                if (lineColor() != CommonStrings::None)
 
5063
                        extraSpace = m_lineWidth / 2.0;
 
5064
        }
 
5065
        else
 
5066
        {
 
5067
                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
5068
                struct SingleLine& sl = ml[ml.size()-1];
 
5069
                if ((sl.Color != CommonStrings::None) && (sl.Width != 0))
 
5070
                        extraSpace = sl.Width / 2.0;
 
5071
        }
 
5072
        return Ypos - extraSpace;
 
5073
}
 
5074
 
 
5075
double PageItem::visualWidth() const
 
5076
{
 
5077
        double extraSpace = 0.0;
 
5078
        if (!isLine())
 
5079
        {
 
5080
                if (NamedLStyle.isEmpty())
 
5081
                {
 
5082
                        if (lineColor() != CommonStrings::None)
 
5083
                                extraSpace = m_lineWidth;
 
5084
                }
 
5085
                else
 
5086
                {
 
5087
                        multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
5088
                        struct SingleLine& sl = ml[ml.size()-1];
 
5089
                        if ((sl.Color != CommonStrings::None) && (sl.Width != 0))
 
5090
                                extraSpace = sl.Width;
 
5091
                }
 
5092
        }
 
5093
        return Width + extraSpace;
 
5094
}
 
5095
 
 
5096
double PageItem::visualHeight() const
 
5097
{
 
5098
        double extraSpace = 0.0;
 
5099
        if (NamedLStyle.isEmpty())
 
5100
        {
 
5101
                if (lineColor() != CommonStrings::None)
 
5102
                        extraSpace = m_lineWidth;
 
5103
        }
 
5104
        else
 
5105
        {
 
5106
                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
5107
                struct SingleLine& sl = ml[ml.size()-1];
 
5108
                if ((sl.Color != CommonStrings::None) && (sl.Width != 0))
 
5109
                        extraSpace = sl.Width;
 
5110
        }
 
5111
        return isLine() ? extraSpace : Height + extraSpace;
 
5112
}
 
5113
 
 
5114
bool PageItem::pointWithinItem(const int x, const int y) const
 
5115
{
 
5116
        const_cast<PageItem*>(this)-> setRedrawBounding();
 
5117
        // FIXME: We should be rounding or truncating here, not letting the compiler do it.
 
5118
        // Should we be rounding, truncating up, or truncating down?
 
5119
        //CB is this now correct?
 
5120
        QRect itemRect( static_cast<int>(floor(BoundingX)), static_cast<int>(floor(BoundingY)), static_cast<int>(ceil(BoundingW)), static_cast<int>(ceil(BoundingH)) );
 
5121
        return itemRect.contains(x, y);
 
5122
}
 
5123
 
 
5124
bool PageItem::mouseWithinItem(const int x, const int y, double scale) const
 
5125
{
 
5126
        QMatrix p;
 
5127
        QRectF transRect;
 
5128
        p.translate(Xpos * scale, Ypos*scale);
 
5129
        p.scale(scale, scale);
 
5130
        p.rotate(rotation());
 
5131
        transRect = p.mapRect(QRectF(0.0, 0.0, width(), height()));
 
5132
        return transRect.contains(x, y);
 
5133
}
 
5134
 
 
5135
bool PageItem::loadImage(const QString& filename, const bool reload, const int gsResolution, bool showMsg)
 
5136
{
 
5137
        bool useImage = (asImageFrame() != NULL);
 
5138
        useImage |= (isAnnotation() && annotation().UseIcons());
 
5139
        if (!useImage)
 
5140
                return false;
 
5141
        QFileInfo fi(filename);
 
5142
        QString clPath(pixm.imgInfo.usedPath);
 
5143
        pixm.imgInfo.valid = false;
 
5144
        pixm.imgInfo.clipPath="";
 
5145
        pixm.imgInfo.PDSpathData.clear();
 
5146
        pixm.imgInfo.layerInfo.clear();
 
5147
        pixm.imgInfo.usedPath="";
 
5148
        imageClip.resize(0);
 
5149
        int lowResTypeBack = pixm.imgInfo.lowResType;
 
5150
        int gsRes=gsResolution;
 
5151
        if (gsResolution==-1) //If it wasn't supplied, get it from PrefsManager.
 
5152
                gsRes=PrefsManager::instance()->gsResolution();
 
5153
        bool dummy;
 
5154
        CMSettings cms(m_Doc, IProfile, IRender);
 
5155
        if (!pixm.LoadPicture(filename, pixm.imgInfo.actualPageNumber, cms, UseEmbedded, true, ScImage::RGBProof, gsRes, &dummy, showMsg))
 
5156
        {
 
5157
                Pfile = fi.absoluteFilePath();
 
5158
                PictureIsAvailable = false;
 
5159
//              PicArt = false;
 
5160
                return false;
 
5161
        }
 
5162
        else
 
5163
        {
 
5164
                QString ext = fi.suffix().toLower();
 
5165
                if (UndoManager::undoEnabled() && !reload)
 
5166
                {
 
5167
                        ItemState<ScImageEffectList> *is = new ItemState<ScImageEffectList>(Um::GetImage, filename, Um::IGetImage);
 
5168
                        is->set("GET_IMAGE", "get_image");
 
5169
                        is->set("OLD_IMAGE_PATH", Pfile);
 
5170
                        is->set("NEW_IMAGE_PATH", filename);
 
5171
                        is->set("FLIPPH",imageFlippedH());
 
5172
                        is->set("FLIPPV",imageFlippedV());
 
5173
                        is->set("SCALING",ScaleType);
 
5174
                        is->set("ASPECT",AspectRatio);
 
5175
                        is->set("XOFF",imageXOffset());
 
5176
                        is->set("XSCALE",imageXScale());
 
5177
                        is->set("YOFF",imageYOffset());
 
5178
                        is->set("YSCALE",imageYScale());
 
5179
                        is->set("FILLT", fillTransparency());
 
5180
                        is->set("LINET", lineTransparency());
 
5181
                        is->setItem(effectsInUse);
 
5182
                        undoManager->action(this, is);
 
5183
                }
 
5184
                double xres = pixm.imgInfo.xres;
 
5185
                double yres = pixm.imgInfo.yres;
 
5186
                PictureIsAvailable = true;
 
5187
//              PicArt = true;
 
5188
                
 
5189
                if (Pfile != filename)
 
5190
                {
 
5191
                        oldLocalScX = LocalScX = 72.0 / xres;
 
5192
                        oldLocalScY = LocalScY = 72.0 / yres;
 
5193
                        oldLocalX = LocalX = 0;
 
5194
                        oldLocalY = LocalY = 0;
 
5195
                        
 
5196
                        if ((m_Doc->toolSettings.useEmbeddedPath) && (!pixm.imgInfo.clipPath.isEmpty()))
 
5197
                        {
 
5198
                                pixm.imgInfo.usedPath = pixm.imgInfo.clipPath;
 
5199
                                clPath = pixm.imgInfo.clipPath;
 
5200
                                if (pixm.imgInfo.PDSpathData.contains(clPath))
 
5201
                                {
 
5202
                                        imageClip = pixm.imgInfo.PDSpathData[clPath].copy();
 
5203
                                        pixm.imgInfo.usedPath = clPath;
 
5204
                                        QMatrix cl;
 
5205
                                        cl.translate(LocalX*LocalScX, LocalY*LocalScY);
 
5206
                                        cl.scale(LocalScX, LocalScY);
 
5207
                                        imageClip.map(cl);
 
5208
                                }
 
5209
                        }
 
5210
                }
 
5211
                
 
5212
                Pfile = fi.absoluteFilePath();
 
5213
                if (reload && pixm.imgInfo.PDSpathData.contains(clPath))
 
5214
                {
 
5215
                        imageClip = pixm.imgInfo.PDSpathData[clPath].copy();
 
5216
                        pixm.imgInfo.usedPath = clPath;
 
5217
                        QMatrix cl;
 
5218
                        cl.translate(LocalX*LocalScX, LocalY*LocalScY);
 
5219
                        cl.scale(LocalScX, LocalScY);
 
5220
                        imageClip.map(cl);
 
5221
                }
 
5222
                BBoxX = pixm.imgInfo.BBoxX;
 
5223
                BBoxH = pixm.imgInfo.BBoxH;
 
5224
                OrigW = pixm.width();
 
5225
                OrigH = pixm.height();
 
5226
                isRaster = !(extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext));
 
5227
                if (!isRaster)
 
5228
                        effectsInUse.clear();
 
5229
                UseEmbedded=pixm.imgInfo.isEmbedded;
 
5230
                if (pixm.imgInfo.isEmbedded)
 
5231
                {
 
5232
                        IProfile = "Embedded " + pixm.imgInfo.profileName;
 
5233
                        EmProfile = "Embedded " + pixm.imgInfo.profileName;
 
5234
                }
 
5235
                else
 
5236
                        IProfile = pixm.imgInfo.profileName;
 
5237
                AdjustPictScale();
 
5238
        }
 
5239
        if (PictureIsAvailable)
 
5240
        {
 
5241
                if ((pixm.imgInfo.colorspace == ColorSpaceDuotone) && (pixm.imgInfo.duotoneColors.count() != 0) && (!reload))
 
5242
                {
 
5243
                        QString efVal = "";
 
5244
                        for (int cc = 0; cc < pixm.imgInfo.duotoneColors.count(); cc++)
 
5245
                        {
 
5246
                                if (!m_Doc->PageColors.contains(pixm.imgInfo.duotoneColors[cc].Name))
 
5247
                                        m_Doc->PageColors.insert(pixm.imgInfo.duotoneColors[cc].Name, pixm.imgInfo.duotoneColors[cc].Color);
 
5248
                                efVal += pixm.imgInfo.duotoneColors[cc].Name+"\n";
 
5249
                        }
 
5250
                        m_Doc->scMW()->propertiesPalette->updateColorList();
 
5251
                        struct ImageEffect ef;
 
5252
                        if (pixm.imgInfo.duotoneColors.count() == 1)
 
5253
                        {
 
5254
                                efVal += "100";
 
5255
                                ef.effectCode = ScImage::EF_COLORIZE;
 
5256
                                ef.effectParameters = efVal;
 
5257
                        }
 
5258
                        else if (pixm.imgInfo.duotoneColors.count() == 2)
 
5259
                        {
 
5260
                                efVal += "100 100";
 
5261
                                QString tmp;
 
5262
                                FPointArray Vals = pixm.imgInfo.duotoneColors[0].Curve;
 
5263
                                tmp.setNum(Vals.size());
 
5264
                                efVal += " "+tmp;
 
5265
                                for (uint p = 0; p < Vals.size(); p++)
 
5266
                                {
 
5267
                                        FPoint pv = Vals.point(p);
 
5268
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5269
                                }
 
5270
                                efVal += " 0";
 
5271
                                Vals = pixm.imgInfo.duotoneColors[1].Curve;
 
5272
                                tmp.setNum(Vals.size());
 
5273
                                efVal += " "+tmp;
 
5274
                                for (uint p = 0; p < Vals.size(); p++)
 
5275
                                {
 
5276
                                        FPoint pv = Vals.point(p);
 
5277
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5278
                                }
 
5279
                                efVal += " 0";
 
5280
                                ef.effectCode = ScImage::EF_DUOTONE;
 
5281
                                ef.effectParameters = efVal;
 
5282
                        }
 
5283
                        else if (pixm.imgInfo.duotoneColors.count() == 3)
 
5284
                        {
 
5285
                                efVal += "100 100 100";
 
5286
                                QString tmp;
 
5287
                                FPointArray Vals = pixm.imgInfo.duotoneColors[0].Curve;
 
5288
                                tmp.setNum(Vals.size());
 
5289
                                efVal += " "+tmp;
 
5290
                                for (uint p = 0; p < Vals.size(); p++)
 
5291
                                {
 
5292
                                        FPoint pv = Vals.point(p);
 
5293
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5294
                                }
 
5295
                                efVal += " 0";
 
5296
                                Vals = pixm.imgInfo.duotoneColors[1].Curve;
 
5297
                                tmp.setNum(Vals.size());
 
5298
                                efVal += " "+tmp;
 
5299
                                for (uint p = 0; p < Vals.size(); p++)
 
5300
                                {
 
5301
                                        FPoint pv = Vals.point(p);
 
5302
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5303
                                }
 
5304
                                efVal += " 0";
 
5305
                                Vals = pixm.imgInfo.duotoneColors[2].Curve;
 
5306
                                tmp.setNum(Vals.size());
 
5307
                                efVal += " "+tmp;
 
5308
                                for (uint p = 0; p < Vals.size(); p++)
 
5309
                                {
 
5310
                                        FPoint pv = Vals.point(p);
 
5311
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5312
                                }
 
5313
                                efVal += " 0";
 
5314
                                ef.effectCode = ScImage::EF_TRITONE;
 
5315
                                ef.effectParameters = efVal;
 
5316
                        }
 
5317
                        else if (pixm.imgInfo.duotoneColors.count() == 4)
 
5318
                        {
 
5319
                                efVal += "100 100 100 100";
 
5320
                                QString tmp;
 
5321
                                FPointArray Vals = pixm.imgInfo.duotoneColors[0].Curve;
 
5322
                                tmp.setNum(Vals.size());
 
5323
                                efVal += " "+tmp;
 
5324
                                for (uint p = 0; p < Vals.size(); p++)
 
5325
                                {
 
5326
                                        FPoint pv = Vals.point(p);
 
5327
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5328
                                }
 
5329
                                efVal += " 0";
 
5330
                                Vals = pixm.imgInfo.duotoneColors[1].Curve;
 
5331
                                tmp.setNum(Vals.size());
 
5332
                                efVal += " "+tmp;
 
5333
                                for (uint p = 0; p < Vals.size(); p++)
 
5334
                                {
 
5335
                                        FPoint pv = Vals.point(p);
 
5336
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5337
                                }
 
5338
                                efVal += " 0";
 
5339
                                Vals = pixm.imgInfo.duotoneColors[2].Curve;
 
5340
                                tmp.setNum(Vals.size());
 
5341
                                efVal += " "+tmp;
 
5342
                                for (uint p = 0; p < Vals.size(); p++)
 
5343
                                {
 
5344
                                        FPoint pv = Vals.point(p);
 
5345
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5346
                                }
 
5347
                                efVal += " 0";
 
5348
                                Vals = pixm.imgInfo.duotoneColors[3].Curve;
 
5349
                                tmp.setNum(Vals.size());
 
5350
                                efVal += " "+tmp;
 
5351
                                for (uint p = 0; p < Vals.size(); p++)
 
5352
                                {
 
5353
                                        FPoint pv = Vals.point(p);
 
5354
                                        efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
 
5355
                                }
 
5356
                                efVal += " 0";
 
5357
                                ef.effectCode = ScImage::EF_QUADTONE;
 
5358
                                ef.effectParameters = efVal;
 
5359
                        }
 
5360
                        effectsInUse.append(ef);
 
5361
                }
 
5362
                pixm.applyEffect(effectsInUse, m_Doc->PageColors, false);
 
5363
//              if (reload)
 
5364
                        pixm.imgInfo.lowResType = lowResTypeBack;
 
5365
                if (pixm.imgInfo.lowResType != 0)
 
5366
                {
 
5367
                        double scaling = pixm.imgInfo.xres / 36.0;
 
5368
                        if (pixm.imgInfo.lowResType == 1)
 
5369
                                scaling = pixm.imgInfo.xres / 72.0;
 
5370
                        // Prevent exagerately large images when using low res preview modes
 
5371
                        uint pixels = qRound(pixm.width() * pixm.height() / (scaling * scaling));
 
5372
                        if (pixels > 3000000)
 
5373
                        {
 
5374
                                double ratio = pixels / 3000000.0;
 
5375
                                scaling *= sqrt(ratio);
 
5376
                        }
 
5377
                        pixm.createLowRes(scaling);
 
5378
                        pixm.imgInfo.lowResScale = scaling;
 
5379
                }
 
5380
                if ((m_Doc->view()->m_canvas->usePreviewVisual()))
 
5381
                {
 
5382
                        VisionDefectColor defect;
 
5383
                        QColor tmpC;
 
5384
                        int h = pixm.qImagePtr()->height();
 
5385
                        int w = pixm.qImagePtr()->width();
 
5386
                        int r, g, b, a;
 
5387
                        QRgb *s;
 
5388
                        QRgb rgb;
 
5389
                        for( int yi=0; yi < h; ++yi )
 
5390
                        {
 
5391
                                s = (QRgb*)(pixm.qImagePtr()->scanLine( yi ));
 
5392
                                for( int xi = 0; xi < w; ++xi )
 
5393
                                {
 
5394
                                        rgb = *s;
 
5395
                                        tmpC.setRgb(rgb);
 
5396
                                        tmpC = defect.convertDefect(tmpC, m_Doc->view()->m_canvas->previewVisual());
 
5397
                                        a = qAlpha(rgb);
 
5398
                                        tmpC.getRgb(&r, &g, &b);
 
5399
                                        *s = qRgba(r, g, b, a);
 
5400
                                        s++;
 
5401
                                }
 
5402
                        }
 
5403
                }
 
5404
        }
 
5405
        return true;
 
5406
}
 
5407
 
 
5408
 
 
5409
void PageItem::drawLockedMarker(ScPainter *p)
 
5410
{
 
5411
        //TODO: CB clean
 
5412
        double scp1 = 1 ;// / ScMW->view->scale();
 
5413
        double ofwh = 6 * scp1;
 
5414
        double ofx = Width - ofwh/2;
 
5415
        double ofy = Height - ofwh*1.5;
 
5416
        double bx1= ofx+ scp1;
 
5417
        double by1= ofy+3 * scp1;
 
5418
        double bw= 4*scp1;
 
5419
        double bh= 2*scp1;
 
5420
        ScribusView* view = m_Doc->view();
 
5421
        p->setPen(Qt::black, 0.5 / view->scale(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
5422
        p->setPenOpacity(1.0);
 
5423
        p->setBrush(Qt::white);
 
5424
        p->setBrushOpacity(1.0);
 
5425
        p->setFillMode(ScPainter::Solid);
 
5426
        p->drawRect(ofx, ofy, ofwh, ofwh);
 
5427
        p->setBrush(Qt::black);
 
5428
        p->drawRect(bx1, by1, bw, bh);
 
5429
        p->setPen(Qt::black, 1.5 / view->scale(), Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin);
 
5430
        if (m_Locked)
 
5431
                p->drawLine(FPoint(bx1+scp1/2, ofy+scp1), FPoint(bx1+scp1/2, by1));
 
5432
        p->drawLine(FPoint(bx1+scp1*3.5, ofy+scp1), FPoint(bx1+scp1*3.5, by1));
 
5433
        p->drawLine(FPoint(bx1+scp1/2, ofy+scp1), FPoint(bx1+scp1*3.5, ofy+scp1));
 
5434
}
 
5435
 
 
5436
void PageItem::drawArrow(ScPainter *p, QMatrix &arrowTrans, int arrowIndex)
 
5437
{
 
5438
        FPointArray arrow = m_Doc->arrowStyles.at(arrowIndex-1).points.copy();
 
5439
        if (NamedLStyle.isEmpty())
 
5440
        {
 
5441
                if (m_lineWidth != 0.0)
 
5442
                        arrowTrans.scale(m_lineWidth, m_lineWidth);
 
5443
        }
 
5444
        else
 
5445
        {
 
5446
                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
5447
                if (ml[ml.size()-1].Width != 0.0)
 
5448
                        arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
 
5449
        }
 
5450
        arrow.map(arrowTrans);
 
5451
        p->setupPolygon(&arrow);
 
5452
        if (m_Doc->layerOutline(LayerNr))
 
5453
                p->strokePath();
 
5454
        else
 
5455
        {
 
5456
                if (NamedLStyle.isEmpty())
 
5457
                {
 
5458
                        if (lineColor() != CommonStrings::None)
 
5459
                        {
 
5460
                                p->setBrush(strokeQColor);
 
5461
                                p->setBrushOpacity(1.0 - lineTransparency());
 
5462
                                p->setLineWidth(0);
 
5463
                                p->setFillMode(ScPainter::Solid);
 
5464
                                p->fillPath();
 
5465
                        }
 
5466
                }
 
5467
                else
 
5468
                {
 
5469
                        multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 
5470
                        QColor tmp;
 
5471
                        if (ml[0].Color != CommonStrings::None)
 
5472
                        {
 
5473
                                SetQColor(&tmp, ml[0].Color, ml[0].Shade);
 
5474
                                p->setBrush(tmp);
 
5475
                                p->setLineWidth(0);
 
5476
                                p->setFillMode(ScPainter::Solid);
 
5477
                                p->fillPath();
 
5478
                        }
 
5479
                        for (int it = ml.size()-1; it > 0; it--)
 
5480
                        {
 
5481
                                if (ml[it].Color != CommonStrings::None)
 
5482
                                {
 
5483
                                        SetQColor(&tmp, ml[it].Color, ml[it].Shade);
 
5484
                                        p->setPen(tmp, ml[it].Width, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
5485
                                        p->strokePath();
 
5486
                                }
 
5487
                        }
 
5488
                }
 
5489
        }
 
5490
}
 
5491
 
 
5492
void PageItem::AdjustPictScale()
 
5493
{
 
5494
        if (itemType()!=PageItem::ImageFrame)
 
5495
                return;
 
5496
        if (ScaleType)
 
5497
                return;
 
5498
        if (OrigW == 0 || OrigH == 0)
 
5499
                return;
 
5500
        LocalX = 0;
 
5501
        LocalY = 0;
 
5502
        double xs = Width / static_cast<double>(OrigW);
 
5503
        double ys = Height / static_cast<double>(OrigH);
 
5504
        if (AspectRatio)
 
5505
        {
 
5506
                LocalScX = qMin(xs, ys);
 
5507
                LocalScY = qMin(xs, ys);
 
5508
        }
 
5509
        else
 
5510
        {
 
5511
                LocalScX = xs;
 
5512
                LocalScY = ys;
 
5513
        }
 
5514
        // Disable broken code. Code must be independent from doc in that function
 
5515
        /*switch (m_Doc->RotMode)
 
5516
        {
 
5517
                case 0:
 
5518
                        LocalX = 0;
 
5519
                        LocalY = 0;
 
5520
                        break;
 
5521
                case 1:
 
5522
                        LocalX = (Width - static_cast<double>(OrigW) * LocalScX) / LocalScX;
 
5523
                        LocalY = 0;
 
5524
                        break;
 
5525
                case 2:
 
5526
                        LocalX = ((Width - static_cast<double>(OrigW) * LocalScX) / LocalScX) / 2.0;
 
5527
                        LocalY = ((Height - static_cast<double>(OrigH) * LocalScY) / LocalScY) / 2.0;
 
5528
                        break;
 
5529
                case 3:
 
5530
                        LocalX = 0;
 
5531
                        LocalY = (Height - static_cast<double>(OrigH) * LocalScY) / LocalScY;
 
5532
                        break;
 
5533
                case 4:
 
5534
                        LocalX = (Width - static_cast<double>(OrigW) * LocalScX) / LocalScX;
 
5535
                        LocalY = (Height - static_cast<double>(OrigH) * LocalScY) / LocalScY;
 
5536
                        break;
 
5537
        }*/
 
5538
        if (imageClip.size() != 0)
 
5539
        {
 
5540
                imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
 
5541
                QMatrix cl;
 
5542
                cl.translate(LocalX*LocalScX, LocalY*LocalScY);
 
5543
                cl.scale(LocalScX, LocalScY);
 
5544
                imageClip.map(cl);
 
5545
        }
 
5546
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY );
 
5547
}
 
5548
 
 
5549
void PageItem::setExternalFile(QString val)
 
5550
{
 
5551
        Pfile = val;
 
5552
        if (!Pfile.isEmpty())
 
5553
        {
 
5554
                QString test = Pfile;
 
5555
                if (QDir::isRelativePath(test))
 
5556
                        test = QDir::homePath()+"/"+Pfile;
 
5557
                test = QDir::cleanPath(QDir::toNativeSeparators(test));
 
5558
                QFileInfo pfi2(test);
 
5559
                Pfile = pfi2.absoluteFilePath();
 
5560
        }
 
5561
}
 
5562
 
 
5563
void PageItem::setFileIconPressed(QString val)
 
5564
{
 
5565
        Pfile2 = val;
 
5566
        if (!Pfile2.isEmpty())
 
5567
        {
 
5568
                QString test = QDir::cleanPath(QDir::toNativeSeparators(QDir::homePath()+"/"+Pfile2));
 
5569
                QFileInfo pfi2(test);
 
5570
                Pfile2 = pfi2.absoluteFilePath();
 
5571
        }
 
5572
}
 
5573
 
 
5574
void PageItem::setFileIconRollover(QString val)
 
5575
{
 
5576
        Pfile3 = val;
 
5577
        if (!Pfile3.isEmpty())
 
5578
        {
 
5579
                QString test = QDir::cleanPath(QDir::toNativeSeparators(QDir::homePath()+"/"+Pfile3));
 
5580
                QFileInfo pfi2(test);
 
5581
                Pfile3 = pfi2.absoluteFilePath();
 
5582
        }
 
5583
}
 
5584
 
 
5585
QRect PageItem::getRedrawBounding(const double viewScale)
 
5586
{
 
5587
        int x = qRound(floor(BoundingX - Oldm_lineWidth / 2.0 - 5) * viewScale);
 
5588
        int y = qRound(floor(BoundingY - Oldm_lineWidth / 2.0 - 5) * viewScale);
 
5589
        int w = qRound(ceil(BoundingW + Oldm_lineWidth + 10) * viewScale);
 
5590
        int h = qRound(ceil(BoundingH + Oldm_lineWidth + 10) * viewScale);
 
5591
        QRect ret = QRect(x, y, w, h);
 
5592
        ret.translate(qRound(-m_Doc->minCanvasCoordinate.x() * viewScale), qRound(-m_Doc->minCanvasCoordinate.y() * viewScale));
 
5593
        return ret;
 
5594
}
 
5595
 
 
5596
 
 
5597
void PageItem::setRedrawBounding()
 
5598
{
 
5599
        double bw, bh;
 
5600
        getBoundingRect(&BoundingX, &BoundingY, &bw, &bh);
 
5601
        BoundingW = bw - BoundingX;
 
5602
        BoundingH = bh - BoundingY;
 
5603
        if (asLine())
 
5604
                BoundingH = qMax(BoundingH, 1.0);
 
5605
}
 
5606
 
 
5607
void PageItem::updateGradientVectors()
 
5608
{
 
5609
        switch (GrType)
 
5610
        {
 
5611
                case 0:
 
5612
                case 1:
 
5613
                        GrStartX = 0;
 
5614
                        GrStartY = Height / 2.0;
 
5615
                        GrEndX = Width;
 
5616
                        GrEndY = Height / 2.0;
 
5617
                        break;
 
5618
                case 2:
 
5619
                        GrStartX = Width / 2.0;
 
5620
                        GrStartY = 0;
 
5621
                        GrEndX = Width / 2.0;
 
5622
                        GrEndY = Height;
 
5623
                        break;
 
5624
                case 3:
 
5625
                        GrStartX = 0;
 
5626
                        GrStartY = 0;
 
5627
                        GrEndX = Width;
 
5628
                        GrEndY = Height;
 
5629
                        break;
 
5630
                case 4:
 
5631
                        GrStartX = 0;
 
5632
                        GrStartY = Height;
 
5633
                        GrEndX = Width;
 
5634
                        GrEndY = 0;
 
5635
                        break;
 
5636
                case 5:
 
5637
                        GrStartX = Width / 2.0;
 
5638
                        GrStartY = Height / 2.0;
 
5639
                        if (Width >= Height)
 
5640
                        {
 
5641
                                GrEndX = Width;
 
5642
                                GrEndY = Height / 2.0;
 
5643
                        }
 
5644
                        else
 
5645
                        {
 
5646
                                GrEndX = Width / 2.0;
 
5647
                                GrEndY = Height;
 
5648
                        }
 
5649
                        break;
 
5650
                default:
 
5651
                        break;
 
5652
        }
 
5653
        //if (ScMW->view->SelItem.count()!=0 && this==ScMW->view->SelItem.at(0))
 
5654
        //if (m_Doc->m_Selection->count()!=0 && m_Doc->m_Selection->primarySelectionIsMyself(this))
 
5655
        //      ScMW->propertiesPalette->updateColorSpecialGradient();
 
5656
        //CB Will only emit if connected, ie is first in GUI selection
 
5657
        double dur=m_Doc->unitRatio();
 
5658
        emit gradientColorUpdate(GrStartX*dur, GrStartY*dur, GrEndX*dur, GrEndY*dur, Width*dur, Height*dur);
 
5659
}
 
5660
 
 
5661
void PageItem::setPolyClip(int up, int down)
 
5662
{
 
5663
        if (PoLine.size() < 4)
 
5664
                return;
 
5665
        double rot;
 
5666
        int upval = up;
 
5667
        int downval = down;
 
5668
        if (up == 0)
 
5669
                upval = 1;
 
5670
        if (textPathFlipped)
 
5671
        {
 
5672
                upval *= -1;
 
5673
                downval *= -1;
 
5674
        }
 
5675
        QPoint np, np2;
 
5676
        QPolygon cl, cl1, cl2;
 
5677
        cl = FlattenPath(PoLine, Segments);
 
5678
        if (cl.size() > 1)
 
5679
        {
 
5680
                Clip.resize(0);
 
5681
                for (int a = 0; a < cl.size()-1; ++a)
 
5682
                {
 
5683
                        rot = xy2Deg(cl.point(a+1).x()-cl.point(a).x(),cl.point(a+1).y()-cl.point(a).y());
 
5684
                        QMatrix ma;
 
5685
                        ma.rotate(rot);
 
5686
                        np = QPoint(0, -upval) * ma;
 
5687
                        np2 = QPoint(0, -downval) * ma;
 
5688
                        cl1.resize(cl1.size()+1);
 
5689
                        cl1.setPoint(cl1.size()-1, np+cl.point(a));
 
5690
                        cl1.resize(cl1.size()+1);
 
5691
                        cl1.setPoint(cl1.size()-1, np+cl.point(a+1));
 
5692
                        cl2.resize(cl2.size()+1);
 
5693
                        cl2.setPoint(cl2.size()-1, np2+cl.point(a));
 
5694
                        cl2.resize(cl2.size()+1);
 
5695
                        cl2.setPoint(cl2.size()-1, np2+cl.point(a+1));
 
5696
                }
 
5697
                cl1.resize(cl1.size()+1);
 
5698
                cl1.setPoint(cl1.size()-1, np+cl.point(cl.size()-1));
 
5699
                cl2.resize(cl2.size()+1);
 
5700
                cl2.setPoint(cl2.size()-1, np2+cl.point(cl.size()-1));
 
5701
                Clip.putPoints(Clip.size(), cl1.size(), cl1);
 
5702
                for (int a2 = cl2.size()-1; a2 > -1; a2--)
 
5703
                {
 
5704
                        Clip.resize(Clip.size()+1);
 
5705
                        Clip.setPoint(Clip.size()-1, cl2.point(a2));
 
5706
                }
 
5707
        }
 
5708
}
 
5709
 
 
5710
void PageItem::updatePolyClip()
 
5711
{
 
5712
        int asce = 1;
 
5713
        int desc = 1;
 
5714
        uint itemTextCount=itemText.length();
 
5715
        for (uint a = 0; a < itemTextCount; ++a)
 
5716
        {
 
5717
                const CharStyle& hl (itemText.charStyle(a));
 
5718
                int des = static_cast<int>(hl.font().descent(hl.fontSize() / 10.0));
 
5719
                int asc = static_cast<int>(hl.font().ascent(hl.fontSize() / 10.0));
 
5720
                asce = qMax(asce, asc);
 
5721
                desc = qMax(desc, des);
 
5722
        }
 
5723
        setPolyClip(static_cast<int>(asce-BaseOffs), static_cast<int>(desc-BaseOffs));
 
5724
}
 
5725
 
 
5726
void PageItem::handleModeEditKey(QKeyEvent * /* k */, bool & /* keyRepeat */)
 
5727
{
 
5728
}
 
5729
 
 
5730
bool PageItem::connectToGUI()
 
5731
{
 
5732
        if (!ScCore->usingGUI())
 
5733
                return false;
 
5734
        if (!m_Doc->m_Selection->primarySelectionIs(this))
 
5735
                return false;
 
5736
        PropertiesPalette* pp=m_Doc->scMW()->propertiesPalette;
 
5737
        connect(this, SIGNAL(myself(PageItem *)), pp, SLOT(SetCurItem(PageItem *)));
 
5738
        connect(this, SIGNAL(frameType(int)), m_Doc->scMW(), SLOT(HaveNewSel(int)));
 
5739
        connect(this, SIGNAL(frameType(int)), m_Doc->view(), SLOT(selectionChanged()));
 
5740
        connect(this, SIGNAL(frameType(int)), pp, SLOT(NewSel(int)));
 
5741
        connect(this, SIGNAL(frameLocked(bool)), pp, SLOT(setLocked(bool)));
 
5742
        connect(this, SIGNAL(frameSizeLocked(bool)), pp, SLOT(setSizeLocked(bool)));
 
5743
        connect(this, SIGNAL(frameFlippedH(bool)), pp, SLOT(setFlippedH(bool)));
 
5744
        connect(this, SIGNAL(frameFlippedV(bool)), pp, SLOT(setFlippedV(bool)));
 
5745
        connect(this, SIGNAL(printEnabled(bool)), pp, SLOT(setPrintingEnabled(bool)));
 
5746
        connect(this, SIGNAL(position(double, double)), pp, SLOT(setXY(double, double)));
 
5747
        connect(this, SIGNAL(widthAndHeight(double, double)), pp, SLOT(setBH(double, double)));
 
5748
//CB unused in 135 connect(this, SIGNAL(colors(QString, QString, double, double)), m_Doc->scMW(), SLOT(setCSMenu()));
 
5749
//      connect(this, SIGNAL(colors(QString, QString, double, double)), pp->Cpal, SLOT(setActFarben(QString, QString, int, int)));
 
5750
//      connect(this, SIGNAL(gradientType(int)), pp->Cpal, SLOT(setActGradient(int)));
 
5751
        connect(this, SIGNAL(patternFill(QString, double, double, double, double, double)), pp->Cpal, SLOT(setActPattern(QString, double, double, double, double, double)));
 
5752
//      connect(this, SIGNAL(gradientColorUpdate(double, double, double, double, double, double)), pp->Cpal, SLOT(setSpecialGradient(double, double, double, double, double, double)));
 
5753
        connect(this, SIGNAL(rotation(double)), pp, SLOT(setR(double)));
 
5754
//      connect(this, SIGNAL(transparency(double, double)), pp->Cpal, SLOT(setActTrans(double, double)));
 
5755
//      connect(this, SIGNAL(blendmode(int, int)), pp->Cpal, SLOT(setActBlend(int, int)));
 
5756
        //Shape signals
 
5757
        //Not connected when transferring code: void columns(int, double); //Number, gap
 
5758
        connect(this, SIGNAL(cornerRadius(double)), pp, SLOT(setRR(double)));
 
5759
        //      connect(view, SIGNAL(ItemTextCols(int, double)), propertiesPalette, SLOT(setCols(int, double)));
 
5760
        //Line signals
 
5761
        connect(this, SIGNAL(lineWidth(double)), pp, SLOT(setLineWidth(double)));
 
5762
        connect(this, SIGNAL(imageOffsetScale(double, double, double, double)), pp, SLOT(setScaleAndOffset(double, double, double, double)));
 
5763
        connect(this, SIGNAL(lineStyleCapJoin(Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle)), pp, SLOT( setLIvalue(Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle)));
 
5764
        //Frame text signals
 
5765
        connect(this, SIGNAL(lineSpacing(double)), pp, SLOT(setLsp(double)));
 
5766
        connect(this, SIGNAL(textToFrameDistances(double, double, double, double)), pp, SLOT(setTextToFrameDistances(double, double, double, double)));
 
5767
        connect(this, SIGNAL(textKerning(double)), pp, SLOT(setExtra(double)));
 
5768
        connect(this, SIGNAL(textStyle(int)), pp, SLOT(setStil(int)));
 
5769
        connect(this, SIGNAL(textStyle(int)), m_Doc->scMW(), SLOT(setStilvalue(int)));
 
5770
        connect(this, SIGNAL(textFont(const QString&)), pp, SLOT(setFontFace(const QString&)));
 
5771
        connect(this, SIGNAL(textSize(double)), pp, SLOT(setSize(double)));
 
5772
        connect(this, SIGNAL(textWidthScale(double)), pp, SLOT(setTScale(double)));
 
5773
        connect(this, SIGNAL(textHeightScale(double)), pp, SLOT(setTScaleV(double)));
 
5774
        connect(this, SIGNAL(textBaseLineOffset(double)), pp, SLOT(setTBase(double)));
 
5775
        connect(this, SIGNAL(textOutline(double)), pp, SLOT(setOutlineW(double)));
 
5776
        connect(this, SIGNAL(textShadow(double, double )), pp, SLOT(setShadowOffs(double, double )));
 
5777
        connect(this, SIGNAL(textUnderline(double, double)), pp, SLOT(setUnderline(double, double)));
 
5778
        connect(this, SIGNAL(textStrike(double, double)), pp, SLOT(setStrike(double, double)));
 
5779
        connect(this, SIGNAL(textColor(QString, QString, double, double)), pp, SLOT(setActFarben(QString, QString, double, double)));
 
5780
//      connect(this, SIGNAL(textFormatting(int)), pp, SLOT(setAli(int)));
 
5781
//      connect(this, SIGNAL(textFormatting(int)), ScMW, SLOT(setAbsValue(int)));
 
5782
 
 
5783
        return true;
 
5784
}
 
5785
 
 
5786
bool PageItem::disconnectFromGUI()
 
5787
{
 
5788
        if (!ScCore->usingGUI())
 
5789
                return false;
 
5790
        // Disconnecting only signals from PP will leave some remaining connections
 
5791
        // and cause progressive slowdowns
 
5792
        // PropertiesPalette* pp=m_Doc->scMW()->propertiesPalette;
 
5793
        // disconnect(this, 0, pp, 0);
 
5794
        disconnect(this, 0, 0, 0);
 
5795
        return true;
 
5796
}
 
5797
 
 
5798
void PageItem::emitAllToGUI()
 
5799
{
 
5800
        updateConstants();
 
5801
 
 
5802
        emit myself(this);
 
5803
        emit frameType(m_ItemType);
 
5804
/*CB using the emit myself* instead of all of these
 
5805
        emit position(Xpos, Ypos);
 
5806
        emit widthAndHeight(Width, Height);
 
5807
        emit rotation(Rot);
 
5808
        emit frameLocked(m_Locked);
 
5809
        emit frameSizeLocked(m_SizeLocked);
 
5810
        emit frameFlippedH(m_ImageIsFlippedH);
 
5811
        emit frameFlippedV(m_ImageIsFlippedV);
 
5812
        emit printEnabled(m_PrintEnabled);
 
5813
        emit lineWidth(m_lineWidth);
 
5814
        emit lineStyleCapJoin(PLineArt, PLineEnd, PLineJoin);
 
5815
        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
 
5816
*/
 
5817
//CB unused in 135 emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
 
5818
//      emit gradientType(GrType);
 
5819
//      double dur=m_Doc->unitRatio();
 
5820
//      emit gradientColorUpdate(GrStartX*dur, GrStartY*dur, GrEndX*dur, GrEndY*dur, Width*dur, Height*dur);
 
5821
//      emit transparency(fillTransparencyVal, lineTransparencyVal);
 
5822
//      emit blendmode(fillBlendmodeVal, lineBlendmodeVal);
 
5823
/*CB using the emit myself* instead of all of these
 
5824
        emit patternFill(patternVal, patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
 
5825
        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 
5826
        emit columns(Cols, ColGap);
 
5827
*/
 
5828
        if (m_Doc->appMode == modeEdit)
 
5829
        {
 
5830
/* maybe already done elsewhere? -- av
 
5831
                emit lineSpacing(currentStyle().lineSpacing());
 
5832
                emit textKerning(currentCharStyle().tracking());
 
5833
                emit textStyle(currentCharStyle().effects());
 
5834
                emit textFont(currentCharStyle().font()->scName());
 
5835
                emit textSize(currentCharStyle().fontSize());
 
5836
*/
 
5837
                //              emit textFormatting(currentStyle().alignment());
 
5838
        }
 
5839
        else
 
5840
        {
 
5841
//TODO remove and use the emit myself
 
5842
                emit lineSpacing(itemText.defaultStyle().lineSpacing());
 
5843
                emit textKerning(itemText.defaultStyle().charStyle().tracking());
 
5844
                emit textStyle(itemText.defaultStyle().charStyle().effects());
 
5845
                emit textFont(itemText.defaultStyle().charStyle().font().scName());
 
5846
                emit textSize(itemText.defaultStyle().charStyle().fontSize());
 
5847
//              emit textFormatting(itemText.defaultStyle().alignment());
 
5848
        }
 
5849
}
 
5850
 
 
5851
void PageItem::setIsAnnotation(bool isAnnot)
 
5852
{
 
5853
        m_isAnnotation=isAnnot;
 
5854
}
 
5855
 
 
5856
void PageItem::setAnnotation(const Annotation& ad)
 
5857
{
 
5858
        m_annotation=ad;
 
5859
}
 
5860
 
 
5861
void PageItem::setImageShown(bool isShown)
 
5862
{
 
5863
        PicArt=isShown;
 
5864
}
 
5865
 
 
5866
void PageItem::updateConstants()
 
5867
{
 
5868
        if (OwnPage!=-1)
 
5869
        {
 
5870
                m_Doc->constants().insert("pagewidth", m_Doc->Pages->at(OwnPage)->width());
 
5871
                m_Doc->constants().insert("pageheight", m_Doc->Pages->at(OwnPage)->height());
 
5872
                m_Doc->constants().insert("marginleft", m_Doc->Pages->at(OwnPage)->Margins.Left);
 
5873
                m_Doc->constants().insert("marginright", m_Doc->Pages->at(OwnPage)->width() - m_Doc->Pages->at(OwnPage)->Margins.Right);
 
5874
                m_Doc->constants().insert("margintop", m_Doc->Pages->at(OwnPage)->Margins.Top);
 
5875
                m_Doc->constants().insert("marginbottom", m_Doc->Pages->at(OwnPage)->height() - m_Doc->Pages->at(OwnPage)->Margins.Bottom);
 
5876
        }
 
5877
        m_Doc->constants().insert("width", Width);
 
5878
        m_Doc->constants().insert("height", Height);
 
5879
}
 
5880
 
 
5881
//CB Old ScribusView MoveItemI
 
5882
void PageItem::moveImageInFrame(double newX, double newY)
 
5883
{
 
5884
        if (m_ItemType!=PageItem::ImageFrame)
 
5885
                return;
 
5886
        if ((locked()) || (!ScaleType))
 
5887
                return;
 
5888
        double dX=0.0, dY=0.0;
 
5889
        if (imageFlippedH())
 
5890
                dX=-newX;
 
5891
        else
 
5892
                dX=newX;
 
5893
        if (imageFlippedV())
 
5894
                dY=-newY;
 
5895
        else
 
5896
                dY=newY;
 
5897
        moveImageXYOffsetBy(dX, dY);
 
5898
        if (imageClip.size() != 0)
 
5899
        {
 
5900
                imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
 
5901
                QMatrix cl;
 
5902
                cl.translate(imageXOffset()*imageXScale(), imageYOffset()*imageYScale());
 
5903
                cl.scale(imageXScale(), imageYScale());
 
5904
                imageClip.map(cl);
 
5905
        }
 
5906
}
 
5907
 
 
5908
 
 
5909
 
 
5910
void PageItem::convertClip()
 
5911
{
 
5912
        if (Clip.count() != 0)
 
5913
        {
 
5914
                FPoint np(Clip.point(0));
 
5915
                PoLine.resize(2);
 
5916
                PoLine.setPoint(0, np);
 
5917
                PoLine.setPoint(1, np);
 
5918
                for (int a = 1; a < Clip.size(); ++a)
 
5919
                {
 
5920
                        np = FPoint(Clip.point(a));
 
5921
                        PoLine.putPoints(PoLine.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y());
 
5922
                }
 
5923
                np = FPoint(Clip.point(0));
 
5924
                PoLine.putPoints(PoLine.size(), 2, np.x(), np.y(), np.x(), np.y());
 
5925
                Clip = FlattenPath(PoLine, Segments);
 
5926
        }
 
5927
        else
 
5928
        {
 
5929
                SetRectFrame();
 
5930
                m_Doc->setRedrawBounding(this);
 
5931
        }
 
5932
}
 
5933
 
 
5934
void PageItem::updateClip()
 
5935
{
 
5936
        if (m_Doc->appMode == modeDrawBezierLine)
 
5937
                return;
 
5938
        if (ContourLine.size() == 0)
 
5939
                ContourLine = PoLine.copy();
 
5940
        int ph = static_cast<int>(qMax(1.0, lineWidth() / 2.0));
 
5941
        bool clipBackup = ClipEdited;
 
5942
        switch (itemType())
 
5943
        {
 
5944
        case PageItem::Line:
 
5945
                Clip.setPoints(4, -ph,-ph, static_cast<int>(width()+ph),-ph,
 
5946
                                  static_cast<int>(width()+ph),static_cast<int>(height()+ph),
 
5947
                                  -ph,static_cast<int>(height()+ph));
 
5948
                break;
 
5949
        default:
 
5950
                if (((!ClipEdited) || (FrameType < 3)) && !(asPathText()))
 
5951
                {
 
5952
                        switch (FrameType)
 
5953
                        {
 
5954
                        case 0:
 
5955
                                SetRectFrame();
 
5956
                                m_Doc->setRedrawBounding(this);
 
5957
                                break;
 
5958
                        case 1:
 
5959
                                SetOvalFrame();
 
5960
                                m_Doc->setRedrawBounding(this);
 
5961
                                break;
 
5962
                        case 2:
 
5963
                                //CB FIXME: stop using nodeEdit.clre or move out of here
 
5964
                                m_Doc->nodeEdit.deselect();
 
5965
                                SetFrameRound();
 
5966
                                m_Doc->setRedrawBounding(this);
 
5967
                                break;
 
5968
                        default:
 
5969
                                break;
 
5970
                        }
 
5971
                        ClipEdited = clipBackup;
 
5972
                        if ((OldB2 != 0) && (OldH2 != 0) && (width() != 0) && (height() != 0))
 
5973
                        {
 
5974
                                double scx = width() / OldB2;
 
5975
                                double scy = height() / OldH2;
 
5976
                                QMatrix ma;
 
5977
                                ma.scale(scx, scy);
 
5978
                                FPointArray gr;
 
5979
                                gr.addPoint(GrStartX, GrStartY);
 
5980
                                gr.addPoint(GrEndX, GrEndY);
 
5981
                                gr.map(ma);
 
5982
                                GrStartX = gr.point(0).x();
 
5983
                                GrStartY = gr.point(0).y();
 
5984
                                GrEndX = gr.point(1).x();
 
5985
                                GrEndY = gr.point(1).y();
 
5986
                                ContourLine.map(ma);
 
5987
                                if (FrameType > 2)
 
5988
                                {
 
5989
                                        PoLine.map(ma);
 
5990
                                        if (asPathText())
 
5991
                                                updatePolyClip();
 
5992
                                        else
 
5993
                                                Clip = FlattenPath(PoLine, Segments);
 
5994
                                }
 
5995
                        }
 
5996
                        OldB2 = width();
 
5997
                        OldH2 = height();
 
5998
                        if ((FrameType < 3) && (!ClipEdited))
 
5999
                                ContourLine = PoLine.copy();
 
6000
                }
 
6001
                else
 
6002
                {
 
6003
                        if (m_Doc->SubMode != -1)
 
6004
                        {
 
6005
                                switch (m_Doc->SubMode)
 
6006
                                {
 
6007
                                case 0:
 
6008
                                        SetRectFrame();
 
6009
                                        m_Doc->setRedrawBounding(this);
 
6010
                                        break;
 
6011
                                case 1:
 
6012
                                        SetOvalFrame();
 
6013
                                        m_Doc->setRedrawBounding(this);
 
6014
                                        break;
 
6015
                                default:
 
6016
                                        SetFrameShape(m_Doc->ValCount, m_Doc->ShapeValues);
 
6017
                                        m_Doc->setRedrawBounding(this);
 
6018
                                        break;
 
6019
                                }
 
6020
                                OldB2 = width();
 
6021
                                OldH2 = height();
 
6022
                                ContourLine = PoLine.copy();
 
6023
                        }
 
6024
                        if ((OldB2 == 0) || (OldH2 == 0) || (width() == 0) || (height() == 0))
 
6025
                                return;
 
6026
                        double scx = width() / OldB2;
 
6027
                        double scy = height() / OldH2;
 
6028
                        QMatrix ma;
 
6029
                        ma.scale(scx, scy);
 
6030
                        FPointArray gr;
 
6031
                        gr.addPoint(GrStartX, GrStartY);
 
6032
                        gr.addPoint(GrEndX, GrEndY);
 
6033
                        gr.map(ma);
 
6034
                        GrStartX = gr.point(0).x();
 
6035
                        GrStartY = gr.point(0).y();
 
6036
                        GrEndX = gr.point(1).x();
 
6037
                        GrEndY = gr.point(1).y();
 
6038
                        PoLine.map(ma);
 
6039
                        ContourLine.map(ma);
 
6040
                        if (asPathText())
 
6041
                                updatePolyClip();
 
6042
                        else
 
6043
                                Clip = FlattenPath(PoLine, Segments);
 
6044
                        OldB2 = width();
 
6045
                        OldH2 = height();
 
6046
                }
 
6047
                break;
 
6048
        }
 
6049
        updateGradientVectors();
 
6050
}
 
6051
 
 
6052
QString PageItem::infoDescription()
 
6053
{
 
6054
        QString htmlText;
 
6055
        htmlText.append(ScribusView::tr("Print: "));
 
6056
        if (printEnabled())
 
6057
                htmlText.append(ScribusView::tr("Enabled"));
 
6058
        else
 
6059
                htmlText.append(ScribusView::tr("Disabled"));
 
6060
        htmlText.append("<br/>");
 
6061
        return htmlText;
 
6062
}
 
6063
 
 
6064
FirstLineOffsetPolicy PageItem::firstLineOffset() const
 
6065
{
 
6066
        return firstLineOffsetP;
 
6067
}
 
6068
 
 
6069
void PageItem::setFirstLineOffset(FirstLineOffsetPolicy flop)
 
6070
{
 
6071
        if(firstLineOffsetP != flop)
 
6072
        {
 
6073
                firstLineOffsetP = flop;
 
6074
        }
 
6075
}
 
6076
 
 
6077
 
 
6078
 
 
6079
 
 
6080