Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

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 <QPainter>
00026 #include <QPen>
00027 #include <QFont>
00028 #include <QRegion>
00029 #include <QPoint>
00030 #include <QFileInfo>
00031 #include <qdrawutil.h>
00032 #include <QRegExp>
00033 #include <QMessageBox>
00034 #include <QPolygon>
00035 #include <cmath>
00036 #include <cassert>
00037 
00038 #include "canvas.h"
00039 #include "scpaths.h"
00040 #include "cmsettings.h"
00041 #include "colorblind.h"
00042 #include "commonstrings.h"
00043 #include "cpalette.h"
00044 #include "guidemanager.h"
00045 #include "page.h"
00046 #include "pageitem_latexframe.h"
00047 #include "prefsmanager.h"
00048 #include "propertiespalette.h"
00049 #include "resourcecollection.h"
00050 #include "sccolorengine.h"
00051 #include "scconfig.h"
00052 #include "scpainter.h"
00053 #include "scpaths.h"
00054 #include "scpattern.h"
00055 #include "scribus.h"
00056 #include "scribusapp.h"
00057 #include "scribuscore.h"
00058 #include "scribusdoc.h"
00059 #include "scribusstructs.h"
00060 #include "scribuswin.h"
00061 #include "selection.h"
00062 #include "text/nlsconfig.h"
00063 #include "undomanager.h"
00064 #include "undostate.h"
00065 #include "util.h"
00066 #include "util_formats.h"
00067 #include "util_math.h"
00068 
00069 using namespace std;
00070 
00071 PageItem::PageItem(const PageItem & other)
00072     : QObject(other.parent()),
00073      UndoObject(other), SingleObservable<PageItem>(other.m_Doc->itemsChanged()),
00074 
00075 // 200 attributes! That is madness, or to quote some famous people from Kriquet:
00076 // "THAT ALL HAS TO GO!"
00077     gXpos(other.gXpos),
00078     gYpos(other.gYpos),
00079     gWidth(other.gWidth),
00080     gHeight(other.gHeight),
00081     GrType(other.GrType),
00082     GrStartX(other.GrStartX),
00083     GrStartY(other.GrStartY),
00084     GrEndX(other.GrEndX),
00085     GrEndY(other.GrEndY),
00086     Cols(other.Cols),
00087     ColGap(other.ColGap),
00088     PLineArt(other.PLineArt),
00089     PLineEnd(other.PLineEnd),
00090     PLineJoin(other.PLineJoin),
00091     NamedLStyle(other.NamedLStyle),
00092     Clip(other.Clip),
00093     PoLine(other.PoLine),
00094     ContourLine(other.ContourLine),
00095     imageClip(other.imageClip),
00096     Segments(other.Segments),
00097     effectsInUse(other.effectsInUse),
00098     PoShow(other.PoShow),
00099     BaseOffs(other.BaseOffs),
00100     textPathType(other.textPathType),
00101     textPathFlipped(other.textPathFlipped),
00102     ClipEdited(other.ClipEdited),
00103     FrameType(other.FrameType),
00104     ItemNr(other.ItemNr),
00105     Frame(other.Frame),
00106     OwnPage(other.OwnPage),
00107     oldOwnPage(other.oldOwnPage),
00108     pixm(other.pixm),
00109     Pfile(other.Pfile),
00110     Pfile2(other.Pfile2),
00111     Pfile3(other.Pfile3),
00112     IProfile(other.IProfile),
00113     UseEmbedded(other.UseEmbedded),
00114     EmProfile(other.EmProfile),
00115     IRender(other.IRender),
00116 
00117     PicAvail(other.PicAvail),
00118     OrigW(other.OrigW),
00119     OrigH(other.OrigH),
00120     BBoxX(other.BBoxX),
00121     BBoxH(other.BBoxH),
00122     CurX(other.CurX),
00123     CurY(other.CurY),
00124     CPos(other.CPos),
00125     itemText(other.itemText),
00126     isBookmark(other.isBookmark),
00127     HasSel(other.HasSel),
00128 //  Tinput(other.Tinput),
00129     isAutoText(other.isAutoText),
00130     BackBox(NULL),  // otherwise other.BackBox->NextBox would be inconsistent
00131     NextBox(NULL),  // otherwise other.NextBox->BackBox would be inconsistent
00132     firstChar(0),   // since this box is unlinked now
00133     MaxChars(0),   // since the layout is invalid now
00134     inPdfArticle(other.inPdfArticle),
00135     isRaster(other.isRaster),
00136     OldB(other.OldB),
00137     OldH(other.OldH),
00138     OldB2(other.OldB2),
00139     OldH2(other.OldH2),
00140     Sizing(other.Sizing),
00141     toPixmap(other.toPixmap),
00142     LayerNr(other.LayerNr),
00143     ScaleType(other.ScaleType),
00144     AspectRatio(other.AspectRatio),
00145     Groups(other.Groups),
00146     DashValues(other.DashValues),
00147     DashOffset(other.DashOffset),
00148     fill_gradient(other.fill_gradient),
00149     fillRule(other.fillRule),
00150     doOverprint(other.doOverprint),
00151     LeftLink(other.LeftLink),
00152     RightLink(other.RightLink),
00153     TopLink(other.TopLink),
00154     BottomLink(other.BottomLink),
00155     LeftLinkID(other.LeftLinkID),
00156     RightLinkID(other.RightLinkID),
00157     TopLinkID(other.TopLinkID),
00158     BottomLinkID(other.BottomLinkID),
00159     LeftLine(other.LeftLine),
00160     RightLine(other.RightLine),
00161     TopLine(other.TopLine),
00162     BottomLine(other.BottomLine),
00163     isTableItem(other.isTableItem),
00164     isSingleSel(other.isSingleSel),
00165     isGroupControl(other.isGroupControl),
00166     groupsLastItem(other.groupsLastItem),
00167     BoundingX(other.BoundingX),
00168     BoundingY(other.BoundingY),
00169     BoundingW(other.BoundingW),
00170     BoundingH(other.BoundingH),
00171     ChangedMasterItem(other.ChangedMasterItem),
00172     OnMasterPage(other.OnMasterPage),
00173     isEmbedded(other.isEmbedded),
00174 
00175     // protected
00176     undoManager(other.undoManager),
00177     AnName(other.AnName),
00178     patternVal(other.patternVal),
00179     patternScaleX(other.patternScaleX),
00180     patternScaleY(other.patternScaleY),
00181     patternOffsetX(other.patternOffsetX),
00182     patternOffsetY(other.patternOffsetY),
00183     patternRotation(other.patternRotation),
00184     fillColorVal(other.fillColorVal),
00185     lineColorVal(other.lineColorVal),
00186     lineShadeVal(other.lineShadeVal),
00187     fillShadeVal(other.fillShadeVal),
00188     fillTransparencyVal(other.fillTransparencyVal),
00189     lineTransparencyVal(other.lineTransparencyVal),
00190     fillBlendmodeVal(other.fillBlendmodeVal),
00191     lineBlendmodeVal(other.lineBlendmodeVal),
00192     m_ImageIsFlippedH(other.m_ImageIsFlippedH),
00193     m_ImageIsFlippedV(other.m_ImageIsFlippedV),
00194     m_Locked(other.m_Locked),
00195     m_SizeLocked(other.m_SizeLocked),
00196     textFlowModeVal(other.textFlowModeVal),
00197     pageItemAttributes(other.pageItemAttributes),
00198     m_PrintEnabled(other.m_PrintEnabled),
00199     tagged(other.tagged),
00200     fillQColor(other.fillQColor),
00201     strokeQColor(other.strokeQColor),
00202     Xpos(other.Xpos),
00203     Ypos(other.Ypos),
00204     Width(other.Width),
00205     Height(other.Height),
00206     Rot(other.Rot),
00207     Select(other.Select),
00208     LocalScX(other.LocalScX),
00209     LocalScY(other.LocalScY),
00210     LocalX(other.LocalX),
00211     LocalY(other.LocalY),
00212     Reverse(other.Reverse),
00213     m_startArrowIndex(other.m_startArrowIndex),
00214     m_endArrowIndex(other.m_endArrowIndex),
00215     Extra(other.Extra),
00216     TExtra(other.TExtra),
00217     BExtra(other.BExtra),
00218     RExtra(other.RExtra),
00219     RadRect(other.RadRect),
00220     oldXpos(other.oldXpos),
00221     oldYpos(other.oldYpos),
00222     oldWidth(other.oldWidth),
00223     oldHeight(other.oldHeight),
00224     oldRot(other.oldRot),
00225     oldLocalScX(other.oldLocalScX),
00226     oldLocalScY(other.oldLocalScY),
00227     oldLocalX(other.oldLocalX),
00228     oldLocalY(other.oldLocalY),
00229     m_Doc(other.m_Doc),
00230     m_isAnnotation(other.m_isAnnotation),
00231     m_annotation(other.m_annotation),
00232     PicArt(other.PicArt),
00233     m_lineWidth(other.m_lineWidth),
00234     Oldm_lineWidth(other.Oldm_lineWidth)
00235 {
00236     QString tmp;
00237     m_Doc->TotalItems++;
00238     AnName += tmp.setNum(m_Doc->TotalItems);
00239     uniqueNr = m_Doc->TotalItems;
00240     invalid = true;
00241 }
00242 
00243 
00244 PageItem::PageItem(ScribusDoc *pa, ItemType newType, double x, double y, double w, double h, double w2, QString fill, QString outline)
00245     // Initialize superclass(es)
00246     : QObject(pa), SingleObservable<PageItem>(pa->itemsChanged()),
00247     // Initialize member variables
00248     itemText(pa),
00249     undoManager(UndoManager::instance()),
00250     lineShadeVal(100),
00251     fillShadeVal(100),
00252     fillTransparencyVal(0.0),
00253     lineTransparencyVal(0.0),
00254     fillBlendmodeVal(0),
00255     lineBlendmodeVal(0),
00256     m_ImageIsFlippedH(0),
00257     m_ImageIsFlippedV(0),
00258     m_Locked(false),
00259     m_SizeLocked(false),
00260     textFlowModeVal(TextFlowDisabled)
00261 {
00262     m_Doc = pa;
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     fillColorVal = fill;
00278     lineColorVal = m_ItemType == PageItem::TextFrame ? fill : outline;
00279     GrType = 0;
00280     GrStartX = 0;
00281     GrStartY = 0;
00282     GrEndX = w;
00283     GrEndY = 0;
00284     patternVal = "";
00285     patternScaleX = 100;
00286     patternScaleY = 100;
00287     patternOffsetX = 0;
00288     patternOffsetY = 0;
00289     patternRotation = 0;
00290     m_lineWidth = w2;
00291     Oldm_lineWidth = w2;
00292     PLineArt = Qt::PenStyle(m_Doc->toolSettings.dLineArt);
00293     PLineEnd = Qt::FlatCap;
00294     PLineJoin = Qt::MiterJoin;
00295     Select = false;
00296     ClipEdited = false;
00297     FrameType = 0;
00298     CurX = 0;
00299     CurY = 0;
00300     CPos = 0;
00301     Extra = 0;
00302     TExtra = 0;
00303     BExtra = 0;
00304     RExtra = 0;
00305     firstChar = 0;
00306     MaxChars = 0;
00307     Pfile = "";
00308     pixm = ScImage();
00309     pixm.imgInfo.lowResType = m_Doc->toolSettings.lowResType;
00310     Pfile2 = "";
00311     Pfile3 = "";
00312     oldLocalScX = LocalScX = 1;
00313     oldLocalScY = LocalScY = 1;
00314     OrigW = 0;
00315     OrigH = 0;
00316     oldLocalX = LocalX = 0;
00317     oldLocalY = LocalY = 0;
00318     BBoxX = 0;
00319     BBoxH = 0;
00320     RadRect = 0;
00321     if ((m_ItemType == TextFrame) || (m_ItemType == ImageFrame) || (m_ItemType == PathText))
00322         // TODO: Frame should become a read-only calculated property
00323         Frame = true;
00324     else
00325         Frame = false;
00326     switch (m_ItemType)
00327     {
00328         case Polygon:
00329             Clip.setPoints(4, static_cast<int>(w/2), 0, static_cast<int>(w), static_cast<int>(h/2),
00330                                 static_cast<int>(w/2), static_cast<int>(h), 0,static_cast<int>(h/2));
00331             break;
00332         default:
00333             Clip.setPoints(4, 0,0, static_cast<int>(w),0, static_cast<int>(w), static_cast<int>(h), 0,static_cast<int>(h));
00334             break;
00335     }
00336     PoLine.resize(0);
00337     ContourLine.resize(0);
00338     imageClip.resize(0);
00339     Segments.clear();
00340     PoShow = false;
00341     BaseOffs = 0;
00342     textPathType = 0;
00343     textPathFlipped = false;
00344     OwnPage = m_Doc->currentPage()->pageNr();
00345     oldOwnPage = OwnPage;
00346     savedOwnPage = OwnPage;
00347     PicArt = true;
00348     PicAvail = false;
00349     m_PrintEnabled = true;
00350     isBookmark = false;
00351     m_isAnnotation = false;
00352     
00353     switch (m_ItemType)
00354     {
00355     case ImageFrame:
00356     case LatexFrame:
00357         //We can't determine if this is a latex frame here
00358         // because c++'s typeinfos are still saying it's 
00359         // a plain pageitem
00360         // This is fixed in the PageItem_LatexFrame constructor
00361         AnName = tr("Image");
00362         setUPixmap(Um::IImageFrame);
00363         break;
00364     case TextFrame:
00365         AnName = tr("Text");
00366         setUPixmap(Um::ITextFrame);
00367         break;
00368     case Line:
00369         AnName = tr("Line");
00370         setUPixmap(Um::ILine);
00371         break;
00372     case Polygon:
00373         AnName = tr("Polygon");
00374         setUPixmap(Um::IPolygon);
00375         break;
00376     case PolyLine:
00377         AnName = tr("Polyline");
00378         setUPixmap(Um::IPolyline);
00379         break;
00380     case PathText:
00381         AnName = tr("PathText");
00382         setUPixmap(Um::IPathText);
00383         break;
00384     default:
00385         AnName = "Item";
00386         break;
00387     }
00388     m_Doc->TotalItems++;
00389     AnName += tmp.setNum(m_Doc->TotalItems); // +" "+QDateTime::currentDateTime().toString();
00390     uniqueNr = m_Doc->TotalItems;
00391     AutoName = true;
00392     setUName(AnName);
00393     m_annotation.setBorderColor(outline);
00394     HasSel = false;
00395 //  Tinput = false;
00396     isAutoText = false;
00397     inPdfArticle = false;
00398     isRaster = false;
00399     Sizing = false;
00400     toPixmap = false;
00401     UseEmbedded = true;
00402     IRender = 1;
00403     EmProfile = "";
00404     Groups.clear();
00405     LayerNr = m_Doc->activeLayer();
00406     ScaleType = true;
00407     AspectRatio = true;
00408     Reverse = false;
00409     NamedLStyle = "";
00410     DashValues.clear();
00411     DashOffset = 0;
00412     fillRule = true;
00413     doOverprint = false;
00414     fill_gradient = VGradient(VGradient::linear);
00415     fill_gradient.clearStops();
00416     if (fillColorVal != CommonStrings::None)
00417     {
00418         const ScColor& col = m_Doc->PageColors[fillColorVal];
00419         fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, fillColorVal, 100);
00420         fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, fillColorVal, 100);
00421     }
00422     else
00423     {
00424         if (m_Doc->toolSettings.dBrush != CommonStrings::None)
00425         {
00426             const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dBrush];
00427             fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
00428             fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
00429         }
00430         else
00431         {
00432             if (lineColorVal != CommonStrings::None)
00433             {
00434                 const ScColor& col = m_Doc->PageColors[lineColorVal];
00435                 fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, lineColorVal, 100);
00436                 fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, lineColorVal, 100);
00437             }
00438             else
00439             {
00440                 if (m_Doc->toolSettings.dPen != CommonStrings::None)
00441                 {
00442                     const ScColor& col = m_Doc->PageColors[m_Doc->toolSettings.dPen];
00443                     fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
00444                     fill_gradient.addStop(ScColorEngine::getRGBColor(col, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
00445                 }
00446             }
00447         }
00448     }
00449     Cols = m_Doc->toolSettings.dCols;
00450     ColGap = m_Doc->toolSettings.dGap;
00451     LeftLink = 0;
00452     RightLink = 0;
00453     TopLink = 0;
00454     BottomLink = 0;
00455     LeftLinkID = 0;
00456     RightLinkID = 0;
00457     TopLinkID = 0;
00458     BottomLinkID = 0;
00459     LeftLine = 0;
00460     RightLine = false;
00461     TopLine = false;
00462     BottomLine = false;
00463     isTableItem = false;
00464     isSingleSel = false;
00465     Dirty = false;
00466     invalid = true;
00467     isGroupControl = false;
00468     groupsLastItem = 0;
00469     ChangedMasterItem = false;
00470     isEmbedded = false;
00471     OnMasterPage = m_Doc->currentPage()->pageName();
00472     m_startArrowIndex = m_Doc->toolSettings.dStartArrow;
00473     m_endArrowIndex = m_Doc->toolSettings.dEndArrow;
00474     effectsInUse.clear();
00475     //Page Item Attributes
00476     pageItemAttributes.clear();
00477     for(ObjAttrVector::Iterator objAttrIt = m_Doc->docItemAttributes.begin() ; objAttrIt != m_Doc->docItemAttributes.end(); ++objAttrIt )
00478     {
00479         if (((*objAttrIt).autoaddto=="textframes" && m_ItemType==TextFrame) ||
00480             ((*objAttrIt).autoaddto=="imageframes" && m_ItemType==ImageFrame)
00481             )
00482             pageItemAttributes.append(*objAttrIt);
00483     }
00484 }
00485 
00486 void PageItem::setXPos(const double newXPos, bool drawingOnly)
00487 {
00488     Xpos = newXPos;
00489     if (drawingOnly || m_Doc->isLoading())
00490         return;
00491     checkChanges();
00492     emit position(Xpos, Ypos);
00493 }
00494 
00495 void PageItem::setYPos(const double newYPos, bool drawingOnly)
00496 {
00497     Ypos = newYPos;
00498     if (drawingOnly || m_Doc->isLoading())
00499         return;
00500     checkChanges();
00501     emit position(Xpos, Ypos);
00502 }
00503 
00504 void PageItem::setXYPos(const double newXPos, const double newYPos, bool drawingOnly)
00505 {
00506     Xpos = newXPos;
00507     Ypos = newYPos;
00508     if (drawingOnly || m_Doc->isLoading())
00509         return;
00510     checkChanges();
00511     emit position(Xpos, Ypos);
00512 }
00513 
00514 void PageItem::moveBy(const double dX, const double dY, bool drawingOnly)
00515 {
00516     if (dX==0.0 && dY==0.0)
00517         return;
00518     if (dX!=0.0)
00519         Xpos+=dX;
00520     if (dY!=0.0)
00521         Ypos+=dY;
00522     if (drawingOnly || m_Doc->isLoading())
00523         return;
00524     checkChanges();
00525     emit position(Xpos, Ypos);
00526 }
00527 
00528 void PageItem::setWidth(const double newWidth)
00529 {
00530     Width = newWidth;
00531     checkChanges();
00532     emit widthAndHeight(Width, Height);
00533 }
00534 
00535 void PageItem::setHeight(const double newHeight)
00536 {
00537     Height = newHeight;
00538     checkChanges();
00539     emit widthAndHeight(Width, Height);
00540 }
00541 
00542 void PageItem::setWidthHeight(const double newWidth, const double newHeight, bool drawingOnly)
00543 {
00544     Width = newWidth;
00545     Height = newHeight;
00546     if (drawingOnly)
00547         return;
00548     checkChanges();
00549     emit widthAndHeight(Width, Height);
00550 }
00551 
00552 void PageItem::setWidthHeight(const double newWidth, const double newHeight)
00553 {
00554     Width = newWidth;
00555     Height = newHeight;
00556     checkChanges();
00557     emit widthAndHeight(Width, Height);
00558 }
00559 
00560 void PageItem::resizeBy(const double dH, const double dW)
00561 {
00562     if (dH==0.0 && dW==0.0)
00563         return;
00564     if (dH!=0.0)
00565         Width+=dH;
00566     if (dW!=0.0)
00567         Height+=dW;
00568     checkChanges();
00569     emit widthAndHeight(Width, Height);
00570 }
00571 
00572 void PageItem::setRotation(const double newRotation, bool drawingOnly)
00573 {
00574     Rot=newRotation;
00575     checkChanges();
00576     if (drawingOnly || m_Doc->isLoading())
00577         return;
00578     emit rotation(Rot);
00579 }
00580 
00581 void PageItem::rotateBy(const double dR)
00582 {
00583     if (dR==0.0)
00584         return;
00585     Rot+=dR;
00586     checkChanges();
00587     emit rotation(Rot);
00588 }
00589 
00590 void PageItem::setSelected(const bool toSelect)
00591 {
00592     Select=toSelect;
00593 }
00594 
00595 void PageItem::setImageXScale(const double newImageXScale)
00596 {
00597     LocalScX=newImageXScale;
00598     checkChanges();
00599     emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00600 }
00601 
00602 void PageItem::setImageYScale(const double newImageYScale)
00603 {
00604     LocalScY=newImageYScale;
00605     checkChanges();
00606     emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00607 }
00608 
00609 void PageItem::setImageXYScale(const double newImageXScale, const double newImageYScale)
00610 {
00611     LocalScX=newImageXScale;
00612     LocalScY=newImageYScale;
00613     checkChanges();
00614     emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00615 }
00616 
00617 void PageItem::setImageXOffset(const double newImageXOffset)
00618 {
00619     LocalX=newImageXOffset;
00620     checkChanges();
00621     emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00622 }
00623 
00624 void PageItem::setImageYOffset(const double newImageYOffset)
00625 {
00626     LocalY=newImageYOffset;
00627     checkChanges();
00628     emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00629 }
00630 
00631 void PageItem::setImageXYOffset(const double newImageXOffset, const double newImageYOffset)
00632 {
00633     LocalX=newImageXOffset;
00634     LocalY=newImageYOffset;
00635     checkChanges();
00636     emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00637 }
00638 
00639 void PageItem::moveImageXYOffsetBy(const double dX, const double dY)
00640 {
00641     if (dX==0.0 && dY==0.0)
00642         return;
00643     if (dX!=0.0)
00644         LocalX+=dX;
00645     if (dY!=0.0)
00646         LocalY+=dY;
00647     checkChanges();
00648     emit imageOffsetScale(LocalScX, LocalScY, LocalX, LocalY);
00649 }
00650 
00651 void PageItem::setReversed(bool newReversed)
00652 {
00653     Reverse=newReversed;
00654 }
00655 
00656 
00658 bool PageItem::frameOverflows() const
00659 {
00660 #ifndef NLS_PROTO
00661     return NextBox == NULL && itemText.length() > static_cast<int>(MaxChars);
00662 #else
00663     return false; // FIXME:NLS
00664 #endif
00665 }
00666 
00667 int PageItem::firstInFrame() const
00668 {
00669     return firstChar;
00670 }
00671 int PageItem::lastInFrame() const
00672 {
00673 #ifndef NLS_PROTO
00674     return qMin(signed(MaxChars), itemText.length()) - 1;
00675 #else
00676     return itemText.length() - 1;
00677 #endif
00678 }
00679 
00680 
00681 void PageItem::link(PageItem* nxt)
00682 {
00683     assert( !nextInChain() );
00684     assert( !nxt->prevInChain() );
00685     for (PageItem* ff=nxt; ff; ff=ff->nextInChain())
00686     {
00687         assert (ff != this);
00688     }
00689     itemText.append(nxt->itemText);
00690     NextBox = nxt;
00691     nxt->BackBox = this;
00692     // update AutoText
00693     if (isAutoText)
00694     {
00695         PageItem* after = nxt;
00696         while (after)
00697         {
00698             after->isAutoText = true;
00699             m_Doc->LastAuto = after;
00700             after = after->NextBox;
00701         }
00702     }
00703     else if (nxt->isAutoText)
00704     {
00705         PageItem* before = this;
00706         while (before)
00707         {
00708             before->isAutoText = true;
00709             m_Doc->FirstAuto = before;
00710             before = before->BackBox;
00711         }
00712     }
00713     invalid = true;
00714     while (nxt)
00715     {
00716         nxt->itemText = itemText;
00717         nxt->invalid = true;
00718         nxt->firstChar = 0;
00719         nxt = nxt->NextBox;
00720     }
00721 }
00722 
00723 void PageItem::unlink()
00724 {
00725     if( NextBox )
00726     {
00727         // make sure lastInFrame is valid
00728         layout();
00729         // move following text to new StoryText
00730         itemText.select(lastInFrame()+1, itemText.length()-lastInFrame()-1);
00731         StoryText follow(m_Doc);
00732         follow.setDefaultStyle(itemText.defaultStyle());
00733         follow.insert(0, itemText, true);
00734         // remove following text from this chain
00735         itemText.removeSelection();
00736         // update auto pointers
00737         if (isAutoText)
00738         {
00739             PageItem* before = this;
00740             while (before) 
00741             {
00742                 before->isAutoText = false;
00743                 before = before->BackBox;
00744             }
00745             m_Doc->FirstAuto = NextBox;
00746         }
00747         // link following frames to new text
00748         NextBox->firstChar = 0;
00749         NextBox->BackBox = NULL;
00750         while (NextBox) {
00751             NextBox->itemText = follow;
00752             NextBox->invalid = true;
00753             NextBox->firstChar = 0;
00754             NextBox = NextBox->NextBox;
00755         }
00756         // NextBox == NULL now
00757     }
00758 }
00759 
00760 
00761 void PageItem::dropLinks()
00762 {
00763     // update auto pointers
00764     if (isAutoText && NextBox == 0)
00765     {
00766         m_Doc->LastAuto = BackBox;
00767     }
00768     if (isAutoText && BackBox == 0)
00769     {
00770         m_Doc->FirstAuto = NextBox;
00771     }
00772     isAutoText = false;
00773 
00774     // leave text in remaining chain
00775     PageItem* before = BackBox;
00776     PageItem* after = NextBox;
00777     if (after != 0 || before != 0)
00778     {
00779         itemText = StoryText(m_Doc);
00780         if (before)
00781             before->NextBox = after;
00782         if (after) 
00783         {
00784             after->BackBox = before;
00785             while (after)
00786             { 
00787                 after->invalid = true;
00788                 after->firstChar = 0;
00789                 after = after->NextBox;
00790             }
00791         }
00792         // JG we should set BackBox and NextBox to NULL at a point
00793     }
00794 }
00795 
00797 bool PageItem::frameDisplays(int textpos) const
00798 {
00799 #ifndef NLS_PROTO
00800     return 0 <= textpos && textpos < signed(MaxChars) &&  textpos < itemText.length();
00801 #else
00802     return true; // FIXME:NLS
00803 #endif
00804 }
00805 
00806 
00808 const ParagraphStyle& PageItem::currentStyle() const
00809 {
00810     if (frameDisplays(CPos))
00811         return itemText.paragraphStyle(CPos);
00812     else
00813         return itemText.defaultStyle();
00814 }
00815 
00817 ParagraphStyle& PageItem::changeCurrentStyle()
00818 {
00819     if (frameDisplays(CPos))
00820         return const_cast<ParagraphStyle&>(itemText.paragraphStyle(CPos));
00821     else
00822         return const_cast<ParagraphStyle&>(itemText.defaultStyle());
00823 }
00824 
00826 const CharStyle& PageItem::currentCharStyle() const
00827 {
00828     if (frameDisplays(CPos))
00829         return itemText.charStyle(CPos);
00830     else
00831         return itemText.defaultStyle().charStyle();
00832 }
00833 
00834 void PageItem::setTextToFrameDistLeft(double newLeft)
00835 {
00836     Extra=newLeft;
00837     emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00838 }
00839 
00840 void PageItem::setTextToFrameDistRight(double newRight)
00841 {
00842     RExtra=newRight;
00843     emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00844 }
00845 
00846 void PageItem::setTextToFrameDistTop(double newTop)
00847 {
00848     TExtra=newTop;
00849     emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00850 }
00851 
00852 void PageItem::setTextToFrameDistBottom(double newBottom)
00853 {
00854     BExtra=newBottom;
00855     emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00856 }
00857 
00858 void PageItem::setTextToFrameDist(double newLeft, double newRight, double newTop, double newBottom)
00859 {
00860     Extra=newLeft;
00861     RExtra=newRight;
00862     TExtra=newTop;
00863     BExtra=newBottom;
00864     emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
00865 }
00866 
00867 double PageItem::gridOffset() const { return m_Doc->typographicSettings.offsetBaseGrid; }
00868 double PageItem::gridDistance() const { return m_Doc->typographicSettings.valueBaseGrid; }
00869 
00870 void PageItem::setGridOffset(double) { } // FIXME
00871 void PageItem::setGridDistance(double) { } // FIXME
00872 void PageItem::setColumns(int n) 
00873 {
00874     Cols = qMax(1, n); //FIXME: undo
00875 }
00876 void PageItem::setColumnGap(double gap)
00877 {
00878     ColGap = gap; //FIXME: undo
00879 }
00880 
00881 void PageItem::setCornerRadius(double newRadius)
00882 {
00883     RadRect=newRadius;
00884     emit cornerRadius(RadRect);
00885 }
00886 
00887 
00888 
00889 
00890 
00891 
00892 
00893 
00894 
00898 void PageItem::DrawObj(ScPainter *