Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pageitem.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           pageitem.cpp  -  description
00009                              -------------------
00010     begin                : Sat Apr 7 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "pageitem.h"
00025 #include "pageitem.moc"
00026 #include <qpainter.h>
00027 #include <qpen.h>
00028 #include <qfont.h>
00029 #include <qregion.h>
00030 #include <qpoint.h>
00031 #include <qfileinfo.h>
00032 #include <qdrawutil.h>
00033 #include <qbitmap.h>
00034 #include <qregexp.h>
00035 #include <qmessagebox.h>
00036 #include <qptrstack.h>
00037 #include <cmath>
00038 #include <cassert>
00039 
00040 #include "scpaths.h"
00041 #include "page.h"
00042 #include "scpainter.h"
00043 #include "scribus.h"
00044 #include "scribuscore.h"
00045 #include "scribusapp.h"
00046 #include "scribusstructs.h"
00047 #include "scribusdoc.h"
00048 #include "scribuswin.h"
00049 #include "selection.h"
00050 #include "prefsmanager.h"
00051 #include "undomanager.h"
00052 #include "undostate.h"
00053 #include "mpalette.h"
00054 #include "cpalette.h"
00055 #include "commonstrings.h"
00056 #include "scconfig.h"
00057 #include "guidemanager.h"
00058 #include "sccolorengine.h"
00059 #include "resourcecollection.h"
00060 
00061 #include "util.h"
00062 #include "scpattern.h"
00063 #include "colorblind.h"
00064 
00065 #include "text/nlsconfig.h"
00066 #ifdef HAVE_CAIRO
00067 #include <cairo.h>
00068 #endif
00069 
00070 using namespace std;
00071 
00072 PageItem::PageItem(const PageItem & other)
00073        : QObject(other.parent()),
00074         UndoObject(other),
00075 
00076 // 200 attributes! That is madness, or to quote some famous people from Kriquet:
00077 // "THAT ALL HAS TO GO!"
00078        gXpos(other.gXpos),
00079        gYpos(other.gYpos),
00080        gWidth(other.gWidth),
00081        gHeight(other.gHeight),
00082        GrType(other.GrType),
00083        GrStartX(other.GrStartX),
00084        GrStartY(other.GrStartY),
00085        GrEndX(other.GrEndX),
00086        GrEndY(other.GrEndY),
00087        Cols(other.Cols),
00088        ColGap(other.ColGap),
00089        PLineArt(other.PLineArt),
00090        PLineEnd(other.PLineEnd),
00091        PLineJoin(other.PLineJoin),
00092        NamedLStyle(other.NamedLStyle),
00093        Clip(other.Clip),
00094        PoLine(other.PoLine),
00095        ContourLine(other.ContourLine),
00096        imageClip(other.imageClip),
00097        Segments(other.Segments),
00098        effectsInUse(other.effectsInUse),
00099        PoShow(other.PoShow),
00100        BaseOffs(other.BaseOffs),
00101        textPathType(other.textPathType),
00102        textPathFlipped(other.textPathFlipped),
00103        ClipEdited(other.ClipEdited),
00104        FrameType(other.FrameType),
00105        ItemNr(other.ItemNr),
00106        Frame(other.Frame),
00107        OwnPage(other.OwnPage),
00108        oldOwnPage(other.oldOwnPage),
00109        pixm(other.pixm),
00110        Pfile(other.Pfile),
00111        Pfile2(other.Pfile2),
00112        Pfile3(other.Pfile3),
00113        IProfile(other.IProfile),
00114        UseEmbedded(other.UseEmbedded),
00115        EmProfile(other.EmProfile),
00116        IRender(other.IRender),
00117 
00118        PicAvail(other.PicAvail),
00119        OrigW(other.OrigW),
00120        OrigH(other.OrigH),
00121        BBoxX(other.BBoxX),
00122        BBoxH(other.BBoxH),
00123        CurX(other.CurX),
00124        CurY(other.CurY),
00125        CPos(other.CPos),
00126        itemText(other.itemText),
00127        isBookmark(other.isBookmark),
00128        HasSel(other.HasSel),
00129 //     Tinput(other.Tinput),
00130        isAutoText(other.isAutoText),
00131        BackBox(NULL),  // otherwise other.BackBox->NextBox would be inconsistent
00132        NextBox(NULL),  // otherwise other.NextBox->BackBox would be inconsistent
00133        firstChar(0),   // since this box is unlinked now
00134        MaxChars(0),   // since the layout is invalid now
00135        inPdfArticle(other.inPdfArticle),
00136        isRaster(other.isRaster),
00137        OldB(other.OldB),
00138        OldH(other.OldH),
00139        OldB2(other.OldB2),
00140        OldH2(other.OldH2),
00141        Sizing(other.Sizing),
00142        toPixmap(other.toPixmap),
00143        LayerNr(other.LayerNr),
00144        ScaleType(other.ScaleType),
00145        AspectRatio(other.AspectRatio),
00146        Groups(other.Groups),
00147        DashValues(other.DashValues),
00148        DashOffset(other.DashOffset),
00149        fill_gradient(other.fill_gradient),
00150        fillRule(other.fillRule),
00151        doOverprint(other.doOverprint),
00152        LeftLink(other.LeftLink),
00153        RightLink(other.RightLink),
00154        TopLink(other.TopLink),
00155        BottomLink(other.BottomLink),
00156        LeftLinkID(other.LeftLinkID),
00157        RightLinkID(other.RightLinkID),
00158        TopLinkID(other.TopLinkID),
00159        BottomLinkID(other.BottomLinkID),
00160        LeftLine(other.LeftLine),
00161        RightLine(other.RightLine),
00162        TopLine(other.TopLine),
00163        BottomLine(other.BottomLine),
00164        isTableItem(other.isTableItem),
00165        isSingleSel(other.isSingleSel),
00166        isGroupControl(other.isGroupControl),
00167        groupsLastItem(other.groupsLastItem),
00168        BoundingX(other.BoundingX),
00169        BoundingY(other.BoundingY),
00170        BoundingW(other.BoundingW),
00171        BoundingH(other.BoundingH),
00172        ChangedMasterItem(other.ChangedMasterItem),
00173        OnMasterPage(other.OnMasterPage),
00174        isEmbedded(other.isEmbedded),
00175 
00176        // protected
00177        undoManager(other.undoManager),
00178        AnName(other.AnName),
00179        patternVal(other.patternVal),
00180        patternScaleX(other.patternScaleX),
00181        patternScaleY(other.patternScaleY),
00182        patternOffsetX(other.patternOffsetX),
00183        patternOffsetY(other.patternOffsetY),
00184        patternRotation(other.patternRotation),
00185        fillColorVal(other.fillColorVal),
00186        lineColorVal(other.lineColorVal),
00187        lineShadeVal(other.lineShadeVal),
00188        fillShadeVal(other.fillShadeVal),
00189        fillTransparencyVal(other.fillTransparencyVal),
00190        lineTransparencyVal(other.lineTransparencyVal),
00191        fillBlendmodeVal(other.fillBlendmodeVal),
00192        lineBlendmodeVal(other.lineBlendmodeVal),
00193        m_ImageIsFlippedH(other.m_ImageIsFlippedH),
00194        m_ImageIsFlippedV(other.m_ImageIsFlippedV),
00195        m_Locked(other.m_Locked),
00196        m_SizeLocked(other.m_SizeLocked),
00197        textFlowModeVal(other.textFlowModeVal),
00198        pageItemAttributes(other.pageItemAttributes),
00199        m_PrintEnabled(other.m_PrintEnabled),
00200        tagged(other.tagged),
00201        fillQColor(other.fillQColor),
00202        strokeQColor(other.strokeQColor),
00203        Xpos(other.Xpos),
00204        Ypos(other.Ypos),
00205        Width(other.Width),
00206        Height(other.Height),
00207        Rot(other.Rot),
00208        Select(other.Select),
00209        LocalScX(other.LocalScX),
00210        LocalScY(other.LocalScY),
00211        LocalX(other.LocalX),
00212        LocalY(other.LocalY),
00213        Reverse(other.Reverse),
00214        m_startArrowIndex(other.m_startArrowIndex),
00215        m_endArrowIndex(other.m_endArrowIndex),
00216        Extra(other.Extra),
00217        TExtra(other.TExtra),
00218        BExtra(other.BExtra),
00219        RExtra(other.RExtra),
00220        RadRect(other.RadRect),
00221        oldXpos(other.oldXpos),
00222        oldYpos(other.oldYpos),
00223        oldWidth(other.oldWidth),
00224        oldHeight(other.oldHeight),
00225        oldRot(other.oldRot),
00226        oldLocalScX(other.oldLocalScX),
00227        oldLocalScY(other.oldLocalScY),
00228        oldLocalX(other.oldLocalX),
00229        oldLocalY(other.oldLocalY),
00230        m_Doc(other.m_Doc),
00231        m_isAnnotation(other.m_isAnnotation),
00232        m_annotation(other.m_annotation),
00233        PicArt(other.PicArt),
00234        m_lineWidth(other.m_lineWidth),
00235        Oldm_lineWidth(other.Oldm_lineWidth)
00236 {
00237        QString tmp;
00238        m_Doc->TotalItems++;
00239        AnName += tmp.setNum(m_Doc->TotalItems);
00240        uniqueNr = m_Doc->TotalItems;
00241        invalid = true;
00242 }
00243 
00244 
00245 PageItem::PageItem(ScribusDoc *pa, ItemType newType, double x, double y, double w, double h, double w2, QString fill, QString outline)
00246        // Initialize superclass(es)
00247        : QObject(pa),
00248        // Initialize member variables
00249        itemText(pa),
00250        undoManager(UndoManager::instance()),
00251        lineShadeVal(100),
00252        fillShadeVal(100),
00253        fillTransparencyVal(0.0),
00254        lineTransparencyVal(0.0),
00255        fillBlendmodeVal(0),
00256        lineBlendmodeVal(0),
00257        m_ImageIsFlippedH(0),
00258        m_ImageIsFlippedV(0),
00259        m_Locked(false),
00260        m_SizeLocked(false),
00261        textFlowModeVal(TextFlowDisabled)
00262 {
00263        QString tmp;
00264        BackBox = 0;
00265        NextBox = 0;
00266        oldXpos = Xpos = x;
00267        oldYpos = Ypos = y;
00268        //CB Surely we can remove some of these?
00269        OldB2 = OldB = oldWidth = Width = w;
00270        OldH2 = OldH = oldHeight = Height = h;
00271        BoundingX = x;
00272        BoundingY = y;
00273        BoundingW = w;
00274        BoundingH = h;
00275        m_ItemType = newType;
00276        oldRot = Rot = 0;
00277        m_Doc = pa;
00278        fillColorVal = fill;
00279        lineColorVal = m_ItemType == PageItem::TextFrame ? fill : outline;
00280        GrType = 0;
00281        GrStartX = 0;
00282        GrStartY = 0;
00283        GrEndX = w;
00284        GrEndY = 0;
00285        patternVal = "";
00286        patternScaleX = 100;
00287        patternScaleY = 100;
00288        patternOffsetX = 0;
00289        patternOffsetY = 0;
00290        patternRotation = 0;
00291        m_lineWidth = w2;
00292        Oldm_lineWidth = w2;
00293        PLineArt = PenStyle(m_Doc->toolSettings.dLineArt);
00294        PLineEnd = FlatCap;
00295        PLineJoin = MiterJoin;
00296        Select = false;
00297        ClipEdited = false;
00298        FrameType = 0;
00299        CurX = 0;
00300        CurY = 0;
00301        CPos = 0;
00302        Extra = 0;
00303        TExtra = 0;
00304        BExtra = 0;
00305        RExtra = 0;
00306        firstChar = 0;
00307        MaxChars = 0;
00308        Pfile = "";
00309        pixm = ScImage();
00310        pixm.imgInfo.lowResType = m_Doc->toolSettings.lowResType;
00311        Pfile2 = "";
00312        Pfile3 = "";
00313        oldLocalScX = LocalScX = 1;
00314        oldLocalScY = LocalScY = 1;
00315        OrigW = 0;
00316        OrigH = 0;
00317        oldLocalX = LocalX = 0;
00318        oldLocalY = LocalY = 0;
00319        BBoxX = 0;
00320        BBoxH = 0;
00321        RadRect = 0;
00322        if ((m_ItemType == TextFrame) || (m_ItemType == ImageFrame) || (m_ItemType == PathText))
00323               // TODO: Frame should become a read-only calculated property
00324               Frame = true;
00325        else
00326               Frame = false;
00327        switch (m_ItemType)
00328        {
00329               case Polygon:
00330                      Clip.setPoints(4, static_cast<int>(w/2), 0, static_cast<int>(w), static_cast<int>(h/2),
00331                                                         static_cast<int>(w/2), static_cast<int>(h), 0,static_cast<int>(h/2));
00332                      break;
00333               default:
00334                      Clip.setPoints(4, 0,0, static_cast<int>(w),0, static_cast<int>(w), static_cast<int>(h), 0,static_cast<int>(h));
00335                      break;
00336        }
00337        PoLine.resize(0);
00338        ContourLine.resize(0);
00339        imageClip.resize(0);
00340        Segments.clear();
00341        PoShow = false;
00342        BaseOffs = 0;
00343        textPathType = 0;
00344        textPathFlipped = false;
00345        OwnPage = m_Doc->currentPage()->pageNr();
00346        oldOwnPage = OwnPage;
00347        savedOwnPage = OwnPage;
00348        PicArt = true;
00349        PicAvail = false;
00350        m_PrintEnabled = true;
00351        isBookmark = false;
00352        m_isAnnotation = false;
00353        switch (m_ItemType)
00354        {
00355        case ImageFrame:
00356               AnName = tr("Image");
00357               setUPixmap(Um::IImageFrame);
00358               break;
00359        case TextFrame:
00360               AnName = tr("Text");
00361               setUPixmap(Um::ITextFrame);
00362               break;
00363        case Line:
00364               AnName = tr("Line");
00365               setUPixmap(Um::ILine);
00366               break;
00367        case Polygon:
00368               AnName = tr("Polygon");
00369               setUPixmap(Um::IPolygon);
00370               break;
00371        case PolyLine:
00372               AnName = tr("Polyline");
00373               setUPixmap(Um::IPolyline);
00374               break;
00375        case PathText:
00376               AnName = tr("PathText");
00377               setUPixmap(Um::IPathText);
00378               break;
00379        default:
00380               AnName = "Item";
00381               break;
00382        }
00383        m_Doc->TotalItems++;
00384        AnName += tmp.setNum(m_Doc->TotalItems); // +" "+QDateTime::currentDateTime().toString();
00385        uniqueNr = m_Doc->TotalItems;
00386        AutoName = true;
00387        setUName(AnName);
00388        m_annotation.setBorderColor(outline);
00389        HasSel = false;
00390 //     Tinput = false;
00391        isAutoText = false;
00392        inPdfArticle = false;
00393        isRaster = false;
00394        Sizing = false;
00395        toPixmap = false;
00396        UseEmbedded = true;
00397        IRender = 1;
00398        EmProfile = "";
00399        Groups.clear();
00400        LayerNr = m_Doc->activeLayer();
00401        ScaleType = true;
00402        AspectRatio = true;
00403        Reverse = false;
00404        NamedLStyle = "";
00405        DashValues.clear();
00406        DashOffset = 0;
00407        fillRule = true;
00408        doOverprint = false;
00409        fill_gradient = VGradient(VGradient::linear);
00410        fill_gradient.clearStops();
00411        if (fillColorVal != CommonStrings::None)
00412        {
00413               const ScColor& col = m_Doc->PageColors[fillColorVal];
00414               fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, fillColorVal, 100);
00415               fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, fillColorVal, 100);
00416        }
00417        else
00418        {
00419               if (m_Doc->toolSettings.dBrush != CommonStrings::None)
00420               {
00421                      const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dBrush];
00422                      fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
00423                      fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
00424               }
00425               else
00426               {
00427                      if (lineColorVal != CommonStrings::None)
00428                      {
00429                             const ScColor& col = m_Doc->PageColors[lineColorVal];
00430                             fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, lineColorVal, 100);
00431                             fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, lineColorVal, 100);
00432                      }
00433                      else
00434                      {
00435                             if (m_Doc->toolSettings.dPen != CommonStrings::None)
00436                             {
00437                                    const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dPen];
00438                                    fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
00439                                    fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
00440                             }
00441                      }
00442               }
00443        }
00444        Cols = m_Doc->toolSettings.dCols;
00445        ColGap = m_Doc->toolSettings.dGap;
00446        LeftLink = 0;
00447        RightLink = 0;
00448        TopLink = 0;
00449        BottomLink = 0;
00450        LeftLinkID = 0;
00451        RightLinkID = 0;
00452        TopLinkID = 0;
00453        BottomLinkID = 0;
00454        LeftLine = 0;
00455        RightLine = false;
00456        TopLine = false;
00457        BottomLine = false;
00458        isTableItem = false;
00459        isSingleSel = false;
00460        Dirty = false;
00461        invalid = true;
00462        isGroupControl = false;
00463        groupsLastItem = 0;
00464        ChangedMasterItem = false;
00465        isEmbedded = false;
00466        OnMasterPage = m_Doc->currentPage()->pageName();
00467        m_startArrowIndex = m_Doc->toolSettings.dStartArrow;
00468        m_endArrowIndex = m_Doc->toolSettings.dEndArrow;
00469        effectsInUse.clear();
00470        //Page Item Attributes
00471        pageItemAttributes.clear();
00472        for(ObjAttrVector::Iterator objAttrIt = m_Doc->docItemAttributes.begin() ; objAttrIt != m_Doc->docItemAttributes.end(); ++objAttrIt )
00473        {
00474               if (((*objAttrIt).autoaddto=="textframes" && m_ItemType==TextFrame) ||
00475                      ((*objAttrIt).autoaddto=="imageframes" && m_ItemType==ImageFrame)
00476                      )
00477                      pageItemAttributes.append(*objAttrIt);
00478        }
00479 }
00480 
00481 void PageItem::setXPos(const double newXPos, bool drawingOnly)
00482 {
00483        Xpos = newXPos;
00484        if (drawingOnly || m_Doc->isLoading())
00485               return;
00486        checkChanges();
00487        emit position(Xpos, Ypos);
00488 }
00489 
00490 void PageItem::setYPos(const double newYPos, bool drawingOnly)
00491 {
00492        Ypos = newYPos;
00493        if (drawingOnly || m_Doc->isLoading())
00494               return;
00495        checkChanges();
00496        emit position(Xpos, Ypos);
00497 }
00498 
00499 void PageItem::setXYPos(const double newXPos, const double newYPos, bool drawingOnly)
00500 {
00501        Xpos = newXPos;
00502        Ypos = newYPos;
00503        if (drawingOnly || m_Doc->isLoading())
00504               return;
00505        checkChanges();
00506        emit position(Xpos, Ypos);
00507 }
00508 
00509 void PageItem::moveBy(const double dX, const double dY, bool drawingOnly)
00510 {
00511        if (dX==0.0 && dY==0.0)
00512               return;
00513        if (dX!=0.0)
00514               Xpos+=dX;
00515        if (dY!=0.0)
00516               Ypos+=dY;
00517        if (drawingOnly || m_Doc->isLoading())
00518               return;
00519        checkChanges();
00520        emit position(Xpos, Ypos);
00521 }
00522 
00523 void PageItem::setWidth(const double newWidth)
00524 {
00525        Width = newWidth;
00526        checkChanges();
00527        emit widthAndHeight(Width, Height);
00528 }
00529 
00530 void PageItem::setHeight(const double newHeight)
00531 {
00532        Height = newHeight;
00533        checkChanges();
00534        emit widthAndHeight(Width, Height);
00535 }
00536 
00537 void PageItem::setWidthHeight(const double newWidth, const double newHeight, bool drawingOnly)
00538 {
00539        Width = newWidth;
00540        Height = newHeight;
00541        if (drawingOnly)
00542               return;
00543        checkChanges();
00544        emit widthAndHeight(Width, Height);
00545 }
00546 
00547 void PageItem::setWidthHeight(const double newWidth, const double newHeight)
00548 {
00549        Width = newWidth;
00550        Height = newHeight;
00551        checkChanges();
00552        emit widthAndHeight(Width, Height);
00553 }
00554 
00555 void PageItem::resizeBy(const double dH, const double dW)
00556 {
00557        if (dH==0.0 && dW==0.0)
00558               return;
00559        if (dH!=0.0)
00560               Width+=dH;
00561        if (dW!=0.0)
00562               Height+=dW;
00563        checkChanges();
00564        emit widthAndHeight(Width, Height);
00565 }
00566 
00567 void PageItem::setRotation(const double newRotation, bool drawingOnly)
00568 {
00569        Rot=newRotation;
00570        checkChanges();
00571        if (drawingOnly || m_Doc->isLoading())
00572               return;
00573        emit rotation(Rot);
00574 }
00575 
00576 void PageItem::rotateBy(const double dR)
00577 {
00578        if (dR==0.0)
00579               return;
00580        Rot+=dR;
00581        checkChanges();
00582        emit rotation(Rot);
00583 }
00584 
00585 void PageItem::setSelected(const bool toSelect)
00586 {
00587        Select=toSelect;
00588 }
00589 
00590 void PageItem::setImageXScale(const double newImageXScale)
00591 {
00592        LocalScX=newImageXScale;
00593        checkChanges();
00594        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00595 }
00596 
00597 void PageItem::setImageYScale(const double newImageYScale)
00598 {
00599        LocalScY=newImageYScale;
00600        checkChanges();
00601        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00602 }
00603 
00604 void PageItem::setImageXYScale(const double newImageXScale, const double newImageYScale)
00605 {
00606        LocalScX=newImageXScale;
00607        LocalScY=newImageYScale;
00608        checkChanges();
00609        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00610 }
00611 
00612 void PageItem::setImageXOffset(const double newImageXOffset)
00613 {
00614        LocalX=newImageXOffset;
00615        checkChanges();
00616        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00617 }
00618 
00619 void PageItem::setImageYOffset(const double newImageYOffset)
00620 {
00621        LocalY=newImageYOffset;
00622        checkChanges();
00623        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00624 }
00625 
00626 void PageItem::setImageXYOffset(const double newImageXOffset, const double newImageYOffset)
00627 {
00628        LocalX=newImageXOffset;
00629        LocalY=newImageYOffset;
00630        checkChanges();
00631        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00632 }
00633 
00634 void PageItem::moveImageXYOffsetBy(const double dX, const double dY)
00635 {
00636        if (dX==0.0 && dY==0.0)
00637               return;
00638        if (dX!=0.0)
00639               LocalX+=dX;
00640        if (dY!=0.0)
00641               LocalY+=dY;
00642        checkChanges();
00643        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00644 }
00645 
00646 void PageItem::setReversed(bool newReversed)
00647 {
00648        Reverse=newReversed;
00649 }
00650 
00651 
00653 bool PageItem::frameOverflows() const
00654 {
00655 #ifndef NLS_PROTO
00656        return NextBox == NULL && itemText.length() > static_cast<int>(MaxChars);
00657 #else
00658        return false; // FIXME:NLS
00659 #endif
00660 }
00661 
00662 int PageItem::firstInFrame() const
00663 {
00664        return firstChar;
00665 }
00666 int PageItem::lastInFrame() const
00667 {
00668 #ifndef NLS_PROTO
00669        return QMIN(signed(MaxChars), itemText.length()) - 1;
00670 #else
00671        return itemText.length() - 1;
00672 #endif
00673 }
00674 
00675 
00676 void PageItem::link(PageItem* nxt)
00677 {
00678        assert( !nextInChain() );
00679        assert( !nxt->prevInChain() );
00680        for (PageItem* ff=nxt; ff; ff=ff->nextInChain())
00681        {
00682               assert (ff != this);
00683        }
00684        itemText.append(nxt->itemText);
00685        NextBox = nxt;
00686        nxt->BackBox = this;
00687        // update AutoText
00688        if (isAutoText)
00689        {
00690               PageItem* after = nxt;
00691               while (after)
00692               {
00693                      after->isAutoText = true;
00694                      m_Doc->LastAuto = after;
00695                      after = after->NextBox;
00696               }
00697        }
00698        else if (nxt->isAutoText)
00699        {
00700               PageItem* before = this;
00701               while (before)
00702               {
00703                      before->isAutoText = true;
00704                      m_Doc->FirstAuto = before;
00705                      before = before->BackBox;
00706               }
00707        }
00708        invalid = true;
00709        while (nxt)
00710        {
00711               nxt->itemText = itemText;
00712               nxt->invalid = true;
00713               nxt->firstChar = 0;
00714               nxt = nxt->NextBox;
00715        }
00716 }
00717 
00718 void PageItem::unlink()
00719 {
00720        if( NextBox )
00721        {
00722               // make sure lastInFrame is valid
00723               layout();
00724               // move following text to new StoryText
00725               itemText.select(lastInFrame()+1, itemText.length()-lastInFrame()-1);
00726               StoryText follow(m_Doc);
00727               follow.setDefaultStyle(itemText.defaultStyle());
00728               follow.insert(0, itemText, true);
00729               // remove following text from this chain
00730               itemText.removeSelection();
00731               // update auto pointers
00732               if (isAutoText)
00733               {
00734                      PageItem* before = this;
00735                      while (before) 
00736                      {
00737                             before->isAutoText = false;
00738                             before = before->BackBox;
00739                      }
00740                      m_Doc->FirstAuto = NextBox;
00741               }
00742               // link following frames to new text
00743               NextBox->firstChar = 0;
00744               NextBox->BackBox = NULL;
00745               while (NextBox) {
00746                      NextBox->itemText = follow;
00747                      NextBox->invalid = true;
00748                      NextBox->firstChar = 0;
00749                      NextBox = NextBox->NextBox;
00750               }
00751               // NextBox == NULL now
00752        }
00753 }
00754 
00755 
00756 void PageItem::dropLinks()
00757 {
00758        // update auto pointers
00759        if (isAutoText && NextBox == 0)
00760        {
00761               m_Doc->LastAuto = BackBox;
00762        }
00763        if (isAutoText && BackBox == 0)
00764        {
00765               m_Doc->FirstAuto = NextBox;
00766        }
00767        isAutoText = false;
00768 
00769        // leave text in remaining chain
00770        PageItem* before = BackBox;
00771        PageItem* after = NextBox;
00772        if (after != 0 || before != 0)
00773        {
00774               itemText = StoryText(m_Doc);
00775               if (before)
00776                      before->NextBox = after;
00777               if (after) 
00778               {
00779                      after->BackBox = before;
00780                      while (after)
00781                      { 
00782                             after->invalid = true;
00783                             after->firstChar = 0;
00784                             after = after->NextBox;
00785                      }
00786               }
00787               // JG we should set BackBox and NextBox to NULL at a point
00788        }
00789 }
00790 
00792 bool PageItem::frameDisplays(int textpos) const
00793 {
00794 #ifndef NLS_PROTO
00795        return 0 <= textpos && textpos < signed(MaxChars) &&  textpos < itemText.length();
00796 #else
00797        return true; // FIXME:NLS
00798 #endif
00799 }
00800 
00801 
00803 const ParagraphStyle& PageItem::currentStyle() const
00804 {
00805        if (frameDisplays(CPos))
00806               return itemText.paragraphStyle(CPos);
00807        else
00808               return itemText.defaultStyle();
00809 }
00810 
00812 ParagraphStyle& PageItem::changeCurrentStyle()
00813 {
00814        if (frameDisplays(CPos))
00815               return const_cast<ParagraphStyle&>(itemText.paragraphStyle(CPos));
00816        else
00817               return const_cast<ParagraphStyle&>(itemText.defaultStyle());
00818 }
00819 
00821 const CharStyle& PageItem::currentCharStyle() const
00822 {
00823        if (frameDisplays(CPos))
00824               return itemText.charStyle(CPos);
00825        else
00826               return itemText.defaultStyle().charStyle();
00827 }
00828 
00829 void PageItem::setTextToFrameDistLeft(double newLeft)
00830 {
00831        Extra=newLeft;
00832        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00833 }
00834 
00835 void PageItem::setTextToFrameDistRight(double newRight)
00836 {
00837        RExtra=newRight;
00838        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00839 }
00840 
00841 void PageItem::setTextToFrameDistTop(double newTop)
00842 {
00843        TExtra=newTop;
00844        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00845 }
00846 
00847 void PageItem::setTextToFrameDistBottom(double newBottom)
00848 {
00849        BExtra=newBottom;
00850        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00851 }
00852 
00853 void PageItem::setTextToFrameDist(double newLeft, double newRight, double newTop, double newBottom)
00854 {
00855        Extra=newLeft;
00856        RExtra=newRight;
00857        TExtra=newTop;
00858        BExtra=newBottom;
00859        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00860 }
00861 
00862 double PageItem::gridOffset() const { return m_Doc->typographicSettings.offsetBaseGrid; }
00863 double PageItem::gridDistance() const { return m_Doc->typographicSettings.valueBaseGrid; }
00864 
00865 void PageItem::setGridOffset(double) { } // FIXME
00866 void PageItem::setGridDistance(double) { } // FIXME
00867 void PageItem::setColumns(int n) 
00868 {
00869        Cols = QMAX(1, n); //FIXME: undo
00870 }
00871 void PageItem::setColumnGap(double gap)
00872 {
00873        ColGap = gap; //FIXME: undo
00874 }
00875 
00876 void PageItem::setCornerRadius(double newRadius)
00877 {
00878        RadRect=newRadius;
00879        emit cornerRadius(RadRect);
00880 }
00881 
00882 
00883 
00884 
00885 
00886 
00887 
00888 
00889 
00891 void PageItem::DrawObj(ScPainter *p, QRect e)
00892 {
00893        double sc;
00894        if (!m_Doc->DoDrawing)
00895        {
00896 //            Tinput = false;
00897               return;
00898        }
00899        DrawObj_Pre(p, sc);
00900        if (m_Doc->layerOutline(LayerNr))
00901        {
00902               if ((itemType()==TextFrame || itemType()==ImageFrame || itemType()==PathText || itemType()==Line || itemType()==PolyLine) && (!isGroupControl))
00903                      DrawObj_Item(p, e, sc);
00904        }
00905        else
00906        {
00907               if (!isGroupControl)
00908                      DrawObj_Item(p, e, sc);
00909        }
00910        DrawObj_Post(p);
00911 }
00912 
00913 void PageItem::DrawObj_Pre(ScPainter *p, double &sc)
00914 {
00915        ScribusView* view = m_Doc->view();
00916        sc = view->scale();
00917        p->save();
00918        if (!isEmbedded)
00919        {
00920 #ifdef HAVE_CAIRO
00921               p->translate(Xpos, Ypos);
00922 #else
00923               p->setZoomFactor(sc);
00924               p->translate(Xpos*sc, Ypos*sc);
00925 #endif
00926        }
00927        p->rotate(Rot);
00928        if (m_Doc->layerOutline(LayerNr))
00929        {
00930               p->setPen(m_Doc->layerMarker(LayerNr), 1, SolidLine, FlatCap, MiterJoin);
00931               p->setFillMode(ScPainter::None);
00932               p->setBrushOpacity(1.0);
00933               p->setPenOpacity(1.0);
00934        }
00935        else
00936        {
00937        if (!isGroupControl)
00938        {
00939 #ifdef HAVE_CAIRO
00940 //#if CAIRO_VERSION > CAIRO_VERSION_ENCODE(1, 1, 6)
00941               if (fillBlendmode() != 0)
00942                      p->beginLayer(1.0 - fillTransparency(), fillBlendmode());
00943 //#endif
00944 #endif
00945 
00946               p->setLineWidth(m_lineWidth);
00947               if (GrType != 0)
00948               {
00949                      if (GrType == 8)
00950                      {
00951                             if ((patternVal.isEmpty()) || (!m_Doc->docPatterns.contains(patternVal)))
00952                             {
00953                                    p->fill_gradient = VGradient(VGradient::linear);
00954                                    if (fillColor() != CommonStrings::None)
00955                                    {
00956                                           p->setBrush(fillQColor);
00957                                           p->setFillMode(ScPainter::Solid);
00958                                    }
00959                                    else
00960                                           p->setFillMode(ScPainter::None);
00961                             }
00962                             else
00963                             {
00964 #ifdef HAVE_CAIRO
00965                                    p->setPattern(&m_Doc->docPatterns[patternVal], patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
00966 #else
00967                                    p->setPattern(&m_Doc->docPatterns[patternVal], patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation+Rot);
00968 #endif
00969                                    p->setFillMode(ScPainter::Pattern);
00970                             }
00971                      }
00972                      else
00973                      {
00974                             if (fill_gradient.Stops() < 2) // fall back to solid filling if there are not enough colorstops in the gradient.
00975                             {
00976                                    if (fillColor() != CommonStrings::None)
00977                                    {
00978                                           p->setBrush(fillQColor);
00979                                           p->setFillMode(ScPainter::Solid);
00980                                    }
00981                                    else
00982                                           p->setFillMode(ScPainter::None);
00983                             }
00984                             else
00985                             {
00986                                    p->setFillMode(ScPainter::Gradient);
00987                                    p->fill_gradient = fill_gradient;
00988                                    QWMatrix grm;
00989                                    grm.rotate(Rot);
00990                                    FPointArray gra;
00991                                    switch (GrType)
00992                                    {
00993                                           case 1:
00994                                           case 2:
00995                                           case 3:
00996                                           case 4:
00997                                           case 6:
00998 #ifdef HAVE_CAIRO
00999                                                  p->setGradient(VGradient::linear, FPoint(GrStartX, GrStartY), FPoint(GrEndX, GrEndY));
01000 #else
01001                                                  gra.setPoints(2, GrStartX, GrStartY, GrEndX, GrEndY);
01002                                                  gra.map(grm);
01003                                                  p->setGradient(VGradient::linear, gra.point(0), gra.point(1));
01004 #endif
01005                                                  break;
01006                                           case 5:
01007                                           case 7:
01008                                                  gra.setPoints(2, GrStartX, GrStartY, GrEndX, GrEndY);
01009                                                  p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
01010                                                  break;
01011                                    }
01012                             }
01013                      }
01014               }
01015               else
01016               {
01017                      p->fill_gradient = VGradient(VGradient::linear);
01018                      if (fillColor() != CommonStrings::None)
01019                      {
01020                             p->setBrush(fillQColor);
01021                             p->setFillMode(ScPainter::Solid);
01022                      }
01023                      else
01024                             p->setFillMode(ScPainter::None);
01025               }
01026               if (lineColor() != CommonStrings::None)
01027               {
01028                      if ((m_lineWidth == 0) && ! asLine())
01029                             p->setLineWidth(0);
01030                      else
01031                      {
01032                             p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin);
01033                             if (DashValues.count() != 0)
01034                                    p->setDash(DashValues, DashOffset);
01035                      }
01036               }
01037               else
01038                      p->setLineWidth(0);
01039               if (fillBlendmode() == 0)
01040                      p->setBrushOpacity(1.0 - fillTransparency());
01041               if (lineBlendmode() == 0)
01042                      p->setPenOpacity(1.0 - lineTransparency());
01043               p->setFillRule(fillRule);
01044               }
01045        }
01046 }
01047 
01048 void PageItem::DrawObj_Post(ScPainter *p)
01049 {
01050        bool doStroke=true;
01051        ScribusView* view = m_Doc->view();
01052        if (!isGroupControl)
01053        {
01054               if (m_Doc->layerOutline(LayerNr))
01055               {
01056                      if (itemType()!=Line)
01057                      {
01058                             p->setPen(m_Doc->layerMarker(LayerNr), 1, SolidLine, FlatCap, MiterJoin);
01059                             p->setFillMode(ScPainter::None);
01060                             p->setBrushOpacity(1.0);
01061                             p->setPenOpacity(1.0);
01062                             if (itemType()==PolyLine)
01063                                    p->setupPolygon(&PoLine, false);
01064                             else if (itemType() == PathText)
01065                             {
01066                                    if (PoShow)
01067                                           p->setupPolygon(&PoLine, false);
01068                                    else
01069                                           doStroke = false;
01070                             }
01071                             else
01072                                    p->setupPolygon(&PoLine);
01073                             if (doStroke)
01074                                    p->strokePath();
01075                             if (itemType()==ImageFrame)
01076                             {
01077                                    if (imageClip.size() != 0)
01078                                    {
01079                                           p->setupPolygon(&imageClip);
01080                                           p->strokePath();
01081                                    }
01082                             }
01083                      }
01084               }
01085               else
01086               {
01087 #ifdef HAVE_CAIRO
01088                      if (fillBlendmode() != 0)
01089                             p->endLayer();
01090 #endif
01091                      if (itemType()==PathText || itemType()==PolyLine || itemType()==Line)
01092                             doStroke=false;
01093                      if ((doStroke) && (!m_Doc->RePos))
01094                      {
01095 #ifdef HAVE_CAIRO
01096                             if (lineBlendmode() != 0)
01097                                    p->beginLayer(1.0 - lineTransparency(), lineBlendmode());
01098 #endif
01099                             if (lineColor() != CommonStrings::None)
01100                             {
01101                                    p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin);
01102                                    if (DashValues.count() != 0)
01103                                           p->setDash(DashValues, DashOffset);
01104                             }
01105                             else
01106                                    p->setLineWidth(0);
01107                             if (!isTableItem)
01108                             {
01109                                    p->setupPolygon(&PoLine);
01110                                    if (NamedLStyle.isEmpty())
01111                                           p->strokePath();
01112                                    else
01113                                    {
01114                                           multiLine ml = m_Doc->MLineStyles[NamedLStyle];
01115                                           QColor tmp;
01116                                           for (int it = ml.size()-1; it > -1; it--)
01117                                           {
01118                                                  struct SingleLine& sl = ml[it];
01119                                                  if ((!sl.Color != CommonStrings::None) && (sl.Width != 0))
01120                                                  {
01121                                                         SetFarbe(&tmp, sl.Color, sl.Shade);
01122                                                         p->setPen(tmp, sl.Width, static_cast<PenStyle>(sl.Dash), static_cast<PenCapStyle>(sl.LineEnd), static_cast<PenJoinStyle>(sl.LineJoin));
01123                                                         p->strokePath();
01124                                                  }
01125                                           }
01126                                    }
01127                             }
01128 #ifdef HAVE_CAIRO
01129                             if (lineBlendmode() != 0)
01130                                    p->endLayer();
01131 #endif
01132                      }
01133               }
01134        }
01135        if ((!isEmbedded) && (!m_Doc->RePos))
01136        {
01137               double scpInv = 1.0 / (QMAX(view->scale(), 1));
01138               if (!isGroupControl)
01139               {
01140                      if ((Frame) && (m_Doc->guidesSettings.framesShown) && ((itemType() == ImageFrame) || (itemType() == TextFrame) || (itemType() == PathText)))
01141                      {
01142                             p->setPen(PrefsManager::instance()->appPrefs.DFrameNormColor, scpInv, DotLine, FlatCap, MiterJoin);
01143                             if ((isBookmark) || (m_isAnnotation))
01144                                    p->setPen(PrefsManager::instance()->appPrefs.DFrameAnnotationColor, scpInv, DotLine, FlatCap, MiterJoin);
01145                             if ((BackBox != 0) || (NextBox != 0))
01146                                    p->setPen(PrefsManager::instance()->appPrefs.DFrameLinkColor, scpInv, SolidLine, FlatCap, MiterJoin);
01147                             if (m_Locked)
01148                                    p->setPen(PrefsManager::instance()->appPrefs.DFrameLockColor, scpInv, SolidLine, FlatCap, MiterJoin);
01149                             p->setFillMode(0);
01150                             if (itemType()==PathText)
01151                             {
01152                                    if (Clip.count() != 0)
01153                                    {
01154                                           FPointArray tclip;
01155                                           FPoint np = FPoint(Clip.point(0));
01156                                           tclip.resize(2);
01157                                           tclip.setPoint(0, np);
01158                                           tclip.setPoint(1, np);
01159                                           for (uint a = 1; a < Clip.size(); ++a)
01160                                           {
01161                                                  np = FPoint(Clip.point(a));
01162                                                  tclip.putPoints(tclip.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y());
01163                                           }
01164                                           np = FPoint(Clip.point(0));
01165                                           tclip.putPoints(tclip.size(), 2, np.x(), np.y(), np.x(), np.y());
01166                                           p->setupPolygon(&tclip);
01167                                    }
01168                             }
01169                             else
01170                                    p->setupPolygon(&PoLine);
01171                             p->strokePath();
01172                      }
01173               }
01174               if ((m_Doc->guidesSettings.framesShown) && textFlowUsesContourLine() && (ContourLine.size() != 0))
01175               {
01176                      p->setPen(lightGray, scpInv, DotLine, FlatCap, MiterJoin);
01177                      p->setupPolygon(&ContourLine);
01178                      p->strokePath();
01179               }
01180               if ((m_Doc->guidesSettings.layerMarkersShown) && (m_Doc->layerCount() > 1) && (!m_Doc->layerOutline(LayerNr)) && ((isGroupControl) || (Groups.count() == 0)))
01181               {
01182                      p->setPen(black, 0.5/ m_Doc->view()->scale(), SolidLine, FlatCap, MiterJoin);
01183                      p->setPenOpacity(1.0);
01184                      p->setBrush(m_Doc->layerMarker(LayerNr));
01185                      p->setBrushOpacity(1.0);
01186                      p->setFillMode(ScPainter::Solid);
01187                      double ofwh = 10;
01188                      double ofx = Width - ofwh/2;
01189                      double ofy = Height - ofwh*3;
01190                      p->drawRect(ofx, ofy, ofwh, ofwh);
01191               }
01192               //CB disabled for now
01193               //if (m_Doc->m_Selection->findItem(this)!=-1)
01194               //     drawLockedMarker(p);
01195        }
01196 //     Tinput = false;
01197        FrameOnly = false;
01198        p->restore();
01199 }
01200 
01201 void PageItem::DrawObj_Embedded(ScPainter *p, QRect e, const CharStyle& style, PageItem* cembedded)
01202 {
01203        if (!cembedded)
01204               return;
01205        if (!m_Doc->DoDrawing)
01206               return;
01207        QPtrList<PageItem> emG;
01208        QPtrStack<PageItem> groupStack;
01209        emG.clear();
01210        emG.append(cembedded);
01211        if (cembedded->Groups.count() != 0)
01212        {
01213               for (uint ga=0; ga<m_Doc->FrameItems.count(); ++ga)
01214               {
01215                      if (m_Doc->FrameItems.at(ga)->Groups.count() != 0)
01216                      {
01217                             if (m_Doc->FrameItems.at(ga)->Groups.top() == cembedded->Groups.top())
01218                             {
01219                                    if (m_Doc->FrameItems.at(ga)->ItemNr != cembedded->ItemNr)
01220                                    {
01221                                           if (emG.find(m_Doc->FrameItems.at(ga)) == -1)
01222                                                  emG.append(m_Doc->FrameItems.at(ga));
01223                                    }
01224                             }
01225                      }
01226               }
01227        }
01228        for (uint em = 0; em < emG.count(); ++em)
01229        {
01230               PageItem* embedded = emG.at(em);
01231               p->save();
01232               embedded->Xpos = Xpos + embedded->gXpos;
01233               embedded->Ypos = Ypos - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos;
01234 #ifdef HAVE_CAIRO
01235               p->translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0)));
01236               if (style.baselineOffset() != 0)
01237               {
01238                      p->translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0));
01239                      embedded->Ypos -= embedded->gHeight * (style.baselineOffset() / 1000.0);
01240               }
01241 #else
01242               p->translate(( embedded->gXpos * (style.scaleH() / 1000.0)) * p->zoomFactor(), (-(embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0)) * p->zoomFactor());
01243               if (style.baselineOffset() != 0)
01244               {
01245                      p->translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0) * p->zoomFactor());
01246                      embedded->Ypos -= embedded->gHeight * (style.baselineOffset() / 1000.0);
01247               }
01248 #endif
01249               p->scale(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
01250               if (embedded->isGroupControl)
01251               {
01252                      p->restore();
01253                      p->save();
01254 #ifdef HAVE_CAIRO
01255                      FPointArray cl = embedded->PoLine.copy();
01256                      QWMatrix mm;
01257                      mm.translate(embedded->Xpos-Xpos, embedded->Ypos-Ypos);
01258                      mm.rotate(embedded->rotation());
01259                      cl.map( mm );
01260                      p->beginLayer(1.0 - embedded->fillTransparency(), embedded->fillBlendmode(), &cl);
01261 #endif
01262                      groupStack.push(embedded->groupsLastItem);
01263                      continue;
01264               }
01265               embedded->Dirty = Dirty;
01266               embedded->invalid = invalid;
01267               double sc;
01268               double pws = embedded->m_lineWidth;
01269               embedded->DrawObj_Pre(p, sc);
01270               switch(embedded->itemType())
01271               {
01272                      case ImageFrame:
01273                      case TextFrame:
01274                      case Polygon:
01275                      case PathText:
01276                             embedded->DrawObj_Item(p, e, sc);
01277                             break;
01278                      case Line:
01279                      case PolyLine:
01280                             embedded->m_lineWidth = pws * QMIN(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
01281                             embedded->DrawObj_Item(p, e, sc);
01282                             break;
01283                      default:
01284                             break;
01285               }
01286               embedded->m_lineWidth = pws * QMIN(style.scaleH() / 1000.0, style.scaleV() / 1000.0);
01287               embedded->DrawObj_Post(p);
01288               p->restore();
01289               if (groupStack.count() != 0)
01290               {
01291                      while (embedded == groupStack.top())
01292                      {
01293 #ifdef HAVE_CAIRO
01294                             p->endLayer();
01295 #endif
01296                             p->restore();
01297                             groupStack.pop();
01298                      }
01299               }
01300               embedded->m_lineWidth = pws;
01301        }
01302 }
01303 
01304 
01305 void PageItem::paintObj(QRect e, QPixmap *ppX)
01306 {
01307        if (!m_Doc->DoDrawing)
01308        {
01309 //            Tinput = false;
01310               FrameOnly = false;
01311               return;
01312        }
01313        //qDebug("paintObj(QRect e, QPixmap *ppX)");
01314        QPainter p;
01315        ScribusView* view = m_Doc->view();
01316        double sc = view->scale();
01317        if (toPixmap)
01318               p.begin(ppX);
01319        else
01320               p.begin(view->viewport());
01321        if ((!toPixmap) && (!m_Doc->RePos))
01322        {
01323               if (!e.isEmpty())
01324                      p.setClipRect(e);
01325               else
01326               {
01327                      int x = view->contentsX();
01328                      int y = view->contentsY();
01329                      QPoint out = view->contentsToViewport(QPoint(x,y));
01330                      p.setClipRect(QRect(out.x(), out.y(), view->visibleWidth(), view->visibleWidth()));
01331               }
01332        }
01333        QPoint in  = QPoint(qRound((Xpos-m_Doc->minCanvasCoordinate.x())*sc), qRound((Ypos-m_Doc->minCanvasCoordinate.y())*sc));
01334        QPoint out = view->contentsToViewport(in);
01335        p.translate(out.x(), out.y());
01336        p.scale(sc, sc);
01337        p.rotate(Rot);
01338        if (Sizing)
01339        {
01340               p.setRasterOp(XorROP);
01341               p.setBrush(NoBrush);
01342               p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
01343               p.drawRect(0, 0, static_cast<int>(OldB), static_cast<int>(OldH));
01344               p.drawRect(0, 0, static_cast<int>(Width), static_cast<int>(Height));
01345               OldB = Width;
01346               OldH = Height;
01347        }
01348        if ((!FrameOnly) && (!m_Doc->RePos))
01349        {
01350               if (Select) // && (!Doc->EditClip))
01351               {
01352                      if (!m_Doc->m_Selection->isEmpty())
01353                      {
01354                             if (Groups.count() == 0)
01355                             {
01356                                    QPainter pr;
01357                                    pr.begin(view->viewport());
01358                                    pr.translate(out.x(), out.y());
01359                                    pr.rotate(Rot);
01360                                    if (m_Locked)
01361                                           pr.setPen(QPen(PrefsManager::instance()->appPrefs.DFrameLockColor, 1, SolidLine, FlatCap, MiterJoin));
01362                                    else
01363                                           pr.setPen(QPen(PrefsManager::instance()->appPrefs.DFrameColor, 1, DotLine, FlatCap, MiterJoin));
01364                                    pr.setBrush(NoBrush);
01365                                    int lw2 = 1;
01366                                    int lw = 1;
01367                                    PenCapStyle le = FlatCap;
01368                                    if (NamedLStyle.isEmpty())
01369                                    {
01370                                           lw2 = qRound(m_lineWidth * sc  / 2.0);
01371                                           lw = qRound(QMAX(m_lineWidth * sc, 1.0));
01372                                           le = PLineEnd;
01373                                    }
01374                                    else
01375                                    {
01376                                           multiLine ml = m_Doc->MLineStyles[NamedLStyle];
01377                                           lw2 = qRound(ml[ml.size()-1].Width * sc  / 2.0);
01378                                           lw = qRound(QMAX(ml[ml.size()-1].Width * sc, 1.0));
01379                                           le = static_cast<PenCapStyle>(ml[ml.size()-1].LineEnd);
01380                                    }
01381                                    if (asLine())
01382                                    {
01383                                           if (le != FlatCap)
01384                                                  pr.drawRect(-lw2, -lw2, qRound(Width*sc)+lw, lw);
01385                                           else
01386                                                  pr.drawRect(-1, -lw2, qRound(Width*sc), lw);
01387                                    }
01388                                    else
01389                                           pr.drawRect(-1, -1, qRound(Width*sc)+2, qRound(Height*sc)+2);
01390                                    pr.setPen(QPen(PrefsManager::instance()->appPrefs.DFrameColor, 1, SolidLine, FlatCap, MiterJoin));
01391                                    pr.setBrush(PrefsManager::instance()->appPrefs.DFrameColor);
01392                                    if ((!m_Locked) && (!m_SizeLocked))
01393                                    {
01394                                           if (! asLine())
01395                                           {
01396                                                  pr.drawRect(-1, -1, 6, 6);
01397                                                  pr.drawRect(qRound(Width*sc), qRound(Height*sc), -6, -6);
01398                                                  pr.drawRect(qRound(Width*sc), -1, -6, 6);
01399                                                  pr.drawRect(-1, qRound(Height*sc), 6, -6);
01400                                                  if (Width > 6)
01401                                                  {
01402                                                         pr.drawRect(qRound(Width/2*sc - 3), qRound(Height*sc), 6, -6);
01403                                                         pr.drawRect(qRound(Width/2*sc - 3), -1, 6, 6);
01404                                                  }
01405                                                  if (Height > 6)
01406                                                  {
01407                                                         pr.drawRect(qRound(Width*sc), qRound(Height/2*sc - 3), -6, 6);
01408                                                         pr.drawRect(-1, qRound(Height/2*sc - 3), 6, 6);
01409                                                  }
01410                                           }
01411                                           else
01412                                           {
01413                                                  pr.drawRect(-3, -3, 6, 6);
01414                                                  pr.drawRect(qRound(Width*sc)+3, -3, -6, 6);
01415                                           }
01416                                    }
01417                                    pr.end();
01418                             }
01419                             else
01420                             {
01421                                    p.setPen(QPen(PrefsManager::instance()->appPrefs.DFrameGroupColor, 1, DotLine, FlatCap, MiterJoin));
01422                                    p.setBrush(NoBrush);
01423                                    p.drawRect(-1, -1, static_cast<int>(Width+2), static_cast<int>(Height+2));
01424                                    if (m_Doc->m_Selection->count() == 1)
01425                                    {
01426                                           QPainter pr;
01427                                           pr.begin(view->viewport());
01428                                           pr.translate(out.x(), out.y());
01429                                           pr.rotate(Rot);
01430                                           pr.setPen(QPen(PrefsManager::instance()->appPrefs.DFrameGroupColor, 1, SolidLine, FlatCap, MiterJoin));
01431                                           pr.setBrush(PrefsManager::instance()->appPrefs.DFrameGroupColor);
01432                                           pr.drawRect(-1, -1, 6, 6);
01433                                           pr.drawRect(static_cast<int>(Width*sc), static_cast<int>(Height*sc), -6, -6);
01434                                           pr.drawRect(static_cast<int>(Width*sc), -1, -6, 6);
01435                                           pr.drawRect(-1, static_cast<int>(Height*sc), 6, -6);
01436                                           if (Width > 6)
01437                                           {
01438                                                  pr.drawRect(static_cast<int>(Width/2*sc - 3), static_cast<int>(Height*sc), 6, -6);
01439                                                  pr.drawRect(static_cast<int>(Width/2*sc - 3), -1, 6, 6);
01440                                           }
01441                                           if (Height > 6)
01442                                           {
01443                                                  pr.drawRect(static_cast<int>(Width*sc), static_cast<int>(Height/2*sc - 3), -6, 6);
01444                                                  pr.drawRect(-1, static_cast<int>(Height/2*sc - 3), 6, 6);
01445                                           }
01446                                           pr.end();
01447                                    }
01448                             }
01449                      }
01450               }
01451               //if (m_Doc->m_Selection->findItem(this)!=-1)
01452               //     drawLockedMarker(p);
01453        }
01454 //     Tinput = false;
01455        FrameOnly = false;
01456        p.end();
01457 //     checkChanges(); // Check changes for undo actions
01458 }
01459 
01460 QImage PageItem::DrawObj_toImage()
01461 {
01462        QPtrList<PageItem> emG;
01463        emG.clear();
01464        double minx = 99999.9;
01465        double miny = 99999.9;
01466        double maxx = -99999.9;
01467        double maxy = -99999.9;
01468        if (Groups.count() != 0)
01469        {
01470               for (uint ga=0; ga<m_Doc->Items->count(); ++ga)
01471               {
01472                      if (m_Doc->Items->at(ga)->Groups.count() != 0)
01473                      {
01474                             if (m_Doc->Items->at(ga)->Groups.top() == Groups.top())
01475                             {
01476                                    if (emG.find(m_Doc->Items->at(ga)) == -1)
01477                                    {
01478                                           emG.append(m_Doc->Items->at(ga));
01479                                           PageItem *currItem = m_Doc->Items->at(ga);
01480                                           if (currItem->rotation() != 0)
01481                                           {
01482                                                  FPointArray pb(4);
01483                                                  pb.setPoint(0, FPoint(currItem->xPos(), currItem->yPos()));
01484                                                  pb.setPoint(1, FPoint(currItem->width(), 0.0, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1.0, 1.0));
01485                                                  pb.setPoint(2, FPoint(currItem->width(), currItem->height(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1.0, 1.0));
01486                                                  pb.setPoint(3, FPoint(0.0, currItem->height(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1.0, 1.0));
01487                                                  for (uint pc = 0; pc < 4; ++pc)
01488                                                  {
01489                                                         minx = QMIN(minx, pb.point(pc).x());
01490                                                         miny = QMIN(miny, pb.point(pc).y());
01491                                                         maxx = QMAX(maxx, pb.point(pc).x());
01492                                                         maxy = QMAX(maxy, pb.point(pc).y());
01493                                                  }
01494                                           }
01495                                           else
01496                                           {
01497                                                  minx = QMIN(minx, currItem->xPos());
01498                                                  miny = QMIN(miny, currItem->yPos());
01499                                                  maxx = QMAX(maxx, currItem->xPos() + currItem->width());
01500                                                  maxy = QMAX(maxy, currItem->yPos() + currItem->height());
01501                                           }
01502                                    }
01503                             }
01504                      }
01505               }
01506               for (uint em = 0; em < emG.count(); ++em)
01507               {
01508                      PageItem* currItem = emG.at(em);
01509                      currItem->gXpos = currItem->xPos() - minx;
01510                      currItem->gYpos = currItem->yPos() - miny;
01511                      currItem->gWidth = maxx - minx;
01512                      currItem->gHeight = maxy - miny;
01513               }
01514        }
01515        else
01516        {
01517               if (rotation() != 0)
01518               {
01519                      FPointArray pb(4);
01520                      pb.setPoint(0, FPoint(xPos(), yPos()));
01521                      pb.setPoint(1, FPoint(width(), 0.0, xPos(), yPos(), rotation(), 1.0, 1.0));
01522                      pb.setPoint(2, FPoint(width(), height(), xPos(), yPos(), rotation(), 1.0, 1.0));
01523                      pb.setPoint(3, FPoint(0.0, height(), xPos(), yPos(), rotation(), 1.0, 1.0));
01524                      for (uint pc = 0; pc < 4; ++pc)
01525                      {
01526                             minx = QMIN(minx, pb.point(pc).x());
01527                             miny = QMIN(miny, pb.point(pc).y());
01528                             maxx = QMAX(maxx, pb.point(pc).x());
01529                             maxy = QMAX(maxy, pb.point(pc).y());
01530                      }
01531               }
01532               else
01533               {
01534                      minx = QMIN(minx, xPos());
01535                      miny = QMIN(miny, yPos());
01536                      maxx = QMAX(maxx, xPos() + width());
01537                      maxy = QMAX(maxy, yPos() + height());
01538               }
01539               gXpos = xPos() - minx;
01540               gYpos = yPos() - miny;
01541               gWidth = maxx - minx;
01542               gHeight = maxy - miny;
01543               emG.append(this);
01544        }
01545        return DrawObj_toImage(emG);
01546 }
01547 
01548 QImage PageItem::DrawObj_toImage(QPtrList<PageItem> &emG)
01549 {
01550        QImage retImg = QImage(qRound(gWidth), qRound(gHeight), 32);
01551        retImg.fill( qRgba(255, 255, 255, 0) );
01552        ScPainter *painter = new ScPainter(&retImg, retImg.width(), retImg.height(), 1.0, 0);
01553        painter->setZoomFactor(1.0);
01554        QPtrStack<PageItem> groupStack;
01555        QPtrStack<PageItem> groupClips;
01556        for (uint em = 0; em < emG.count(); ++em)
01557        {
01558               PageItem* embedded = emG.at(em);
01559               if (embedded->isGroupControl)
01560               {
01561 #ifdef HAVE_CAIRO
01562                      FPointArray cl = embedded->PoLine.copy();
01563                      QWMatrix mm;
01564                      mm.translate(embedded->gXpos, embedded->gYpos);
01565                      mm.rotate(embedded->rotation());
01566                      cl.map( mm );
01567                      painter->beginLayer(1.0 - embedded->fillTransparency(), embedded->fillBlendmode(), &cl);
01568 #endif
01569                      groupClips.push(embedded);
01570                      groupStack.push(embedded->groupsLastItem);
01571                      continue;
01572               }
01573               painter->save();
01574               double x = embedded->xPos();
01575               double y = embedded->yPos();
01576               embedded->Xpos = embedded->gXpos;
01577               embedded->Ypos = embedded->gYpos;
01578               painter->translate(embedded->gXpos, embedded->gYpos);
01579               embedded->isEmbedded = true;
01580               embedded->invalid = true;
01581               embedded->DrawObj(painter, QRect(0, 0, retImg.width(), retImg.height()));
01582               embedded->Xpos = x;
01583               embedded->Ypos = y;
01584               embedded->isEmbedded = false;
01585               painter->restore();
01586               if (groupStack.count() != 0)
01587               {
01588                      while (embedded == groupStack.top())
01589                      {
01590 //                          PageItem *tmpItem = groupClips.pop();
01591 //                          FPointArray cl = tmpItem->PoLine.copy();
01592 //                          QWMatrix mm;
01593 //                          mm.translate(tmpItem->gXpos, tmpItem->gYpos);
01594 //                          mm.rotate(tmpItem->rotation());
01595 //                          cl.map( mm );
01596 #ifdef HAVE_CAIRO
01597                             painter->endLayer();
01598 #endif
01599                             painter->restore();
01600                             groupStack.pop();
01601                      }
01602               }
01603        }
01604        painter->end();
01605        delete painter;
01606        return retImg;
01607 }
01608 
01609 QString PageItem::ExpandToken(uint base)
01610 {
01611        uint zae = 0;
01612        QChar ch = itemText.text(base);
01613        QString chstr = ch;
01614        if (ch == SpecialChars::PAGENUMBER) {
01615               // compatibility mode: ignore subsequent pagenumber chars
01616               if (base > 0 && itemText.text(base-1) == SpecialChars::PAGENUMBER) {
01617                      return "";
01618               }
01619               if ((!m_Doc->masterPageMode()) && (OwnPage != -1))
01620               {
01621                      QString out("%1");
01622                      //CB Section numbering
01623                      chstr = out.arg(m_Doc->getSectionPageNumberForPageIndex(OwnPage), -(int)zae);
01624               }
01625               else 
01626                      return "#";
01627        }
01628        return chstr;
01629 }
01630 
01631 void PageItem::SetFarbe(QColor *tmp, QString farbe, int shad)
01632 {
01633        const ScColor& col = m_Doc->PageColors[farbe];
01634        *tmp = ScColorEngine::getShadeColorProof(col, m_Doc, shad);
01635        if ((m_Doc->view()) && (m_Doc->view()->viewAsPreview) && (m_Doc->view()->previewVisual != 0))
01636        {
01637               VisionDefectColor *defect = new VisionDefectColor();
01638               *tmp = defect->convertDefect(*tmp, m_Doc->view()->previewVisual);
01639               delete defect;
01640        }
01641 }
01642 
01653 double PageItem::layoutGlyphs(const CharStyle& style, const QString chars, GlyphLayout& layout)
01654 {
01655        double retval = 0.0;
01656        double asce = style.font().ascent(style.fontSize() / 10.0);
01657        int chst = style.effects() & 1919;
01658 /*     if (chars[0] == SpecialChars::ZWSPACE ||
01659               chars[0] == SpecialChars::ZWNBSPACE ||
01660               chars[0] == SpecialChars::NBSPACE ||
01661               chars[0] == SpecialChars::NBHYPHEN ||
01662               chars[0] == SpecialChars::SHYPHEN ||
01663               chars[0] == SpecialChars::PARSEP ||
01664               chars[0] == SpecialChars::COLBREAK ||
01665               chars[0] == SpecialChars::LINEBREAK ||
01666               chars[0] == SpecialChars::FRAMEBREAK ||
01667               chars[0] == SpecialChars::TAB)
01668        {
01669               layout.glyph = ScFace::CONTROL_GLYPHS + chars[0].unicode();
01670        }
01671        else */
01672        {
01673               layout.glyph = style.font().char2CMap(chars[0].unicode());
01674        }
01675        
01676        double tracking = 0.0;
01677        if ( (style.effects() & ScStyle_StartOfLine) == 0)
01678               tracking = style.fontSize() * style.tracking() / 10000.0;
01679 
01680        layout.xoffset = tracking;
01681        layout.yoffset = 0;
01682        if (chst != ScStyle_Default)
01683        {
01684               if (chst & ScStyle_Superscript)
01685               {
01686                      retval -= asce * m_Doc->typographicSettings.valueSuperScript / 100.0;
01687                      layout.yoffset -= asce * m_Doc->typographicSettings.valueSuperScript / 100.0;
01688                      layout.scaleV = layout.scaleH = QMAX(m_Doc->typographicSettings.scalingSuperScript / 100.0, 10.0 / style.fontSize());
01689               }
01690               else if (chst & ScStyle_Subscript)
01691               {
01692                      retval += asce * m_Doc->typographicSettings.valueSubScript / 100.0;
01693                      layout.yoffset += asce * m_Doc->typographicSettings.valueSubScript / 100.0;
01694                      layout.scaleV = layout.scaleH = QMAX(m_Doc->typographicSettings.scalingSubScript / 100.0, 10.0 / style.fontSize());
01695               }
01696               else {
01697                      layout.scaleV = layout.scaleH = 1.0;
01698               }
01699               layout.scaleH *= style.scaleH() / 1000.0;
01700               layout.scaleV *= style.scaleV() / 1000.0;
01701               if (chst & ScStyle_AllCaps)
01702               {
01703                      layout.glyph = style.font().char2CMap(chars[0].upper().unicode());
01704               }
01705               if (chst & ScStyle_SmallCaps)
01706               {
01707                      double smallcapsScale = m_Doc->typographicSettings.valueSmallCaps / 100.0;
01708                      QChar uc = chars[0].upper();
01709                      if (uc != chars[0])
01710                      {
01711                             layout.glyph = style.font().char2CMap(chars[0].upper().unicode());
01712                             layout.scaleV *= smallcapsScale;
01713                             layout.scaleH *= smallcapsScale;
01714                      }
01715               }
01716        }
01717        else {
01718               layout.scaleH = style.scaleH() / 1000.0;
01719               layout.scaleV = style.scaleV() / 1000.0;
01720        }      
01721        
01722 /*     if (layout.glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBSPACE.unicode())) {
01723               uint replGlyph = style.font().char2CMap(QChar(' '));
01724               layout.xadvance = style.font().glyphWidth(replGlyph, style.fontSize() / 10) * layout.scaleH;
01725               layout.yadvance = style.font().glyphBBox(replGlyph, style.fontSize() / 10).ascent * layout.scaleV;
01726        }
01727        else if (layout.glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBHYPHEN.unicode())) {
01728               uint replGlyph = style.font().char2CMap(QChar('-'));
01729               layout.xadvance = style.font().glyphWidth(replGlyph, style.fontSize() / 10) * layout.scaleH;
01730               layout.yadvance = style.font().glyphBBox(replGlyph, style.fontSize() / 10).ascent * layout.scaleV;
01731        }
01732        else if (layout.glyph >= ScFace::CONTROL_GLYPHS) {
01733               layout.xadvance = 0;
01734               layout.yadvance = 0;
01735        }
01736        else */
01737        {
01738               layout.xadvance = style.font().glyphWidth(layout.glyph, style.fontSize() / 10) * layout.scaleH;
01739               layout.yadvance = style.font().glyphBBox(layout.glyph, style.fontSize() / 10).ascent * layout.scaleV;
01740        }
01741        if (layout.xadvance > 0)
01742               layout.xadvance += tracking;
01743 
01744        if (chars.length() > 1) {
01745               layout.grow();
01746               layoutGlyphs(style, chars.mid(1), *layout.more);
01747               layout.xadvance += style.font().glyphKerning(layout.glyph, layout.more->glyph, style.fontSize() / 10) * layout.scaleH;
01748               if (layout.more->yadvance > layout.yadvance)
01749                      layout.yadvance = layout.more->yadvance;
01750        }
01751        else {
01752               layout.shrink();
01753        }
01754        return retval;
01755 }
01756 
01757 void PageItem::drawGlyphs(ScPainter *p, const CharStyle& style, GlyphLayout& glyphs)
01758 {
01759        uint glyph = glyphs.glyph;
01760        if ((m_Doc->guidesSettings.showControls) && 
01761               (glyph == style.font().char2CMap(QChar(' ')) || glyph >=  ScFace::CONTROL_GLYPHS))
01762        {
01763               bool stroke = false;
01764               if (glyph >=  ScFace::CONTROL_GLYPHS)
01765                      glyph -= ScFace::CONTROL_GLYPHS;
01766               else
01767                      glyph = 32;
01768               QWMatrix chma, chma4, chma5;
01769               FPointArray points;
01770               if (glyph == SpecialChars::TAB.unicode())
01771               {
01772                      points = m_Doc->symTab.copy();
01773                      chma4.translate(glyphs.xoffset + glyphs.xadvance - ((style.fontSize() / 10.0) * glyphs.scaleH * 0.7), glyphs.yoffset - ((style.fontSize() / 10.0) * glyphs.scaleV * 0.5));
01774               }
01775               else if (glyph == SpecialChars::COLBREAK.unicode())
01776               {
01777                      points = m_Doc->symNewCol.copy();
01778                      chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.6));
01779               }
01780               else if (glyph == SpecialChars::FRAMEBREAK.unicode())
01781               {
01782                      points = m_Doc->symNewFrame.copy();
01783                      chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.6));
01784               }
01785               else if (glyph == SpecialChars::PARSEP.unicode())
01786               {
01787                      points = m_Doc->symReturn.copy();
01788                      chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.8));
01789               }
01790               else if (glyph == SpecialChars::LINEBREAK.unicode())
01791               {
01792                      points = m_Doc->symNewLine.copy();
01793                      chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.4));
01794               }
01795               else if (glyph == SpecialChars::NBSPACE.unicode() ||
01796                              glyph == 32)
01797               {
01798                      stroke = (glyph == 32);
01799                      points = m_Doc->symNonBreak.copy();
01800                      chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV * 0.4));
01801               }
01802               else if (glyph == SpecialChars::NBHYPHEN.unicode())
01803               {
01804                      points = style.font().glyphOutline(style.font().char2CMap(QChar('-')), style.fontSize() / 100);
01805                      chma4.translate(glyphs.xoffset, glyphs.yoffset-((style.fontSize() / 10.0) * glyphs.scaleV));
01806               }
01807               else if (glyph == SpecialChars::SHYPHEN.unicode())
01808               {
01809                      points.resize(0);
01810                      points.addQuadPoint(0, -10, 0, -10, 0, -6, 0, -6);
01811                      stroke = true;
01812               }
01813               else // ???
01814               {
01815                      points.resize(0);
01816                      points.addQuadPoint(0, -10, 0, -10, 0, -9, 0, -9);                    
01817                      points.addQuadPoint(0, -9, 0, -9, 1, -9, 1, -9);               
01818                      points.addQuadPoint(1, -9, 1, -9, 1, -10, 1, -10);                    
01819                      points.addQuadPoint(1, -10, 1, -10, 0, -10, 0, -10);                  
01820               }
01821               chma.scale(glyphs.scaleH * style.fontSize() / 100.0, glyphs.scaleV * style.fontSize() / 100.0);
01822 #ifdef HAVE_CAIRO
01823               points.map(chma * chma4);
01824 #else
01825               chma5.scale(p->zoomFactor(), p->zoomFactor());
01826               points.map(chma * chma4 * chma5);
01827 #endif
01828               p->setupTextPolygon(&points);
01829               QColor oldBrush = p->brush();
01830               p->setBrush( (style.effects() & ScStyle_SuppressSpace) ? Qt::green
01831                                    : PrefsManager::instance()->appPrefs.DControlCharColor);
01832               if (stroke)
01833               {
01834                      QColor tmp = p->pen();
01835                      p->setPen(p->brush(), 1, SolidLine, FlatCap, MiterJoin);
01836                      p->setLineWidth(style.fontSize() * glyphs.scaleV / 200.0);
01837                      p->strokePath();
01838                      p->setPen(tmp, 1, SolidLine, FlatCap, MiterJoin);
01839               }
01840               else
01841               {
01842                      p->setFillMode(1);
01843                      p->fillPath();
01844               }
01845               p->setBrush(oldBrush);
01846               if (glyphs.more)
01847               {
01848 #ifdef HAVE_CAIRO
01849                      p->translate(glyphs.xadvance, 0);
01850 #else
01851                      p->translate(glyphs.xadvance * p->zoomFactor(), 0);
01852 #endif
01853                      drawGlyphs(p, style, *glyphs.more);
01854               }                    
01855               return;
01856        }
01857        else if (glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBSPACE.unicode()) ||
01858                       glyph == (ScFace::CONTROL_GLYPHS + 32)) 
01859               glyph = style.font().char2CMap(QChar(' '));
01860        else if (glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBHYPHEN.unicode()))
01861               glyph = style.font().char2CMap(QChar('-'));
01862        
01863        if (glyph >= ScFace::CONTROL_GLYPHS) {
01864 //            qDebug(QString("drawGlyphs: skipping %1").arg(glyph));
01865               // all those are empty
01866               if (glyphs.more)
01867               {
01868 #ifdef HAVE_CAIRO
01869                      p->translate(glyphs.xadvance, 0);
01870 #else
01871                      p->translate(glyphs.xadvance * p->zoomFactor(), 0);
01872 #endif
01873                      drawGlyphs(p, style, *glyphs.more);
01874               }                    
01875               return;
01876        }
01877 //     if (style.font().canRender(QChar(glyph)))
01878        {
01879               FPointArray gly = style.font().glyphOutline(glyph);
01880               // Do underlining first so you can get typographically correct
01881               // underlines when drawing a white outline
01882               if ((style.effects() & ScStyle_Underline) || ((style.effects() & ScStyle_UnderlineWords) && glyph != style.font().char2CMap(QChar(' '))))
01883               {
01884                      double st, lw;
01885                      if ((style.underlineOffset() != -1) || (style.underlineWidth() != -1))
01886                      {
01887                             if (style.underlineOffset() != -1)
01888                                    st = (style.underlineOffset() / 1000.0) * (style.font().descent(style.fontSize() / 10.0));
01889                             else
01890                                    st = style.font().underlinePos(style.fontSize() / 10.0);
01891                             if (style.underlineWidth() != -1)
01892                                    lw = (style.underlineWidth() / 1000.0) * (style.fontSize() / 10.0);
01893                             else
01894                                    lw = QMAX(style.font().strokeWidth(style.fontSize() / 10.0), 1);
01895                      }
01896                      else
01897                      {
01898                             st = style.font().underlinePos(style.fontSize() / 10.0);
01899                             lw = QMAX(style.font().strokeWidth(style.fontSize() / 10.0), 1);
01900                      }
01901                      if (style.baselineOffset() != 0)
01902                             st += (style.fontSize() / 10.0) * glyphs.scaleV * (style.baselineOffset() / 1000.0);
01903                      QColor tmpC = p->pen();
01904                      p->setPen(p->brush());
01905                      p->setLineWidth(lw);
01906                      if (style.effects() & ScStyle_Subscript)
01907                             p->drawLine(FPoint(glyphs.xoffset, glyphs.yoffset - st), FPoint(glyphs.xoffset + glyphs.xadvance, glyphs.yoffset - st));
01908                      else
01909                             p->drawLine(FPoint(glyphs.xoffset, -st), FPoint(glyphs.xoffset + glyphs.xadvance, -st));
01910                      p->setPen(tmpC);
01911               }
01912               if (gly.size() > 3)
01913               {
01914                      if (glyph == 0)
01915                      {
01916 //                          qDebug(QString("glyph 0: (%1,%2) * %3 %4 + %5").arg(glyphs.xoffset).arg(glyphs.yoffset).arg(glyphs.scaleH).arg(glyphs.scaleV).arg(glyphs.xadvance));
01917                      }
01918 #ifdef HAVE_CAIRO
01919                      p->save();
01920                      p->translate(glyphs.xoffset, glyphs.yoffset - ((style.fontSize() / 10.0) * glyphs.scaleV));
01921                      if (Reverse)
01922                      {
01923                             p->scale(-1, 1);
01924                             p->translate(-glyphs.xadvance, 0);
01925                      }
01926                      if (style.baselineOffset() != 0)
01927                             p->translate(0, -(style.fontSize() / 10.0) * (style.baselineOffset() / 1000.0));
01928                      double glxSc = glyphs.scaleH * style.fontSize() / 100.00;
01929                      double glySc = glyphs.scaleV * style.fontSize() / 100.0;
01930                      p->scale(glxSc, glySc);
01931 #else
01932                      QWMatrix chma, chma2, chma3, chma4, chma5, chma6;
01933                      chma.scale(glyphs.scaleH * style.fontSize() / 100.00, glyphs.scaleV * style.fontSize() / 100.0);
01934                      chma5.scale(p->zoomFactor(), p->zoomFactor());
01935                      if (Reverse)
01936                      {
01937                             chma3.scale(-1, 1);
01938                             chma3.translate(-glyphs.xadvance, 0);
01939                      }
01940                      chma4.translate(glyphs.xoffset, glyphs.yoffset - ((style.fontSize() / 10.0) * glyphs.scaleV));
01941                      if (style.baselineOffset() != 0)
01942                             chma6.translate(0, -(style.fontSize() / 10.0) * (style.baselineOffset() / 1000.0) * p->zoomFactor());
01943                      gly.map(chma * chma3 * chma4 * chma5 * chma6);
01944 #endif
01945                      p->setFillMode(1);
01946                      bool fr = p->fillRule();
01947                      p->setFillRule(false);
01948 //                   double a = gly.point(0).x();
01949 //                   double b = gly.point(0).y();
01950 //                   double c = gly.point(3).x();
01951 //                   double d = gly.point(3).y();
01952 //                   qDebug(QString("drawglyphs: %1 (%2,%3) (%4,%5) scaled %6,%7 trans %8,%9")
01953 //                             .arg(gly.size()).arg(a).arg(b).arg(c).arg(d)
01954 //                             .arg(p->worldMatrix().m11()).arg(p->worldMatrix().m22()).arg(p->worldMatrix().dx()).arg(p->worldMatrix().dy()));
01955                      p->setupTextPolygon(&gly);
01956                      if (m_Doc->layerOutline(LayerNr))
01957                      {
01958                             p->save();
01959                             p->setPen(m_Doc->layerMarker(LayerNr), 0.5, SolidLine, FlatCap, MiterJoin);
01960                             p->setFillMode(ScPainter::None);
01961                             p->setBrushOpacity(1.0);
01962                             p->setPenOpacity(1.0);
01963                             p->strokePath();
01964                             p->restore();
01965                             p->setFillRule(fr);
01966 #ifdef HAVE_CAIRO
01967                             p->restore();
01968 #endif
01969                             if (glyphs.more)
01970                             {
01971 #ifdef HAVE_CAIRO
01972                                    p->translate(glyphs.xadvance, 0);
01973 #else
01974                                    p->translate(glyphs.xadvance * p->zoomFactor(), 0);
01975 #endif
01976                                    drawGlyphs(p, style, *glyphs.more);
01977                             }
01978                             return;
01979                      }
01980                      if (glyph == 0)
01981                      {
01982                             p->setPen(PrefsManager::instance()->appPrefs.DControlCharColor, 1, SolidLine, FlatCap, MiterJoin);
01983                             p->setLineWidth(style.fontSize() * glyphs.scaleV * style.outlineWidth() * 2 / 10000.0);
01984                             p->strokePath();
01985                      }
01986                      else if ((style.font().isStroked()) && ((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) != 0))
01987                      {
01988                             QColor tmp = p->brush();
01989                             p->setPen(tmp, 1, SolidLine, FlatCap, MiterJoin);
01990                             p->setLineWidth(style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0);
01991                             p->strokePath();
01992                      }
01993                      else
01994                      {
01995                             if ((style.effects() & ScStyle_Shadowed) && (style.strokeColor() != CommonStrings::None))
01996                             {
01997                                    p->save();
01998 #ifdef HAVE_CAIRO
01999                                    p->translate((style.fontSize() * glyphs.scaleH * style.shadowXOffset() / 10000.0) / glxSc, -(style.fontSize() * glyphs.scaleV * style.shadowYOffset() / 10000.0) / glySc);
02000 #else
02001                                    p->translate((style.fontSize() * glyphs.scaleH * style.shadowXOffset() / 10000.0) * p->zoomFactor(), -(style.fontSize() * glyphs.scaleV * style.shadowYOffset() / 10000.0) * p->zoomFactor());
02002 #endif
02003                                    QColor tmp = p->brush();
02004                                    p->setBrush(p->pen());
02005 #ifdef HAVE_CAIRO
02006                                    p->setupTextPolygon(&gly);
02007 #endif
02008                                    p->fillPath();
02009                                    p->setBrush(tmp);
02010                                    p->restore();
02011 #ifdef HAVE_CAIRO
02012                                    p->setupTextPolygon(&gly);
02013 #endif
02014                             }
02015                             if (style.fillColor() != CommonStrings::None)
02016                                    p->fillPath();
02017                             if ((style.effects() & ScStyle_Outline) && (style.strokeColor() != CommonStrings::None) && ((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) != 0))
02018                             {
02019 #ifdef HAVE_CAIRO
02020                                    p->setLineWidth((style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0) / glySc);
02021 #else
02022                                    p->setLineWidth(style.fontSize() * glyphs.scaleV * style.outlineWidth() / 10000.0);
02023 #endif
02024                                    p->strokePath();
02025                             }
02026                      }
02027                      p->setFillRule(fr);
02028 #ifdef HAVE_CAIRO
02029                      p->restore();
02030 #endif
02031               }
02032               else {
02033 //                   qDebug(QString("drawGlyphs: empty glyph %1").arg(glyph));
02034               }
02035               if (style.effects() & ScStyle_Strikethrough)
02036               {
02037                      double st, lw;
02038                      if ((style.strikethruOffset() != -1) || (style.strikethruWidth() != -1))
02039                      {
02040                             if (style.strikethruOffset() != -1)
02041                                    st = (style.strikethruOffset() / 1000.0) * (style.font().ascent(style.fontSize() / 10.0));
02042                             else
02043                                    st = style.font().strikeoutPos(style.fontSize() / 10.0);
02044                             if (style.strikethruWidth() != -1)
02045                                    lw = (style.strikethruWidth() / 1000.0) * (style.fontSize() / 10.0);
02046                             else
02047                                    lw = QMAX(style.font().strokeWidth(style.fontSize() / 10.0), 1);
02048                      }
02049                      else
02050                      {
02051                             st = style.font().strikeoutPos(style.fontSize() / 10.0);
02052                             lw = QMAX(style.font().strokeWidth(style.fontSize() / 10.0), 1);
02053                      }
02054                      if (style.baselineOffset() != 0)
02055                             st += (style.fontSize() / 10.0) * glyphs.scaleV * (style.baselineOffset() / 1000.0);
02056                      p->setPen(p->brush());
02057                      p->setLineWidth(lw);
02058                      p->drawLine(FPoint(glyphs.xoffset, glyphs.yoffset - st), FPoint(glyphs.xoffset + glyphs.xadvance, glyphs.yoffset - st));
02059               }
02060        }
02061 /*     else
02062        {
02063               p->setLineWidth(1);
02064               p->setPen(red);
02065               p->setBrush(red);
02066               p->setFillMode(1);
02067               p->drawRect(glyphs.xoffset, glyphs.yoffset - (style.fontSize() / 10.0) * glyphs.scaleV , (style.fontSize() / 10.0) * glyphs.scaleH, (style.fontSize() / 10.0) * glyphs.scaleV);
02068        }
02069        */     
02070        if (glyphs.more)
02071        {
02072 #ifdef HAVE_CAIRO
02073               p->translate(glyphs.xadvance, 0);
02074 #else
02075               p->translate(glyphs.xadvance * p->zoomFactor(), 0);
02076 #endif
02077               drawGlyphs(p, style, *glyphs.more);
02078        }
02079 }
02080 
02081 void PageItem::DrawPolyL(QPainter *p, QPointArray pts)
02082 {
02083        QColor tmp;
02084        ScribusView* view = m_Doc->view();
02085        if (Segments.count() != 0)
02086        {
02087               QValueList<uint>::Iterator it2end=Segments.end();
02088               uint FirstVal = 0;
02089               for (QValueList<uint>::Iterator it2 = Segments.begin(); it2 != it2end; ++it2)
02090               {
02091                      if (NamedLStyle.isEmpty())
02092                             p->drawPolyline(pts, FirstVal, (*it2)-FirstVal);
02093                      else
02094                      {
02095                             multiLine ml = m_Doc->MLineStyles[NamedLStyle];
02096                             for (int it = ml.size()-1; it > -1; it--)
02097                             {
02098                                    SetFarbe(&tmp, ml[it].Color, ml[it].Shade);
02099                                    p->setPen(QPen(tmp,
02100                                                                 QMAX(static_cast<int>(ml[it].Width* view->scale()), 1),
02101                                                                 static_cast<PenStyle>(ml[it].Dash),
02102                                                                 static_cast<PenCapStyle>(ml[it].LineEnd),
02103                                                                 static_cast<PenJoinStyle>(ml[it].LineJoin)));
02104                                    p->drawPolyline(pts, FirstVal, (*it2)-FirstVal);
02105                             }
02106                      }
02107                      FirstVal = (*it2);
02108               }
02109               if (NamedLStyle.isEmpty())
02110                      p->drawPolyline(pts, FirstVal);
02111               else
02112               {
02113                      multiLine ml = m_Doc->MLineStyles[NamedLStyle];
02114                      for (int it = ml.size()-1; it > -1; it--)
02115                      {
02116                             SetFarbe(&tmp, ml[it].Color, ml[it].Shade);
02117                             p->setPen(QPen(tmp,
02118                                                          QMAX(static_cast<int>(ml[it].Width* view->scale()), 1),
02119                                                          static_cast<PenStyle>(ml[it].Dash),
02120                                                          static_cast<PenCapStyle>(ml[it].LineEnd),
02121                                                          static_cast<PenJoinStyle>(ml[it].LineJoin)));
02122                             p->drawPolyline(pts, FirstVal);
02123                      }
02124               }
02125        }
02126        else
02127        {
02128               if (NamedLStyle.isEmpty())
02129                      p->drawPolyline(pts);
02130               else
02131               {
02132                      multiLine ml = m_Doc->MLineStyles[NamedLStyle];
02133                      for (int it = ml.size()-1; it > -1; it--)
02134                      {
02135                             SetFarbe(&tmp, ml[it].Color, ml[it].Shade);
02136                             p->setPen(QPen(tmp,
02137                                                          QMAX(static_cast<int>(ml[it].Width*view->scale()), 1),
02138                                                          static_cast<PenStyle>(ml[it].Dash),
02139                                                          static_cast<PenCapStyle>(ml[it].LineEnd),
02140                                                          static_cast<PenJoinStyle>(ml[it].LineJoin)));
02141                             p->drawPolyline(pts);
02142                      }
02143               }
02144        }
02145 }
02146 
02147 void PageItem::setItemName(const QString& newName)
02148 {
02149        if (AnName == newName)
02150               return; // nothing to do -> return
02151        if (newName.isEmpty())
02152               return;
02153        AnName = generateUniqueCopyName(newName);
02154        if (UndoManager::undoEnabled())
02155        {
02156               SimpleState *ss = new SimpleState(Um::Rename, QString(Um::FromTo).arg(AnName).arg(newName));
02157               ss->set("OLD_NAME", AnName);
02158               ss->set("NEW_NAME", newName);
02159               undoManager->action(this, ss);
02160        }
02161        setUName(AnName); // set the name for the UndoObject too
02162 }
02163 
02164 void PageItem::setPattern(const QString &newPattern)
02165 {
02166        if (patternVal != newPattern)
02167               patternVal = newPattern;
02168 }
02169 
02170 void PageItem::setPatternTransform(double scaleX, double scaleY, double offsetX, double offsetY, double rotation)
02171 {
02172        patternScaleX = scaleX;
02173        patternScaleY = scaleY;
02174        patternOffsetX = offsetX;
02175        patternOffsetY = offsetY;
02176        patternRotation = rotation;
02177 }
02178 
02179 void  PageItem::patternTransform(double &scaleX, double &scaleY, double &offsetX, double &offsetY, double &rotation) const
02180 {
02181         scaleX = patternScaleX;
02182         scaleY = patternScaleY;
02183         offsetX = patternOffsetX;
02184         offsetY = patternOffsetY;
02185         rotation = patternRotation;
02186 }
02187 
02188 void PageItem::setFillColor(const QString &newColor)
02189 {
02190        if (fillColorVal == newColor)
02191        {
02192               setFillQColor();
02193               return;
02194        }
02195        if (UndoManager::undoEnabled())
02196        {
02197               SimpleState *ss = new SimpleState(Um::SetFill,
02198                                                                         QString(Um::ColorFromTo).arg(fillColorVal).arg(newColor),
02199                                           Um::IFill);
02200               ss->set("FILL", "fill");
02201               ss->set("OLD_FILL", fillColorVal);
02202               ss->set("NEW_FILL", newColor);
02203               undoManager->action(this, ss);
02204        }
02205        fillColorVal = newColor;
02206        if (GrType == 0)
02207        {
02208               fill_gradient = VGradient(VGradient::linear);
02209               fill_gradient.clearStops();
02210               if (fillColorVal != CommonStrings::None)
02211               {
02212                      const ScColor& col = m_Doc->PageColors[fillColorVal];
02213                      fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, fillColorVal, 100);
02214                      fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, fillColorVal, 100);
02215               }
02216        }
02217        setFillQColor();
02218        emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
02219 }
02220 
02221 void PageItem::setFillShade(int newShade)
02222 {
02223        if (fillShadeVal == newShade)
02224        {
02225               setFillQColor();
02226               return;
02227        }
02228        if (UndoManager::undoEnabled())
02229        {
02230               SimpleState *ss = new SimpleState(Um::SetShade,
02231                                                                         QString(Um::FromTo).arg(fillShadeVal).arg(newShade),
02232                                                                         Um::IShade);
02233               ss->set("SHADE", "shade");
02234               ss->set("OLD_SHADE", fillShadeVal);
02235               ss->set("NEW_SHADE", newShade);
02236               undoManager->action(this, ss);
02237        }
02238        fillShadeVal = newShade;
02239        setFillQColor();
02240        emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
02241 }
02242 
02243 void PageItem::setFillTransparency(double newTransparency)
02244 {
02245        if (fillTransparencyVal == newTransparency)
02246               return; // nothing to do -> return
02247        if (UndoManager::undoEnabled())
02248        {
02249               SimpleState *ss = new SimpleState(Um::Transparency,
02250                                                                         QString(Um::FromTo).arg(fillTransparencyVal).arg(newTransparency),
02251                                                                         Um::ITransparency);
02252               ss->set("TRANSPARENCY", "transparency");
02253               ss->set("OLD_TP", fillTransparencyVal);
02254               ss->set("NEW_TP", newTransparency);
02255               undoManager->action(this, ss);
02256        }
02257        fillTransparencyVal = newTransparency;
02258 }
02259 
02260 void PageItem::setFillBlendmode(int newBlendmode)
02261 {
02262        if (fillBlendmodeVal == newBlendmode)
02263               return; // nothing to do -> return
02264        fillBlendmodeVal = newBlendmode;
02265 }
02266 
02267 void PageItem::setLineColor(const QString &newColor)
02268 {
02269        if (lineColorVal == newColor)
02270        {
02271               setLineQColor();
02272               return;
02273        }
02274        if (UndoManager::undoEnabled())
02275        {
02276               SimpleState *ss = new SimpleState(Um::SetLineColor,
02277                                                                         QString(Um::ColorFromTo).arg(lineColorVal).arg(newColor),
02278                                                                         Um::IFill);
02279               ss->set("LINE_COLOR", "line_color");
02280               ss->set("OLD_COLOR", lineColorVal);
02281               ss->set("NEW_COLOR", newColor);
02282               undoManager->action(this, ss);
02283        }
02284        lineColorVal = newColor;
02285        setLineQColor();
02286        emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
02287 }
02288 
02289 void PageItem::setLineShade(int newShade)
02290 {
02291        if (lineShadeVal == newShade)
02292        {
02293               setLineQColor();
02294               return;
02295        }
02296        if (UndoManager::undoEnabled())
02297        {
02298               SimpleState *ss = new SimpleState(Um::SetLineShade,
02299                                                                         QString(Um::FromTo).arg(lineShadeVal).arg(newShade),
02300                                                                         Um::IShade);
02301               ss->set("LINE_SHADE", "line_shade");
02302               ss->set("OLD_SHADE", lineShadeVal);
02303               ss->set("NEW_SHADE", newShade);
02304               undoManager->action(this, ss);
02305        }
02306        lineShadeVal = newShade;
02307        setLineQColor();
02308        emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
02309 }
02310 
02311 void PageItem::setLineQColor()
02312 {
02313        if (lineColorVal != CommonStrings::None)
02314        {
02315               const ScColor& col = m_Doc->PageColors[lineColorVal];
02316               strokeQColor = ScColorEngine::getShadeColorProof(col, m_Doc, lineShadeVal);
02317        }
02318        if ((m_Doc->view()) && (m_Doc->view()->viewAsPreview) && (m_Doc->view()->previewVisual != 0))
02319        {
02320               VisionDefectColor *defect = new VisionDefectColor();
02321               strokeQColor = defect->convertDefect(strokeQColor, m_Doc->view()->previewVisual);
02322               delete defect;
02323        }
02324 }
02325 
02326 void PageItem::setFillQColor()
02327 {
02328        if (fillColorVal != CommonStrings::None)
02329        {
02330               const ScColor& col = m_Doc->PageColors[fillColorVal];
02331               fillQColor = ScColorEngine::getShadeColorProof(col, m_Doc, fillShadeVal);
02332        }
02333        if ((m_Doc->view()) && (m_Doc->view()->viewAsPreview) && (m_Doc->view()->previewVisual != 0))
02334        {
02335               VisionDefectColor *defect = new VisionDefectColor();
02336               fillQColor = defect->convertDefect(fillQColor, m_Doc->view()->previewVisual);
02337               delete defect;
02338        }
02339 }
02340 
02341 void PageItem::setLineTransparency(double newTransparency)
02342 {
02343        if (lineTransparencyVal == newTransparency)
02344               return; // nothing to do -> return
02345        if (UndoManager::undoEnabled())
02346        {
02347               SimpleState *ss = new SimpleState(Um::LineTransparency,
02348                                                                         QString(Um::FromTo).arg(lineTransparencyVal).arg(newTransparency),
02349                                                                         Um::ITransparency);
02350               ss->set("LINE_TRANSPARENCY", "transparency");
02351               ss->set("OLD_TP", lineTransparencyVal);
02352               ss->set("NEW_TP", newTransparency);
02353               undoManager->action(this, ss);
02354        }
02355        lineTransparencyVal = newTransparency;
02356 }
02357 
02358 void PageItem::setLineBlendmode(int newBlendmode)
02359 {
02360        if (lineBlendmodeVal == newBlendmode)
02361               return; // nothing to do -> return
02362        lineBlendmodeVal = newBlendmode;
02363 }
02364 
02365 void PageItem::setLineStyle(PenStyle newStyle)
02366 {
02367        if (PLineArt == newStyle)
02368               return; // nothing to do -> return
02369        if (UndoManager::undoEnabled())
02370        {
02371               SimpleState *ss = new SimpleState(Um::LineStyle,"",Um::ILineStyle);
02372               ss->set("LINE_STYLE", "line_style");
02373               ss->set("OLD_STYLE", static_cast<int>(PLineArt));
02374               ss->set("NEW_STYLE", static_cast<int>(newStyle));
02375               undoManager->action(this, ss);
02376        }
02377        PLineArt = newStyle;
02378 }
02379 
02380 void PageItem::setLineWidth(double newWidth)
02381 {
02382        if (m_lineWidth == newWidth)
02383               return; // nothing to do -> return
02384        if (UndoManager::undoEnabled())
02385        {
02386               SimpleState *ss = new SimpleState(Um::LineWidth,
02387                                           QString(Um::FromTo).arg(m_lineWidth).arg(newWidth),Um::ILineStyle);
02388               ss->set("LINE_WIDTH", "line_width");
02389               ss->set("OLD_WIDTH", m_lineWidth);
02390               ss->set("NEW_WIDTH", newWidth);
02391               undoManager->action(this, ss);
02392        }
02393        Oldm_lineWidth=m_lineWidth;
02394        m_lineWidth = newWidth;
02395 }
02396 
02397 void PageItem::setLineEnd(PenCapStyle newStyle)
02398 {
02399        if (PLineEnd == newStyle)
02400               return; // nothing to do -> return
02401        if (UndoManager::undoEnabled())
02402        {
02403               SimpleState *ss = new SimpleState(Um::LineEnd,"",Um::ILineStyle);
02404               ss->set("LINE_END", "line_end");
02405               ss->set("OLD_STYLE", static_cast<int>(PLineEnd));
02406               ss->set("NEW_STYLE", static_cast<int>(newStyle));
02407               undoManager->action(this, ss);
02408        }
02409        PLineEnd = newStyle;
02410 }
02411 
02412 void PageItem::setLineJoin(PenJoinStyle newStyle)
02413 {
02414        if (PLineJoin == newStyle)
02415               return; // nothing to do -> return
02416        if (UndoManager::undoEnabled())
02417        {
02418               SimpleState *ss = new SimpleState(Um::LineJoin,"",Um::ILineStyle);
02419               ss->set("LINE_JOIN", "line_join");
02420               ss->set("OLD_STYLE", static_cast<int>(PLineJoin));
02421               ss->set("NEW_STYLE", static_cast<int>(newStyle));
02422               undoManager->action(this, ss);
02423        }
02424        PLineJoin = newStyle;
02425 }
02426 
02427 void PageItem::setCustomLineStyle(const QString& newStyle)
02428 {
02429        if (NamedLStyle == newStyle)
02430               return; // nothing to do -> return
02431        if (UndoManager::undoEnabled())
02432        {
02433               QString oldStyle = NamedLStyle.isEmpty() ? Um::NoStyle : NamedLStyle;
02434               QString nStyle   = newStyle.isEmpty() ? Um::NoStyle : newStyle;
02435               QString action   = newStyle.isEmpty() ? Um::NoLineStyle : Um::CustomLineStyle;
02436               SimpleState *ss = new SimpleState(action,
02437                             QString(Um::FromTo).arg(oldStyle).arg(nStyle),Um::ILineStyle);
02438               ss->set("CUSTOM_LINE_STYLE", "customlinestyle");
02439               ss->set("OLD_STYLE", NamedLStyle);
02440               ss->set("NEW_STYLE", newStyle);
02441               undoManager->action(this, ss);
02442        }
02443        NamedLStyle = newStyle;
02444 }
02445 
02446 void PageItem::setStartArrowIndex(int newIndex)
02447 {
02448        if (m_startArrowIndex == newIndex)
02449               return; // nothing to do -> return
02450        if (UndoManager::undoEnabled())
02451        {
02452               SimpleState *ss = new SimpleState(Um::StartArrow,"",Um::IArrow);
02453               ss->set("START_ARROW", "startarrow");
02454               ss->set("OLD_INDEX", m_startArrowIndex);
02455               ss->set("NEW_INDEX", newIndex);
02456               undoManager->action(this, ss);
02457        }
02458        m_startArrowIndex = newIndex;
02459 }
02460 
02461 void PageItem::setEndArrowIndex(int newIndex)
02462 {
02463        if (m_endArrowIndex == newIndex)
02464               return; // nothing to do -> return
02465        if (UndoManager::undoEnabled())
02466        {
02467               SimpleState *ss = new SimpleState(Um::EndArrow,"",Um::IArrow);
02468               ss->set("END_ARROW", "endarrow");
02469               ss->set("OLD_INDEX", m_endArrowIndex);
02470               ss->set("NEW_INDEX", newIndex);
02471               undoManager->action(this, ss);
02472        }
02473        m_endArrowIndex = newIndex;
02474 }
02475 
02476 void PageItem::setImageFlippedH(bool flipped)
02477 {
02478        if (flipped != m_ImageIsFlippedH)
02479               flipImageH();
02480 }
02481 
02482 void PageItem::flipImageH()
02483 {
02484        if (UndoManager::undoEnabled())
02485        {
02486               SimpleState *ss = new SimpleState(Um::FlipH, 0, Um::IFlipH);
02487               ss->set("IMAGEFLIPH", "imagefliph");
02488               undoManager->action(this, ss);
02489        }
02490        m_ImageIsFlippedH = !m_ImageIsFlippedH;
02491        emit frameFlippedH(m_ImageIsFlippedH);
02492 }
02493 
02494 void PageItem::setImageFlippedV(bool flipped)
02495 {
02496        if (flipped != m_ImageIsFlippedV)
02497               flipImageV();
02498 }
02499 
02500 void PageItem::flipImageV()
02501 {
02502        if (UndoManager::undoEnabled())
02503        {
02504               SimpleState *ss = new SimpleState(Um::FlipV, 0, Um::IFlipV);
02505               ss->set("IMAGEFLIPV", "imageflipv");
02506               undoManager->action(this, ss);
02507        }
02508        m_ImageIsFlippedV = !m_ImageIsFlippedV;
02509        emit frameFlippedV(m_ImageIsFlippedV);
02510 }
02511 
02512 void PageItem::setImageScalingMode(bool freeScale, bool keepRatio)
02513 {
02514        if (ScaleType == freeScale && AspectRatio == keepRatio)
02515               return;
02516        if (UndoManager::undoEnabled())
02517        {
02518               QString from = ScaleType ? Um::FreeScaling : Um::FrameSize;
02519               from += ", ";
02520               from += AspectRatio ? Um::KeepRatio : Um::BreakRatio;
02521               QString to = freeScale ? Um::FreeScaling : Um::FrameSize;
02522               to += ", ";
02523               to += keepRatio ? Um::KeepRatio : Um::BreakRatio;
02524               SimpleState *ss = new SimpleState(Um::ImageScaling, QString(Um::FromTo).arg(from).arg(to), Um::IImageScaling);
02525               if (freeScale != ScaleType)
02526                      ss->set("SCALE_TYPE", freeScale);
02527               if (keepRatio != AspectRatio)
02528                      ss->set("ASPECT_RATIO", keepRatio);
02529               undoManager->action(this, ss);
02530        }
02531        ScaleType = freeScale;
02532        AspectRatio = keepRatio;
02533        AdjustPictScale();
02534        m_Doc->view()->RefreshItem(this);
02535 }
02536 
02537 void PageItem::toggleLock()
02538 {
02539        if (UndoManager::undoEnabled())
02540        {
02541               SimpleState *ss;
02542               if (m_Locked)
02543                      ss = new SimpleState(Um::UnLock, 0, Um::IUnLock);
02544               else
02545                      ss = new SimpleState(Um::Lock, 0, Um::ILock);
02546               ss->set("LOCK", "lock");
02547               undoManager->action(this, ss);
02548        }
02549        m_Locked = !m_Locked;
02550        emit frameLocked(m_Locked);
02551 }
02552 
02553 void PageItem::setLocked(bool isLocked)
02554 {
02555        if (isLocked != m_Locked)
02556               toggleLock();
02557 }
02558 
02559 void PageItem::toggleSizeLock()
02560 {
02561        if (UndoManager::undoEnabled())
02562        {
02563               SimpleState *ss;
02564               if (m_SizeLocked)
02565                      ss = new SimpleState(Um::SizeUnLock, 0, Um::IUnLock);
02566               else
02567                      ss = new SimpleState(Um::SizeLock, 0, Um::ILock);
02568               ss->set("SIZE_LOCK", "size_lock");
02569               undoManager->action(this, ss);
02570        }
02571        m_SizeLocked = !m_SizeLocked;
02572        emit frameSizeLocked(m_SizeLocked);
02573 }
02574 
02575 void PageItem::setSizeLocked(bool isLocked)
02576 {
02577        if (isLocked != m_SizeLocked)
02578               toggleSizeLock();
02579 }
02580 
02581 
02582 void PageItem::setPrintEnabled(bool toPrint)
02583 {
02584        if (toPrint != m_PrintEnabled)
02585               togglePrintEnabled();
02586 }
02587 
02588 void PageItem::togglePrintEnabled()
02589 {
02590        if (UndoManager::undoEnabled())
02591        {
02592               SimpleState *ss;
02593               if (m_PrintEnabled)
02594                      ss = new SimpleState(Um::DisablePrint, 0, Um::IDisablePrint);
02595               else
02596                      ss = new SimpleState(Um::EnablePrint, 0, Um::IEnablePrint);
02597               ss->set("PRINT_ENABLED", "print_enabled");
02598               undoManager->action(this, ss);
02599        }
02600        m_PrintEnabled=!m_PrintEnabled;
02601        emit printEnabled(m_PrintEnabled);
02602 }
02603 
02604 void PageItem::setTextFlowMode(TextFlowMode mode)
02605 {
02606        if (textFlowModeVal == mode)
02607               return;
02608        if (UndoManager::undoEnabled())
02609        {
02610               QString stateMessage;
02611               if( mode == TextFlowUsesFrameShape )
02612                      stateMessage = Um::ObjectFrame;
02613               else if( mode == TextFlowUsesBoundingBox )
02614                      stateMessage = Um::BoundingBox;
02615               else if( mode == TextFlowUsesContourLine )
02616                      stateMessage = Um::ContourLine;
02617               else if( mode == TextFlowUsesImageClipping )
02618                      stateMessage = Um::ImageClip;
02619               else
02620                      stateMessage = Um::NoTextFlow;
02621               SimpleState *ss = new SimpleState(stateMessage, "", Um::IFont);
02622               ss->set("TEXTFLOW_OLDMODE", (int) textFlowModeVal);
02623               ss->set("TEXTFLOW_NEWMODE", (int) mode);
02624               undoManager->action(this, ss);
02625        }
02626        textFlowModeVal = mode;
02627 }
02628 
02629 void PageItem::convertTo(ItemType newType)
02630 {
02631        if (m_ItemType == newType)
02632               return; // nothing to do -> return
02633        assert(newType != 1);       //DEBUG CR 2005-02-06
02634        assert(newType != 3);       //DEBUG CR 2005-02-06
02635        QString fromType = "", toType = "";
02636        switch (m_ItemType)
02637        {
02638               case ImageFrame:
02639                      fromType = Um::ImageFrame;
02640                      break;
02641               case TextFrame:
02642                      fromType = Um::TextFrame;
02643                      break;
02644               case Polygon:
02645                      fromType = Um::Polygon;
02646                      break;
02647               default:
02648                      fromType = "";
02649                      break;
02650        }
02651        switch (newType)
02652        {
02653               case ImageFrame:
02654                      toType = Um::ImageFrame;
02655                      setUPixmap(Um::IImageFrame);
02656                      break;
02657               case TextFrame:
02658                      toType = Um::TextFrame;
02659                      setUPixmap(Um::ITextFrame);
02660                      break;
02661               case Polygon:
02662                      toType = Um::Polygon;
02663                      setUPixmap(Um::IPolygon);
02664                      break;
02665               case PolyLine:
02666                      toType = Um::Polyline;
02667                      setUPixmap(Um::IPolyline);
02668                      break;
02669               default:
02670                      toType = "";
02671                      setUPixmap(NULL);
02672                      break;
02673        }
02674        /*
02675        if (UndoManager::undoEnabled())
02676        {
02677               SimpleState *ss = new SimpleState(Um::ConvertTo + " " + toType,
02678                                                                         QString(Um::FromTo).arg(fromType).arg(toType));
02679               ss->set("CONVERT", "convert");
02680               ss->set("PAGEITEM", reinterpret_cast<int>(this));
02681               ss->set("OLD_TYPE", m_ItemType);
02682               ss->set("NEW_TYPE", newType);
02683               undoManager->action(this, ss);
02684        }
02685        */
02686        m_ItemType = newType;
02687        emit frameType(m_ItemType);
02688 }
02689 
02690 void PageItem::setLayer(int layerId)
02691 {
02692        if (LayerNr == layerId)
02693               return;
02694        if (UndoManager::undoEnabled())
02695        {
02696               SimpleState *ss = new SimpleState(Um::SendToLayer,
02697                                                                         QString(Um::FromTo).arg(LayerNr).arg(layerId),
02698                                                                         Um::ILayerAction);
02699               ss->set("SEND_TO_LAYER", "send_to_layer");
02700               ss->set("OLD_LAYER", LayerNr);
02701               ss->set("NEW_LAYER", layerId);
02702               undoManager->action(this, ss);
02703        }
02704        LayerNr = layerId;
02705 }
02706 
02707 void PageItem::checkChanges(bool force)
02708 {
02709        // has the item been resized
02710        if (force || ((oldWidth != Width || oldHeight != Height) && shouldCheck()))
02711               resizeUndoAction();
02712        // has the item been rotated
02713        if (force || ((oldRot != Rot) && (shouldCheck())))
02714               rotateUndoAction();
02715        // has the item been moved
02716        if (force || ((oldXpos != Xpos || oldYpos != Ypos) && shouldCheck()))
02717               moveUndoAction();
02718        // has the item's image been moved
02719        if (force || ((oldLocalX != LocalX || oldLocalY != LocalY) && shouldCheck()))
02720               changeImageOffsetUndoAction();
02721        // has the item's image been scaled
02722        if (force || ((oldLocalScX != LocalScX || oldLocalScY != LocalScY) && shouldCheck()))
02723               changeImageScaleUndoAction();
02724 }
02725 
02726 bool PageItem::shouldCheck()
02727 {
02728        return ((!m_Doc->view()->mousePressed()) &&
02729                      (!ScCore->primaryMainWindow()->arrowKeyDown()) &&
02730                      (!ScCore->primaryMainWindow()->propertiesPalette->userActionOn()));
02731 }
02732 
02733 void PageItem::moveUndoAction()
02734 {
02735        if (!shouldCheck())
02736               return;
02737        if (oldXpos == Xpos && oldYpos == Ypos)
02738               return;
02739        if (UndoManager::undoEnabled())
02740        {
02741               QString oldp;
02742               QString newp;
02743               if (oldOwnPage == -1)
02744                      oldp = Um::ScratchSpace;
02745               else
02746                      oldp = QString(Um::PageNmbr).arg(m_Doc->FirstPnum + oldOwnPage);
02747               if (OwnPage == -1)
02748                      newp = Um::ScratchSpace;
02749               else
02750                      newp = QString(Um::PageNmbr).arg(m_Doc->FirstPnum + OwnPage);
02751               SimpleState *ss = new SimpleState(Um::Move,
02752                                           QString(Um::MoveFromTo).arg(oldXpos).arg(oldYpos).arg(oldp).
02753                                                                   arg(Xpos).arg(Ypos).arg(newp), Um::IMove);
02754               ss->set("OLD_XPOS", oldXpos);
02755               ss->set("OLD_YPOS", oldYpos);
02756               ss->set("NEW_XPOS", Xpos);
02757               ss->set("NEW_YPOS", Ypos);
02758               undoManager->action(this, ss);
02759        }
02760        oldXpos = Xpos;
02761        oldYpos = Ypos;
02762        oldOwnPage = OwnPage;
02763 }
02764 
02765 void PageItem::resizeUndoAction()
02766 {
02767        if (!shouldCheck())
02768               return;
02769        if (oldHeight == Height && oldWidth == Width)
02770               return;
02771        if (UndoManager::undoEnabled())
02772        {
02773               SimpleState *ss = new SimpleState(Um::Resize,
02774                            QString(Um::ResizeFromTo).arg(oldWidth).arg(oldHeight).arg(Width).arg(Height),
02775                                           Um::IResize);
02776               ss->set("OLD_WIDTH", oldWidth);
02777               ss->set("OLD_HEIGHT", oldHeight);
02778               ss->set("NEW_WIDTH", Width);
02779               ss->set("NEW_HEIGHT", Height);
02780               ss->set("OLD_RXPOS", oldXpos);
02781               ss->set("OLD_RYPOS", oldYpos);
02782               ss->set("NEW_RXPOS", Xpos);
02783               ss->set("NEW_RYPOS", Ypos);
02784               ss->set("OLD_RROT", oldRot);
02785               ss->set("NEW_RROT", Rot);
02786               undoManager->action(this, ss);
02787        }
02788        oldXpos = Xpos;
02789        oldYpos = Ypos;
02790        oldHeight = Height;
02791        oldWidth = Width;
02792        oldOwnPage = OwnPage;
02793        oldRot = Rot;
02794 }
02795 
02796 void PageItem::rotateUndoAction()
02797 {
02798        if (!shouldCheck())
02799               return;
02800        if (oldRot == Rot)
02801               return;
02802        if (UndoManager::undoEnabled())
02803        {
02804               SimpleState *ss = new SimpleState(Um::Rotate,
02805                                           QString(Um::FromTo).arg(oldRot).arg(Rot),
02806                                           Um::IRotate);
02807               ss->set("OLD_ROT", oldRot);
02808               ss->set("NEW_ROT", Rot);
02809               ss->set("OLD_RXPOS", oldXpos);
02810               ss->set("OLD_RYPOS", oldYpos);
02811               ss->set("NEW_RXPOS", Xpos);
02812               ss->set("NEW_RYPOS", Ypos);
02813               ss->set("OLD_RWIDTH", oldWidth);
02814               ss->set("OLD_RHEIGHT", oldHeight);
02815               ss->set("NEW_RWIDTH", Width);
02816               ss->set("NEW_RHEIGHT", Height);
02817               undoManager->action(this, ss);
02818        }
02819        oldRot = Rot;
02820        oldXpos = Xpos;
02821        oldYpos = Ypos;
02822        oldOwnPage = OwnPage;
02823        oldWidth = Width;
02824        oldHeight = Height;
02825 }
02826 
02827 void PageItem::changeImageOffsetUndoAction()
02828 {
02829        if (!shouldCheck())
02830               return;
02831        if (oldLocalX == LocalX && oldLocalY == LocalY)
02832               return;
02833        if (UndoManager::undoEnabled())
02834        {
02835               SimpleState *ss = new SimpleState(Um::ImageOffset,
02836                      QString(Um::ImageOffsetFromTo).arg(oldLocalX).arg(oldLocalY).arg(LocalX).arg(LocalY), Um::IMove);
02837               ss->set("OLD_IMAGEXOFFSET", oldLocalX);
02838               ss->set("OLD_IMAGEYOFFSET", oldLocalY);
02839               ss->set("NEW_IMAGEXOFFSET", LocalX);
02840               ss->set("NEW_IMAGEYOFFSET", LocalY);
02841               undoManager->action(this, ss);
02842        }
02843        oldLocalX = LocalX;
02844        oldLocalY = LocalY;
02845 }
02846 
02847 void PageItem::changeImageScaleUndoAction()
02848 {
02849        if (!shouldCheck())
02850               return;
02851        if (oldLocalScX == LocalScX && oldLocalScY == LocalScY)
02852               return;
02853        if (UndoManager::undoEnabled())
02854        {
02855               SimpleState *ss = new SimpleState(Um::ImageScale,
02856                      QString(Um::ImageScaleFromTo).arg(oldLocalScX).arg(oldLocalScY).arg(LocalScX).arg(LocalScY), Um::IMove);
02857               ss->set("OLD_IMAGEXSCALE", oldLocalScX);
02858               ss->set("OLD_IMAGEYSCALE", oldLocalScY);
02859               ss->set("NEW_IMAGEXSCALE", LocalScX);
02860               ss->set("NEW_IMAGEYSCALE", LocalScY);
02861               undoManager->action(this, ss);
02862        }
02863        oldLocalScX = LocalScX;
02864        oldLocalScY = LocalScY;
02865 }
02866 
02867 void PageItem::restore(UndoState *state, bool isUndo)
02868 {
02869        bool useRasterBackup = m_Doc->useRaster;
02870        bool SnapGuidesBackup = m_Doc->SnapGuides;
02871        m_Doc->useRaster = false;
02872        m_Doc->SnapGuides = false;
02873        ScribusView* view = m_Doc->view();
02874        SimpleState *ss = dynamic_cast<SimpleState*>(state);
02875        bool oldMPMode=m_Doc->masterPageMode();
02876        m_Doc->setMasterPageMode(!OnMasterPage.isEmpty());
02877        Page *oldCurrentPage = m_Doc->currentPage();
02878        if (!OnMasterPage.isEmpty())
02879        {
02880               oldCurrentPage = m_Doc->currentPage();
02881               m_Doc->setCurrentPage(m_Doc->MasterPages.at(m_Doc->MasterNames[OnMasterPage]));
02882        }
02883        if (ss)
02884        {
02885               if (ss->contains("OLD_XPOS"))
02886                      restoreMove(ss, isUndo);
02887               else if (ss->contains("OLD_HEIGHT"))
02888                      restoreResize(ss, isUndo);
02889               else if (ss->contains("OLD_ROT"))
02890                      restoreRotate(ss, isUndo);
02891               else if (ss->contains("FILL"))
02892                      restoreFill(ss, isUndo);
02893               else if (ss->contains("SHADE"))
02894                      restoreShade(ss, isUndo);
02895               else if (ss->contains("LINE_COLOR"))
02896                      restoreLineColor(ss, isUndo);
02897               else if (ss->contains("LINE_SHADE"))
02898                      restoreLineShade(ss, isUndo);
02899               else if (ss->contains("IMAGEFLIPH"))
02900               {
02901                      select();
02902                      m_Doc->itemSelection_FlipH();
02903               }
02904               else if (ss->contains("IMAGEFLIPV"))
02905               {
02906                      select();
02907                      m_Doc->itemSelection_FlipV();
02908               }
02909               else if (ss->contains("LOCK"))
02910               {
02911                      select();
02912                      m_Doc->itemSelection_ToggleLock();
02913               }
02914               else if (ss->contains("SIZE_LOCK"))
02915               {
02916                      select();
02917                      m_Doc->itemSelection_ToggleSizeLock();
02918               }
02919               else if (ss->contains("PRINT_ENABLED"))
02920               {
02921                      select();
02922                      m_Doc->itemSelection_TogglePrintEnabled();
02923               }
02924               else if (ss->contains("NEW_NAME"))
02925                      restoreName(ss, isUndo);
02926               else if (ss->contains("TRANSPARENCY"))
02927                      restoreFillTP(ss, isUndo);
02928               else if (ss->contains("LINE_TRANSPARENCY"))
02929                      restoreLineTP(ss, isUndo);
02930               else if (ss->contains("LINE_STYLE"))
02931                      restoreLineStyle(ss, isUndo);
02932               else if (ss->contains("LINE_END"))
02933                      restoreLineEnd(ss, isUndo);
02934               else if (ss->contains("LINE_JOIN"))
02935                      restoreLineJoin(ss, isUndo);
02936               else if (ss->contains("LINE_WIDTH"))
02937                      restoreLineWidth(ss, isUndo);
02938               else if (ss->contains("CUSTOM_LINE_STYLE"))
02939                      restoreCustomLineStyle(ss, isUndo);
02940               else if (ss->contains("START_ARROW"))
02941                      restoreArrow(ss, isUndo, true);
02942               else if (ss->contains("END_ARROW"))
02943                      restoreArrow(ss, isUndo, false);
02944               else if (ss->contains("PSTYLE"))
02945                      restorePStyle(ss, isUndo);
02946               else if (ss->contains("CONVERT"))
02947                      restoreType(ss, isUndo);
02948               else if (ss->contains("TEXTFLOW_OLDMODE"))
02949                      restoreTextFlowing(ss, isUndo);
02950               else if (ss->contains("SCALE_TYPE"))
02951                      restoreImageScaleType(ss, isUndo);
02952               else if (ss->contains("OLD_IMAGEXSCALE"))
02953                      restoreImageScaleChange(ss, isUndo);
02954               else if (ss->contains("OLD_IMAGEXOFFSET"))
02955                      restoreImageOffsetChange(ss, isUndo);     
02956               else if (ss->contains("ASPECT_RATIO"))
02957                      restoreImageScaleType(ss, isUndo);
02958               else if (ss->contains("EDIT_CONTOUR"))
02959                      restorePoly(ss, isUndo, true);
02960               else if (ss->contains("EDIT_SHAPE"))
02961                      restorePoly(ss, isUndo, false);
02962               else if (ss->contains("RESET_CONTOUR"))
02963                      restoreContourLine(ss, isUndo);
02964               else if (ss->contains("MIRROR_PATH_H"))
02965               {
02966                      bool editContour = view->EditContour;
02967                      view->EditContour = ss->getBool("IS_CONTOUR");
02968                      select();
02969                      m_Doc->MirrorPolyH(m_Doc->m_Selection->itemAt(0));
02970                      view->EditContour = editContour;
02971               }
02972               else if (ss->contains("MIRROR_PATH_V"))
02973               {
02974                      bool editContour = view->EditContour;
02975                      view->EditContour = ss->getBool("IS_CONTOUR");
02976                      select();
02977                      m_Doc->MirrorPolyV(m_Doc->m_Selection->itemAt(0));
02978                      view->EditContour = editContour;
02979               }
02980               else if (ss->contains("SEND_TO_LAYER"))
02981                      restoreLayer(ss, isUndo);
02982               else if (ss->contains("GET_IMAGE"))
02983                      restoreGetImage(ss, isUndo);
02984               else if (ss->contains("EDIT_SHAPE_OR_CONTOUR"))
02985                      restoreShapeContour(ss, isUndo);
02986               else if (ss->contains("APPLY_IMAGE_EFFECTS"))
02987                      restoreImageEffects(ss, isUndo);
02988        }
02989        if (!OnMasterPage.isEmpty())
02990               m_Doc->setCurrentPage(oldCurrentPage);
02991        m_Doc->setMasterPageMode(oldMPMode);
02992        m_Doc->useRaster = useRasterBackup;
02993        m_Doc->SnapGuides = SnapGuidesBackup;
02994 }
02995 
02996 void PageItem::restoreMove(SimpleState *state, bool isUndo)
02997 {
02998        double ox = state->getDouble("OLD_XPOS");
02999        double oy = state->getDouble("OLD_YPOS");
03000        double  x = state->getDouble("NEW_XPOS");
03001        double  y = state->getDouble("NEW_YPOS");
03002        double mx = ox - x;
03003        double my = oy - y;
03004        if (!isUndo)
03005        {
03006               mx = -mx;
03007               my = -my;
03008        }
03009        m_Doc->MoveItem(mx, my, this, false);
03010        oldXpos = Xpos;
03011        oldYpos = Ypos;
03012        oldOwnPage = OwnPage;
03013 }
03014 
03015 void PageItem::restoreResize(SimpleState *state, bool isUndo)
03016 {
03017        double  ow = state->getDouble("OLD_WIDTH");
03018        double  oh = state->getDouble("OLD_HEIGHT");
03019        double   w = state->getDouble("NEW_WIDTH");
03020        double   h = state->getDouble("NEW_HEIGHT");
03021        double  ox = state->getDouble("OLD_RXPOS");
03022        double  oy = state->getDouble("OLD_RYPOS");
03023        double   x = state->getDouble("NEW_RXPOS");
03024        double   y = state->getDouble("NEW_RYPOS");
03025        double ort = state->getDouble("OLD_RROT");
03026        double  rt = state->getDouble("NEW_RROT");
03027        double  mx = ox - x;
03028        double  my = oy - y;
03029        if (isUndo)
03030        {
03031               m_Doc->SizeItem(ow, oh, this, false, true, true);
03032               m_Doc->MoveItem(mx, my, this, false);
03033               m_Doc->RotateItem(ort, this);
03034        }
03035        else
03036        {
03037               mx = -mx;
03038               my = -my;
03039               m_Doc->SizeItem(w, h, this, false, true, true);
03040               m_Doc->MoveItem(mx, my, this, false);
03041               m_Doc->RotateItem(rt, this);
03042        }
03043        oldWidth = Width;
03044        oldHeight = Height;
03045        oldXpos = Xpos;
03046        oldYpos = Ypos;
03047        oldOwnPage = OwnPage;
03048        oldRot = Rot;
03049 }
03050 
03051 void PageItem::restoreRotate(SimpleState *state, bool isUndo)
03052 {
03053        double ort = state->getDouble("OLD_ROT");
03054        double  rt = state->getDouble("NEW_ROT");
03055        double  ox = state->getDouble("OLD_RXPOS");
03056        double  oy = state->getDouble("OLD_RYPOS");
03057        double   x = state->getDouble("NEW_RXPOS");
03058        double   y = state->getDouble("NEW_RYPOS");
03059        double  ow = state->getDouble("OLD_RWIDTH");
03060        double  oh = state->getDouble("OLD_RHEIGHT");
03061        double   w = state->getDouble("NEW_RWIDTH");
03062        double   h = state->getDouble("NEW_RHEIGHT");
03063        double mx = ox - x;
03064        double my = oy - y;
03065        //CB Commented out test code
03066        //QRect oldR(getRedrawBounding(view->scale()));
03067        if (isUndo)
03068        {
03069               /*Rot=ort;
03070               Xpos+=mx;
03071               Ypos+=my;
03072               Width=ow;
03073               Height=oh;*/
03074               m_Doc->RotateItem(ort, this);
03075               m_Doc->MoveItem(mx, my, this, false);
03076               m_Doc->SizeItem(ow, oh, this, false, true, true);
03077        }
03078        else
03079        {
03080               mx = -mx;
03081               my = -my;
03082               /*
03083               Rot=rt;
03084               Xpos-=mx;
03085               Ypos-=my;
03086               Width=w;
03087               Height=h;
03088               */
03089               m_Doc->RotateItem(rt, this);
03090               m_Doc->MoveItem(mx, my, this, false);
03091               m_Doc->SizeItem(w, h, this, false, true, true);
03092        }
03093        /*
03094        m_Doc->setRedrawBounding(this);
03095        QRect newR(getRedrawBounding(view->scale()));
03096        view->updateContents(newR.unite(oldR));
03097        OwnPage = m_Doc->OnPage(this);
03098        */
03099        oldRot = Rot;
03100        oldXpos = Xpos;
03101        oldYpos = Ypos;
03102        oldOwnPage = OwnPage;
03103        oldWidth = Width;
03104        oldHeight = Height;
03105 }
03106 
03107 void PageItem::restoreFill(SimpleState *state, bool isUndo)
03108 {
03109        QString fill = state->get("OLD_FILL");
03110        if (!isUndo)
03111               fill = state->get("NEW_FILL");
03112        select();
03113        m_Doc->ItemBrush(fill);
03114 }
03115 
03116 void PageItem::restoreShade(SimpleState *state, bool isUndo)
03117 {
03118        int shade = state->getInt("OLD_SHADE");
03119        if (!isUndo)
03120               shade = state->getInt("NEW_SHADE");
03121        select();
03122        m_Doc->ItemBrushShade(shade);
03123 }
03124 
03125 void PageItem::restoreLineColor(SimpleState *state, bool isUndo)
03126 {
03127        QString fill = state->get("OLD_COLOR");
03128        if (!isUndo)
03129               fill = state->get("NEW_COLOR");
03130        select();
03131        m_Doc->ItemPen(fill);
03132 }
03133 
03134 void PageItem::restoreLineShade(SimpleState *state, bool isUndo)
03135 {
03136        int shade = state->getInt("OLD_SHADE");
03137        if (!isUndo)
03138               shade = state->getInt("NEW_SHADE");
03139        select();
03140        m_Doc->ItemPenShade(shade);
03141 }
03142 
03143 void PageItem::restoreFillTP(SimpleState *state, bool isUndo)
03144 {
03145        double tp = state->getDouble("OLD_TP");
03146        if (!isUndo)
03147               tp = state->getDouble("NEW_TP");
03148        select();
03149        m_Doc->itemSelection_SetItemFillTransparency(tp);
03150 }
03151 
03152 void PageItem::restoreLineTP(SimpleState *state, bool isUndo)
03153 {
03154        double tp = state->getDouble("OLD_TP");
03155        if (!isUndo)
03156               tp = state->getDouble("NEW_TP");
03157        select();
03158        m_Doc->itemSelection_SetItemLineTransparency(tp);
03159 }
03160 
03161 
03162 void PageItem::restoreLineStyle(SimpleState *state, bool isUndo)
03163 {
03164        PenStyle ps = static_cast<PenStyle>(state->getInt("OLD_STYLE"));
03165        if (!isUndo)
03166               ps = static_cast<PenStyle>(state->getInt("NEW_STYLE"));
03167        select();
03168        m_Doc->ChLineArt(ps);
03169 }
03170 
03171 void PageItem::restoreLineEnd(SimpleState *state, bool isUndo)
03172 {
03173        PenCapStyle pcs = static_cast<PenCapStyle>(state->getInt("OLD_STYLE"));
03174        if (!isUndo)
03175               pcs = static_cast<PenCapStyle>(state->getInt("NEW_STYLE"));
03176        select();
03177        m_Doc->ChLineEnd(pcs);
03178 }
03179 
03180 void PageItem::restoreLineJoin(SimpleState *state, bool isUndo)
03181 {
03182        PenJoinStyle pjs = static_cast<PenJoinStyle>(state->getInt("OLD_STYLE"));
03183        if (!isUndo)
03184               pjs = static_cast<PenJoinStyle>(state->getInt("NEW_STYLE"));
03185        select();
03186        m_Doc->ChLineJoin(pjs);
03187 }
03188 
03189 void PageItem::restoreLineWidth(SimpleState *state, bool isUndo)
03190 {
03191        double w = state->getDouble("OLD_WIDTH");
03192        if (!isUndo)
03193               w = state->getDouble("NEW_WIDTH");
03194        select();
03195        m_Doc->ChLineWidth(w);
03196 }
03197 
03198 void PageItem::restoreCustomLineStyle(SimpleState *state, bool isUndo)
03199 {
03200        QString style = state->get("OLD_STYLE");
03201        if (!isUndo)
03202               style = state->get("NEW_STYLE");
03203        setCustomLineStyle(style);
03204 }
03205 
03206 void PageItem::restoreName(SimpleState *state, bool isUndo)
03207 {
03208        QString name = state->get("OLD_NAME");
03209        if (!isUndo)
03210               name = state->get("NEW_NAME");
03211        setItemName(name);
03212 }
03213 
03214 void PageItem::restoreArrow(SimpleState *state, bool isUndo, bool isStart)
03215 {
03216        int i = state->getInt("OLD_INDEX");
03217        if (!isUndo)
03218               i = state->getInt("NEW_INDEX");
03219        if (isStart)
03220               setStartArrowIndex(i);
03221        else
03222               setEndArrowIndex(i);
03223 }
03224 
03225 
03226 void PageItem::restorePStyle(SimpleState *state, bool isUndo)
03227 {
03228        int styleid = state->getInt("OLD_STYLE");
03229        if (!isUndo)
03230               styleid = state->getInt("NEW_STYLE");
03231        //will be done later with other text-undo:
03232        //     m_Doc->chAbStyle(this, styleid);
03233 }
03234 
03235 
03236 // This must go into class ScribusDoc!
03237 // For now we'll just make it independent of 'this' -- AV
03238 void PageItem::restoreType(SimpleState *state, bool isUndo)
03239 {
03240        // well, probably not the best way to handle pointers...
03241        PageItem * item = reinterpret_cast<PageItem *>(state->getInt("PAGEITEM"));
03242        int type = state->getInt("OLD_TYPE");
03243        if (!isUndo)
03244               type = state->getInt("NEW_TYPE");
03245        ScribusView* view = m_Doc->view();
03246        view->Deselect(false);
03247        view->SelectItem(item, false);
03248        switch (type) {
03249               case ImageFrame: view->ToPicFrame(); break;
03250               case TextFrame: view->ToTextFrame(); break;
03251               case Polygon: view->ToPolyFrame(); break;
03252               case PolyLine: view->ToBezierFrame(); break;
03253        }
03254        m_Doc->scMW()->setAppMode(modeNormal);
03255 }
03256 
03257 void PageItem::restoreTextFlowing(SimpleState *state, bool isUndo)
03258 {
03259        TextFlowMode oldMode = (TextFlowMode) state->getInt("TEXTFLOW_OLDMODE");
03260        TextFlowMode newMode = (TextFlowMode) state->getInt("TEXTFLOW_NEWMODE");
03261        if (isUndo)
03262               textFlowModeVal = oldMode;
03263        else
03264               textFlowModeVal = newMode;
03265 }
03266 
03267 void PageItem::restoreImageScaleType(SimpleState *state, bool isUndo)
03268 {
03269        bool type=ScaleType;
03270        if (state->contains("SCALE_TYPE"))
03271        {
03272               if (isUndo)
03273                      type = !state->getBool("SCALE_TYPE");
03274               else
03275                      type = state->getBool("SCALE_TYPE");
03276        }
03277 
03278        bool ratio=AspectRatio;
03279        if (state->contains("ASPECT_RATIO"))
03280        {
03281               if (isUndo)
03282                      ratio = !state->getBool("ASPECT_RATIO");
03283               else
03284                      ratio = state->getBool("ASPECT_RATIO");
03285        }
03286 
03287        setImageScalingMode(type, ratio);
03288 }
03289 
03290 void PageItem::restoreImageScaleChange(SimpleState *state, bool isUndo)
03291 {
03292        double oscx = state->getDouble("OLD_IMAGEXSCALE");
03293        double oscy = state->getDouble("OLD_IMAGEYSCALE");
03294        double  scx = state->getDouble("NEW_IMAGEXSCALE");
03295        double  scy = state->getDouble("NEW_IMAGEYSCALE");
03296        Selection tempSelection(this, false);
03297        tempSelection.addItem(this, true);
03298        if (!isUndo)
03299               m_Doc->itemSelection_SetImageScale(scx, scy, &tempSelection);
03300        else
03301               m_Doc->itemSelection_SetImageScale(oscx, oscy, &tempSelection);
03302 }
03303 
03304 void PageItem::restoreImageOffsetChange(SimpleState *state, bool isUndo)
03305 {
03306        double ox = state->getDouble("OLD_IMAGEXOFFSET");
03307        double oy = state->getDouble("OLD_IMAGEYOFFSET");
03308        double  x = state->getDouble("NEW_IMAGEXOFFSET");
03309        double  y = state->getDouble("NEW_IMAGEYOFFSET");
03310        Selection tempSelection(this, false);
03311        tempSelection.addItem(this, true);
03312        if (!isUndo)
03313               m_Doc->itemSelection_SetImageOffset(x, y, &tempSelection);
03314        else
03315               m_Doc->itemSelection_SetImageOffset(ox, oy, &tempSelection);
03316 }
03317 
03318 void PageItem::restorePoly(SimpleState *state, bool isUndo, bool isContour)
03319 {
03320        int mode    = state->getInt("MODE");
03321        int rot     = state->getInt("ROT");
03322        ScribusView* view = m_Doc->view();
03323        double scaling = state->getDouble("SCALING");
03324        bool editContour = view->EditContour;
03325        view->EditContour = isContour;
03326        select();
03327        if (isUndo)
03328        {
03329               if (mode % 2 != 0 && mode != 0)
03330                      --mode;
03331               else
03332                      ++mode;
03333               if (mode == 2)
03334                      scaling = (1.0 - (100.0 / (100.0 + scaling))) * 100.0;
03335               else if (mode == 3)
03336                      scaling = ((100.0 / (100.0 - scaling)) - 1.0) * 100.0;
03337        }
03338        view->TransformPoly(mode, rot, scaling);
03339        view->EditContour = editContour;
03340 }
03341 
03342 void PageItem::restoreContourLine(SimpleState *state, bool isUndo)
03343 {
03344        ItemState<FPointArray> *is = dynamic_cast<ItemState<FPointArray>*>(state);
03345        if (is)
03346        {
03347               if (isUndo)
03348                      ContourLine = is->getItem();
03349               else
03350                      ContourLine = PoLine.copy();
03351               ClipEdited = true;
03352        }
03353 }
03354 
03355 void PageItem::restoreLayer(SimpleState *state, bool isUndo)
03356 {
03357        ScribusView* view = m_Doc->view();
03358        setLayer(isUndo ? state->getInt("OLD_LAYER") : state->getInt("NEW_LAYER"));
03359        view->Deselect(true);
03360        view->updateContents();
03361 }
03362 
03363 void PageItem::restoreGetImage(SimpleState *state, bool isUndo)
03364 {
03365        QString fn = state->get("OLD_IMAGE_PATH");
03366        if (!isUndo)
03367               fn = state->get("NEW_IMAGE_PATH");
03368        if (fn.isEmpty())
03369        {
03370               Selection tempSelection(this, false);
03371               tempSelection.addItem(this, true);
03372               m_Doc->itemSelection_ClearItem(&tempSelection);
03373        }
03374        else
03375               loadImage(fn, false);
03376 }
03377 
03378 void PageItem::restoreShapeContour(UndoState *state, bool isUndo)
03379 {
03380        ItemState<QPair<FPointArray,FPointArray> > *istate =
03381                      dynamic_cast<ItemState<QPair<FPointArray,FPointArray> >*>(state);
03382        if (istate)
03383        {
03384               FPointArray oldClip = istate->getItem().first;
03385               FPointArray newClip = istate->getItem().second;
03386               bool isContour = istate->getBool("IS_CONTOUR");
03387               double oldX = istate->getDouble("OLD_X");
03388               double oldY = istate->getDouble("OLD_Y");
03389               double newX = istate->getDouble("NEW_X");
03390               double newY = istate->getDouble("NEW_Y");
03391               double mx = oldX - newX;
03392               double my = oldY - newY;
03393 
03394               if (isUndo)
03395               {
03396                      if (isContour)
03397                             ContourLine = oldClip;
03398                      else
03399                             PoLine = oldClip;
03400               }
03401               else
03402               {
03403                      mx = -mx;
03404                      my = -my;
03405                      if (isContour)
03406                             ContourLine = newClip;
03407                      else
03408                             PoLine = newClip;
03409               }
03410               m_Doc->AdjustItemSize(this);
03411               m_Doc->MoveItem(mx, my, this, false);
03412               m_Doc->view()->slotUpdateContents();
03413        }
03414 
03415 }
03416 
03417 void PageItem::restoreImageEffects(UndoState *state, bool isUndo)
03418 {
03419        ItemState<QPair<ScImageEffectList, ScImageEffectList> > *istate =
03420        dynamic_cast<ItemState<QPair<ScImageEffectList,ScImageEffectList> >*>(state);
03421        if (istate)
03422        {
03423               if (isUndo)
03424                      effectsInUse = istate->getItem().first;
03425               else
03426                      effectsInUse = istate->getItem().second;
03427 
03428               select();
03429               m_Doc->updatePic();
03430        }
03431 }
03432 
03433 void PageItem::select()
03434 {
03435        m_Doc->view()->Deselect(false);
03436        //CB #2969 add this true parm to addItem so we dont connectToGUI, the rest of view->SelectItem isnt needed anyway
03437        m_Doc->m_Selection->addItem(this, true);
03438 }
03439 
03440 ObjAttrVector* PageItem::getObjectAttributes()
03441 {
03442        return &pageItemAttributes;
03443 }
03444 
03445 ObjectAttribute PageItem::getObjectAttribute(QString attributeName) const
03446 {
03447        int countFound=0;
03448        ObjAttrVector::const_iterator foundIt = pageItemAttributes.begin();
03449        for(ObjAttrVector::const_iterator objAttrIt = pageItemAttributes.begin() ; objAttrIt != pageItemAttributes.end(); ++objAttrIt )
03450        {
03451               if ((*objAttrIt).name==attributeName)
03452               {
03453                      ++countFound;
03454                      foundIt=objAttrIt;
03455               }
03456        }
03457        ObjectAttribute returnAttribute;
03458        if(countFound==1)
03459               returnAttribute=(*foundIt);
03460        else
03461               returnAttribute.name=QString::null;
03462        return returnAttribute;
03463 }
03464 
03465 
03466 void PageItem::setObjectAttributes(ObjAttrVector* map)
03467 {
03468        pageItemAttributes=*map;
03469 }
03470 
03471 QString PageItem::generateUniqueCopyName(const QString originalName) const
03472 {
03473        if (!m_Doc->itemNameExists(originalName))
03474               return originalName;
03475 
03476        // Start embellishing the name until we get an acceptable unique name
03477        // first we prefix `Copy of' if it's not already there
03478        QString newname(originalName);
03479        if (!originalName.startsWith( tr("Copy of")))
03480               newname.prepend( tr("Copy of")+" ");
03481 
03482        // See if the name prefixed by "Copy of " is free
03483        if (m_Doc->itemNameExists(newname))
03484        {
03485               // Search the string for (number) at the end and capture
03486               // both the number and the text leading up to it sans brackets.
03487               //     Copy of fred (5)
03488               //     ^^^^^^^^^^^^  ^   (where ^ means captured)
03489               static QRegExp rx("^(.*)\\s+\\((\\d+)\\)$");
03490               int numMatches = rx.searchRev(newname);
03491               // Add a (number) suffix to the end of the name. We start at the
03492               // old suffix's value if there was one, or at 2 if there was not.
03493               int suffixnum = 2;
03494               QString prefix(newname);
03495               if (numMatches != -1)
03496               {
03497                      // Already had a suffix; use the name w/o suffix for prefix and
03498                      // grab the old suffix value as a starting point.
03499                      QStringList matches = rx.capturedTexts();
03500                      prefix = matches[1];
03501                      suffixnum = matches[2].toInt();
03502               }
03503               // Keep on incrementing the suffix 'till we find a free name
03504               do
03505               {
03506                      newname = prefix + " (" + QString::number(suffixnum) + ")";
03507                      suffixnum ++;
03508               }
03509               while (m_Doc->itemNameExists(newname));
03510        }
03511        assert(!m_Doc->itemNameExists(newname));
03512        return newname;
03513 }
03514 
03515 void PageItem::setTagged(bool tag)
03516 {
03517        tagged=tag;
03518 }
03519 
03520 void PageItem::replaceNamedResources(ResourceCollection& newNames) 
03521 {
03522        QMap<QString,QString>::ConstIterator it;
03523 
03524        it = newNames.colors().find(fillColor());
03525        if (it != newNames.colors().end())
03526               setFillColor(*it);
03527 
03528        it = newNames.colors().find(lineColor());
03529        if (it != newNames.colors().end())
03530               setFillColor(*it);
03531 
03532        QPtrVector<VColorStop> cstops = fill_gradient.colorStops();
03533        for (uint cst = 0; cst < fill_gradient.Stops(); ++cst)
03534        {
03535               it = newNames.colors().find(cstops.at(cst)->name);
03536               if (it != newNames.colors().end())
03537                      cstops.at(cst)->name = *it;
03538        }
03539        
03540        it = newNames.patterns().find(pattern());
03541        if (it != newNames.patterns().end())
03542               setPattern(*it);
03543 
03544        it = newNames.lineStyles().find(customLineStyle());
03545        if (it != newNames.lineStyles().end())
03546               setCustomLineStyle(*it);
03547 
03548        if (prevInChain() == NULL)
03549               itemText.replaceNamedResources(newNames);
03550 }
03551 
03552 
03553 void PageItem::getNamedResources(ResourceCollection& lists) const
03554 {
03555        lists.collectColor(fillColor());
03556        lists.collectColor(lineColor());
03557        QPtrVector<VColorStop> cstops = fill_gradient.colorStops();
03558        for (uint cst = 0; cst < fill_gradient.Stops(); ++cst)
03559        {
03560               lists.collectColor(cstops.at(cst)->name);
03561        }
03562        lists.collectPattern(pattern());
03563        lists.collectLineStyle(customLineStyle());
03564        if (prevInChain() == NULL)
03565               itemText.getNamedResources(lists);
03566 }
03567 
03568 void PageItem::copyToCopyPasteBuffer(struct CopyPasteBuffer *Buffer)
03569 {
03570        Buffer->PType = itemType();
03571        Buffer->Xpos = Xpos;
03572        Buffer->Ypos = Ypos;
03573        Buffer->Width = Width;
03574        Buffer->Height = Height;
03575        Buffer->RadRect = RadRect;
03576        Buffer->FrameType = FrameType;
03577        Buffer->ClipEdited = ClipEdited;
03578        Buffer->Pwidth = m_lineWidth;
03579        Buffer->Pcolor = fillColor();
03580        Buffer->Pcolor2 = lineColor();
03581        Buffer->Shade = fillShade();
03582        Buffer->Shade2 = lineShade();
03583        Buffer->FillRule = fillRule;
03584        Buffer->GrColor = "";
03585        Buffer->GrColor2 = "";
03586        Buffer->GrShade = 100;
03587        Buffer->GrShade2 = 100;
03588        Buffer->fill_gradient = fill_gradient;
03589        Buffer->GrType = GrType;
03590        Buffer->GrStartX = GrStartX;
03591        Buffer->GrStartY = GrStartY;
03592        Buffer->GrEndX = GrEndX;
03593        Buffer->GrEndY = GrEndY;
03594        Buffer->Rot = Rot;
03595        Buffer->PLineArt = PLineArt;
03596        Buffer->PLineEnd = PLineEnd;
03597        Buffer->PLineJoin = PLineJoin;
03598        Buffer->LocalScX = LocalScX;
03599        Buffer->LocalScY = LocalScY;
03600        Buffer->LocalX = LocalX;
03601        Buffer->LocalY = LocalY;
03602        Buffer->PicArt = PicArt;
03603        Buffer->flippedH = imageFlippedH();
03604        Buffer->flippedV = imageFlippedV();
03605 /*     Buffer->BBoxX = BBoxX;
03606        Buffer->BBoxH = BBoxH; */
03607        Buffer->isPrintable = printEnabled();
03608        Buffer->isBookmark = isBookmark;
03609 //     Buffer->BMnr = BMnr;
03610        Buffer->m_isAnnotation = m_isAnnotation;
03611        Buffer->m_annotation = m_annotation;
03612        Buffer->Extra = Extra;
03613        Buffer->TExtra = TExtra;
03614        Buffer->BExtra = BExtra;
03615        Buffer->RExtra = RExtra;
03616        Buffer->Pfile = Pfile;
03617        Buffer->Pfile2 = Pfile2;
03618        Buffer->Pfile3 = Pfile3;
03619        QString Text = "";
03620        uint itemTextCount=itemText.length();
03621        if (itemTextCount != 0)
03622        {
03623               for (uint a=0; a<itemTextCount; ++a)
03624               {
03625                      if( (itemText.text(a) == '\n') || (itemText.text(a) == '\r'))
03626                             Text += QString(QChar(5))+"\t";
03627                      else if(itemText.text(a) == '\t')
03628                             Text += QString(QChar(4))+"\t";
03629                      else
03630                             Text += itemText.text(a,1)+"\t";
03631                      Text += itemText.charStyle(a).font().scName()+"\t";
03632                      Text += QString::number(itemText.charStyle(a).fontSize() / 10.0)+"\t";
03633                      Text += itemText.charStyle(a).fillColor()+"\t";
03634                      Text += QString::number(itemText.charStyle(a).tracking())+"\t";
03635                      Text += QString::number(itemText.charStyle(a).fillShade())+'\t';
03636                      Text += QString::number(itemText.charStyle(a).effects())+'\t';
03637                      Text += QString::number(findParagraphStyle(m_Doc, itemText.paragraphStyle(a)))+'\t';
03638                      Text += itemText.charStyle(a).strokeColor()+"\t";
03639                      Text += QString::number(itemText.charStyle(a).strokeShade())+'\t';
03640                      Text += QString::number(itemText.charStyle(a).scaleH())+'\t';
03641                      Text += QString::number(itemText.charStyle(a).scaleV())+'\t';
03642                      Text += QString::number(itemText.charStyle(a).baselineOffset())+'\t';
03643                      Text += QString::number(itemText.charStyle(a).shadowXOffset())+'\t';
03644                      Text += QString::number(itemText.charStyle(a).shadowYOffset())+'\t';
03645                      Text += QString::number(itemText.charStyle(a).outlineWidth())+'\t';
03646                      Text += QString::number(itemText.charStyle(a).underlineOffset())+'\t';
03647                      Text += QString::number(itemText.charStyle(a).underlineWidth())+'\t';
03648                      Text += QString::number(itemText.charStyle(a).strikethruOffset())+'\t';
03649                      Text += QString::number(itemText.charStyle(a).strikethruWidth())+'\n';
03650               }
03651        }
03652        Buffer->itemText = Text;
03653        Buffer->Clip = Clip.copy();
03654        Buffer->PoLine = PoLine.copy();
03655        Buffer->ContourLine = ContourLine.copy();
03656        //Buffer->UseContour = textFlowUsesContourLine();
03657        Buffer->DashValues = DashValues;
03658        Buffer->DashOffset = DashOffset;
03659        Buffer->PoShow = PoShow;
03660        Buffer->BaseOffs = BaseOffs;
03661        Buffer->textPathFlipped = textPathFlipped;
03662        Buffer->textPathType = textPathType;
03663        Buffer->TextflowMode = textFlowMode();
03664        Buffer->Groups = Groups;
03665        Buffer->IProfile = IProfile;
03666        Buffer->IRender = IRender;
03667        Buffer->UseEmbedded = UseEmbedded;
03668        Buffer->EmProfile = EmProfile;
03669        Buffer->LayerNr = LayerNr;
03670        Buffer->ScaleType = ScaleType;
03671        Buffer->AspectRatio = AspectRatio;
03672        Buffer->Locked = locked();
03673        Buffer->LockRes = sizeLocked();
03674        Buffer->Transparency = fillTransparency();
03675        Buffer->TranspStroke = lineTransparency();
03676        Buffer->TransBlend = fillBlendmode();
03677        Buffer->TransBlendS = lineBlendmode();
03678        Buffer->Reverse = Reverse;
03679        Buffer->NamedLStyle = NamedLStyle;
03680        Buffer->Cols = Cols;
03681        Buffer->ColGap = ColGap;
03682        Buffer->isTableItem = isTableItem;
03683        Buffer->TopLine = TopLine;
03684        Buffer->LeftLine = LeftLine;
03685        Buffer->RightLine = RightLine;
03686        Buffer->BottomLine = BottomLine;
03687        if (isTableItem)
03688        {
03689               if (TopLink != 0)
03690                      Buffer->TopLinkID = TopLink->ItemNr;
03691               else
03692                      Buffer->TopLinkID = -1;
03693               if (LeftLink != 0)
03694                      Buffer->LeftLinkID = LeftLink->ItemNr;
03695               else
03696                      Buffer->LeftLinkID = -1;
03697               if (RightLink != 0)
03698                      Buffer->RightLinkID = RightLink->ItemNr;
03699               else
03700                      Buffer->RightLinkID = -1;
03701               if (BottomLink != 0)
03702                      Buffer->BottomLinkID = BottomLink->ItemNr;
03703               else
03704                      Buffer->BottomLinkID = -1;
03705        }
03706        Buffer->startArrowIndex = m_startArrowIndex;
03707        Buffer->endArrowIndex = m_endArrowIndex;
03708 }
03709 
03710 
03711 //Moved from View
03712 void PageItem::SetFrameShape(int count, double *vals)
03713 {
03714        PoLine.resize(0);
03715        for (int a = 0; a < count-3; a += 4)
03716        {
03717               if (vals[a] < 0)
03718               {
03719                      PoLine.setMarker();
03720                      continue;
03721               }
03722               double x1 = Width * vals[a] / 100.0;
03723               double y1 = Height * vals[a+1] / 100.0;
03724               double x2 = Width * vals[a+2] / 100.0;
03725               double y2 = Height * vals[a+3] / 100.0;
03726               PoLine.addPoint(x1, y1);
03727               PoLine.addPoint(x2, y2);
03728        }
03729        Clip = FlattenPath(PoLine, Segments);
03730        ClipEdited = true;
03731 }
03732 
03733 void PageItem::SetRectFrame()
03734 {
03735        static double rect[] = {  0.0,   0.0,   0.0,   0.0,
03736                                                  100.0,   0.0, 100.0,   0.0,
03737                                                  100.0,   0.0, 100.0,   0.0,
03738                                                  100.0, 100.0, 100.0, 100.0,
03739                                                  100.0, 100.0, 100.0, 100.0,
03740                                                    0.0, 100.0,   0.0, 100.0,
03741                                                    0.0, 100.0,   0.0, 100.0,
03742                                                    0.0,   0.0,   0.0,   0.0};
03743        SetFrameShape(32, rect);
03744        ClipEdited = false;
03745        FrameType = 0;
03746 }
03747 
03748 void PageItem::SetOvalFrame()
03749 {
03750        static double rect[] = {   100.0,  50.0, 100.0,       77.615235,
03751                                                         50.0, 100.0,  77.615235, 100.0,
03752                                                         50.0, 100.0,  22.385765, 100.0,
03753                                                          0.0,  50.0,   0.0,       77.615235,
03754                                                          0.0,  50.0,   0.0,       22.385765,
03755                                                         50.0,   0.0,  22.385765,   0.0,
03756                                                         50.0,   0.0,  77.615235,   0.0,
03757                                                     100.0,  50.0, 100.0,       22.385765};
03758        SetFrameShape(32, rect);
03759        FrameType = 1;
03760        ClipEdited = false;
03761 }
03762 
03763 void PageItem::SetFrameRound()
03764 {
03765        setCornerRadius(QMIN(RadRect, QMIN(Width,Height)/2));
03766        PoLine.resize(0);
03767        double rr = fabs(RadRect);
03768        double bezierFactor=0.552284749; //Bezier Control Point Factor: 8/3*(sin(45)-0.5)
03769        double rrxBezierFactor=rr*bezierFactor;
03770        double Width_rr=Width-rr;
03771        double Height_rr=Height-rr;
03772        if (RadRect > 0)
03773        {
03774               PoLine.addQuadPoint(rr, 0, rr, 0, Width_rr, 0, Width_rr, 0);
03775               PoLine.addQuadPoint(Width_rr, 0, Width_rr+rrxBezierFactor, 0, Width, rr, Width, rrxBezierFactor);
03776               PoLine.addQuadPoint(Width, rr, Width, rr, Width, Height_rr, Width, Height_rr);
03777               PoLine.addQuadPoint(Width, Height_rr, Width, Height_rr+rrxBezierFactor, Width_rr, Height, Width_rr+rrxBezierFactor, Height);
03778               PoLine.addQuadPoint(Width_rr, Height, Width_rr, Height, rr, Height, rr, Height);
03779               PoLine.addQuadPoint(rr, Height, rrxBezierFactor, Height, 0, Height_rr, 0, Height_rr+rrxBezierFactor);
03780               PoLine.addQuadPoint(0, Height_rr, 0, Height_rr, 0, rr, 0, rr);
03781               PoLine.addQuadPoint(0, rr, 0, rrxBezierFactor, rr, 0, rr*bezierFactor, 0);
03782        }
03783        else
03784        {
03785               PoLine.addQuadPoint(rr, 0, rr, 0, Width_rr, 0, Width_rr, 0);
03786               PoLine.addQuadPoint(Width_rr, 0, Width_rr, rrxBezierFactor, Width, rr, Width-rrxBezierFactor, rr);
03787               PoLine.addQuadPoint(Width, rr, Width, rr, Width, Height_rr, Width, Height_rr);
03788               PoLine.addQuadPoint(Width, Height_rr, Width-rrxBezierFactor, Height_rr, Width_rr, Height, Width_rr, Height-rrxBezierFactor);
03789               PoLine.addQuadPoint(Width_rr, Height, Width_rr, Height, rr, Height, rr, Height);
03790               PoLine.addQuadPoint(rr, Height, rr, Height-rrxBezierFactor, 0, Height_rr, rrxBezierFactor, Height_rr);
03791               PoLine.addQuadPoint(0, Height_rr, 0, Height_rr, 0, rr, 0, rr);
03792               PoLine.addQuadPoint(0, rr, rrxBezierFactor, rr, rr, 0, rr, rr*bezierFactor);
03793        }
03794        Clip = FlattenPath(PoLine, Segments);
03795        ClipEdited = false;
03796        FrameType = 2;
03797 }
03798 
03799 void PageItem::getBoundingRect(double *x1, double *y1, double *x2, double *y2) const
03800 {
03801        double minx = 99999.9;
03802        double miny = 99999.9;
03803        double maxx = -99999.9;
03804        double maxy = -99999.9;
03805        if (Rot != 0)
03806        {
03807               FPointArray pb;
03808               pb.resize(0);
03809               pb.addPoint(FPoint(Xpos, Ypos));
03810               pb.addPoint(FPoint(Width,    0.0, Xpos, Ypos, Rot, 1.0, 1.0));
03811               pb.addPoint(FPoint(Width, Height, Xpos, Ypos, Rot, 1.0, 1.0));
03812               pb.addPoint(FPoint(  0.0, Height, Xpos, Ypos, Rot, 1.0, 1.0));
03813               for (uint pc = 0; pc < 4; ++pc)
03814               {
03815                      minx = QMIN(minx, pb.point(pc).x());
03816                      miny = QMIN(miny, pb.point(pc).y());
03817                      maxx = QMAX(maxx, pb.point(pc).x());
03818                      maxy = QMAX(maxy, pb.point(pc).y());
03819               }
03820               *x1 = minx;
03821               *y1 = miny;
03822               *x2 = maxx;
03823               *y2 = maxy;
03824        }
03825        else
03826        {
03827               *x1 = Xpos;
03828               *y1 = Ypos;
03829               *x2 = Xpos + Width;
03830               *y2 = Ypos + Height;
03831        }
03832 }
03833 
03834 
03835 bool PageItem::pointWithinItem(const int x, const int y) const
03836 {
03837        const_cast<PageItem*>(this)-> setRedrawBounding();
03838        // FIXME: We should be rounding or truncating here, not letting the compiler do it.
03839        // Should we be rounding, truncating up, or truncating down?
03840        //CB is this now correct?
03841        QRect itemRect( static_cast<int>(floor(BoundingX)), static_cast<int>(floor(BoundingY)), static_cast<int>(ceil(BoundingW)), static_cast<int>(ceil(BoundingH)) );
03842        return itemRect.contains(x, y);
03843 }
03844 
03845 bool PageItem::mouseWithinItem(QWidget* vport, const int x, const int y, double scale) const
03846 {
03847        QPainter p;
03848        QRect transRect;
03849        p.begin(vport);
03850        p.translate(static_cast<int>(Xpos * scale), static_cast<int>(Ypos*scale));
03851        p.scale(scale, scale);
03852        p.rotate(rotation());
03853        transRect = p.xForm(QRect(0, 0, static_cast<int>(width()), static_cast<int>(height())));
03854        p.end();
03855        return transRect.contains(x, y);
03856 }
03857 
03858 bool PageItem::loadImage(const QString& filename, const bool reload, const int gsResolution, bool showMsg)
03859 {
03860        if (! asImageFrame())
03861               return false;
03862        QFileInfo fi(filename);
03863        QString clPath(pixm.imgInfo.usedPath);
03864        pixm.imgInfo.valid = false;
03865        pixm.imgInfo.clipPath="";
03866        pixm.imgInfo.PDSpathData.clear();
03867        pixm.imgInfo.layerInfo.clear();
03868        pixm.imgInfo.usedPath="";
03869        imageClip.resize(0);
03870        int lowResTypeBack = pixm.imgInfo.lowResType;
03871        int gsRes=gsResolution;
03872        if (gsResolution==-1) //If it wasn't supplied, get it from PrefsManager.
03873               gsRes=PrefsManager::instance()->gsResolution();
03874        bool dummy;
03875        CMSettings cms(m_Doc, IProfile, IRender);
03876        if (!pixm.LoadPicture(filename, cms, UseEmbedded, true, ScImage::RGBProof, gsRes, &dummy, showMsg))
03877        {
03878               Pfile = fi.absFilePath();
03879               PicAvail = false;
03880 //            PicArt = false;
03881               return false;
03882        }
03883        else
03884        {
03885               if (UndoManager::undoEnabled() && !reload)
03886               {
03887                      SimpleState *ss = new SimpleState(Um::GetImage, filename, Um::IGetImage);
03888                      ss->set("GET_IMAGE", "get_image");
03889                      ss->set("OLD_IMAGE_PATH", Pfile);
03890                      ss->set("NEW_IMAGE_PATH", filename);
03891                      undoManager->action(this, ss);
03892               }
03893               double xres = pixm.imgInfo.xres;
03894               double yres = pixm.imgInfo.yres;
03895               PicAvail = true;
03896 //            PicArt = true;
03897               
03898               if (Pfile != filename)
03899               {
03900                      oldLocalScX = LocalScX = 72.0 / xres;
03901                      oldLocalScY = LocalScY = 72.0 / yres;
03902                      oldLocalX = LocalX = 0;
03903                      oldLocalY = LocalY = 0;
03904                      
03905                      if ((m_Doc->toolSettings.useEmbeddedPath) && (!pixm.imgInfo.clipPath.isEmpty()))
03906                      {
03907                             pixm.imgInfo.usedPath = pixm.imgInfo.clipPath;
03908                             clPath = pixm.imgInfo.clipPath;
03909                             if (pixm.imgInfo.PDSpathData.contains(clPath))
03910                             {
03911                                    imageClip = pixm.imgInfo.PDSpathData[clPath].copy();
03912                                    pixm.imgInfo.usedPath = clPath;
03913                                    QWMatrix cl;
03914                                    cl.translate(LocalX*LocalScX, LocalY*LocalScY);
03915                                    cl.scale(LocalScX, LocalScY);
03916                                    imageClip.map(cl);
03917                             }
03918                      }
03919               }
03920               
03921               Pfile = fi.absFilePath();
03922               if (reload && pixm.imgInfo.PDSpathData.contains(clPath))
03923               {
03924                      imageClip = pixm.imgInfo.PDSpathData[clPath].copy();
03925                      pixm.imgInfo.usedPath = clPath;
03926                      QWMatrix cl;
03927                      cl.translate(LocalX*LocalScX, LocalY*LocalScY);
03928                      cl.scale(LocalScX, LocalScY);
03929                      imageClip.map(cl);
03930               }
03931               BBoxX = pixm.imgInfo.BBoxX;
03932               BBoxH = pixm.imgInfo.BBoxH;
03933               OrigW = pixm.width();
03934               OrigH = pixm.height();
03935               QString ext = fi.extension(false).lower();
03936               isRaster = !(ext == "pdf" || ext == "ps" || ext == "eps" || ext == "epsi");
03937               UseEmbedded=pixm.imgInfo.isEmbedded;
03938               if (pixm.imgInfo.isEmbedded)
03939               {
03940                      IProfile = "Embedded " + pixm.imgInfo.profileName;
03941                      EmProfile = "Embedded " + pixm.imgInfo.profileName;
03942               }
03943               else
03944                      IProfile = pixm.imgInfo.profileName;
03945        }
03946        if (PicAvail)
03947        {
03948               if ((pixm.imgInfo.colorspace == 3) && (pixm.imgInfo.duotoneColors.count() != 0) && (!reload))
03949               {
03950                      QString efVal = "";
03951                      for (uint cc = 0; cc < pixm.imgInfo.duotoneColors.count(); cc++)
03952                      {
03953                             if (!m_Doc->PageColors.contains(pixm.imgInfo.duotoneColors[cc].Name))
03954                                    m_Doc->PageColors.insert(pixm.imgInfo.duotoneColors[cc].Name, pixm.imgInfo.duotoneColors[cc].Color);
03955                             efVal += pixm.imgInfo.duotoneColors[cc].Name+"\n";
03956                      }
03957                      m_Doc->scMW()->propertiesPalette->updateColorList();
03958                      struct ScImage::imageEffect ef;
03959                      if (pixm.imgInfo.duotoneColors.count() == 1)
03960                      {
03961                             efVal += "100";
03962                             ef.effectCode = ScImage::EF_COLORIZE;
03963                             ef.effectParameters = efVal;
03964                      }
03965                      else if (pixm.imgInfo.duotoneColors.count() == 2)
03966                      {
03967                             efVal += "100 100";
03968                             QString tmp;
03969                             FPointArray Vals = pixm.imgInfo.duotoneColors[0].Curve;
03970                             tmp.setNum(Vals.size());
03971                             efVal += " "+tmp;
03972                             for (uint p = 0; p < Vals.size(); p++)
03973                             {
03974                                    FPoint pv = Vals.point(p);
03975                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
03976                             }
03977                             efVal += " 0";
03978                             Vals = pixm.imgInfo.duotoneColors[1].Curve;
03979                             tmp.setNum(Vals.size());
03980                             efVal += " "+tmp;
03981                             for (uint p = 0; p < Vals.size(); p++)
03982                             {
03983                                    FPoint pv = Vals.point(p);
03984                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
03985                             }
03986                             efVal += " 0";
03987                             ef.effectCode = ScImage::EF_DUOTONE;
03988                             ef.effectParameters = efVal;
03989                      }
03990                      else if (pixm.imgInfo.duotoneColors.count() == 3)
03991                      {
03992                             efVal += "100 100 100";
03993                             QString tmp;
03994                             FPointArray Vals = pixm.imgInfo.duotoneColors[0].Curve;
03995                             tmp.setNum(Vals.size());
03996                             efVal += " "+tmp;
03997                             for (uint p = 0; p < Vals.size(); p++)
03998                             {
03999                                    FPoint pv = Vals.point(p);
04000                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
04001                             }
04002                             efVal += " 0";
04003                             Vals = pixm.imgInfo.duotoneColors[1].Curve;
04004                             tmp.setNum(Vals.size());
04005                             efVal += " "+tmp;
04006                             for (uint p = 0; p < Vals.size(); p++)
04007                             {
04008                                    FPoint pv = Vals.point(p);
04009                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
04010                             }
04011                             efVal += " 0";
04012                             Vals = pixm.imgInfo.duotoneColors[2].Curve;
04013                             tmp.setNum(Vals.size());
04014                             efVal += " "+tmp;
04015                             for (uint p = 0; p < Vals.size(); p++)
04016                             {
04017                                    FPoint pv = Vals.point(p);
04018                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
04019                             }
04020                             efVal += " 0";
04021                             ef.effectCode = ScImage::EF_TRITONE;
04022                             ef.effectParameters = efVal;
04023                      }
04024                      else if (pixm.imgInfo.duotoneColors.count() == 4)
04025                      {
04026                             efVal += "100 100 100 100";
04027                             QString tmp;
04028                             FPointArray Vals = pixm.imgInfo.duotoneColors[0].Curve;
04029                             tmp.setNum(Vals.size());
04030                             efVal += " "+tmp;
04031                             for (uint p = 0; p < Vals.size(); p++)
04032                             {
04033                                    FPoint pv = Vals.point(p);
04034                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
04035                             }
04036                             efVal += " 0";
04037                             Vals = pixm.imgInfo.duotoneColors[1].Curve;
04038                             tmp.setNum(Vals.size());
04039                             efVal += " "+tmp;
04040                             for (uint p = 0; p < Vals.size(); p++)
04041                             {
04042                                    FPoint pv = Vals.point(p);
04043                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
04044                             }
04045                             efVal += " 0";
04046                             Vals = pixm.imgInfo.duotoneColors[2].Curve;
04047                             tmp.setNum(Vals.size());
04048                             efVal += " "+tmp;
04049                             for (uint p = 0; p < Vals.size(); p++)
04050                             {
04051                                    FPoint pv = Vals.point(p);
04052                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
04053                             }
04054                             efVal += " 0";
04055                             Vals = pixm.imgInfo.duotoneColors[3].Curve;
04056                             tmp.setNum(Vals.size());
04057                             efVal += " "+tmp;
04058                             for (uint p = 0; p < Vals.size(); p++)
04059                             {
04060                                    FPoint pv = Vals.point(p);
04061                                    efVal += QString(" %1 %2").arg(pv.x()).arg(pv.y());
04062                             }
04063                             efVal += " 0";
04064                             ef.effectCode = ScImage::EF_QUADTONE;
04065                             ef.effectParameters = efVal;
04066                      }
04067                      effectsInUse.append(ef);
04068               }
04069               pixm.applyEffect(effectsInUse, m_Doc->PageColors, false);
04070               if (reload)
04071                      pixm.imgInfo.lowResType = lowResTypeBack;
04072               if (pixm.imgInfo.lowResType != 0)
04073               {
04074                      double scaling = pixm.imgInfo.xres / 36.0;
04075                      if (pixm.imgInfo.lowResType == 1)
04076                             scaling = pixm.imgInfo.xres / 72.0;
04077                      // Prevent exagerately large images when using low res preview modes
04078                      uint pixels = qRound(pixm.width() * pixm.height() / (scaling * scaling));
04079                      if (pixels > 3000000)
04080                      {
04081                             double ratio = pixels / 3000000.0;
04082                             scaling *= sqrt(ratio);
04083                      }
04084                      pixm.createLowRes(scaling);
04085                      pixm.imgInfo.lowResScale = scaling;
04086               }
04087               if ((m_Doc->view()->viewAsPreview) && (m_Doc->view()->previewVisual != 0))
04088               {
04089                      VisionDefectColor *defect = new VisionDefectColor();
04090                      QColor tmpC;
04091                      int h = pixm.qImagePtr()->height();
04092                      int w = pixm.qImagePtr()->width();
04093                      int r, g, b, a;
04094                      QRgb *s;
04095                      QRgb rgb;
04096                      for( int yi=0; yi < h; ++yi )
04097                      {
04098                             s = (QRgb*)(pixm.qImagePtr()->scanLine( yi ));
04099                             for( int xi = 0; xi < w; ++xi )
04100                             {
04101                                    rgb = *s;
04102                                    tmpC.setRgb(rgb);
04103                                    tmpC = defect->convertDefect(tmpC, m_Doc->view()->previewVisual);
04104                                    a = qAlpha(rgb);
04105                                    tmpC.getRgb(&r, &g, &b);
04106                                    *s = qRgba(r, g, b, a);
04107                                    s++;
04108                             }
04109                      }
04110                      delete defect;
04111               }
04112        }
04113        return true;
04114 }
04115 
04116 
04117 void PageItem::drawLockedMarker(ScPainter *p)
04118 {
04119        //TODO: CB clean
04120        double scp1 = 1 ;// / ScMW->view->scale();
04121        double ofwh = 6 * scp1;
04122        double ofx = Width - ofwh/2;
04123        double ofy = Height - ofwh*1.5;
04124        double bx1= ofx+ scp1;
04125        double by1= ofy+3 * scp1;
04126        double bw= 4*scp1;
04127        double bh= 2*scp1;
04128        ScribusView* view = m_Doc->view();
04129        p->setPen(Qt::black, 0.5 / view->scale(), SolidLine, FlatCap, MiterJoin);
04130        p->setPenOpacity(1.0);
04131        p->setBrush(Qt::white);
04132        p->setBrushOpacity(1.0);
04133        p->setFillMode(ScPainter::Solid);
04134        p->drawRect(ofx, ofy, ofwh, ofwh);
04135        p->setBrush(Qt::black);
04136        p->drawRect(bx1, by1, bw, bh);
04137        p->setPen(Qt::black, 1.5 / view->scale(), SolidLine, FlatCap, RoundJoin);
04138        if (m_Locked)
04139               p->drawLine(FPoint(bx1+scp1/2, ofy+scp1), FPoint(bx1+scp1/2, by1));
04140        p->drawLine(FPoint(bx1+scp1*3.5, ofy+scp1), FPoint(bx1+scp1*3.5, by1));
04141        p->drawLine(FPoint(bx1+scp1/2, ofy+scp1), FPoint(bx1+scp1*3.5, ofy+scp1));
04142 }
04143 
04144 void PageItem::AdjustPictScale()
04145 {
04146        if (itemType()!=PageItem::ImageFrame)
04147               return;
04148        if (ScaleType)
04149               return;
04150        if (OrigW == 0 || OrigH == 0)
04151               return;
04152        LocalX = 0;
04153        LocalY = 0;
04154        double xs = Width / static_cast<double>(OrigW);
04155        double ys = Height / static_cast<double>(OrigH);
04156        if (AspectRatio)
04157        {
04158               LocalScX = QMIN(xs, ys);
04159               LocalScY = QMIN(xs, ys);
04160        }
04161        else
04162        {
04163               LocalScX = xs;
04164               LocalScY = ys;
04165        }
04166        if (imageClip.size() != 0)
04167        {
04168               imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
04169               QWMatrix cl;
04170               cl.translate(LocalX*LocalScX, LocalY*LocalScY);
04171               cl.scale(LocalScX, LocalScY);
04172               imageClip.map(cl);
04173        }
04174        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY );
04175 }
04176 
04177 QRect PageItem::getRedrawBounding(const double viewScale)
04178 {
04179        int x = qRound(floor(BoundingX - Oldm_lineWidth / 2.0 - 5) * viewScale);
04180        int y = qRound(floor(BoundingY - Oldm_lineWidth / 2.0 - 5) * viewScale);
04181        int w = qRound(ceil(BoundingW + Oldm_lineWidth + 10) * viewScale);
04182        int h = qRound(ceil(BoundingH + Oldm_lineWidth + 10) * viewScale);
04183        QRect ret = QRect(x, y, w, h);
04184        ret.moveBy(qRound(-m_Doc->minCanvasCoordinate.x() * viewScale), qRound(-m_Doc->minCanvasCoordinate.y() * viewScale));
04185        return ret;
04186 }
04187 
04188 
04189 void PageItem::setRedrawBounding()
04190 {
04191        double bw, bh;
04192        getBoundingRect(&BoundingX, &BoundingY, &bw, &bh);
04193        BoundingW = bw - BoundingX;
04194        BoundingH = bh - BoundingY;
04195        if (asLine())
04196               BoundingH = QMAX(BoundingH, 1);
04197 }
04198 
04199 void PageItem::updateGradientVectors()
04200 {
04201 /*     switch (GrType)
04202        {
04203               case 0:
04204               case 1:
04205                      GrStartX = 0;
04206                      GrStartY = Height / 2.0;
04207                      GrEndX = Width;
04208                      GrEndY = Height / 2.0;
04209                      break;
04210               case 2:
04211                      GrStartX = Width / 2.0;
04212                      GrStartY = 0;
04213                      GrEndX = Width / 2.0;
04214                      GrEndY = Height;
04215                      break;
04216               case 3:
04217                      GrStartX = 0;
04218                      GrStartY = 0;
04219                      GrEndX = Width;
04220                      GrEndY = Height;
04221                      break;
04222               case 4:
04223                      GrStartX = 0;
04224                      GrStartY = Height;
04225                      GrEndX = Width;
04226                      GrEndY = 0;
04227                      break;
04228               case 5:
04229                      GrStartX = Width / 2.0;
04230                      GrStartY = Height / 2.0;
04231                      if (Width >= Height)
04232                      {
04233                             GrEndX = Width;
04234                             GrEndY = Height / 2.0;
04235                      }
04236                      else
04237                      {
04238                             GrEndX = Width / 2.0;
04239                             GrEndY = Height;
04240                      }
04241                      break;
04242               default:
04243                      break;
04244        } */
04245        //if (ScMW->view->SelItem.count()!=0 && this==ScMW->view->SelItem.at(0))
04246        //if (m_Doc->m_Selection->count()!=0 && m_Doc->m_Selection->primarySelectionIsMyself(this))
04247        //     ScMW->propertiesPalette->updateColorSpecialGradient();
04248        //CB Will only emit if connected, ie is first in GUI selection
04249        double dur=m_Doc->unitRatio();
04250        emit gradientColorUpdate(GrStartX*dur, GrStartY*dur, GrEndX*dur, GrEndY*dur, Width*dur, Height*dur);
04251 }
04252 
04253 void PageItem::setPolyClip(int up, int down)
04254 {
04255        Clip.resize(0);
04256        if (PoLine.size() < 4)
04257               return;
04258        double rot;
04259        int upval = up;
04260        int downval = down;
04261        if (up == 0)
04262               upval = 1;
04263        if (textPathFlipped)
04264        {
04265               upval *= -1;
04266               downval *= -1;
04267        }
04268        QPoint np, np2;
04269        QPointArray cl, cl1, cl2;
04270        cl = FlattenPath(PoLine, Segments);
04271        for (uint a = 0; a < cl.size()-1; ++a)
04272        {
04273               rot = xy2Deg(cl.point(a+1).x()-cl.point(a).x(),cl.point(a+1).y()-cl.point(a).y());
04274               QWMatrix ma;
04275               ma.rotate(rot);
04276               np = ma*QPoint(0, -upval);
04277               np2 = ma*QPoint(0, -downval);
04278               cl1.resize(cl1.size()+1);
04279               cl1.setPoint(cl1.size()-1, np+cl.point(a));
04280               cl1.resize(cl1.size()+1);
04281               cl1.setPoint(cl1.size()-1, np+cl.point(a+1));
04282               cl2.resize(cl2.size()+1);
04283               cl2.setPoint(cl2.size()-1, np2+cl.point(a));
04284               cl2.resize(cl2.size()+1);
04285               cl2.setPoint(cl2.size()-1, np2+cl.point(a+1));
04286        }
04287        cl1.resize(cl1.size()+1);
04288        cl1.setPoint(cl1.size()-1, np+cl.point(cl.size()-1));
04289        cl2.resize(cl2.size()+1);
04290        cl2.setPoint(cl2.size()-1, np2+cl.point(cl.size()-1));
04291        Clip.putPoints(Clip.size(), cl1.size(), cl1);
04292        for (int a2 = cl2.size()-1; a2 > -1; a2--)
04293        {
04294               Clip.resize(Clip.size()+1);
04295               Clip.setPoint(Clip.size()-1, cl2.point(a2));
04296        }
04297 }
04298 
04299 void PageItem::updatePolyClip()
04300 {
04301        int asce = 1;
04302        int desc = 1;
04303        uint itemTextCount=itemText.length();
04304        for (uint a = 0; a < itemTextCount; ++a)
04305        {
04306               const CharStyle& hl (itemText.charStyle(a));
04307               int des = static_cast<int>(hl.font().descent(hl.fontSize() / 10.0));
04308               int asc = static_cast<int>(hl.font().ascent(hl.fontSize() / 10.0));
04309               asce = QMAX(asce, asc);
04310               desc = QMAX(desc, des);
04311        }
04312        setPolyClip(static_cast<int>(asce-BaseOffs), static_cast<int>(desc-BaseOffs));
04313 }
04314 
04315 void PageItem::handleModeEditKey(QKeyEvent * /* k */, bool & /* keyRepeat */)
04316 {
04317 }
04318 
04319 bool PageItem::connectToGUI()
04320 {
04321        if (!ScCore->usingGUI())
04322               return false;
04323        if (!m_Doc->m_Selection->primarySelectionIs(this))
04324               return false;
04325        Mpalette* pp=m_Doc->scMW()->propertiesPalette;
04326        connect(this, SIGNAL(myself(PageItem *)), pp, SLOT(SetCurItem(PageItem *)));
04327        connect(this, SIGNAL(frameType(int)), m_Doc->scMW(), SLOT(HaveNewSel(int)));
04328        connect(this, SIGNAL(frameType(int)), m_Doc->view(), SLOT(selectionChanged()));
04329        connect(this, SIGNAL(frameType(int)), pp, SLOT(NewSel(int)));
04330        connect(this, SIGNAL(frameLocked(bool)), pp, SLOT(setLocked(bool)));
04331        connect(this, SIGNAL(frameSizeLocked(bool)), pp, SLOT(setSizeLocked(bool)));
04332        connect(this, SIGNAL(frameFlippedH(bool)), pp, SLOT(setFlippedH(bool)));
04333        connect(this, SIGNAL(frameFlippedV(bool)), pp, SLOT(setFlippedV(bool)));
04334        connect(this, SIGNAL(printEnabled(bool)), pp, SLOT(setPrintingEnabled(bool)));
04335        connect(this, SIGNAL(position(double, double)), pp, SLOT(setXY(double, double)));
04336        connect(this, SIGNAL(widthAndHeight(double, double)), pp, SLOT(setBH(double, double)));
04337        connect(this, SIGNAL(colors(QString, QString, int, int)), m_Doc->scMW(), SLOT(setCSMenu()));
04338 //     connect(this, SIGNAL(colors(QString, QString, int, int)), pp->Cpal, SLOT(setActFarben(QString, QString, int, int)));
04339 //     connect(this, SIGNAL(gradientType(int)), pp->Cpal, SLOT(setActGradient(int)));
04340        connect(this, SIGNAL(patternFill(QString, double, double, double, double, double)), pp->Cpal, SLOT(setActPattern(QString, double, double, double, double, double)));
04341 //     connect(this, SIGNAL(gradientColorUpdate(double, double, double, double, double, double)), pp->Cpal, SLOT(setSpecialGradient(double, double, double, double, double, double)));
04342        connect(this, SIGNAL(rotation(double)), pp, SLOT(setR(double)));
04343 //     connect(this, SIGNAL(transparency(double, double)), pp->Cpal, SLOT(setActTrans(double, double)));
04344 //     connect(this, SIGNAL(blendmode(int, int)), pp->Cpal, SLOT(setActBlend(int, int)));
04345        //Shape signals
04346        //Not connected when transferring code: void columns(int, double); //Number, gap
04347        connect(this, SIGNAL(cornerRadius(double)), pp, SLOT(setRR(double)));
04348        //     connect(view, SIGNAL(ItemTextCols(int, double)), propertiesPalette, SLOT(setCols(int, double)));
04349        //Line signals
04350        connect(this, SIGNAL(lineWidth(double)), pp, SLOT(setSvalue(double)));
04351        connect(this, SIGNAL(imageOffsetScale(double, double, double, double)), pp, SLOT(setLvalue(double, double, double, double)));
04352        connect(this, SIGNAL(lineStyleCapJoin(Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle)), pp, SLOT( setLIvalue(Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle)));
04353        //Frame text signals
04354        connect(this, SIGNAL(lineSpacing(double)), pp, SLOT(setLsp(double)));
04355        connect(this, SIGNAL(textToFrameDistances(double, double, double, double)), pp, SLOT(setDvals(double, double, double, double)));
04356        connect(this, SIGNAL(textKerning(int)), pp, SLOT(setExtra(int)));
04357        connect(this, SIGNAL(textStyle(int)), pp, SLOT(setStil(int)));
04358        connect(this, SIGNAL(textStyle(int)), m_Doc->scMW(), SLOT(setStilvalue(int)));
04359        connect(this, SIGNAL(textFont(const QString&)), m_Doc->scMW(), SLOT(AdjustFontMenu(const QString&)));
04360        connect(this, SIGNAL(textFont(const QString&)), pp, SLOT(setFontFace(const QString&)));
04361        connect(this, SIGNAL(textSize(int)), pp, SLOT(setSize(int)));
04362        connect(this, SIGNAL(textSize(int)), m_Doc->scMW(), SLOT(setFSizeMenu(int)));
04363        connect(this, SIGNAL(textWidthScale(int)), pp, SLOT(setTScale(int)));
04364        connect(this, SIGNAL(textHeightScale(int)), pp, SLOT(setTScaleV(int)));
04365        connect(this, SIGNAL(textBaseLineOffset(int)), pp, SLOT(setTBase(int)));
04366        connect(this, SIGNAL(textOutline(int)), pp, SLOT(setOutlineW(int)));
04367        connect(this, SIGNAL(textShadow(int, int )), pp, SLOT(setShadowOffs(int, int )));
04368        connect(this, SIGNAL(textUnderline(int, int)), pp, SLOT(setUnderline(int, int)));
04369        connect(this, SIGNAL(textStrike(int, int)), pp, SLOT(setStrike(int, int)));
04370        connect(this, SIGNAL(textColor(QString, QString, int, int)), pp, SLOT(setActFarben(QString, QString, int, int)));
04371 //     connect(this, SIGNAL(textFormatting(int)), pp, SLOT(setAli(int)));
04372 //     connect(this, SIGNAL(textFormatting(int)), ScMW, SLOT(setAbsValue(int)));
04373 
04374        return true;
04375 }
04376 
04377 bool PageItem::disconnectFromGUI()
04378 {
04379        if (!ScCore->usingGUI())
04380               return false;
04381        disconnect(this, 0, 0, 0);
04382        return true;
04383 }
04384 
04385 void PageItem::emitAllToGUI()
04386 {
04387        updateConstants();
04388 
04389        emit myself(this);
04390        emit frameType(m_ItemType);
04391        emit position(Xpos, Ypos);
04392        emit widthAndHeight(Width, Height);
04393        emit rotation(Rot);
04394        emit frameLocked(m_Locked);
04395        emit frameSizeLocked(m_SizeLocked);
04396        emit frameFlippedH(m_ImageIsFlippedH);
04397        emit frameFlippedV(m_ImageIsFlippedV);
04398        emit printEnabled(m_PrintEnabled);
04399        emit lineWidth(m_lineWidth);
04400        emit lineStyleCapJoin(PLineArt, PLineEnd, PLineJoin);
04401        emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
04402        emit colors(lineColorVal, fillColorVal, lineShadeVal, fillShadeVal);
04403 //     emit gradientType(GrType);
04404 //     double dur=m_Doc->unitRatio();
04405 //     emit gradientColorUpdate(GrStartX*dur, GrStartY*dur, GrEndX*dur, GrEndY*dur, Width*dur, Height*dur);
04406 //     emit transparency(fillTransparencyVal, lineTransparencyVal);
04407 //     emit blendmode(fillBlendmodeVal, lineBlendmodeVal);
04408        emit patternFill(patternVal, patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
04409        emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
04410        emit columns(Cols, ColGap);
04411        if (m_Doc->appMode == modeEdit)
04412        {
04413 /* maybe already done elsewhere? -- av
04414               emit lineSpacing(currentStyle().lineSpacing());
04415               emit textKerning(currentCharStyle().tracking());
04416               emit textStyle(currentCharStyle().effects());
04417               emit textFont(currentCharStyle().font()->scName());
04418               emit textSize(currentCharStyle().fontSize());
04419 */
04420               //            emit textFormatting(currentStyle().alignment());
04421        }
04422        else
04423        {
04424               emit lineSpacing(itemText.defaultStyle().lineSpacing());
04425               emit textKerning(itemText.defaultStyle().charStyle().tracking());
04426               emit textStyle(itemText.defaultStyle().charStyle().effects());
04427               emit textFont(itemText.defaultStyle().charStyle().font().scName());
04428               emit textSize(itemText.defaultStyle().charStyle().fontSize());
04429 //            emit textFormatting(itemText.defaultStyle().alignment());
04430        }
04431 }
04432 
04433 void PageItem::setIsAnnotation(bool isAnnot)
04434 {
04435        m_isAnnotation=isAnnot;
04436 }
04437 
04438 void PageItem::setAnnotation(const Annotation& ad)
04439 {
04440        m_annotation=ad;
04441 }
04442 
04443 void PageItem::setImageShown(bool isShown)
04444 {
04445        PicArt=isShown;
04446 }
04447 
04448 void PageItem::updateConstants()
04449 {
04450        if (OwnPage!=-1)
04451        {
04452               m_Doc->constants().insert("pagewidth", m_Doc->Pages->at(OwnPage)->width());
04453               m_Doc->constants().insert("pageheight", m_Doc->Pages->at(OwnPage)->height());
04454        }
04455        m_Doc->constants().insert("width", Width);
04456        m_Doc->constants().insert("height", Height);
04457 }
04458 
04459 //CB Old ScribusView MoveItemI
04460 void PageItem::moveImageInFrame(double newX, double newY)
04461 {
04462        if (m_ItemType!=PageItem::ImageFrame)
04463               return;
04464        if ((locked()) || (!ScaleType))
04465               return;
04466        double dX=0.0, dY=0.0;
04467        if (imageFlippedH())
04468               dX=-newX;
04469        else
04470               dX=newX;
04471        if (imageFlippedV())
04472               dY=-newY;
04473        else
04474               dY=newY;
04475        moveImageXYOffsetBy(dX, dY);
04476        if (imageClip.size() != 0)
04477        {
04478               imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
04479               QWMatrix cl;
04480               cl.translate(imageXOffset()*imageXScale(), imageYOffset()*imageYScale());
04481               cl.scale(imageXScale(), imageYScale());
04482               imageClip.map(cl);
04483        }
04484 }
04485 
04486 
04487 
04488 void PageItem::convertClip()
04489 {
04490        if (Clip.count() != 0)
04491        {
04492               FPoint np(Clip.point(0));
04493               PoLine.resize(2);
04494               PoLine.setPoint(0, np);
04495               PoLine.setPoint(1, np);
04496               for (uint a = 1; a < Clip.size(); ++a)
04497               {
04498                      np = FPoint(Clip.point(a));
04499                      PoLine.putPoints(PoLine.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y());
04500               }
04501               np = FPoint(Clip.point(0));
04502               PoLine.putPoints(PoLine.size(), 2, np.x(), np.y(), np.x(), np.y());
04503               Clip = FlattenPath(PoLine, Segments);
04504        }
04505        else
04506        {
04507               SetRectFrame();
04508               m_Doc->setRedrawBounding(this);
04509        }
04510 }
04511 
04512 void PageItem::updateClip()
04513 {
04514        if (m_Doc->appMode == modeDrawBezierLine)
04515               return;
04516        int ph = static_cast<int>(QMAX(1.0, lineWidth() / 2.0));
04517        switch (itemType())
04518        {
04519        case PageItem::Line:
04520               Clip.setPoints(4, -ph,-ph, static_cast<int>(width()+ph),-ph,
04521                                 static_cast<int>(width()+ph),static_cast<int>(height()+ph),
04522                                 -ph,static_cast<int>(height()+ph));
04523               break;
04524        default:
04525               if (((!ClipEdited) || (FrameType < 3)) && !(asPathText()))
04526               {
04527                      switch (FrameType)
04528                      {
04529                      case 0:
04530                             SetRectFrame();
04531                             m_Doc->setRedrawBounding(this);
04532                             break;
04533                      case 1:
04534                             SetOvalFrame();
04535                             m_Doc->setRedrawBounding(this);
04536                             break;
04537                      case 2:
04538                             //CB FIXME: stop using clre or move out of here
04539                             m_Doc->view()->ClRe = -1;
04540                             SetFrameRound();
04541                             m_Doc->setRedrawBounding(this);
04542                             break;
04543                      default:
04544                             break;
04545                      }
04546                      if ((OldB2 != 0) && (OldH2 != 0) && (width() != 0) && (height() != 0))
04547                      {
04548                             double scx = width() / OldB2;
04549                             double scy = height() / OldH2;
04550                             QWMatrix ma;
04551                             ma.scale(scx, scy);
04552                             FPointArray gr;
04553                             gr.addPoint(GrStartX, GrStartY);
04554                             gr.addPoint(GrEndX, GrEndY);
04555                             gr.map(ma);
04556                             GrStartX = gr.point(0).x();
04557                             GrStartY = gr.point(0).y();
04558                             GrEndX = gr.point(1).x();
04559                             GrEndY = gr.point(1).y();
04560                             if (FrameType > 2)
04561                             {
04562                                    PoLine.map(ma);
04563                                    ContourLine.map(ma);
04564                                    if (asPathText())
04565                                           updatePolyClip();
04566                                    else
04567                                           Clip = FlattenPath(PoLine, Segments);
04568                             }
04569                      }
04570                      OldB2 = width();
04571                      OldH2 = height();
04572                      if (FrameType < 3)
04573                             ContourLine = PoLine.copy();
04574               }
04575               else
04576               {
04577                      if (m_Doc->SubMode != -1)
04578                      {
04579                             switch (m_Doc->SubMode)
04580                             {
04581                             case 0:
04582                                    SetRectFrame();
04583                                    m_Doc->setRedrawBounding(this);
04584                                    break;
04585                             case 1:
04586                                    SetOvalFrame();
04587                                    m_Doc->setRedrawBounding(this);
04588                                    break;
04589                             default:
04590                                    SetFrameShape(m_Doc->ValCount, m_Doc->ShapeValues);
04591                                    m_Doc->setRedrawBounding(this);
04592                                    break;
04593                             }
04594                             OldB2 = width();
04595                             OldH2 = height();
04596                             ContourLine = PoLine.copy();
04597                      }
04598                      if ((OldB2 == 0) || (OldH2 == 0) || (width() == 0) || (height() == 0))
04599                             return;
04600                      double scx = width() / OldB2;
04601                      double scy = height() / OldH2;
04602                      QWMatrix ma;
04603                      ma.scale(scx, scy);
04604                      FPointArray gr;
04605                      gr.addPoint(GrStartX, GrStartY);
04606                      gr.addPoint(GrEndX, GrEndY);
04607                      gr.map(ma);
04608                      GrStartX = gr.point(0).x();
04609                      GrStartY = gr.point(0).y();
04610                      GrEndX = gr.point(1).x();
04611                      GrEndY = gr.point(1).y();
04612                      PoLine.map(ma);
04613                      ContourLine.map(ma);
04614                      if (asPathText())
04615                             updatePolyClip();
04616                      else
04617                             Clip = FlattenPath(PoLine, Segments);
04618                      OldB2 = width();
04619                      OldH2 = height();
04620               }
04621               break;
04622        }
04623        updateGradientVectors();
04624 }