Rev 20536 |
Rev 21768 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
scribusdoc.cpp - description
-------------------
begin : Fre Apr 6 21:47:55 CEST 2001
copyright : (C) 2001 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <memory>
#include <utility>
#include <sstream>
#include <QByteArray>
#include <QDebug>
#include <QEventLoop>
#include <QFile>
#include <QList>
#include <QTime>
#include <QPainter>
#include <QPixmap>
#include <QProgressBar>
#include "canvas.h"
#include "cmserrorhandling.h"
#include "commonstrings.h"
#include "colormgmt/sccolormgmtengine.h"
#include "desaxe/digester.h"
#include "desaxe/saxXML.h"
#include "fileloader.h"
#include "filewatcher.h"
#include "guidemanager.h"
#include "hruler.h"
#include "hyphenator.h"
#include "layers.h"
#include "page.h"
#include "pageitem.h"
#include "pageitem_imageframe.h"
#include "pageitem_latexframe.h"
#include "pageitem_line.h"
#include "pageitem_pathtext.h"
#include "pageitem_polygon.h"
#include "pageitem_polyline.h"
#include "pageitem_textframe.h"
#include "pagepalette.h"
#include "pagesize.h"
#include "pagestructs.h"
#include "prefsfile.h"
#include "prefsmanager.h"
#include "resourcecollection.h"
#include "sccolorengine.h"
#include "scmessagebox.h"
#include "scpainter.h"
#include "scraction.h"
#include "scribus.h"
#include "scribusXml.h"
#include "scribuscore.h"
#include "scribusdoc.h"
#include "scribusview.h"
#include "scribuswin.h"
#include "sclimits.h"
#include "selection.h"
#include "serializer.h"
#include "storyeditor.h"
#include "text/nlsconfig.h"
#include "undomanager.h"
#include "undostate.h"
#include "units.h"
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
// static const bool FRAMESELECTION_EDITS_DEFAULTSTYLE = false;
/**
This class forwards change events for pages and pageitems to
the region occupied by this page or pageitem.
*/
class DocUpdater : public Observer<Page*>, public Observer<PageItem*>
{
ScribusDoc* doc;
int m_updateEnabled;
bool m_docChangeNeeded;
public:
DocUpdater(ScribusDoc* d) : doc(d), m_updateEnabled(0), m_docChangeNeeded(false) {}
bool inUpdateSession() const
{
return m_updateEnabled > 0;
}
void beginUpdate(void)
{
if (m_updateEnabled == 0)
m_docChangeNeeded = false;
++m_updateEnabled;
}
void endUpdate(void)
{
--m_updateEnabled;
if (m_updateEnabled <= 0)
{
if (m_docChangeNeeded)
{
doc->changed();
m_docChangeNeeded = false;
}
}
}
void changed(Page* pg, bool /*layout*/)
{
QRectF pagebox(pg->xOffset(), pg->yOffset(), pg->width(), pg->height());
doc->invalidateRegion(pagebox);
doc->regionsChanged()->update(pagebox);
if (m_updateEnabled <= 0)
{
doc->changed();
return;
}
m_docChangeNeeded = true;
}
void changed(PageItem* it, bool layout)
{
it->invalidateLayout();
if (layout)
it->layout();
doc->regionsChanged()->update(it->getBoundingRect());
if (m_updateEnabled <= 0)
{
doc->changed();
return;
}
m_docChangeNeeded = true;
}
void setDocChangeNeeded(bool changeNeeded = true)
{
m_docChangeNeeded = changeNeeded;
}
};
ScribusDoc::ScribusDoc() : UndoObject( tr("Document")), Observable<ScribusDoc>(NULL),
m_hasGUI(false),
prefsData(PrefsManager::instance()->appPrefs),
undoManager(UndoManager::instance()),
loading(false),
modified(false),
ActiveLayer(0),
docUnitIndex(prefsData.docUnitIndex),
docUnitRatio(unitGetRatioFromIndex(docUnitIndex)),
automaticTextFrames(0),
m_masterPageMode(false),
m_ScMW(0),
m_View(0),
m_guardedObject(this),
is12doc(false),
NrItems(0),
First(1), Last(0),
viewCount(0), viewID(0),
SnapGuides(false), GuideLock(false),
scratch(prefsData.scratch),
GapHorizontal(prefsData.GapHorizontal),
GapVertical(prefsData.GapVertical),
// ScratchLeft(prefsData.ScratchLeft),
// ScratchRight(prefsData.ScratchRight),
// ScratchTop(prefsData.ScratchTop),
// ScratchBottom(prefsData.ScratchBottom),
minCanvasCoordinate(FPoint(0, 0)),
maxCanvasCoordinate(FPoint(scratch.Left + scratch.Right, scratch.Top + scratch.Bottom)),
rulerXoffset(0.0), rulerYoffset(0.0),
Pages(0), MasterPages(), DocPages(),
MasterNames(),
Items(0), MasterItems(), DocItems(), FrameItems(),
m_Selection(new Selection(this, true)),
pageWidth(0), pageHeight(0),
pageSets(prefsData.pageSets),
PageSp(1), PageSpa(0),
currentPageLayout(0),
PageOri(0), m_pageSize(),
FirstPnum(1),
useRaster(false),
PageColors(this, true),
appMode(modeNormal),
SubMode(-1),
ShapeValues(0),
ValCount(0),
DocName( tr("Document")+"-"),
UsedFonts(),
AllFonts(&prefsData.AvailFonts),
AObjects(),
papColor(prefsData.DpapColor),
CurrentSel(-1),
nodeEdit(),
typographicSettings(prefsData.typographicSettings),
guidesSettings(prefsData.guidesSettings),
toolSettings(prefsData.toolSettings),
checkerProfiles(prefsData.checkerProfiles),
curCheckProfile(prefsData.curCheckProfile),
LastAuto(0), FirstAuto(0),
DraggedElem(0),
ElemToLink(0),
DragElements(),
docParagraphStyles(),
docCharStyles(),
Layers(),
marginColored(prefsData.marginColored),
GroupCounter(1),
JavaScripts(),
TotalItems(0),
MinWordLen(prefsData.MinWordLen),
HyCount(prefsData.HyCount),
Language(prefsData.Language),
Automatic(prefsData.Automatic),
AutoCheck(prefsData.AutoCheck),
PDF_Options(prefsData.PDF_Options),
RePos(false),
BookMarks(),
OldBM(false),
hasName(false),
RotMode(0),
AutoSave(prefsData.AutoSave),
AutoSaveTime(prefsData.AutoSaveTime),
autoSaveTimer(new QTimer(this)),
MLineStyles(),
arrowStyles(prefsData.arrowStyles),
WinHan(0),
DoDrawing(true),
OpenNodes(),
CurTimer(0),
docLayerErrors(),
docItemErrors(),
masterItemErrors(),
docItemAttributes(prefsData.defaultItemAttributes),
docToCSetups(prefsData.defaultToCSetups),
// sections
symReturn(), symNewLine(), symTab(), symNonBreak(), symNewCol(), symNewFrame(),
docHyphenator(0),
m_itemCreationTransaction(NULL),
m_alignTransaction(NULL),
m_currentPage(NULL),
m_updateManager(),
m_docUpdater(NULL)
{
init();
bleeds = prefsData.bleeds;
PDF_Options.bleeds = bleeds;
PDF_Options.useDocBleeds = true;
Print_Options.firstUse = true;
}
ScribusDoc::ScribusDoc(const QString& docName, int unitindex, const PageSize& pagesize, const MarginStruct& margins, const DocPagesSetup& pagesSetup) : UndoObject( tr("Document")),
m_hasGUI(false),
prefsData(PrefsManager::instance()->appPrefs),
undoManager(UndoManager::instance()),
loading(false),
modified(false),
ActiveLayer(0),
docUnitIndex(unitindex),
docUnitRatio(unitGetRatioFromIndex(docUnitIndex)),
automaticTextFrames(pagesSetup.autoTextFrames),
m_masterPageMode(false),
m_ScMW(0),
m_View(0),
m_guardedObject(this),
is12doc(false),
NrItems(0),
First(1), Last(0),
viewCount(0), viewID(0),
SnapGuides(false), GuideLock(false),
scratch(prefsData.scratch),
GapHorizontal(prefsData.GapHorizontal),
GapVertical(prefsData.GapVertical),
// ScratchLeft(prefsData.ScratchLeft),
// ScratchRight(prefsData.ScratchRight),
// ScratchTop(prefsData.ScratchTop),
// ScratchBottom(prefsData.ScratchBottom),
minCanvasCoordinate(FPoint(0, 0)),
maxCanvasCoordinate(FPoint(scratch.Left + scratch.Right, scratch.Top + scratch.Bottom)),
rulerXoffset(0.0), rulerYoffset(0.0),
Pages(0), MasterPages(), DocPages(),
MasterNames(),
Items(0), MasterItems(), DocItems(), FrameItems(),
m_Selection(new Selection(this, true)),
pageWidth(pagesize.width()), pageHeight(pagesize.height()),
pageMargins(margins),
marginPreset(prefsData.marginPreset),
pageSets(prefsData.pageSets),
PageSp(pagesSetup.columnCount), PageSpa(pagesSetup.columnDistance),
currentPageLayout(pagesSetup.pageArrangement),
PageOri(pagesSetup.orientation), m_pageSize(pagesize.name()),
FirstPnum(pagesSetup.firstPageNumber),
useRaster(false),
PageColors(this, true),
appMode(modeNormal),
SubMode(-1),
ShapeValues(0),
ValCount(0),
DocName(docName),
UsedFonts(),
AllFonts(&prefsData.AvailFonts),
AObjects(),
papColor(prefsData.DpapColor),
CurrentSel(-1),
nodeEdit(),
typographicSettings(prefsData.typographicSettings),
guidesSettings(prefsData.guidesSettings),
toolSettings(prefsData.toolSettings),
checkerProfiles(prefsData.checkerProfiles),
curCheckProfile(prefsData.curCheckProfile),
LastAuto(0), FirstAuto(0),
DraggedElem(0),
ElemToLink(0),
DragElements(),
docParagraphStyles(),
docCharStyles(),
Layers(),
marginColored(prefsData.marginColored),
GroupCounter(1),
JavaScripts(),
TotalItems(0),
MinWordLen(prefsData.MinWordLen),
HyCount(prefsData.HyCount),
Language(prefsData.Language),
Automatic(prefsData.Automatic),
AutoCheck(prefsData.AutoCheck),
PDF_Options(prefsData.PDF_Options),
RePos(false),
BookMarks(),
OldBM(false),
hasName(false),
RotMode(0),
AutoSave(prefsData.AutoSave),
AutoSaveTime(prefsData.AutoSaveTime),
autoSaveTimer(new QTimer(this)),
MLineStyles(),
arrowStyles(prefsData.arrowStyles),
WinHan(0),
DoDrawing(true),
OpenNodes(),
CurTimer(0),
docLayerErrors(),
docItemErrors(),
masterItemErrors(),
docItemAttributes(prefsData.defaultItemAttributes),
docToCSetups(prefsData.defaultToCSetups),
// sections
symReturn(), symNewLine(), symTab(), symNonBreak(), symNewCol(), symNewFrame(),
docHyphenator(0),
m_itemCreationTransaction(NULL),
m_alignTransaction(NULL),
m_currentPage(NULL),
m_updateManager(),
m_docUpdater(NULL)
{
pageSets[pagesSetup.pageArrangement].FirstPage = pagesSetup.firstPageLocation;
init();
bleeds = prefsData.bleeds;
PDF_Options.bleeds = bleeds;
PDF_Options.useDocBleeds = true;
Print_Options.firstUse = true;
}
void ScribusDoc::init()
{
Q_CHECK_PTR(m_Selection);
Q_CHECK_PTR(autoSaveTimer);
HasCMS = false;
CMSSettings.CMSinUse = false;
DocInputRGBProf = NULL;
DocInputCMYKProf = NULL;
DocInputImageRGBProf = NULL;
DocInputImageCMYKProf = NULL;
DocOutputProf = NULL;
DocPrinterProf = NULL;
stdTransRGBMon = NULL;
stdTransCMYKMon = NULL;
stdProof = NULL;
stdTransImg = NULL;
stdProofImg = NULL;
stdTransCMYK = NULL;
stdProofCMYK = NULL;
stdTransRGB = NULL;
stdProofGC = NULL;
stdProofCMYKGC = NULL;
SetDefaultCMSParams();
// init update change management
setUpdateManager(&m_updateManager);
m_itemsChanged.setUpdateManager(&m_updateManager);
m_pagesChanged.setUpdateManager(&m_updateManager);
m_regionsChanged.setUpdateManager(&m_updateManager);
nodeEdit.setUpdateManager(&m_updateManager);
// setup update() event chains
m_docUpdater = new DocUpdater(this);
m_itemsChanged.connectObserver(m_docUpdater);
m_pagesChanged.connectObserver(m_docUpdater);
PrefsManager *prefsManager = PrefsManager::instance();
CMSSettings = prefsManager->appPrefs.DCMSset;
PDF_Options.SolidProf = CMSSettings.DefaultSolidColorRGBProfile;
PDF_Options.ImageProf = CMSSettings.DefaultImageRGBProfile;
PDF_Options.PrintProf = CMSSettings.DefaultPrinterProfile;
PDF_Options.Intent = CMSSettings.DefaultIntentColors;
PDF_Options.Intent2 = CMSSettings.DefaultIntentImages;
AddFont(prefsData.toolSettings.defFont);//, prefsData.AvailFonts[prefsData.toolSettings.defFont]->Font);
toolSettings.defFont = prefsData.toolSettings.defFont;
toolSettings.defSize = prefsData.toolSettings.defSize;
toolSettings.tabFillChar = prefsData.toolSettings.tabFillChar;
toolSettings.dispX = prefsData.toolSettings.dispX;
toolSettings.dispY = prefsData.toolSettings.dispY;
toolSettings.constrain = prefsData.toolSettings.constrain;
PageColors.ensureDefaultColors();
if (prefsData.toolSettings.dPen != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dPen, prefsData.DColors[prefsData.toolSettings.dPen]);
toolSettings.dPen = prefsData.toolSettings.dPen;
if (prefsData.toolSettings.dPenLine != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dPenLine, prefsData.DColors[prefsData.toolSettings.dPenLine]);
toolSettings.dPenLine = prefsData.toolSettings.dPenLine;
if (prefsData.toolSettings.dPenText != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dPenText, prefsData.DColors[prefsData.toolSettings.dPenText]);
toolSettings.dPenText = prefsData.toolSettings.dPenText;
if (prefsData.toolSettings.dStrokeText != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dStrokeText, prefsData.DColors[prefsData.toolSettings.dStrokeText]);
toolSettings.dStrokeText = prefsData.toolSettings.dStrokeText;
if (prefsData.toolSettings.dBrush != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dBrush, prefsData.DColors[prefsData.toolSettings.dBrush]);
toolSettings.dBrush = prefsData.toolSettings.dBrush;
if (prefsData.toolSettings.dBrushPict != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dBrushPict, prefsData.DColors[prefsData.toolSettings.dBrushPict]);
toolSettings.dBrushPict = prefsData.toolSettings.dBrushPict;
if (prefsData.toolSettings.dTextBackGround != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dTextBackGround, prefsData.DColors[prefsData.toolSettings.dTextBackGround]);
toolSettings.dTextBackGround = prefsData.toolSettings.dTextBackGround;
if (prefsData.toolSettings.dTextLineColor != CommonStrings::None)
PageColors.insert(prefsData.toolSettings.dTextLineColor, prefsData.DColors[prefsData.toolSettings.dTextLineColor]);
ParagraphStyle pstyle;
pstyle.setDefaultStyle(true);
pstyle.setName(CommonStrings::DefaultParagraphStyle);
pstyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing);
pstyle.setLineSpacing(15);
pstyle.setAlignment(ParagraphStyle::Leftaligned);
pstyle.setLeftMargin(0);
pstyle.setFirstIndent(0);
pstyle.setRightMargin(0);
pstyle.setGapBefore(0);
pstyle.setGapAfter(0);
pstyle.setHasDropCap(false);
pstyle.setDropCapLines(2);
pstyle.setDropCapOffset(0);
pstyle.charStyle().setParent("");
CharStyle cstyle;
cstyle.setDefaultStyle(true);
cstyle.setName(CommonStrings::DefaultCharacterStyle);
cstyle.setFont(prefsData.AvailFonts[toolSettings.defFont]);
cstyle.setFontSize(toolSettings.defSize);
cstyle.setFeatures(QStringList(CharStyle::INHERIT));
cstyle.setFillColor(toolSettings.dPenText);
cstyle.setFillShade(toolSettings.dTextPenShade);
cstyle.setStrokeColor(toolSettings.dStrokeText);
cstyle.setStrokeShade(toolSettings.dTextStrokeShade);
cstyle.setBaselineOffset(0);
cstyle.setShadowXOffset(50);
cstyle.setShadowYOffset(-50);
cstyle.setOutlineWidth(10);
cstyle.setUnderlineOffset(typographicSettings.valueUnderlinePos);
cstyle.setUnderlineWidth(typographicSettings.valueUnderlineWidth);
cstyle.setStrikethruOffset(typographicSettings.valueStrikeThruPos);
cstyle.setStrikethruWidth(typographicSettings.valueStrikeThruPos);
cstyle.setScaleH(1000);
cstyle.setScaleV(1000);
cstyle.setTracking(0);
cstyle.setLanguage(PrefsManager::instance()->appPrefs.Language);
docParagraphStyles.create(pstyle);
docParagraphStyles.makeDefault( &(docParagraphStyles[0]) );
docCharStyles.create(cstyle);
docCharStyles.makeDefault( &(docCharStyles[0]) );
docParagraphStyles[0].breakImplicitCharStyleInheritance();
docParagraphStyles[0].charStyle().setContext( & docCharStyles );
// docParagraphStyles[0].charStyle().setName( "cdocdefault" ); // DONT TRANSLATE
currentStyle = pstyle;
Layers.addLayer( tr("Background") );
// Fixme: Check PDF version input
PDF_Options.Version = (PDFOptions::PDFVersion)prefsData.PDF_Options.Version;
PDF_Options.firstUse = true;
docPatterns.clear();
if (AutoSave && ScCore->usingGUI())
autoSaveTimer->start(AutoSaveTime);
//Do this after all the collections have been created and cleared!
m_masterPageMode=true; // quick hack to force the change of pointers in setMasterPageMode();
setMasterPageMode(false);
addSymbols();
}
ScribusDoc::~ScribusDoc()
{
m_guardedObject.nullify();
CloseCMSProfiles();
while (!DocItems.isEmpty())
{
delete DocItems.takeFirst();
}
FrameItems.clear();
while (!MasterPages.isEmpty())
{
delete MasterPages.takeFirst();
}
while (!DocPages.isEmpty())
{
delete DocPages.takeFirst();
}
while (!MasterItems.isEmpty())
{
delete MasterItems.takeFirst();
}
QMap<QString,int>::Iterator it3;
for (it3 = UsedFonts.begin(); it3 != UsedFonts.end(); ++it3)
{
if (!(*AllFonts)[it3.key()].localForDocument().isEmpty())
(*AllFonts).removeFont(it3.key());
else
(*AllFonts)[it3.key()].decreaseUsage();
}
if (docHyphenator)
delete docHyphenator;
}
void ScribusDoc::setup(const int unitIndex, const int fp, const int firstLeft, const int orientation, const int firstPageNumber, const QString& defaultPageSize, const QString& documentName)
{
docUnitIndex=unitIndex;
pageSets[fp].FirstPage = firstLeft;
PageOri = orientation;
m_pageSize = defaultPageSize;
FirstPnum = firstPageNumber;
currentPageLayout = fp;
setName(documentName);
HasCMS = false;
if (!PDF_Options.UseLPI)
{
PDF_Options.LPISettings.clear();
struct LPIData lpo;
lpo.Frequency = 133;
lpo.SpotFunc = 3;
lpo.Angle = 105;
PDF_Options.LPISettings.insert("Cyan", lpo);
lpo.Angle = 75;
PDF_Options.LPISettings.insert("Magenta", lpo);
lpo.Angle = 90;
PDF_Options.LPISettings.insert("Yellow", lpo);
lpo.Angle = 45;
PDF_Options.LPISettings.insert("Black", lpo);
ActiveLayer = 0;
}
appMode = modeNormal;
PrefsManager *prefsManager=PrefsManager::instance();
PageColors = prefsManager->colorSet();
PageColors.ensureDefaultColors();
PageColors.setDocument(this);
CMSSettings = prefsManager->appPrefs.DCMSset;
PDF_Options.SolidProf = CMSSettings.DefaultSolidColorRGBProfile;
PDF_Options.ImageProf = CMSSettings.DefaultImageRGBProfile;
PDF_Options.PrintProf = CMSSettings.DefaultPrinterProfile;
PDF_Options.Intent = CMSSettings.DefaultIntentColors;
PDF_Options.Intent2 = CMSSettings.DefaultIntentImages;
BlackPoint = CMSSettings.BlackPoint;
SoftProofing = CMSSettings.SoftProofOn;
Gamut = CMSSettings.GamutCheck;
IntentColors = CMSSettings.DefaultIntentColors;
IntentImages = CMSSettings.DefaultIntentImages;
if (ScCore->haveCMS() && CMSSettings.CMSinUse)
{
if (OpenCMSProfiles(ScCore->InputProfiles, ScCore->InputProfilesCMYK, ScCore->MonitorProfiles, ScCore->PrinterProfiles))
{
HasCMS = true;
PDF_Options.SComp = CMSSettings.ComponentsInput2;
}
else
{
SetDefaultCMSParams();
HasCMS = false;
}
}
}
void ScribusDoc::setGUI(bool hasgui, ScribusMainWindow* mw, ScribusView* view)
{
m_hasGUI = hasgui;
m_ScMW=mw;
//FIXME: stop using m_View
m_View=view;
}
void ScribusDoc::createHyphenator()
{
if (docHyphenator)
return;
docHyphenator = new Hyphenator(m_ScMW, this);
Q_CHECK_PTR(docHyphenator);
}
void ScribusDoc::setLoading(const bool docLoading)
{
loading = docLoading;
}
bool ScribusDoc::isLoading() const
{
return loading;
}
//AV: eeks. That should not be used
ScribusView* ScribusDoc::view() const
{
// return (WinHan ? (((ScribusWin*) WinHan)->view()) : 0);
return m_View;
}
const ScGuardedPtr<ScribusDoc>& ScribusDoc::guardedPtr() const
{
return m_guardedObject;
}
void ScribusDoc::CloseCMSProfiles()
{
HasCMS = false;
SetDefaultCMSParams();
}
void ScribusDoc::SetDefaultCMSParams()
{
BlackPoint = true;
SoftProofing = false;
Gamut = false;
IntentColors = Intent_Relative_Colorimetric;
IntentImages = Intent_Relative_Colorimetric;
DocInputRGBProf = ScCore->defaultRGBProfile;
DocInputCMYKProf = ScCore->defaultCMYKProfile;
DocInputImageRGBProf = ScCore->defaultRGBProfile;
DocInputImageCMYKProf = ScCore->defaultCMYKProfile;
DocOutputProf = ScCore->defaultRGBProfile;
DocPrinterProf = ScCore->defaultCMYKProfile;
stdTransRGBMon = ScCore->defaultRGBToScreenSolidTrans;
stdTransCMYKMon = ScCore->defaultCMYKToRGBTrans;
stdTransRGB = ScCore->defaultCMYKToRGBTrans;
stdTransCMYK = ScCore->defaultRGBToCMYKTrans;
stdProof = ScCore->defaultRGBToScreenSolidTrans;
stdProofGC = ScCore->defaultRGBToScreenSolidTrans;
stdProofCMYK = ScCore->defaultCMYKToRGBTrans;
stdProofCMYKGC = ScCore->defaultCMYKToRGBTrans;
stdTransImg = ScCore->defaultRGBToScreenImageTrans;
stdProofImg = ScCore->defaultRGBToScreenImageTrans;
stdProofImgCMYK = ScCore->defaultCMYKToScreenImageTrans;
}
bool ScribusDoc::OpenCMSProfiles(ProfilesL InPo, ProfilesL InPoCMYK, ProfilesL MoPo, ProfilesL PrPo)
{
HasCMS = false;
ScColorProfile inputProf = NULL;
DocInputRGBProf = ScColorMgmtEngine::openProfileFromFile( InPo[CMSSettings.DefaultSolidColorRGBProfile] );
DocInputCMYKProf = ScColorMgmtEngine::openProfileFromFile( InPoCMYK[CMSSettings.DefaultSolidColorCMYKProfile] );
DocOutputProf = ScColorMgmtEngine::openProfileFromFile( MoPo[CMSSettings.DefaultMonitorProfile] );
DocPrinterProf = ScColorMgmtEngine::openProfileFromFile( PrPo[CMSSettings.DefaultPrinterProfile] );
DocInputImageRGBProf = ScColorMgmtEngine::openProfileFromFile( InPo[CMSSettings.DefaultImageRGBProfile] );
DocInputImageCMYKProf = ScColorMgmtEngine::openProfileFromFile( InPoCMYK[CMSSettings.DefaultImageCMYKProfile] );
if ((!DocInputRGBProf) || (!DocInputCMYKProf) || (!DocOutputProf) || (!DocPrinterProf) || (!DocInputImageCMYKProf) || (!DocInputImageRGBProf))
{
CMSSettings.CMSinUse = false;
return false;
}
int dcmsFlags = 0;
int dcmsFlagsGC = 0;
dcmsFlags |= Ctf_LowResPrecalc;
dcmsFlagsGC |= Ctf_LowResPrecalc;
// int dcmsFlags2 = cmsFLAGS_NOTPRECALC;
if (CMSSettings.GamutCheck)
dcmsFlagsGC |= Ctf_GamutCheck;
if (CMSSettings.BlackPoint)
{
dcmsFlags |= Ctf_BlackPointCompensation;
dcmsFlagsGC |= Ctf_BlackPointCompensation;
}
stdTransRGBMon = ScColorMgmtEngine::createTransform(DocInputRGBProf, Format_RGB_16,
DocOutputProf, Format_RGB_16,
IntentColors, dcmsFlags);
stdTransCMYKMon = ScColorMgmtEngine::createTransform(DocInputCMYKProf, Format_CMYK_16,
DocOutputProf, Format_RGB_16,
IntentColors, dcmsFlags);
// TODO : check input profiles used for images
stdProofImg = ScColorMgmtEngine::createProofingTransform(DocInputImageRGBProf, Format_RGBA_8,
DocOutputProf, Format_RGBA_8, DocPrinterProf, IntentImages,
Intent_Relative_Colorimetric, dcmsFlagsGC);
stdProofImgCMYK = ScColorMgmtEngine::createProofingTransform(DocInputImageCMYKProf, Format_CMYK_8,
DocOutputProf, Format_RGBA_8, DocPrinterProf, IntentImages,
Intent_Relative_Colorimetric, dcmsFlagsGC);
stdTransImg = ScColorMgmtEngine::createTransform(DocInputRGBProf, Format_RGBA_8,
DocOutputProf, Format_RGBA_8,
IntentImages, dcmsFlags);
stdTransRGB = ScColorMgmtEngine::createTransform(DocInputCMYKProf, Format_CMYK_16,
DocInputRGBProf, Format_RGB_16,
IntentColors, dcmsFlags);
stdTransCMYK = ScColorMgmtEngine::createTransform(DocInputRGBProf, Format_RGB_16,
DocInputCMYKProf, Format_CMYK_16,
IntentColors, dcmsFlags);
ScColorProfile inputProfRGB;
ScColorProfile inputProfCMYK;
if (DocPrinterProf.colorSpace() == ColorSpace_Cmyk)
{
inputProf = (CMSSettings.SoftProofOn && CMSSettings.SoftProofFullOn) ? DocInputCMYKProf : DocPrinterProf;
inputProfRGB = DocInputRGBProf;
inputProfCMYK = inputProf;
}
else
{
inputProf = (CMSSettings.SoftProofOn && CMSSettings.SoftProofFullOn) ? DocInputRGBProf : DocPrinterProf;
inputProfRGB = inputProf;
inputProfCMYK = DocInputCMYKProf;
}
stdProof = ScColorMgmtEngine::createProofingTransform(inputProfRGB, Format_RGB_16,
DocOutputProf, Format_RGB_16,
DocPrinterProf,
IntentColors,
Intent_Relative_Colorimetric, dcmsFlags);
stdProofGC = ScColorMgmtEngine::createProofingTransform(inputProfRGB, Format_RGB_16,
DocOutputProf, Format_RGB_16,
DocPrinterProf,
IntentColors,
Intent_Relative_Colorimetric, dcmsFlags | Ctf_GamutCheck);
stdProofCMYK = ScColorMgmtEngine::createProofingTransform(inputProfCMYK, Format_CMYK_16,
DocOutputProf, Format_RGB_16,
DocPrinterProf,
IntentColors,
Intent_Relative_Colorimetric, dcmsFlags);
stdProofCMYKGC = ScColorMgmtEngine::createProofingTransform(inputProfCMYK, Format_CMYK_16,
DocOutputProf, Format_RGB_16,
DocPrinterProf,
IntentColors,
Intent_Relative_Colorimetric, dcmsFlags | Ctf_GamutCheck);
if (DocInputRGBProf.colorSpace() == ColorSpace_Rgb)
CMSSettings.ComponentsInput2 = 3;
if (DocInputRGBProf.colorSpace() == ColorSpace_Cmyk)
CMSSettings.ComponentsInput2 = 4;
if (DocInputRGBProf.colorSpace() == ColorSpace_Cmy)
CMSSettings.ComponentsInput2 = 3;
bool success = (stdTransRGBMon && stdTransCMYKMon && stdProofImg && stdProofImgCMYK &&
stdTransImg && stdTransRGB && stdTransCMYK && stdProof &&
stdProofGC && stdProofCMYK && stdProofCMYKGC);
if (!success)
{
// Reset to the default handler otherwise may enter a loop
// if an error occur afterwards
CloseCMSProfiles();
CMSSettings.CMSinUse = false;
QString message = tr("An error occurred while opening ICC profiles, color management is not enabled." );
if (ScCore->usingGUI())
QMessageBox::warning(m_ScMW, CommonStrings::trWarning, message, QMessageBox::Ok, 0, 0);
else
qWarning( "%s", message.toLocal8Bit().data() );
return false;
}
return true;
}
void ScribusDoc::enableCMS(bool enable)
{
m_ScMW->setStatusBarInfoText( tr("Adjusting Colors"));
m_ScMW->mainWindowProgressBar->reset();
int cc = PageColors.count() + MasterItems.count() + DocItems.count();
m_ScMW->mainWindowProgressBar->setMaximum(cc);
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
bool oldCM = CMSSettings.CMSinUse;
bool newCM = enable;
CloseCMSProfiles();
CMSSettings.CMSinUse = newCM;
HasCMS = CMSSettings.CMSinUse;
BlackPoint = CMSSettings.BlackPoint;
SoftProofing = CMSSettings.SoftProofOn;
Gamut = CMSSettings.GamutCheck;
IntentColors = CMSSettings.DefaultIntentColors;
IntentImages = CMSSettings.DefaultIntentImages;
if (!CMSSettings.CMSinUse)
{
HasCMS = false;
if (oldCM)
{
m_ScMW->recalcColors(m_ScMW->mainWindowProgressBar);
RecalcPictures(&ScCore->InputProfiles, &ScCore->InputProfilesCMYK, m_ScMW->mainWindowProgressBar);
}
}
else if (OpenCMSProfiles(ScCore->InputProfiles, ScCore->InputProfilesCMYK, ScCore->MonitorProfiles, ScCore->PrinterProfiles) )
{
HasCMS = true;
PDF_Options.SComp = CMSSettings.ComponentsInput2;
PDF_Options.SolidProf = CMSSettings.DefaultSolidColorRGBProfile;
PDF_Options.ImageProf = CMSSettings.DefaultImageRGBProfile;
PDF_Options.PrintProf = CMSSettings.DefaultPrinterProfile;
PDF_Options.Intent = CMSSettings.DefaultIntentColors;
m_ScMW->recalcColors(m_ScMW->mainWindowProgressBar);
RecalcPictures(&ScCore->InputProfiles, &ScCore->InputProfilesCMYK, m_ScMW->mainWindowProgressBar);
}
else
{
SetDefaultCMSParams();
HasCMS = false;
}
m_ScMW->mainWindowProgressBar->setValue(cc);
qApp->restoreOverrideCursor();
m_ScMW->setStatusBarInfoText("");
m_ScMW->mainWindowProgressBar->reset();
}
void ScribusDoc::getNamedResources(ResourceCollection& lists) const
{
lists.availableFonts = AllFonts;
lists.availableColors = const_cast<ColorList*>(& PageColors);
const QList<PageItem*> * itemlist = & MasterItems;
while (itemlist != NULL)
{
for (int i=0; i < itemlist->count(); ++i)
{
const PageItem * currItem = const_cast<QList<PageItem*>*>(itemlist)->at(i);
if (currItem)
currItem->getNamedResources(lists);
}
if (itemlist == &MasterItems)
itemlist = &DocItems;
else if (itemlist == &DocItems)
itemlist = &FrameItems;
else
itemlist = NULL;
}
for (int i = 0; i < docParagraphStyles.count(); ++i)
docParagraphStyles[i].getNamedResources(lists);
for (int i = 0; i < docCharStyles.count(); ++i)
docCharStyles[i].getNamedResources(lists);
// for (uint i = 0; i < docLineStyles.count(); ++i)
// docLineStyles[i].getNamedResources(lists);
QMap<QString,ScPattern>::ConstIterator it;
for (it = docPatterns.begin(); it != docPatterns.end(); ++it)
{
ScPattern pa = *it;
for (int o = 0; o < pa.items.count(); o++)
{
pa.items.at(o)->getNamedResources(lists);
}
}
}
bool ScribusDoc::styleExists(QString styleName)
{
for (int ff = 0; ff < paragraphStyles().count(); ++ff)
{
if (paragraphStyles()[ff].name() == styleName)
return true;
}
return false;
}
QList<int> ScribusDoc::getSortedStyleList()
{
QList<int> retList;
for (int ff = 0; ff < docParagraphStyles.count(); ++ff)
{
if (docParagraphStyles[ff].parent().isEmpty())
{
if (!retList.contains(ff))
retList.append(ff);
continue;
}
QList<int> retList2;
QString name = docParagraphStyles[ff].name();
QString par = docParagraphStyles[ff].parent();
retList2.prepend(ff);
while ((!par.isEmpty()) && (par != name))
{
int pp = docParagraphStyles.find(par);
if ((pp >= 0) && (!retList2.contains(pp)))
retList2.prepend(pp);
par = (pp >= 0) ? docParagraphStyles[pp].parent() : QString();
}
for (int r = 0; r < retList2.count(); ++r)
{
if (!retList.contains(retList2[r]))
retList.append(retList2[r]);
}
}
return retList;
}
QList<int> ScribusDoc::getSortedCharStyleList()
{
QList<int> retList;
for (int ff = 0; ff < docCharStyles.count(); ++ff)
{
if (docCharStyles[ff].parent().isEmpty())
{
if (!retList.contains(ff))
retList.append(ff);
continue;
}
QList<int> retList2;
QString name = docCharStyles[ff].name();
QString par = docCharStyles[ff].parent();
retList2.prepend(ff);
while ((!par.isEmpty()) && (par != name))
{
int pp = docCharStyles.find(par);
if ((pp >= 0) && (!retList2.contains(pp)))
retList2.prepend(pp);
par = (pp >= 0) ? docCharStyles[pp].parent() : QString();
}
for (int r = 0; r < retList2.count(); ++r)
{
if (!retList.contains(retList2[r]))
retList.append(retList2[r]);
}
}
return retList;
}
void ScribusDoc::replaceStyles(const QMap<QString,QString>& newNameForOld)
{
ResourceCollection newNames;
newNames.mapStyles(newNameForOld);
replaceNamedResources(newNames);
}
void ScribusDoc::replaceNamedResources(ResourceCollection& newNames)
{
// replace names in items
QList<PageItem*> * itemlist = & MasterItems;
while (itemlist != NULL)
{
for (int i=0; i < itemlist->count(); ++i)
{
PageItem * currItem = itemlist->at(i);
if (currItem)
currItem->replaceNamedResources(newNames);
}
if (itemlist == &MasterItems)
itemlist = &DocItems;
else if (itemlist == &DocItems)
itemlist = &FrameItems;
else
itemlist = NULL;
}
// replace names in styles...
for (int i=docParagraphStyles.count()-1; i >= 0; --i)
{
if (newNames.styles().contains(docParagraphStyles[i].name()))
docParagraphStyles.remove(i);
else
docParagraphStyles[i].replaceNamedResources(newNames);
}
for (int i=docCharStyles.count()-1; i >= 0; --i)
{
if (newNames.charStyles().contains(docCharStyles[i].name()))
docCharStyles.remove(i);
else
docCharStyles[i].replaceNamedResources(newNames);
}
QMap<QString,ScPattern>::Iterator it;
for (it = docPatterns.begin(); it != docPatterns.end(); ++it)
{
if (newNames.patterns().contains(it.key()))
docPatterns.erase(it);
else
{
ScPattern pa = *it;
for (int o = 0; o < pa.items.count(); o++)
{
pa.items.at(o)->replaceNamedResources(newNames);
}
}
}
if (newNames.colors().count() > 0 || newNames.fonts().count() > 0)
{
docCharStyles.invalidate();
docParagraphStyles.invalidate();
}
else
{
if (newNames.charStyles().count() > 0)
docCharStyles.invalidate();
if (newNames.styles().count() > 0)
docParagraphStyles.invalidate();
}
if (!isLoading() && !(newNames.colors().isEmpty() && newNames.fonts().isEmpty() && newNames.patterns().isEmpty()
&& newNames.styles().isEmpty() && newNames.charStyles().isEmpty() && newNames.lineStyles().isEmpty()) )
changed();
}
void ScribusDoc::replaceCharStyles(const QMap<QString,QString>& newNameForOld)
{
ResourceCollection newNames;
newNames.mapCharStyles(newNameForOld);
replaceNamedResources(newNames);
/*
// replace style in items
QPtrList<PageItem> * itemlist = & MasterItems;
while (itemlist != NULL)
{
for (uint i=0; i < itemlist->count(); ++i)
{
PageItem_TextFrame * currItem = itemlist->at(i)->asTextFrame();
if (currItem)
currItem->itemText.replaceCharStyles(newNameForOld);
}
if (itemlist == &MasterItems)
itemlist = &DocItems;
else if (itemlist == &DocItems)
itemlist = &FrameItems;
else
itemlist = NULL;
}
// replace names in styles
for (uint i=0; i < docParagraphStyles.count(); ++i)
{
// ...parent of parstyle's charstyle
const QString& parent(docParagraphStyles[i].charStyle().parent());
if (newNameForOld.contains(parent))
docParagraphStyles[i].charStyle().setParent(newNameForOld[parent]);
}
for (int i=docCharStyles.count()-1; i >= 0; --i)
{
// ...parent of charstyle
const QString& parent(docCharStyles[i].parent());
if (newNameForOld.contains(parent))
docCharStyles[i].setParent(newNameForOld[parent]);
// ... as name
if (newNameForOld.contains(docCharStyles[i].name()))
docCharStyles.remove(i);
}
*/
}
void ScribusDoc::redefineStyles(const StyleSet<ParagraphStyle>& newStyles, bool removeUnused)
{
docParagraphStyles.redefine(newStyles, false);
if (removeUnused)
{
QMap<QString, QString> deletion;
QString deflt("");
for (int i=0; i < docParagraphStyles.count(); ++i)
{
const QString& nam(docParagraphStyles[i].name());
if (newStyles.find(nam) < 0)
deletion[nam] = deflt;
}
if (deletion.count() > 0)
replaceStyles(deletion);
}
// repair charstyle context:
for (int i=0; i < docParagraphStyles.count(); ++i)
{
ParagraphStyle& sty(docParagraphStyles[i]);
if (docParagraphStyles.isDefault(sty))
{
sty.breakImplicitCharStyleInheritance(true);
sty.charStyle().setContext( & docCharStyles );
// sty.charStyle().setName( "cdocdefault" ); // DONT TRANSLATE
}
else {
sty.breakImplicitCharStyleInheritance(false);
}
}
docParagraphStyles.invalidate();
}
void ScribusDoc::redefineCharStyles(const StyleSet<CharStyle>& newStyles, bool removeUnused)
{
docCharStyles.redefine(newStyles, false);
if (removeUnused)
{
QMap<QString, QString> deletion;
QString deflt("");
for (int i=0; i < docCharStyles.count(); ++i)
{
const QString& nam(docCharStyles[i].name());
if (newStyles.find(nam) < 0)
{
deletion[nam] = deflt;
}
}
if (deletion.count() > 0)
replaceCharStyles(deletion);
}
docCharStyles.invalidate();
}
/*
* Split out from loadStyles in editFormats.cpp so it's callable from anywhere,
* including plugins.
* - 2004-09-14 Craig Ringer
*/
// dont like this here. could as well be a static method for reading this stuff into temp., then always use redefineXY() - av
void ScribusDoc::loadStylesFromFile(QString fileName)
{
StyleSet<ParagraphStyle> *wrkStyles = &docParagraphStyles;
StyleSet<CharStyle> *wrkCharStyles = &docCharStyles;
QMap<QString, multiLine> *wrkLineStyles = &MLineStyles;
int oldStyles = wrkStyles->count();
int oldCharStyles = wrkCharStyles->count();
int oldLineStyles = wrkLineStyles->count();
if (!fileName.isEmpty())
{
FileLoader fl(fileName);
if (fl.testFile() == -1)
//TODO put in nice user warning
return;
if (!fl.readStyles(this, *wrkStyles))
{
//TODO put in nice user warning
}
if (!fl.readCharStyles(this, *wrkCharStyles))
{
//TODO put in nice user warning
}
if (!fl.readLineStyles(wrkLineStyles))
{
//TODO put in nice user warning
}
if ( !isLoading() && ((wrkStyles->count() > oldStyles)
|| (wrkCharStyles->count() > oldCharStyles)
|| (wrkLineStyles->count() > oldLineStyles) ) )
changed();
}
}
void ScribusDoc::loadStylesFromFile(QString fileName, StyleSet<ParagraphStyle> *tempStyles,
StyleSet<CharStyle> *tempCharStyles,
QMap<QString, multiLine> *tempLineStyles)
{
StyleSet<ParagraphStyle> *wrkStyles = tempStyles;
StyleSet<CharStyle> *wrkCharStyles = tempCharStyles;
QMap<QString, multiLine> *wrkLineStyles = tempLineStyles;
if (!fileName.isEmpty())
{
FileLoader fl(fileName);
if (fl.testFile() == -1)
//TODO put in nice user warning
return;
if (!fl.readStyles(this, *wrkStyles))
{
//TODO put in nice user warning
}
if (!fl.readCharStyles(this, *wrkCharStyles))
{
//TODO put in nice user warning
}
if (!fl.readLineStyles(wrkLineStyles))
{
//TODO put in nice user warning
}
// Which are the default styles
// Sadly StyleSet is not updated at import
// and it might break something to do so.
// We need to loop then - pm
// ParagraphStyle* parDefault(wrkStyles->getDefault());
// CharStyle* charDefault(wrkCharStyles->getDefault());
QFileInfo fi(fileName);
QString importPrefix(tr("Imported ","Prefix of imported default style"));
QString importSuffix(" (" + fi.baseName() + ")");
for(int j(0) ; j < wrkStyles->count() ; ++j)
{
if((*wrkStyles)[j].isDefaultStyle())
{
ParagraphStyle& parDefault((*wrkStyles)[j]);
parDefault.setDefaultStyle(false);
QMap<QString, QString> namesMap;
namesMap[parDefault.name()] = importPrefix + parDefault.name() + importSuffix;
for(int i(0) ; i < wrkStyles->count() ; ++i)
{
if( (*wrkStyles)[i] != parDefault )
namesMap[(*wrkStyles)[i].name()] = (*wrkStyles)[i].name();
}
wrkStyles->rename(namesMap);
}
}
for(int j(0) ; j < wrkCharStyles->count() ; ++j)
{
if((*wrkCharStyles)[j].isDefaultStyle())
{
CharStyle& charDefault((*wrkCharStyles)[j]);
charDefault.setDefaultStyle(false);
QMap<QString, QString> namesMap;
namesMap[charDefault.name()] = importPrefix + charDefault.name() + importSuffix;
for(int i(0) ; i < wrkCharStyles->count() ; ++i)
{
if( (*wrkCharStyles)[i] != charDefault )
namesMap[(*wrkCharStyles)[i].name()] = (*wrkCharStyles)[i].name();
}
wrkCharStyles->rename(namesMap);
}
}
}
}
void ScribusDoc::lockGuides(bool isLocked)
{
if (GuideLock == isLocked)
return;
GuideLock = isLocked;
if (UndoManager::undoEnabled())
{
QString name;
if (isLocked)
name = Um::LockGuides;
else
name = Um::UnlockGuides;
SimpleState *ss = new SimpleState(name, "", Um::ILockGuides);
ss->set("GUIDE_LOCK", isLocked);
undoManager->action(this, ss);
}
}
void ScribusDoc::undoRedoBegin()
{
m_docUpdater->beginUpdate();
m_Selection->delaySignalsOn();
}
void ScribusDoc::undoRedoDone()
{
m_Selection->delaySignalsOff();
m_docUpdater->endUpdate();
// Ensure PP is properly disabled when selection is empty
// after undoing or redoing an action
if (m_Selection->count() == 0)
emit firstSelectedItemType(-1);
}
void ScribusDoc::restore(UndoState* state, bool isUndo)
{
SimpleState *ss = dynamic_cast<SimpleState*>(state);
if (ss)
{
bool layersUndo=false;
if (ss->contains("GROUP"))
restoreGrouping(ss, isUndo);
else if (ss->contains("UNGROUP"))
restoreUngrouping(ss, isUndo);
else if (ss->contains("GUIDE_LOCK"))
{
if (isUndo)
GuideLock = !ss->getBool("GUIDE_LOCK");
else
GuideLock = ss->getBool("GUIDE_LOCK");
}
else if (ss->contains("UP_LAYER"))
{
if (isUndo)
lowerLayer(ss->getInt("ACTIVE"));
else
raiseLayer(ss->getInt("ACTIVE"));
layersUndo=true;
}
else if (ss->contains("DOWN_LAYER"))
{
if (isUndo)
raiseLayer(ss->getInt("ACTIVE"));
else
lowerLayer(ss->getInt("ACTIVE"));
layersUndo=true;
}
else if (ss->contains("PRINT_LAYER"))
{
bool print = ss->getBool("PRINT");
setLayerPrintable(ss->getInt("ACTIVE"), isUndo ? !print : print);
layersUndo=true;
}
else if (ss->contains("LAYER_FLOW"))
{
bool flow = ss->getBool("FLOW");
setLayerFlow(ss->getInt("ACTIVE"), isUndo ? !flow : flow);
layersUndo=true;
}
else if (ss->contains("LAYER_LOCK"))
{
bool lock = ss->getBool("LOCK");
setLayerLocked(ss->getInt("ACTIVE"), isUndo ? !lock : lock);
layersUndo=true;
}
else if (ss->contains("LAYER_TRANSPARENCY"))
{
double old_trans = ss->getDouble("OLD_TRANS");
double new_trans = ss->getDouble("NEW_TRANS");
setLayerTransparency(ss->getInt("ACTIVE"), isUndo ? old_trans : new_trans);
layersUndo=true;
}
else if (ss->contains("LAYER_BLENDMODE"))
{
int old_blend = ss->getInt("OLD_BLENDMODE");
int new_blend = ss->getInt("NEW_BLENDMODE");
setLayerBlendMode(ss->getInt("ACTIVE"), isUndo ? old_blend : new_blend);
layersUndo=true;
}
else if (ss->contains("ADD_LAYER"))
{
if (isUndo)
deleteLayer(ss->getInt("LAYER_NR"), false);
else
{
int layerNumber=addLayer( ss->get("NAME"), false );
int newLayerNumber=ss->getInt("LAYER_NR");
bool renumberedOk=renumberLayer(layerNumber, newLayerNumber);
Q_ASSERT(renumberedOk);
}
layersUndo=true;
}
else if (ss->contains("REMOVE_LAYER"))
{
if (isUndo)
{
int layerNumber=addLayer( ss->get("NAME"), false );
int newLayerNumber=ss->getInt("LAYER_NR");
bool renumberedOk=renumberLayer(layerNumber, newLayerNumber);
Q_ASSERT(renumberedOk);
layerNumber=newLayerNumber;
//Layer is at the top now, lower it until it reaches the old level
int level = ss->getInt("LEVEL");
while (layerLevelFromNumber(layerNumber)!=level)
lowerLayer(layerNumber);
}
else
deleteLayer(ss->getInt("LAYER_NR"), ss->getBool("DELETE"));
layersUndo=true;
}
else if (ss->contains("CHANGE_NAME"))
{
QString name = ss->get("OLD_NAME");
if (!isUndo)
name = ss->get("NEW_NAME");
changeLayerName(ss->getInt("ACTIVE"), name);
layersUndo=true;
}
else if (ss->contains("OLD_MASTERPAGE"))
restoreMasterPageApplying(ss, isUndo);
else if (ss->contains("PAGE_COPY"))
restoreCopyPage(ss, isUndo);
else if (ss->contains("PAGE_MOVE"))
restoreMovePage(ss, isUndo);
else if (ss->contains("PAGE_CHANGEPROPS"))
{
if (isUndo)
{
changePageMargins(ss->getDouble("OLD_PAGE_INITIALTOP"), ss->getDouble("OLD_PAGE_INITIALBOTTOM"),
ss->getDouble("OLD_PAGE_INITIALLEFT"), ss->getDouble("OLD_PAGE_INITIALRIGHT"),
ss->getDouble("OLD_PAGE_INITIALHEIGHT"), ss->getDouble("OLD_PAGE_INITIALWIDTH"),
ss->getDouble("OLD_PAGE_HEIGHT"), ss->getDouble("OLD_PAGE_WIDTH"), ss->getInt("OLD_PAGE_ORIENTATION"),
ss->get("OLD_PAGE_SIZE"), ss->getInt("OLD_PAGE_MARGINPRESET"), ss->getBool("OLD_PAGE_MOVEOBJECTS"), ss->getInt("PAGE_NUM"), ss->getInt("OLD_PAGE_TYPE"));
}
else
{
changePageMargins(ss->getDouble("NEW_PAGE_INITIALTOP"), ss->getDouble("NEW_PAGE_INITIALBOTTOM"),
ss->getDouble("NEW_PAGE_INITIALLEFT"), ss->getDouble("NEW_PAGE_INITIALRIGHT"),
ss->getDouble("NEW_PAGE_INITIALHEIGHT"), ss->getDouble("NEW_PAGE_INITIALWIDTH"),
ss->getDouble("NEW_PAGE_HEIGHT"), ss->getDouble("NEW_PAGE_WIDTH"), ss->getInt("NEW_PAGE_ORIENTATION"),
ss->get("NEW_PAGE_SIZE"), ss->getInt("NEW_PAGE_MARGINPRESET"), ss->getBool("OLD_PAGE_MOVEOBJECTS"), ss->getInt("PAGE_NUM"), ss->getInt("NEW_PAGE_TYPE"));
}
}
if (layersUndo)
{
if (ScCore->usingGUI())
{
m_ScMW->changeLayer(ss->getInt("ACTIVE"));
m_ScMW->layerPalette->rebuildList();
m_ScMW->layerPalette->markActiveLayer(activeLayer());
}
}
}
}
void ScribusDoc::restoreGrouping(SimpleState *state, bool isUndo)
{
double x, y, w, h;
Selection tmpSelection(this, false);
int itemCount = state->getInt("itemcount");
m_Selection->setGroupRect();
m_Selection->getGroupRect(&x, &y, &w, &h);
m_Selection->delaySignalsOn();
m_Selection->clear();
for (int i = 0; i < itemCount; ++i)
{
int itemNr = getItemNrfromUniqueID(state->getUInt(QString("item%1").arg(i)));
if (Items->at(itemNr)->uniqueNr == state->getUInt(QString("item%1").arg(i)))
tmpSelection.addItem(Items->at(itemNr));
}
if (isUndo)
{
uint docSelectionCount=tmpSelection.count();
PageItem *currItem;
uint lowestItem = 999999;
for (uint a=0; a<docSelectionCount; ++a)
{
currItem = tmpSelection.itemAt(a);
lowestItem = qMin(lowestItem, currItem->ItemNr);
}
if ((lowestItem > 0) && (Items->at(lowestItem-1)->Groups.count() != 0))
{
if (Items->at(lowestItem-1)->Groups.top() == tmpSelection.itemAt(0)->Groups.top())
{
tmpSelection.addItem(Items->at(lowestItem-1), true);
}
}
itemSelection_UnGroupObjects(&tmpSelection);
}
else
itemSelection_GroupObjects(false, false, &tmpSelection);
QRectF rect(x, y , w, h);
regionsChanged()->update(rect.adjusted(-10, -10, 20, 20));
m_Selection->delaySignalsOff();
}
void ScribusDoc::restoreUngrouping(SimpleState *state, bool isUndo)
{
double x, y, w, h;
Selection tmpSelection(this, false);
int itemCount = state->getInt("itemcount");
m_Selection->setGroupRect();
m_Selection->getGroupRect(&x, &y, &w, &h);
m_Selection->delaySignalsOn();
m_Selection->clear();
for (int i = 0; i < itemCount; ++i)
{
int itemNr = getItemNrfromUniqueID(state->getUInt(QString("item%1").arg(i)));
if (Items->at(itemNr)->uniqueNr == state->getUInt(QString("item%1").arg(i)))
{
if (isUndo)
Items->at(itemNr)->isTableItem = static_cast<bool>(state->getInt(QString("tableitem%1").arg(i)));
tmpSelection.addItem(Items->at(itemNr));
}
}
if (isUndo)
itemSelection_GroupObjects(false, false, &tmpSelection);
else
{
uint docSelectionCount=tmpSelection.count();
PageItem *currItem;
uint lowestItem = 999999;
for (uint a=0; a<docSelectionCount; ++a)
{
currItem = tmpSelection.itemAt(a);
lowestItem = qMin(lowestItem, currItem->ItemNr);
}
if ((lowestItem > 0) && (Items->at(lowestItem-1)->Groups.count() != 0))
{
if (Items->at(lowestItem-1)->Groups.top() == tmpSelection.itemAt(0)->Groups.top())
{
tmpSelection.addItem(Items->at(lowestItem-1));
}
}
itemSelection_UnGroupObjects(&tmpSelection);
}
QRectF rect(x, y , w, h);
regionsChanged()->update(rect.adjusted(-10, -10, 20, 20));
m_Selection->delaySignalsOff();
}
void ScribusDoc::setName(const QString& name)
{
DocName = name;
}
void ScribusDoc::setModified(const bool isModified)
{
if (modified != isModified)
{
modified = isModified;
update();
}
}
bool ScribusDoc::isModified() const
{
return modified;
}
/** sets page properties */
void ScribusDoc::setPage(double b, double h, double t, double l, double r, double bo, double sp, double ab, bool atf, int fp)
{
pageWidth = b;
pageHeight = h;
pageMargins.Top = t;
pageMargins.Left = l;
pageMargins.Right = r;
pageMargins.Bottom = bo;
PageSp = sp;
PageSpa = ab;
currentPageLayout = fp;
automaticTextFrames = atf;
//CB Moved from scribus.cpp. Overrides the defaults...
// PDF_Options.BleedTop = pageMargins.Top;
// PDF_Options.BleedLeft = pageMargins.Left;
// PDF_Options.BleedRight = pageMargins.Right;
// PDF_Options.BleedBottom = pageMargins.Bottom;
}
void ScribusDoc::resetPage(MarginStruct& newMargins, int fp)
{
pageMargins = newMargins;
currentPageLayout = fp;
}
bool ScribusDoc::AddFont(QString name, int fsize)
{
bool ret = false;
// FT_Face face;
if (UsedFonts.contains(name))
return true;
if (! AllFonts->contains(name) || name == "" )
return false;
// face = (*AllFonts)[name]->ftFace();
// if ( !face )
// return false;
/* if ((*AllFonts)[name].ReadMetrics()) FIXME: needed?
{
// (*AllFonts)[name]->CharWidth[13] = 0;
// (*AllFonts)[name]->CharWidth[28] = 0;
// (*AllFonts)[name]->CharWidth[26] = 0;
// (*AllFonts)[name]->CharWidth[9] = 1;
QString afnm = (*AllFonts)[name].fontFilePath().left((*AllFonts)[name].fontFilePath().length()-3);
QFile afm(afnm+"afm");
if(!(afm.exists()))
{
afm.setName(afnm+"pfm");
}
if(!(afm.exists())) {
afm.setName(afnm+"AFM");
}
if(!(afm.exists()))
{
afm.setName(afnm+"PFM");
}
if(!(afm.exists()))
{
afm.setName(afnm+"Afm");
}
if(!(afm.exists()))
{
afm.setName(afnm+"Pfm");
}
if (afm.exists())
FT_Attach_File(face, afm.name());
}
*/
UsedFonts[name] = fsize;
(*AllFonts)[name].increaseUsage();
ret = true;
return ret;
}
QStringList ScribusDoc::getItemAttributeNames()
{
QStringList nameList;
for(ObjAttrVector::Iterator it = docItemAttributes.begin(); it!= docItemAttributes.end(); ++it)
nameList.append((*it).name);
return nameList;
}
void ScribusDoc::addSymbols()
{
symReturn.resize(0);
symReturn.addQuadPoint(1.98438, 9.14062, 1.98438, 9.14062, 1.98438, 4.03125, 1.98438, 4.03125);
symReturn.addQuadPoint(1.98438, 4.03125, 1.98438, 4.03125, 0.546875, 3.45312, 1.09375, 4);
symReturn.addQuadPoint(0.546875, 3.45312, 0.546875, 3.45312, 0, 2.0625, 0, 2.92188);
symReturn.addQuadPoint(0, 2.0625, 0, 2.0625, 0.65625, 0.5, 0, 1.04688);
symReturn.addQuadPoint(0.65625, 0.5, 0.65625, 0.5, 2.3125, 0, 1.28125, 0);
symReturn.addQuadPoint(2.3125, 0, 2.3125, 0, 5.40625, 0, 5.40625, 0);
symReturn.addQuadPoint(5.40625, 0, 5.40625, 0, 5.40625, 0.84375, 5.40625, 0.84375);
symReturn.addQuadPoint(5.40625, 0.84375, 5.40625, 0.84375, 4.70312, 0.84375, 4.70312, 0.84375);
symReturn.addQuadPoint(4.70312, 0.84375, 4.70312, 0.84375, 4.70312, 9.14062, 4.70312, 9.14062);
symReturn.addQuadPoint(4.70312, 9.14062, 4.70312, 9.14062, 3.875, 9.14062, 3.875, 9.14062);
symReturn.addQuadPoint(3.875, 9.14062, 3.875, 9.14062, 3.875, 0.84375, 3.875, 0.84375);
symReturn.addQuadPoint(3.875, 0.84375, 3.875, 0.84375, 2.78125, 0.84375, 2.78125, 0.84375);
symReturn.addQuadPoint(2.78125, 0.84375, 2.78125, 0.84375, 2.78125, 9.14062, 2.78125, 9.14062);
symReturn.addQuadPoint(2.78125, 9.14062, 2.78125, 9.14062, 1.98438, 9.14062, 1.98438, 9.14062);
symNewLine.resize(0);
symNewLine.addQuadPoint(6.51562, 2.625, 6.51562, 2.625, 0.90625, 2.64062, 0.90625, 2.64062);
symNewLine.addQuadPoint(0.90625, 2.64062, 0.90625, 2.64062, 1.4375, 1.92188, 1.26562, 2.1875);
symNewLine.addQuadPoint(1.4375, 1.92188, 1.4375, 1.92188, 1.76562, 1.14062, 1.75, 1.42188);
symNewLine.addQuadPoint(1.76562, 1.14062, 1.76562, 1.14062, 1.60938, 1.03125, 1.60938, 1.03125);
symNewLine.addQuadPoint(1.60938, 1.03125, 1.60938, 1.03125, 0.90625, 1.92188, 0.90625, 1.92188);
symNewLine.addQuadPoint(0.90625, 1.92188, 0.90625, 1.92188, 0, 2.90625, 0.578125, 2.23438);
symNewLine.addQuadPoint(0, 2.90625, 0, 2.90625, 0.75, 3.875, 0.75, 3.875);
symNewLine.addQuadPoint(0.75, 3.875, 0.75, 3.875, 1.57812, 4.78125, 1.1875, 4.40625);
symNewLine.addQuadPoint(1.57812, 4.78125, 1.57812, 4.78125, 1.65625, 4.79688, 1.65625, 4.79688);
symNewLine.addQuadPoint(1.65625, 4.79688, 1.65625, 4.79688, 1.76562, 4.65625, 1.76562, 4.65625);
symNewLine.addQuadPoint(1.76562, 4.65625, 1.76562, 4.65625, 0.90625, 3.17188, 1.73438, 4.34375);
symNewLine.addQuadPoint(0.90625, 3.17188, 0.90625, 3.17188, 0.96875, 3.125, 0.96875, 3.125);
symNewLine.addQuadPoint(0.96875, 3.125, 0.96875, 3.125, 6.75, 3.125, 6.75, 3.125);
symNewLine.addQuadPoint(6.75, 3.125, 6.75, 3.125, 6.51562, 2.625, 6.51562, 2.625);
symNewLine.addQuadPoint(6.51562, 2.625, 6.51562, 2.625, 6.51562, 2.625, 6.51562, 2.625);
symNewLine.addQuadPoint(999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999);
symNewLine.addQuadPoint(6.875, 0, 6.875, 0, 6.51562, 0, 6.51562, 0);
symNewLine.addQuadPoint(6.51562, 0, 6.51562, 0, 6.51562, 2.84375, 6.51562, 2.84375);
symNewLine.addQuadPoint(6.51562, 2.84375, 6.51562, 2.84375, 6.75, 3.125, 6.51562, 3.125);
symNewLine.addQuadPoint(6.75, 3.125, 6.75, 3.125, 6.85938, 3.0625, 6.85938, 3.0625);
symNewLine.addQuadPoint(6.85938, 3.0625, 6.85938, 3.0625, 6.875, 0, 6.875, 0);
symTab.resize(0);
symTab.addQuadPoint(4.82812, 3.96875, 4.82812, 3.96875, 4.5625, 3.73438, 4.5625, 3.96875);
symTab.addQuadPoint(4.5625, 3.73438, 4.5625, 3.73438, 5.07812, 3.10938, 4.5625, 3.57812);
symTab.addQuadPoint(5.07812, 3.10938, 5.07812, 3.10938, 0, 3.10938, 0, 3.10938);
symTab.addQuadPoint(0, 3.10938, 0, 3.10938, 0, 2.625, 0, 2.625);
symTab.addQuadPoint(0, 2.625, 0, 2.625, 5.53125, 2.625, 5.53125, 2.625);
symTab.addQuadPoint(5.53125, 2.625, 5.53125, 2.625, 6.3125, 1.8125, 6.3125, 1.8125);
symTab.addQuadPoint(6.3125, 1.8125, 6.3125, 1.8125, 5.64062, 1.29688, 5.64062, 1.29688);
symTab.addQuadPoint(5.64062, 1.29688, 5.64062, 1.29688, 0, 1.29688, 0, 1.29688);
symTab.addQuadPoint(0, 1.29688, 0, 1.29688, 0, 0.8125, 0, 0.8125);
symTab.addQuadPoint(0, 0.8125, 0, 0.8125, 5.01562, 0.8125, 5.01562, 0.8125);
symTab.addQuadPoint(5.01562, 0.8125, 5.01562, 0.8125, 4.45312, 0.265625, 4.45312, 0.453125);
symTab.addQuadPoint(4.45312, 0.265625, 4.45312, 0.265625, 4.6875, 0, 4.45312, 0);
symTab.addQuadPoint(4.6875, 0, 4.6875, 0, 5.90625, 0.828125, 4.875, 0);
symTab.addQuadPoint(5.90625, 0.828125, 5.90625, 0.828125, 6.9375, 1.79688, 6.9375, 1.64062);
symTab.addQuadPoint(6.9375, 1.79688, 6.9375, 1.79688, 5.95312, 2.96875, 6.9375, 1.95312);
symTab.addQuadPoint(5.95312, 2.96875, 5.95312, 2.96875, 4.82812, 3.96875, 4.98438, 3.96875);
symNonBreak.resize(0);
symNonBreak.addQuadPoint(1.32812, 2.59375, 1.32812, 2.59375, 0.390625, 2.21875, 0.796875, 2.59375);
symNonBreak.addQuadPoint(0.390625, 2.21875, 0.390625, 2.21875, 0, 1.3125, 0, 1.84375);
symNonBreak.addQuadPoint(0, 1.3125, 0, 1.3125, 0.390625, 0.390625, 0, 0.765625);
symNonBreak.addQuadPoint(0.390625, 0.390625, 0.390625, 0.390625, 1.32812, 0, 0.796875, 0);
symNonBreak.addQuadPoint(1.32812, 0, 1.32812, 0, 2.23438, 0.390625, 1.85938, 0);
symNonBreak.addQuadPoint(2.23438, 0.390625, 2.23438, 0.390625, 2.60938, 1.29688, 2.60938, 0.765625);
symNonBreak.addQuadPoint(2.60938, 1.29688, 2.60938, 1.29688, 2.23438, 2.21875, 2.60938, 1.84375);
symNonBreak.addQuadPoint(2.23438, 2.21875, 2.23438, 2.21875, 1.32812, 2.59375, 1.875, 2.59375);
symNewCol.resize(0);
symNewCol.addQuadPoint(1.73438, 0, 1.73438, 0, 2.67188, 0.109375, 2.03125, 0);
symNewCol.addQuadPoint(2.67188, 0.109375, 2.67188, 0.109375, 3.59375, 0.203125, 3.26562, 0.21875);
symNewCol.addQuadPoint(3.59375, 0.203125, 3.59375, 0.203125, 3.79688, 0.1875, 3.64062, 0.203125);
symNewCol.addQuadPoint(3.79688, 0.1875, 3.79688, 0.1875, 4, 0.171875, 3.92188, 0.171875);
symNewCol.addQuadPoint(4, 0.171875, 4, 0.171875, 4.20312, 0.1875, 4.20312, 0.1875);
symNewCol.addQuadPoint(4.20312, 0.1875, 4.20312, 0.1875, 4.3125, 1.39062, 4.20312, 0.5625);
symNewCol.addQuadPoint(4.3125, 1.39062, 4.3125, 1.39062, 4.42188, 2.64062, 4.42188, 2.21875);
symNewCol.addQuadPoint(4.42188, 2.64062, 4.42188, 2.64062, 4.28125, 2.73438, 4.28125, 2.73438);
symNewCol.addQuadPoint(4.28125, 2.73438, 4.28125, 2.73438, 3.75, 1.03125, 4.01562, 2.64062);
symNewCol.addQuadPoint(3.75, 1.03125, 3.75, 1.03125, 3.67188, 1.03125, 3.67188, 1.03125);
symNewCol.addQuadPoint(3.67188, 1.03125, 3.67188, 1.03125, 0.28125, 6.20312, 0.28125, 6.20312);
symNewCol.addQuadPoint(0.28125, 6.20312, 0.28125, 6.20312, 0, 5.95312, 0.03125, 6.17188);
symNewCol.addQuadPoint(0, 5.95312, 0, 5.95312, 3.35938, 0.71875, 3.35938, 0.71875);
symNewCol.addQuadPoint(3.35938, 0.71875, 3.35938, 0.71875, 3.375, 0.640625, 3.375, 0.640625);
symNewCol.addQuadPoint(3.375, 0.640625, 3.375, 0.640625, 2.4375, 0.484375, 2.79688, 0.5625);
symNewCol.addQuadPoint(2.4375, 0.484375, 2.4375, 0.484375, 1.67188, 0.140625, 1.71875, 0.328125);
symNewCol.addQuadPoint(1.67188, 0.140625, 1.67188, 0.140625, 1.73438, 0, 1.73438, 0);
symNewFrame.resize(0);
symNewFrame.addQuadPoint(1.75, 6.20312, 1.75, 6.20312, 2.67188, 6.09375, 2.0625, 6.20312);
symNewFrame.addQuadPoint(2.67188, 6.09375, 2.67188, 6.09375, 3.60938, 5.98438, 3.28125, 5.98438);
symNewFrame.addQuadPoint(3.60938, 5.98438, 3.60938, 5.98438, 3.84375, 6.01562, 3.6875, 5.98438);
symNewFrame.addQuadPoint(3.84375, 6.01562, 3.84375, 6.01562, 4.07812, 6.03125, 4, 6.03125);
symNewFrame.addQuadPoint(4.07812, 6.03125, 4.07812, 6.03125, 4.20312, 6.01562, 4.20312, 6.01562);
symNewFrame.addQuadPoint(4.20312, 6.01562, 4.20312, 6.01562, 4.32812, 4.79688, 4.21875, 5.625);
symNewFrame.addQuadPoint( 4.32812, 4.79688, 4.32812, 4.79688, 4.42188, 3.5625, 4.42188, 3.98438);
symNewFrame.addQuadPoint(4.42188, 3.5625, 4.42188, 3.5625, 4.29688, 3.45312, 4.29688, 3.45312);
symNewFrame.addQuadPoint(4.29688, 3.45312, 4.29688, 3.45312, 3.75, 5.17188, 4.03125, 3.54688);
symNewFrame.addQuadPoint(3.75, 5.17188, 3.75, 5.17188, 3.67188, 5.17188, 3.67188, 5.17188);
symNewFrame.addQuadPoint(3.67188, 5.17188, 3.67188, 5.17188, 0.28125, 0, 0.28125, 0);
symNewFrame.addQuadPoint(0.28125, 0, 0.28125, 0, 0, 0.25, 0.03125, 0.015625);
symNewFrame.addQuadPoint(0, 0.25, 0, 0.25, 3.375, 5.46875, 3.375, 5.46875);
symNewFrame.addQuadPoint(3.375, 5.46875, 3.375, 5.46875, 3.39062, 5.54688, 3.39062, 5.54688);
symNewFrame.addQuadPoint(3.39062, 5.54688, 3.39062, 5.54688, 2.4375, 5.70312, 2.8125, 5.625);
symNewFrame.addQuadPoint(2.4375, 5.70312, 2.4375, 5.70312, 1.67188, 6.0625, 1.71875, 5.875);
symNewFrame.addQuadPoint(1.67188, 6.0625, 1.67188, 6.0625, 1.75, 6.20312, 1.75, 6.20312);
}
Page* ScribusDoc::addPage(const int pageIndex, const QString& masterPageName, const bool addAutoFrame)
{
assert(masterPageMode()==false);
Page* addedPage = new Page(scratch.Left, DocPages.count()*(pageHeight+scratch.Bottom+scratch.Top)+scratch.Top, pageWidth, pageHeight);
assert(addedPage!=NULL);
addedPage->setDocument(this);
addedPage->Margins.Top = pageMargins.Top;
addedPage->Margins.Bottom = pageMargins.Bottom;
addedPage->initialMargins.Top = pageMargins.Top;
addedPage->initialMargins.Bottom = pageMargins.Bottom;
addedPage->initialMargins.Left = pageMargins.Left;
addedPage->initialMargins.Right = pageMargins.Right;
addedPage->setPageNr(pageIndex);
addedPage->m_pageSize = m_pageSize;
addedPage->PageOri = PageOri;
addedPage->marginPreset = marginPreset;
DocPages.insert(pageIndex, addedPage);
assert(DocPages.at(pageIndex)!=NULL);
setCurrentPage(addedPage);
//if (!masterPageMode())
if (!masterPageName.isEmpty())
applyMasterPage(masterPageName, pageIndex);
setLocationBasedPageLRMargins(pageIndex);
if (addAutoFrame && automaticTextFrames)
addAutomaticTextFrame(pageIndex);
// if (!isLoading())
// changed();
return addedPage;
}
Page* ScribusDoc::addMasterPage(const int pageNumber, const QString& pageName)
{
//CB We dont create master pages (yet) with a pageCount based location
//Page* addedPage = new Page(ScratchLeft, MasterPages.count()*(pageHeight+ScratchBottom+ScratchTop)+ScratchTop, pageWidth, pageHeight);
Page* addedPage = new Page(scratch.Left, scratch.Top, pageWidth, pageHeight);
int pgN = pageNumber;
if (pageNumber > MasterPages.count())
pgN = MasterPages.count();
assert(addedPage!=NULL);
addedPage->setDocument(this);
addedPage->Margins.Top = pageMargins.Top;
addedPage->Margins.Bottom = pageMargins.Bottom;
addedPage->Margins.Left = pageMargins.Left;//todo fix for layouts
addedPage->Margins.Right = pageMargins.Right;
addedPage->initialMargins.Top = pageMargins.Top;
addedPage->initialMargins.Bottom = pageMargins.Bottom;
addedPage->initialMargins.Left = pageMargins.Left;
addedPage->initialMargins.Right = pageMargins.Right;
addedPage->m_pageSize = m_pageSize;
addedPage->PageOri = PageOri;
addedPage->marginPreset = marginPreset;
addedPage->MPageNam = "";
addedPage->setPageName(pageName);
addedPage->setPageNr(pgN);
MasterNames.insert(pageName, pgN);
MasterPages.insert(pgN, addedPage);
assert(MasterPages.at(pgN)!=NULL);
if (!isLoading())
changed();
return addedPage;
}
bool ScribusDoc::renameMasterPage(const QString& oldPageName, const QString& newPageName)
{
Q_ASSERT(oldPageName!=CommonStrings::masterPageNormal && oldPageName!=CommonStrings::trMasterPageNormal);
if (MasterNames.contains(oldPageName) && !MasterNames.contains(newPageName))
{
//Rename our master page lists
int number=MasterNames[oldPageName];
MasterNames.insert(newPageName, number);
MasterNames.remove(oldPageName);
Q_ASSERT(MasterPages.at(number)->pageName()==oldPageName);
MasterPages.at(number)->setPageName(newPageName);
//Update any pages that were linking to our old name
Page* docPage=NULL;
for (int i=0; i < DocPages.count(); ++i )
{
docPage=DocPages[i];
if (docPage->MPageNam == oldPageName)
docPage->MPageNam = newPageName;
}
//Update any items that were linking to our old name
uint masterItemsCount=MasterItems.count();
for (uint i = 0; i < masterItemsCount; ++i)
{
if (MasterItems.at(i)->OnMasterPage == oldPageName)
MasterItems.at(i)->OnMasterPage = newPageName;
}
changed();
return true;
}
return false;
}
void ScribusDoc::deleteMasterPage(const int pageNumber)
{
assert(masterPageMode());
assert( Pages->count() > 1 && Pages->count() > pageNumber );
setCurrentPage(Pages->at(0));
Page* page = Pages->takeAt(pageNumber);
QString oldPageName(page->pageName());
delete page;
// #10658 : renumber masterpages and masterpage objects
// in order to avoid crash after masterpage deletion
for (int i = 0; i < MasterPages.count(); ++i)
MasterPages.at(i)->setPageNr(i);
for (int i = 0; i < MasterItems.count(); ++i)
{
if (MasterItems.at(i)->OwnPage > pageNumber)
MasterItems.at(i)->OwnPage--;
}
// remove the master page from the master page name list
//MasterNames.remove(page->PageNam);
/*CB TODO moved back to muster.cpp for now as this must happen after reformPages
MasterNames.clear();
for (uint a = 0; a < Pages->count(); ++a)
MasterNames[Pages->at(a)->PageNam] = Pages->at(a)->pageNr();
// and fix up any pages that refer to the deleted master page
for (Page* docPage = DocPages.first(); docPage; docPage = DocPages.next() )
{
if (docPage->MPageNam == oldPageName)
docPage->MPageNam = CommonStrings::masterPageNormal;
}
*/
//QPtrList docs: The item after the removed item becomes the new current list item if the removed item is not the last item in the list. If the last item is removed, the new last item becomes the current item.
changed();
}
void ScribusDoc::rebuildMasterNames(void)
{
MasterNames.clear();
for (int a = 0; a < MasterPages.count(); ++a)
MasterNames[MasterPages.at(a)->pageName()] = MasterPages.at(a)->pageNr();
}
void ScribusDoc::replaceMasterPage(const QString& oldMasterPage)
{
uint pageIndex = 0;
QMap<QString,int>::Iterator it = MasterNames.begin();
QListIterator<Page *> dpIt(DocPages);
Page* docPage=NULL;
while(dpIt.hasNext())
//for (Page* docPage = currentDoc->DocPages.first(); docPage; docPage = currentDoc->DocPages.next() )
{
docPage=dpIt.next();
if (docPage->MPageNam == oldMasterPage)
{
PageLocation pageLoc = locationOfPage(pageIndex);
if (pageLoc == LeftPage)
{
if (MasterNames.contains( CommonStrings::trMasterPageNormalLeft))
docPage->MPageNam = CommonStrings::trMasterPageNormalLeft;
else if (MasterNames.contains( CommonStrings::trMasterPageNormal))
docPage->MPageNam = CommonStrings::trMasterPageNormal;
else
docPage->MPageNam = it.key();
}
else if (pageLoc == RightPage)
{
if (MasterNames.contains( CommonStrings::trMasterPageNormalRight))
docPage->MPageNam = CommonStrings::trMasterPageNormalRight;
else if (MasterNames.contains( CommonStrings::trMasterPageNormal))
docPage->MPageNam = CommonStrings::trMasterPageNormal;
else
docPage->MPageNam = it.key();
}
else
{
if (MasterNames.contains( CommonStrings::trMasterPageNormalMiddle))
docPage->MPageNam = CommonStrings::trMasterPageNormalMiddle;
else if (MasterNames.contains( CommonStrings::trMasterPageNormal))
docPage->MPageNam = CommonStrings::trMasterPageNormal;
else
docPage->MPageNam = it.key();
}
}
pageIndex++;
}
}
void ScribusDoc::deletePage(const int pageNumber)
{
assert( Pages->count() > 1 && Pages->count() > pageNumber );
//#5561: If we are going to delete the first page, do not set the current page to it
setCurrentPage(Pages->at(pageNumber!=0?0:1));
Page* page = Pages->takeAt(pageNumber);
delete page;
reformPages();
changed();
}
void ScribusDoc::movePage(const int fromPage, const int toPage, const int dest, const int position)
{
QList<Page*> pageList;
int numPages = dest;
for (int i = fromPage; i < toPage; ++i)
{
pageList.append(Pages->takeAt(fromPage));
if (i <= numPages)
--numPages;
}
int pageListCount=pageList.count();
switch (position)
{
case 0: //Before Page
for (int j = 0; j < pageListCount; ++j)
Pages->insert(numPages++, pageList.at(j));
break;
case 1: //After Page
for (int j = 0; j < pageListCount; ++j)
Pages->insert(++numPages, pageList.at(j));
break;
case 2: //To End
for (int j = 0; j < pageListCount; ++j)
Pages->append(pageList.at(j));
break;
}
if (UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::MovePage, "", Um::IDocument);
ss->set("PAGE_MOVE", "page_move");
ss->set("PAGE_MOVE_FROM", fromPage);
ss->set("PAGE_MOVE_TO", toPage);
ss->set("PAGE_MOVE_DEST", dest);
ss->set("PAGE_MOVE_NEWPOS", position);
undoManager->action(this, ss, DocName, Um::IDocument);
}
reformPages();
if (m_View && m_ScMW )
{
m_View->reformPagesView();
m_ScMW->updateGUIAfterPagesChanged();
}
changed();
}
void ScribusDoc::restoreMovePage(SimpleState *state, bool isUndo)
{
int fromPage = state->getInt("PAGE_MOVE_FROM");
int toPage = state->getInt("PAGE_MOVE_TO");
int position = state->getInt("PAGE_MOVE_NEWPOS");
int dest = state->getInt("PAGE_MOVE_DEST");
if (isUndo)
{
int newPageDest = fromPage;
int newPageFrom = 0;
int newPageTo = 0;
int newPosition = 0;
int pagesMoved = toPage - fromPage;
switch (position)
{
case 0: //Before Page
newPageDest = (toPage <= dest) ? fromPage : toPage;
newPageFrom = (toPage <= dest) ? (dest - pagesMoved) : dest;
break;
case 1: //After Page
newPageDest = (toPage <= dest) ? fromPage : toPage;
newPageFrom = (toPage <= dest) ? (dest-pagesMoved + 1) : (dest + 1);
break;
case 2: //To End
newPageFrom = Pages->count() - pagesMoved;
break;
}
newPageTo = newPageFrom + pagesMoved;
movePage(newPageFrom, newPageTo, newPageDest, newPosition);
}
else
movePage(fromPage, toPage, dest, position);
}
int ScribusDoc::addAutomaticTextFrame(const int pageNumber)
{
if (!automaticTextFrames)
return -1;
Page *addToPage=DocPages.at(pageNumber);
if ((!masterPageMode()) && (usesAutomaticTextFrames()))// && (!isLoading()))
{
int z = itemAdd(PageItem::TextFrame, PageItem::Unspecified,
addToPage->Margins.Left+addToPage->xOffset(),
addToPage->Margins.Top+addToPage->yOffset(), pageWidth-addToPage->Margins.Right-addToPage->Margins.Left,
pageHeight-addToPage->Margins.Bottom-addToPage->Margins.Top,
1, CommonStrings::None, toolSettings.dPen, true);
Items->at(z)->isAutoText = true;
Items->at(z)->Cols = qRound(PageSp);
Items->at(z)->ColGap = PageSpa;
if (LastAuto != 0) {
LastAuto->link(Items->at(z));
}
else
FirstAuto = Items->at(z);
LastAuto = Items->at(z);
Items->at(z)->setRedrawBounding();
return z;
}
return -1;
}
int ScribusDoc::addLayer(const QString& layerName, const bool activate)
{
int lnr = Layers.addLayer(layerName);
if (lnr==-1)
return -1;
if (activate)
setActiveLayer(lnr);
const ScLayer* ll = Layers.layerByNumber(lnr);
if (!ll)
qWarning() << "Layer added without undo, could not get layer back for undo action creation";
else
if (UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::AddLayer, "", Um::ICreate);
ss->set("ADD_LAYER", "add_layer");
ss->set("ACTIVE", ActiveLayer);
ss->set("NAME", ll->Name);
ss->set("LAYER_NR", ll->LNr);
undoManager->action(this, ss, DocName, Um::ILayer);
}
return lnr;
}
void ScribusDoc::copyLayer(int layerNumberToCopy, int whereToInsert)
{
if(!setActiveLayer(whereToInsert))
return;
Selection sourceSelection(this);
for (int ite(0); ite < Items->count(); ++ite)
{
PageItem *itemToCopy = Items->at(ite);
if (itemToCopy->LayerNr == layerNumberToCopy)
{
sourceSelection.addItem(itemToCopy);
}
}
if (sourceSelection.count() > 0)
{
Selection targetSelection(Serializer(*this).cloneObjects(sourceSelection));
for(int si(0); si < targetSelection.count(); ++si)
{
targetSelection.itemAt(si)->setLayer(whereToInsert);
}
}
}
bool ScribusDoc::deleteLayer(const int layerNumber, const bool deleteItems)
{
if (Layers.count() < 2)
return false;
const ScLayer* lToRemove = Layers.layerByNumber(layerNumber);
if (!lToRemove)
return false;
int layerLevel = lToRemove->Level;
QString name = lToRemove->Name;
UndoTransaction* activeTransaction = NULL;
if (UndoManager::undoEnabled())
activeTransaction = new UndoTransaction(undoManager->beginTransaction("Layer", Um::IDocument, Um::DeleteLayer, "", Um::IDelete));
rebuildItemLists();
if (ScCore->usingGUI())
removeLayer(layerNumber, deleteItems);
/*
//Layer found, do we want to delete its items too?
if (masterPageMode)
MasterPages = Pages;
else
DocPages = Pages;
for (uint b = 0; b < MasterItems.count(); ++b)
{
if (MasterItems.at(b)->LayerNr == layerNumber)
{
if (deleteItems)
{
MasterItems.at(b)->setTagged(true);
MasterItems.at(b)->setLocked(false);
}
else
MasterItems.at(b)->setTagged(false);
}
}
// if (view->SelItem.count() != 0)
// view->DeleteItem();
// view->SelItem.clear();
for (uint b = 0; b < DocItems.count(); ++b)
{
if (DocItems.at(b)->LayerNr == l)
{
if (deleteItems)
{
DocItems.at(b)->setTagged(true);
DocItems.at(b)->setLocked(false);
}
else
DocItems.at(b)->setLayer(0);
}
}
// if (view->SelItem.count() != 0)
// view->DeleteItem();
bool deletedOk=deleteTaggedItems();
Q_ASSERT(deletedOk);
*/
//Now delete the layer
Layers.removeLayerByNumber(layerNumber);
if (activeTransaction)
{
SimpleState *ss = new SimpleState(Um::DeleteLayer, "", Um::IDelete);
ss->set("REMOVE_LAYER", "remove_layer");
ss->set("ACTIVE", layerNumber);
ss->set("LEVEL", layerLevel);
ss->set("NAME", name);
ss->set("LAYER_NR", layerNumber);
ss->set("DELETE", deleteItems);
undoManager->action(this, ss, DocName, Um::ILayer);
activeTransaction->commit();
delete activeTransaction;
activeTransaction = NULL;
}
// setActiveLayer(layerNumberFromLevel(0));
return true;
}
int ScribusDoc::activeLayer()
{
return ActiveLayer;
}
const QString& ScribusDoc::activeLayerName()
{
const ScLayer* ll = Layers.layerByNumber(ActiveLayer);
Q_ASSERT(ll);
return ll->Name;
}
bool ScribusDoc::setActiveLayer(const int layerToActivate)
{
const ScLayer* ll = Layers.layerByNumber(layerToActivate);
Q_ASSERT(ll);
if (ll)
ActiveLayer=layerToActivate;
return (ll != NULL);
}
bool ScribusDoc::setActiveLayer(const QString& layerNameToActivate)
{
const ScLayer* ll = Layers.layerByName(layerNameToActivate);
Q_ASSERT(ll);
if (ll)
ActiveLayer=ll->LNr;
return (ll != NULL);
}
bool ScribusDoc::setLayerPrintable(const int layerNumber, const bool isPrintable)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
if (it->isPrintable!=isPrintable && UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(isPrintable ? Um::PrintLayer : Um::DoNotPrintLayer, "", Um::IPrint);
ss->set("PRINT_LAYER", "print_layer");
ss->set("ACTIVE", it->LNr);
ss->set("PRINT", isPrintable);
undoManager->action(this, ss, it->Name, Um::ILayer);
}
it->isPrintable = isPrintable;
found=true;
break;
}
}
if (found)
changed();
return found;
}
bool ScribusDoc::layerPrintable(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return it->isPrintable;
}
return false;
}
bool ScribusDoc::setLayerVisible(const int layerNumber, const bool isViewable)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
it->isViewable = isViewable;
found=true;
break;
}
}
if (found)
changed();
return found;
}
bool ScribusDoc::layerVisible(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return it->isViewable;
}
return false;
}
bool ScribusDoc::setLayerLocked(const int layerNumber, const bool isLocked)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
// == because isEditable vs isLocked...
if (it->isEditable==isLocked && UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(isLocked ? Um::SetLayerLocked : Um::SetLayerUnlocked, "", Um::ILayer);
ss->set("LAYER_LOCK", "layer_lock");
ss->set("ACTIVE", it->LNr);
ss->set("LOCK", isLocked);
undoManager->action(this, ss, it->Name, Um::ILayer);
}
it->isEditable = !isLocked;
found=true;
break;
}
}
if (found)
changed();
return found;
}
bool ScribusDoc::layerLocked(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return !it->isEditable;
}
return false;
}
bool ScribusDoc::setLayerFlow(const int layerNumber, const bool flow)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
if (it->flowControl!=flow && UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(flow ? Um::FlowLayer : Um::DisableFlowLayer, "", Um::ITextFrame);
ss->set("LAYER_FLOW", "layer_flow");
ss->set("ACTIVE", it->LNr);
ss->set("FLOW", flow);
undoManager->action(this, ss, it->Name, Um::ILayer);
}
it->flowControl = flow;
found=true;
break;
}
}
if (found)
{
// #9188 : invalidate layout of items below layer
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
break;
invalidateLayer(it->LNr);
}
changed();
}
return found;
}
bool ScribusDoc::layerFlow(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return it->flowControl;
}
return false;
}
bool ScribusDoc::setLayerTransparency(const int layerNumber, double trans)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
if (it->transparency!=trans && UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::SetLayerTransparency, "", Um::ILayer);
ss->set("LAYER_TRANSPARENCY", "layer_transparency");
ss->set("ACTIVE", it->LNr);
ss->set("OLD_TRANS", it->transparency);
ss->set("NEW_TRANS", trans);
undoManager->action(this, ss, it->Name, Um::ILayer);
}
it->transparency = trans;
found=true;
break;
}
}
if (found)
changed();
return found;
}
double ScribusDoc::layerTransparency(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return it->transparency;
}
return 1.0;
}
bool ScribusDoc::setLayerBlendMode(const int layerNumber, int blend)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
if (it->blendMode!=blend && UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::SetLayerBlendMode, "", Um::ILayer);
ss->set("LAYER_BLENDMODE", "layer_blendmode");
ss->set("ACTIVE", it->LNr);
ss->set("OLD_BLENDMODE", it->blendMode);
ss->set("NEW_BLENDMODE", blend);
undoManager->action(this, ss, it->Name, Um::ILayer);
}
it->blendMode = blend;
found=true;
break;
}
}
if (found)
changed();
return found;
}
int ScribusDoc::layerBlendMode(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return it->blendMode;
}
return 0;
}
bool ScribusDoc::setLayerOutline(const int layerNumber, const bool outline)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
it->outlineMode = outline;
found=true;
break;
}
}
if (found)
changed();
return found;
}
bool ScribusDoc::layerOutline(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return it->outlineMode;
}
return false;
}
bool ScribusDoc::setLayerMarker(const int layerNumber, QColor color)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
bool found=false;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
{
it->markerColor = color;
found=true;
break;
}
}
if (found)
changed();
return found;
}
QColor ScribusDoc::layerMarker(const int layerNumber)
{
ScLayers::iterator itend=Layers.end();
ScLayers::iterator it;
for (it = Layers.begin(); it != itend; ++it)
{
if (it->LNr == layerNumber)
return it->markerColor;
}
return QColor(0, 0, 0);
}
int ScribusDoc::layerLevelFromNumber(const int layerNumber)
{
uint layerCount=Layers.count();
for (uint i=0; i < layerCount; ++i)
{
if (Layers[i].LNr == layerNumber)
return Layers[i].Level;
}
return -1;
}
int ScribusDoc::layerCount() const
{
return Layers.count();
}
int ScribusDoc::layerNumberFromLevel(const int layerLevel)
{
uint layerCount=Layers.count();
for (uint i=0; i < layerCount; ++i)
{
if (Layers[i].Level == layerLevel)
return Layers[i].LNr;
}
return -1;
}
bool ScribusDoc::lowerLayer(const int layerNumber)
{
return lowerLayerByLevel(layerLevelFromNumber(layerNumber));
}
bool ScribusDoc::lowerLayerByLevel(const int layerLevel)
{
if (Layers.count() < 2)
return false;
if (UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::LowerLayer, "", Um::IDown);
ss->set("DOWN_LAYER", "down_layer");
ss->set("ACTIVE", layerLevel-1);
undoManager->action(this, ss, DocName, Um::ILayer);
}
ScLayers::iterator it;
ScLayers::iterator itend=Layers.end();
for (it = Layers.begin(); it != itend; ++it)
{
if (it->Level == layerLevel-1)
break;
}
ScLayers::iterator it2;
ScLayers::iterator it2end=Layers.end();
for (it2 = Layers.begin(); it2 != it2end; ++it2)
{
if (it2->Level == layerLevel)
break;
}
it2->Level -= 1;
it->Level += 1;
// #9188 : invalidate layout of items in below layers
int maxLevel = qMax(it->Level, it2->Level);
for (it = Layers.begin(); it != itend; ++it)
{
if (it->flowControl)
invalidateLayer(it->LNr);
if (it->Level == maxLevel)
break;
}
return true;
}
bool ScribusDoc::raiseLayer(const int layerNumber)
{
return raiseLayerByLevel(layerLevelFromNumber(layerNumber));
}
bool ScribusDoc::raiseLayerByLevel(const int layerLevel)
{
if (Layers.count() < 2)
return false;
if (UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::RaiseLayer, "", Um::IUp);
ss->set("UP_LAYER", "up_layer");
ss->set("ACTIVE", layerLevel+1);
undoManager->action(this, ss, DocName, Um::ILayer);
}
ScLayers::iterator it;
ScLayers::iterator itend=Layers.end();
for (it = Layers.begin(); it != itend; ++it)
{
if (it->Level == layerLevel+1)
break;
}
ScLayers::iterator it2;
ScLayers::iterator it2end=Layers.end();
for (it2 = Layers.begin(); it2 != it2end; ++it2)
{
if (it2->Level == layerLevel)
break;
}
it2->Level += 1;
it->Level -= 1;
// #9188 : invalidate layout of items in below layers
int maxLevel = qMax(it->Level, it2->Level);
for (it = Layers.begin(); it != itend; ++it)
{
if (it->flowControl)
invalidateLayer(it->LNr);
if (it->Level == maxLevel)
break;
}
return true;
}
QString ScribusDoc::layerName(const int layerNumber) const
{
uint layerCount=Layers.count();
for (uint i=0; i < layerCount; ++i)
{
if (Layers[i].LNr == layerNumber)
return Layers[i].Name;
}
return QString::null;
}
bool ScribusDoc::changeLayerName(const int layerNumber, const QString& newName)
{
uint layerCount=Layers.count();
bool found=false;
for (uint i=0; i < layerCount; ++i)
{
if (Layers[i].LNr == layerNumber)
{
if (Layers[i].Name != newName)
{
if (UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::SetLayerName,
QString(Um::FromTo).arg(Layers[i].Name).arg(newName),
Um::IDown);
ss->set("CHANGE_NAME", "change_name");
ss->set("ACTIVE", ActiveLayer);
ss->set("NEW_NAME", newName);
ss->set("OLD_NAME", Layers[i].Name);
undoManager->action(this, ss, DocName, Um::ILayer);
}
Layers[i].Name = newName;
found=true;
}
break;
}
}
if (found)
changed();
return found;
}
bool ScribusDoc::layerContainsItems(const int layerNumber)
{
uint masterItemsCount=MasterItems.count();
for (uint i = 0; i < masterItemsCount; ++i)
{
if (MasterItems.at(i)->LayerNr == layerNumber)
return true;
}
uint docItemsCount=DocItems.count();
for (uint i = 0; i < docItemsCount; ++i)
{
if (DocItems.at(i)->LayerNr == layerNumber)
return true;
}
return false;
}
void ScribusDoc::orderedLayerList(QStringList* list)
{
Q_ASSERT(list!=NULL);
uint layerCount=Layers.count();
if (layerCount != 0)
{
for (uint i=0; i < layerCount; ++i)
{
ScLayers::iterator itend=Layers.end();
for (ScLayers::iterator it = Layers.begin(); it != itend; ++it)
{
if (layerCount-(*it).Level-1 == i)
list->append((*it).Name);
}
}
}
}
bool ScribusDoc::renumberLayer(const int layerNumber, const int newLayerNumber)
{
uint layerCount=Layers.count();
uint foundIndex = 0;
bool found=false;
//Find layer to renumber, if found the new number, return as it exists already.
for (uint i=0; i < layerCount; ++i)
{
if (Layers[i].LNr == layerNumber)
{
foundIndex=i;
found=true;
}
else
if (Layers[i].LNr == newLayerNumber)
return false;
}
if (!found)
return false;
Layers[foundIndex].LNr=newLayerNumber;
return true;
}
//Make the doc delete the items, not the view. TODO: Currently does nada, zilch, zero
bool ScribusDoc::deleteTaggedItems()
{
QString tooltip = Um::ItemsInvolved + "\n";
//Master Items
for (int b = 0; b < MasterItems.count(); ++b)
{
if (MasterItems.at(b)->isTagged())
{
}
}
//Doc Items
for (int b = 0; b < DocItems.count(); ++b)
{
if (DocItems.at(b)->isTagged())
{
}
}
return true;
}
void ScribusDoc::replaceLineStyleColors(const QMap<QString, QString>& colorMap)
{
multiLine::iterator its;
QMap<QString, QString>::const_iterator it;
QMap<QString,multiLine>::iterator itl;
for (itl = MLineStyles.begin(); itl != MLineStyles.end(); ++itl)
{
multiLine& mline = itl.value();
for (its = mline.begin(); its != mline.end(); ++its)
{
struct SingleLine& sline = *its;
it = colorMap.find(sline.Color);
if (it != colorMap.end())
sline.Color = it.value();
}
}
}
void ScribusDoc::getUsedColors(ColorList &colorsToUse, bool spot)
{
bool found;
colorsToUse.clear();
colorsToUse.setDocument(this);
ColorList::Iterator it;
ResourceCollection resources;
this->getNamedResources(resources);
const QMap<QString, QString>& resColors = resources.colors();
for (it = PageColors.begin(); it != PageColors.end(); ++it)
{
found = false;
// Tool preferences colors
if ((it.key() == toolSettings.dBrush) || (it.key() == toolSettings.dPen) || (it.key() == toolSettings.dBrushPict)
|| (it.key() == toolSettings.dPenLine) || (it.key() == toolSettings.dPenText))
{
if (spot)
{
if (it.value().isSpotColor())
colorsToUse.insert(it.key(), it.value());
}
else
colorsToUse.insert(it.key(), it.value());
continue;
}
// Current paragraph style colors
if ((it.key() == currentStyle.charStyle().fillColor()) || (it.key() == currentStyle.charStyle().strokeColor()))
found = true;
// Resources colors
if (!found)
found = resColors.contains(it.key());
// Line styles colors
if (!found)
found = lineStylesUseColor(it.key());
if (found)
{
if (spot)
{
if (it.value().isSpotColor())
colorsToUse.insert(it.key(), it.value());
}
else
colorsToUse.insert(it.key(), it.value());
continue;
}
}
}
bool ScribusDoc::lineStylesUseColor(const QString& colorName)
{
bool found = false;
QMap<QString,multiLine>::const_iterator itm, itmend;
multiLine::const_iterator its, itsend;
itmend = MLineStyles.constEnd();
for (itm = MLineStyles.constBegin(); itm != itmend && !found; ++itm)
{
const multiLine& ml = itm.value();
itsend = ml.constEnd();
for (its = ml.constBegin(); its != itsend; ++its)
{
if ( its->Color == colorName )
{
found = true;
break;
}
}
}
return found;
}
bool ScribusDoc::addPattern(QString &name, ScPattern& pattern)
{
if (docPatterns.contains(name))
name = tr("Copy_of_")+name;
docPatterns.insert(name, pattern);
return true;
}
void ScribusDoc::setPatterns(QMap<QString, ScPattern> &patterns)
{
docPatterns.clear();
docPatterns = patterns;
// for (QMap<QString, ScPattern>::Iterator it = patterns.begin(); it != patterns.end(); ++it)
// {
// docPatterns.insert(it.key(), it.data());
// }
/* for (int c=0; c<DocItems.count(); ++c)
{
PageItem *ite = DocItems.at(c);
if ((!docPatterns.contains(ite->pattern())) && (ite->GrType == 8))
{
ite->setPattern("");
ite->GrType = 0;
}
}
for (int c=0; c<MasterItems.count(); ++c)
{
PageItem *ite = MasterItems.at(c);
if ((!docPatterns.contains(ite->pattern())) && (ite->GrType == 8))
{
ite->setPattern("");
ite->GrType = 0;
}
}
for (int c=0; c<FrameItems.count(); ++c)
{
PageItem *ite = FrameItems.at(c);
if ((!docPatterns.contains(ite->pattern())) && (ite->GrType == 8))
{
ite->setPattern("");
ite->GrType = 0;
}
} */
}
QStringList ScribusDoc::getUsedPatterns()
{
QStringList results;
for (int c = 0; c < MasterItems.count(); ++c)
{
if ((!results.contains(MasterItems.at(c)->pattern())) && (MasterItems.at(c)->GrType == 8))
results.append(MasterItems.at(c)->pattern());
}
for (int c = 0; c < DocItems.count(); ++c)
{
if ((!results.contains(DocItems.at(c)->pattern())) && (DocItems.at(c)->GrType == 8))
results.append(DocItems.at(c)->pattern());
}
for (int c = 0; c < FrameItems.count(); ++c)
{
if ((!results.contains(FrameItems.at(c)->pattern())) && (FrameItems.at(c)->GrType == 8))
results.append(FrameItems.at(c)->pattern());
}
for (int c = 0; c < results.count(); ++c)
{
QStringList pats = getUsedPatternsHelper(results[c], results);
if (!pats.isEmpty())
results += pats;
}
return results;
}
QStringList ScribusDoc::getUsedPatternsSelection(Selection* customSelection)
{
QStringList results;
uint selectedItemCount = customSelection->count();
if (selectedItemCount != 0)
{
for (uint a = 0; a < selectedItemCount; ++a)
{
PageItem *currItem = customSelection->itemAt(a);
if (currItem->GrType == 8)
{
const QString& pat = currItem->pattern();
if (!pat.isEmpty() && !results.contains(pat))
results.append(currItem->pattern());
}
}
for (int c = 0; c < results.count(); ++c)
{
QStringList pats = getUsedPatternsHelper(results[c], results);
if (!pats.isEmpty())
results += pats;
}
return results;
}
else
return QStringList();
}
QStringList ScribusDoc::getUsedPatternsHelper(QString pattern, QStringList &results)
{
ScPattern *pat = &docPatterns[pattern];
QStringList pats;
pats.clear();
for (int c = 0; c < pat->items.count(); ++c)
{
if (pat->items.at(c)->GrType == 8)
{
const QString& patName = pat->items.at(c)->pattern();
if (!patName.isEmpty() && !results.contains(patName))
pats.append(patName);
}
}
if (!pats.isEmpty())
{
for (int c = 0; c < pats.count(); ++c)
{
getUsedPatternsHelper(pats[c], results);
}
}
return pats;
}
QMap<QString,int> ScribusDoc::reorganiseFonts()
{
// QTime t;
// t.start();
QMap<QString,int> Really;
//QMap<QString,QFont> DocF;
//DocF = UsedFonts;
uint counter = 0;
for (uint lc = 0; lc < 3; ++lc)
{
switch (lc)
{
case 0:
counter = MasterItems.count();
break;
case 1:
counter = DocItems.count();
break;
case 2:
counter = FrameItems.count();
break;
}
PageItem* it = NULL;
for (uint d = 0; d < counter; ++d)
{
switch (lc)
{
case 0:
it = MasterItems.at(d);
break;
case 1:
it = DocItems.at(d);
break;
case 2:
it = FrameItems.at(d);
break;
}
if ((it->itemType() == PageItem::TextFrame) || (it->itemType() == PageItem::PathText))
{
QString fontName(it->itemText.defaultStyle().charStyle().font().replacementName());
Really.insert(fontName, UsedFonts[fontName]);
int start = it->firstInFrame();
int stop = it->lastInFrame();
for (int e = start; e <= stop; ++e)
{
QString rep = it->itemText.charStyle(e).font().replacementName();
if (Really.contains(rep))
continue;
Really.insert(rep, UsedFonts[rep]);
}
}
}
}
QMap<QString,int>::Iterator itfo, itnext;
for (itfo = UsedFonts.begin(); itfo != UsedFonts.end(); itfo = itnext)
{
itnext = itfo;
++itnext;
if (!Really.contains(itfo.key()))
{
(*AllFonts)[itfo.key()].decreaseUsage();
UsedFonts.erase(itfo);
}
}
PrefsManager* prefsManager=PrefsManager::instance();
AddFont(prefsManager->appPrefs.toolSettings.defFont);//, prefsManager->appPrefs.AvailFonts[prefsManager->appPrefs.toolSettings.defFont]->Font);
AddFont(toolSettings.defFont);//, prefsManager->appPrefs.AvailFonts[toolSettings.defFont]->Font);
// qDebug( "Time elapsed: %d ms", t.elapsed() );
return Really;
}
void ScribusDoc::getUsedFonts(QMap<QString, QMap<uint, FPointArray> > & Really)
{
PageItem* it = NULL;
uint counter = 0;
for (uint lc = 0; lc < 3; ++lc)
{
switch (lc)
{
case 0:
counter = MasterItems.count();
break;
case 1:
counter = DocItems.count();
break;
case 2:
counter = FrameItems.count();
break;
}
for (uint d = 0; d < counter; ++d)
{
switch (lc)
{
case 0:
it = MasterItems.at(d);
break;
case 1:
it = DocItems.at(d);
break;
case 2:
it = FrameItems.at(d);
break;
}
checkItemForFonts(it, Really, lc);
}
}
QStringList patterns = getUsedPatterns();
for (int c = 0; c < patterns.count(); ++c)
{
ScPattern pa = docPatterns[patterns[c]];
for (int o = 0; o < pa.items.count(); o++)
{
checkItemForFonts(pa.items.at(o), Really, 3);
}
}
}
void ScribusDoc::checkItemForFonts(PageItem *it, QMap<QString, QMap<uint, FPointArray> > & Really, uint lc)
{
FPointArray gly;
QChar chstr;
if (!it->isTextFrame() && !it->isPathText())
return;
/* May be needed for fixing #10371 completely
if (it->isAnnotation())
{
int annotType = it->annotation().Type();
bool mustEmbed = ((annotType >= 2) && (annotType <= 6) && (annotType != 4));
if (mustEmbed && (!Really.contains(it->itemText.defaultStyle().charStyle().font().replacementName())))
{
Really.insert(it->itemText.defaultStyle().charStyle().font().replacementName(), QMap<uint, FPointArray>());
}
}*/
int start = it->isTextFrame() ? it->firstInFrame() : 0;
int stop = it->isTextFrame() ? it->lastInFrame() + 1 : it->itemText.length();
for (int e = start; e < stop; ++e)
{
if (! Really.contains(it->itemText.charStyle(e).font().replacementName()) )
{
if (!it->itemText.charStyle(e).font().replacementName().isEmpty())
Really.insert(it->itemText.charStyle(e).font().replacementName(), QMap<uint, FPointArray>());
}
uint chr = it->itemText.text(e).unicode();
if ((chr == 13) || (chr == 32) || ((chr >= 26) && (chr <= 29)))
continue;
if (chr == 9)
{
for (int t1 = 0; t1 < it->itemText.paragraphStyle(e).tabValues().count(); t1++)
{
if (it->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar.isNull())
continue;
chstr = it->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar;
if ((it->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (it->itemText.charStyle(e).effects() & ScStyle_AllCaps))
{
if (chstr.toUpper() != chstr)
chstr = chstr.toUpper();
}
chr = chstr.unicode();
uint gl = it->itemText.charStyle(e).font().char2CMap(chstr);
gly = it->itemText.charStyle(e).font().glyphOutline(gl);
if (!it->itemText.charStyle(e).font().replacementName().isEmpty())
Really[it->itemText.charStyle(e).font().replacementName()].insert(gl, gly);
}
for (int t1 = 0; t1 < it->itemText.defaultStyle().tabValues().count(); t1++)
{
if (it->itemText.defaultStyle().tabValues()[t1].tabFillChar.isNull())
continue;
chstr = it->itemText.defaultStyle().tabValues()[t1].tabFillChar;
if ((it->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (it->itemText.charStyle(e).effects() & ScStyle_AllCaps))
{
if (chstr.toUpper() != chstr)
chstr = chstr.toUpper();
}
chr = chstr.unicode();
uint gl = it->itemText.charStyle(e).font().char2CMap(chstr);
gly = it->itemText.charStyle(e).font().glyphOutline(gl);
if (!it->itemText.charStyle(e).font().replacementName().isEmpty())
Really[it->itemText.charStyle(e).font().replacementName()].insert(gl, gly);
}
continue;
}
if ((chr == 30) || (chr == 23))
{
//Our page number collection string
QString pageNumberText(QString::null);
if (chr == 30)
{
if (e > 0 && it->itemText.text(e-1) == SpecialChars::PAGENUMBER)
pageNumberText=SpecialChars::ZWNBSPACE;
else if (lc!=0) //If not on a master page just get the page number for the page and the text
pageNumberText=getSectionPageNumberForPageIndex(it->OwnPage);
else
{
//Else, for a page number in a text frame on a master page we must scan
//all pages to see which ones use this page and get their page numbers.
//We only add each character of the pages' page number text if its nothing
//already in the pageNumberText variable. No need to add glyphs twice.
QString newText;
uint docPageCount=DocPages.count();
for (uint a = 0; a < docPageCount; ++a)
{
if (DocPages.at(a)->MPageNam == it->OnMasterPage)
{
newText=getSectionPageNumberForPageIndex(a);
for (int nti=0;nti<newText.length();++nti)
if (pageNumberText.indexOf(newText[nti])==-1)
pageNumberText+=newText[nti];
}
}
}
}
else
{
if (lc!=0)
{
QString out("%1");
int key = getSectionKeyForPageIndex(it->OwnPage);
if (key == -1)
pageNumberText = "";
else
pageNumberText = out.arg(getStringFromSequence(sections[key].type, sections[key].toindex - sections[key].fromindex + 1));
}
else
{
QString newText;
uint docPageCount=DocPages.count();
for (uint a = 0; a < docPageCount; ++a)
{
if (DocPages.at(a)->MPageNam == it->OnMasterPage)
{
QString out("%1");
int key = getSectionKeyForPageIndex(a);
if (key == -1)
newText = "";
else
newText = out.arg(getStringFromSequence(sections[key].type, sections[key].toindex - sections[key].fromindex + 1));
for (int nti=0;nti<newText.length();++nti)
if (pageNumberText.indexOf(newText[nti])==-1)
pageNumberText+=newText[nti];
}
}
}
}
//Now scan and add any glyphs used in page numbers
for (int pnti=0;pnti<pageNumberText.length(); ++pnti)
{
uint chr = pageNumberText[pnti].unicode();
if (it->itemText.charStyle(e).font().canRender(chr))
{
uint gl = it->itemText.charStyle(e).font().char2CMap(pageNumberText[pnti]);
FPointArray gly(it->itemText.charStyle(e).font().glyphOutline(gl));
if (!it->itemText.charStyle(e).font().replacementName().isEmpty())
Really[it->itemText.charStyle(e).font().replacementName()].insert(gl, gly);
}
}
continue;
}
if (it->itemText.charStyle(e).effects() & ScStyle_SmartHyphenVisible)
{
uint gl = it->itemText.charStyle(e).font().char2CMap(QChar('-'));
FPointArray gly(it->itemText.charStyle(e).font().glyphOutline(gl));
if (!it->itemText.charStyle(e).font().replacementName().isEmpty())
Really[it->itemText.charStyle(e).font().replacementName()].insert(gl, gly);
}
if ((it->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (it->itemText.charStyle(e).effects() & ScStyle_AllCaps))
{
chstr = it->itemText.text(e);
if (chstr.toUpper() != chstr)
chstr = chstr.toUpper();
chr = chstr.unicode();
}
if (it->itemText.charStyle(e).font().canRender(chr))
{
uint gl = it->itemText.charStyle(e).font().char2CMap(chr);
gly = it->itemText.charStyle(e).font().glyphOutline(gl);
if (!it->itemText.charStyle(e).font().replacementName().isEmpty())
Really[it->itemText.charStyle(e).font().replacementName()].insert(gl, gly);
}
}
}
void ScribusDoc::getUsedProfiles(ProfilesL& usedProfiles)
{
PageItem* it = NULL;
QString profileName;
QStringList profileNames;
uint counter = 0;
usedProfiles.clear();
profileNames.append(CMSSettings.DefaultSolidColorRGBProfile);
profileNames.append(CMSSettings.DefaultSolidColorCMYKProfile);
if( profileNames.indexOf(CMSSettings.DefaultImageRGBProfile) < 0 )
profileNames.append(CMSSettings.DefaultImageRGBProfile);
if( profileNames.indexOf(CMSSettings.DefaultImageCMYKProfile) < 0 )
profileNames.append(CMSSettings.DefaultImageCMYKProfile);
if( profileNames.indexOf(CMSSettings.DefaultMonitorProfile) < 0 )
profileNames.append(CMSSettings.DefaultMonitorProfile);
if( profileNames.indexOf(CMSSettings.DefaultPrinterProfile) < 0 )
profileNames.append(CMSSettings.DefaultPrinterProfile);
for (uint lc = 0; lc < 3; ++lc)
{
if (lc == 0)
counter = MasterItems.count();
else if(lc == 1)
counter = DocItems.count();
else if(lc == 2)
counter = FrameItems.count();
for (uint d = 0; d < counter; ++d)
{
if (lc == 0)
it = MasterItems.at(d);
else if(lc == 1)
it = DocItems.at(d);
else if(lc == 2)
it = FrameItems.at(d);
if (it->IProfile.isEmpty() || profileNames.contains(it->IProfile))
continue;
profileNames.append(it->IProfile);
}
}
for( QStringList::Iterator pIter = profileNames.begin(); pIter != profileNames.end(); pIter++ )
{
if (ScCore->InputProfiles.contains(*pIter))
usedProfiles[*pIter] = ScCore->InputProfiles[*pIter];
else if (ScCore->InputProfilesCMYK.contains(*pIter))
usedProfiles[*pIter] = ScCore->InputProfilesCMYK[*pIter];
else if (ScCore->PrinterProfiles.contains(*pIter))
usedProfiles[*pIter] = ScCore->PrinterProfiles[*pIter];
}
}
void ScribusDoc::setUnitIndex(const int newIndex)
{
docUnitIndex=newIndex;
docUnitRatio = unitGetRatioFromIndex( docUnitIndex );
}
int ScribusDoc::unitIndex() const
{
return docUnitIndex;
}
double ScribusDoc::unitRatio() const
{
return docUnitRatio;
}
bool ScribusDoc::applyMasterPage(const QString& pageName, const int pageNumber)
{
if (!MasterNames.contains(pageName))
return false;
if (UndoManager::undoEnabled())
{
if (DocPages.at(pageNumber)->MPageNam != pageName)
{
SimpleState *ss = new SimpleState(Um::ApplyMasterPage, QString(Um::FromTo).arg(DocPages.at(pageNumber)->MPageNam).arg(pageName));
ss->set("PAGE_NUMBER", pageNumber);
ss->set("OLD_MASTERPAGE", DocPages.at(pageNumber)->MPageNam);
ss->set("NEW_MASTERPAGE", pageName);
undoManager->action(this, ss);
}
}
// QString mna = pageName;
// if (mna == CommonStrings::trMasterPageNormal)
// mna = CommonStrings::masterPageNormal;
// if (!MasterNames.contains(mna))
// mna = CommonStrings::masterPageNormal;
Page* Ap = DocPages.at(pageNumber);
Ap->MPageNam = pageName;
const int MpNr = MasterNames[pageName];
Page* Mp = MasterPages.at(MpNr);
PageItem *currItem;
// for (currItem = Ap->FromMaster.first(); currItem; currItem = Ap->FromMaster.next())
// {
// if (currItem->ChangedMasterItem)
// {
// Ap->FromMaster.remove(currItem);
// delete currItem;
// }
// }
Ap->FromMaster.clear();
for (int itn = 0; itn < MasterItems.count(); ++itn)
{
currItem = MasterItems.at(itn);
if (currItem->OwnPage == MpNr)
Ap->FromMaster.append(currItem);
}
if (!isLoading())
{
// PV - apply auto guides from MP only if there are no auto guides
// on original page
if (Ap->guides.horizontalAutoCount() != 0 || Ap->guides.verticalAutoCount() != 0)
Mp->guides.copy(&Ap->guides, GuideManagerCore::Standard);
else
Mp->guides.copy(&Ap->guides);
Ap->initialMargins.Top = Mp->Margins.Top;
Ap->initialMargins.Bottom = Mp->Margins.Bottom;
if (pageSets[currentPageLayout].Columns != 1)
{
PageLocation pageLoc=locationOfPage(pageNumber);
if (pageLoc==LeftPage) //Left hand page
{
if (Mp->LeftPg != 0)
{
Ap->initialMargins.Right = Mp->initialMargins.Right;
Ap->initialMargins.Left = Mp->initialMargins.Left;
}
else
{
Ap->initialMargins.Left = Mp->initialMargins.Right;
Ap->initialMargins.Right = Mp->initialMargins.Left;
}
}
else if (pageLoc==RightPage) // Right hand page
{
if (Mp->LeftPg != 0)
{
Ap->initialMargins.Left = Mp->initialMargins.Right;
Ap->initialMargins.Right = Mp->initialMargins.Left;
}
else
{
Ap->initialMargins.Right = Mp->initialMargins.Right;
Ap->initialMargins.Left = Mp->initialMargins.Left;
}
}
else //Middle pages
{
Ap->initialMargins.Left = Mp->initialMargins.Left;
Ap->initialMargins.Right = Mp->initialMargins.Right;
}
}
else
{
Ap->initialMargins.Left = Mp->Margins.Left;
Ap->initialMargins.Right = Mp->Margins.Right;
}
}
//TODO make a return false if not possible to apply the master page
if (!isLoading())
changed();
return true;
}
void ScribusDoc::restoreMasterPageApplying(SimpleState *state, bool isUndo)
{
int pageNumber = state->getInt("PAGE_NUMBER");
QString oldName = state->get("OLD_MASTERPAGE");
QString newName = state->get("NEW_MASTERPAGE");
if (isUndo)
applyMasterPage(oldName, pageNumber);
else
applyMasterPage(newName, pageNumber);
}
void ScribusDoc::restoreCopyPage(SimpleState *state, bool isUndo)
{
int pnum = state->getInt("PAGE_NUM");
int extPage = state->getInt("EXISTING_PAGE");
int whereTo = state->getInt("WHERE_TO");
int copyCount = state->getInt("COPY_COUNT");
if (isUndo)
{
int destLocation=extPage + 1;
if (whereTo==0)
--destLocation;
else if (whereTo==2)
destLocation=DocPages.count();
for (int i = 0; i < copyCount; ++i)
{
m_ScMW->deletePage(destLocation, destLocation);
if (whereTo == 2)
--destLocation;
}
}
else
copyPage(pnum, extPage, whereTo, copyCount);
}
//TODO: Handle saving to versions of SLA, and other formats
bool ScribusDoc::save(const QString& fileName, QString* savedFile)
{
QProgressBar* mainWindowProgressBar=NULL;
if (ScCore->usingGUI())
{
mainWindowProgressBar=m_ScMW->mainWindowProgressBar;
mainWindowProgressBar->reset();
}
FileLoader fl(fileName);
bool ret = fl.saveFile(fileName, this, savedFile);
if (ret)
{
setName(fileName);
setModified(false);
hasName = true;
}
return ret;
}
bool ScribusDoc::changePageMargins(const double initialTop, const double initialBottom, const double initialLeft, const double initialRight, const double initialHeight, const double initialWidth, const double height, const double width, const int orientation, const QString& pageSize, const int marginPreset, const bool moveObjects, const int pageNumber, const int pageType)
{
bool retVal=true;
if (pageNumber==-1)
{
//find page and set values
return false;
}
else
{
if (currentPage()==NULL)
retVal=false;
else
{
QRectF pagebox(currentPage()->xOffset(), currentPage()->yOffset(), qMax( currentPage()->width(), width), qMax(currentPage()->height(), height));
if (UndoManager::undoEnabled())
{
SimpleState *ss = new SimpleState(Um::ChangePageProps);//, QString("%1").arg(pageNumber), Um::IPage);
ss->set("PAGE_CHANGEPROPS", "page_changeprops");
ss->set("PAGE_NUM", pageNumber);
ss->set("OLD_PAGE_INITIALTOP", currentPage()->initialMargins.Top);
ss->set("OLD_PAGE_INITIALBOTTOM", currentPage()->initialMargins.Bottom);
ss->set("OLD_PAGE_INITIALLEFT", currentPage()->initialMargins.Left);
ss->set("OLD_PAGE_INITIALRIGHT", currentPage()->initialMargins.Right);
ss->set("OLD_PAGE_INITIALHEIGHT", currentPage()->initialHeight());
ss->set("OLD_PAGE_INITIALWIDTH", currentPage()->initialWidth());
ss->set("OLD_PAGE_HEIGHT", currentPage()->height());
ss->set("OLD_PAGE_WIDTH", currentPage()->width());
ss->set("OLD_PAGE_ORIENTATION", currentPage()->PageOri);
ss->set("OLD_PAGE_SIZE", currentPage()->m_pageSize);
ss->set("OLD_PAGE_TYPE", currentPage()->LeftPg);
ss->set("OLD_PAGE_MARGINPRESET", currentPage()->marginPreset);
ss->set("OLD_PAGE_MOVEOBJECTS", moveObjects);
ss->set("NEW_PAGE_INITIALTOP", initialTop);
ss->set("NEW_PAGE_INITIALBOTTOM", initialBottom);
ss->set("NEW_PAGE_INITIALLEFT", initialLeft);
ss->set("NEW_PAGE_INITIALRIGHT", initialRight);
ss->set("NEW_PAGE_INITIALHEIGHT", initialHeight);
ss->set("NEW_PAGE_INITIALWIDTH", initialWidth);
ss->set("NEW_PAGE_HEIGHT", height);
ss->set("NEW_PAGE_WIDTH", width);
ss->set("NEW_PAGE_ORIENTATION", orientation);
ss->set("NEW_PAGE_SIZE", pageSize);
ss->set("NEW_PAGE_TYPE", pageType);
ss->set("NEW_PAGE_MARGINPRESET", marginPreset);
undoManager->action(this, ss);
}
//set the current page's values
currentPage()->initialMargins.Top = initialTop;
currentPage()->initialMargins.Bottom = initialBottom;
currentPage()->initialMargins.Left = initialLeft;
currentPage()->initialMargins.Right = initialRight;
currentPage()->setInitialHeight(initialHeight);
currentPage()->setInitialWidth(initialWidth);
currentPage()->setHeight(height);
currentPage()->setWidth(width);
currentPage()->PageOri = orientation;
currentPage()->m_pageSize = pageSize;
currentPage()->LeftPg = pageType;
currentPage()->marginPreset = marginPreset;
reformPages(moveObjects);
invalidateRegion(pagebox);
regionsChanged()->update(pagebox);
changed();
}
}
return retVal;
}
void ScribusDoc::recalculateColors()
{
//Adjust Items of the 3 types to the colors
uint itemsCount=Items->count();
updateAllItemQColors();
for (uint c=0; c<itemsCount; ++c)
{
PageItem *ite = Items->at(c);
QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
ite->SetQColor(&cstops.at(cst)->color, cstops.at(cst)->name, cstops.at(cst)->shade);
}
uint masterItemsCount=MasterItems.count();
for (uint c=0; c<masterItemsCount; ++c)
{
PageItem *ite = MasterItems.at(c);
QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
ite->SetQColor(&cstops.at(cst)->color, cstops.at(cst)->name, cstops.at(cst)->shade);
}
uint frameItemsCount=FrameItems.count();
for (uint c=0; c<frameItemsCount; ++c)
{
PageItem *ite = FrameItems.at(c);
QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
ite->SetQColor(&cstops.at(cst)->color, cstops.at(cst)->name, cstops.at(cst)->shade);
}
QStringList patterns = docPatterns.keys();
for (int c = 0; c < patterns.count(); ++c)
{
ScPattern pa = docPatterns[patterns[c]];
if (pa.items.count() <= 0)
continue;
for (int o = 0; o < pa.items.count(); o++)
{
PageItem *ite = pa.items.at(o);
QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
ite->SetQColor(&cstops.at(cst)->color, cstops.at(cst)->name, cstops.at(cst)->shade);
if (ite->asImageFrame())
loadPict(ite->Pfile, ite, true, false);
}
PageItem *ite = pa.items.at(0);
docPatterns[patterns[c]].pattern = ite->DrawObj_toImage(pa.items);
}
}
void ScribusDoc::setScTextDefaultsFromDoc(ScText *sctextdata)
{
if (sctextdata==NULL)
return;
#ifndef NLS_PROTO
reinterpret_cast<CharStyle&>(*sctextdata) = currentStyle.charStyle();
// sctextdata->cab = 0;
#endif
}
bool ScribusDoc::copyPageToMasterPage(const int pageNumber, const int leftPage, const int maxLeftPage, const QString& masterPageName, bool copyFromAppliedMaster)
{
assert(!masterPageMode());
if (masterPageMode())
return false;
int GrMax = GroupCounter;
Page* sourcePage = Pages->at(pageNumber);
int nr = MasterPages.count();
Page* targetPage=addMasterPage(nr, masterPageName);
assert(targetPage!=NULL);
//Backup currentpage, and dont use sourcepage here as we might convert a non current page
Page* oldCurrentPage = currentPage();
//Must set current page for pasteitem to work properly
setLoading(true);
targetPage->copySizingProperties(sourcePage, sourcePage->Margins);
//Grab the left page setting for the current document layout from the dialog, and increment, singlePage==1 remember.
if (currentPageLayout != singlePage)
{
int lp = leftPage;
if (lp == 0)
lp = 1;
else if (lp == maxLeftPage-1)
lp = 0;
else
++lp;
targetPage->LeftPg = lp;
}
sourcePage->guides.copy(&targetPage->guides);
uint end = DocItems.count();
uint end2 = MasterItems.count();
Selection tempSelection(this, false);
m_Selection->clear();
//Copy the items from our current document page's applied *master* page
if (copyFromAppliedMaster)
{
if (!sourcePage->MPageNam.isEmpty() && MasterNames.contains(sourcePage->MPageNam))
{
Page* pageMaster=NULL;
for (int i=0; i < MasterPages.count(); ++i )
{
pageMaster=MasterPages[i];
if (pageMaster->pageName() == sourcePage->MPageNam)
break;
}
if (Layers.count()!= 0 && pageMaster!=NULL)
{
int currActiveLayer = activeLayer();
for (ScLayers::iterator it = Layers.begin(); it != Layers.end(); ++it)
{
setActiveLayer(it->LNr);
for (uint ite = 0; ite < end2; ++ite)
{
PageItem *itemToCopy = MasterItems.at(ite);
if ((itemToCopy->OnMasterPage == pageMaster->pageName()) && (it->LNr == itemToCopy->LayerNr))
tempSelection.addItem(itemToCopy, true);
}
if (tempSelection.count() != 0)
{
setMasterPageMode(true);
ScriXmlDoc *ss = new ScriXmlDoc();
QString dataS = ss->WriteElem(this, view(), &tempSelection);
setCurrentPage(targetPage);
ss->ReadElem(dataS, prefsData.AvailFonts, this, targetPage->xOffset(), targetPage->yOffset(), false, true, prefsData.GFontSub, view());
delete ss;
setMasterPageMode(false);
}
tempSelection.clear();
}
setActiveLayer(currActiveLayer);
}
}
}
//Copy the items from our current *document* page
if (Layers.count()!= 0)
{
int currActiveLayer = activeLayer();
for (ScLayers::iterator it = Layers.begin(); it != Layers.end(); ++it)
{
setActiveLayer(it->LNr);
for (uint ite = 0; ite < end; ++ite)
{
PageItem *itemToCopy = DocItems.at(ite);
if ((itemToCopy->OwnPage == static_cast<int>(sourcePage->pageNr())) && (it->LNr == itemToCopy->LayerNr))
tempSelection.addItem(itemToCopy, true);
}
if (tempSelection.count() != 0)
{
ScriXmlDoc *ss = new ScriXmlDoc();
QString dataS = ss->WriteElem(this, view(), &tempSelection);
setMasterPageMode(true);
setCurrentPage(targetPage);
ss->ReadElemToLayer(dataS, prefsData.AvailFonts, this, targetPage->xOffset(), targetPage->yOffset(), false, true, prefsData.GFontSub, view(), it->LNr);
delete ss;
setMasterPageMode(false);
}
tempSelection.clear();
}
setActiveLayer(currActiveLayer);
}
//Make sure our copied items have the master page name and own page set.
uint end3 = MasterItems.count();
for (uint a = end2; a < end3; ++a)
{
PageItem *newItem = MasterItems.at(a);
newItem->OnMasterPage = masterPageName;
newItem->OwnPage = MasterNames[masterPageName];
}
targetPage->MPageNam = "";
setLoading(false);
GroupCounter = GrMax + 1;
//Reset the current page..
setMasterPageMode(false);
setCurrentPage(oldCurrentPage);
changed();
return true;
}
int ScribusDoc::itemAdd(const PageItem::ItemType itemType, const PageItem::ItemFrameType frameType, const double x, const double y, const double b, const double h, const double w, const QString& fill, const QString& outline, const bool itemFinalised)
{
assert(itemFinalised); // av: caller must wrap transaction around this if wanted
UndoTransaction* activeTransaction = NULL;
if (UndoManager::undoEnabled()) // && !m_itemCreationTransaction)
{
activeTransaction = new UndoTransaction(undoManager->beginTransaction());
}
PageItem* newItem=NULL;
switch( itemType )
{
//Q_ASSERTs here will warn on creation issues when a coder specifies the frameType incorrectly
//for items that do not have/need a frameType for creation.
case PageItem::ImageFrame:
newItem = new PageItem_ImageFrame(this, x, y, b, h, w, toolSettings.dBrushPict, CommonStrings::None);
Q_ASSERT(frameType==PageItem::Rectangle || frameType==PageItem::Unspecified);
break;
case PageItem::TextFrame:
newItem = new PageItem_TextFrame(this, x, y, b, h, w, CommonStrings::None, outline);
Q_ASSERT(frameType==PageItem::Rectangle || frameType==PageItem::Unspecified);
break;
case PageItem::Line:
{
//CB 5521 Remove false minimum line width
double lineWidth = w; // == 0.0 ? 1.0 : w;
newItem = new PageItem_Line(this, x, y, b, h, lineWidth, CommonStrings::None, outline);
Q_ASSERT(frameType==PageItem::Unspecified);
}
break;
case PageItem::Polygon:
newItem = new PageItem_Polygon(this, x, y, b, h, w, fill, outline);
Q_ASSERT(frameType==PageItem::Rectangle || frameType==PageItem::Ellipse || frameType==PageItem::Unspecified);
break;
case PageItem::PolyLine:
newItem = new PageItem_PolyLine(this, x, y, b, h, w, fill, outline);
Q_ASSERT(frameType==PageItem::Unspecified);
break;
case PageItem::PathText:
//Currently used only in fileloader
newItem = new PageItem_PathText(this, x, y, b, h, w, fill, outline);
Q_ASSERT(frameType==PageItem::Unspecified);
break;
case PageItem::LatexFrame:
newItem = new PageItem_LatexFrame(this, x, y, b, h, w, toolSettings.dBrushPict, CommonStrings::None);
Q_ASSERT(frameType==PageItem::Rectangle || frameType==PageItem::Unspecified);
break;
default:
// qDebug() << "unknown item type";
assert (false);
}
Q_CHECK_PTR(newItem);
if (newItem==NULL)
return -1;
Items->append(newItem);
newItem->ItemNr = Items->count()-1;
//Add in item default values based on itemType and frameType
itemAddDetails(itemType, frameType, newItem->ItemNr);
if (UndoManager::undoEnabled())
{
ItemState<PageItem*> *is = new ItemState<PageItem*>("Create PageItem");
is->set("CREATE_ITEM", "create_item");
is->setItem(newItem);
//Undo target rests with the Page for object specific undo
UndoObject *target = Pages->at(0);
if (newItem->OwnPage > -1)
target = Pages->at(newItem->OwnPage);
undoManager->action(target, is);
//If the item is created "complete" (ie, not being created by drag/resize, commit to undomanager)
if (activeTransaction)
{
//dont think we need this now ... newItem->checkChanges(true);
activeTransaction->commit(Pages->at(newItem->OwnPage)->getUName(), newItem->getUPixmap(),
Um::Create + " " + newItem->getUName(), "", Um::ICreate);
delete activeTransaction;
activeTransaction = NULL;
}
}
return newItem->ItemNr;
}
int ScribusDoc::itemAddArea(const PageItem::ItemType itemType, const PageItem::ItemFrameType frameType, const double x, const double y, const double w, const QString& fill, const QString& outline, const bool itemFinalised)
{
double xo = m_currentPage->xOffset();
double yo = m_currentPage->yOffset();
QPair<double, double> tl = m_currentPage->guides.topLeft(x - xo, y - yo);
QPair<double, double> tr = m_currentPage->guides.topRight(x - xo, y - yo);
QPair<double, double> bl = m_currentPage->guides.bottomLeft(x - xo, y - yo);
return itemAdd(itemType, frameType, tl.first + xo, tl.second + yo, tr.first - tl.first, bl.second - tl.second, w, fill, outline, itemFinalised);
}
int ScribusDoc::itemAddUserFrame(InsertAFrameData &iafData)
{
double x1=0.0,y1=0.0,w1=iafData.width,h1=iafData.height;
std::vector<int> pageNs;
if (iafData.locationType==0) // On the current page or on a range of pages
pageNs.push_back(currentPage()->pageNr()+1);
else if (iafData.locationType==1) // On all pages
{
parsePagesString(QString("1-%1").arg(Pages->count()), &pageNs, Pages->count());
}
else
parsePagesString(iafData.pageList, &pageNs, Pages->count());
Page* oldCurrentPage = currentPage();
int z=-2;
PageItem *prevItem=0; //Previous item for text frame linking
if (iafData.linkToExistingFrame && iafData.linkToExistingFramePtr!=NULL &&
iafData.linkToExistingFramePtr->itemType()==PageItem::TextFrame &&
DocItems.contains(iafData.linkToExistingFramePtr))
prevItem=iafData.linkToExistingFramePtr;
UndoTransaction transaction(undoManager->beginTransaction(iafData.frameType==PageItem::TextFrame ? Um::TextFrame : Um::ImageFrame,
iafData.frameType==PageItem::TextFrame ? Um::ITextFrame : Um::IImageFrame,
Um::InsertFrame, "", Um::ICreate));
for (uint i=0;i<pageNs.size();++i)
{
Page* targetPage = Pages->at(pageNs[i]-1);
//We need this for the itemAdd, FIXME later
setCurrentPage(targetPage);
if (iafData.positionType==0) // Frame starts at top left of page margins
{
x1=targetPage->xOffset()+targetPage->Margins.Left;
y1=targetPage->yOffset()+targetPage->Margins.Top;
}
else if (iafData.positionType==1) // Frame starts at top left of page
{
x1=targetPage->xOffset();
y1=targetPage->yOffset();
}
else if (iafData.positionType==2) // Frame starts at top left of page - bleeds
{
x1=targetPage->xOffset()-bleeds.Left;
y1=targetPage->yOffset()-bleeds.Top;
}
else if (iafData.positionType==3) // Frame starts at custom position
{
x1=targetPage->xOffset()+iafData.x;
y1=targetPage->yOffset()+iafData.y;
}
if (iafData.sizeType==0) // Frame is size of page margins
{
w1=targetPage->width()-targetPage->Margins.Right-targetPage->Margins.Left;
h1=targetPage->height()-targetPage->Margins.Bottom-targetPage->Margins.Top;
}
else if (iafData.sizeType==1) // Frame is size of page
{
w1=targetPage->width();
h1=targetPage->height();
}
else if (iafData.sizeType==2) // Frame is size of page + bleed
{
w1=targetPage->width()+bleeds.Right+bleeds.Left;
h1=targetPage->height()+bleeds.Bottom+bleeds.Top;
}
else if (iafData.sizeType==3) //Frame is size of imported image, we resize below when we load it
{
w1=h1=1;
}
else if (iafData.sizeType==4) // Frame is custom size
{
w1=iafData.width;
h1=iafData.height;
}
z=itemAdd(iafData.frameType, PageItem::Unspecified, x1, y1, w1, h1, toolSettings.dWidth, CommonStrings::None, toolSettings.dPenText, true);
if (z!=-1)
{
PageItem* currItem=Items->at(z);
setRedrawBounding(currItem);
if (iafData.frameType==PageItem::ImageFrame && !iafData.source.isEmpty())
{
if (QFile::exists(iafData.source))
{
PrefsManager::instance()->prefsFile->getContext("dirs")->set("images", iafData.source.left(iafData.source.lastIndexOf("/")));
currItem->EmProfile = "";
currItem->pixm.imgInfo.isRequest = false;
currItem->UseEmbedded = true;
currItem->IProfile = CMSSettings.DefaultImageRGBProfile;
currItem->IRender = CMSSettings.DefaultIntentImages;
qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
loadPict(iafData.source, currItem, false, true);
if (iafData.sizeType==3) //Frame is size of imported image
{
currItem->setWidth(static_cast<double>(currItem->OrigW * 72.0 / currItem->pixm.imgInfo.xres));
currItem->setHeight(static_cast<double>(currItem->OrigH * 72.0 / currItem->pixm.imgInfo.yres));
currItem->OldB2 = currItem->width();
currItem->OldH2 = currItem->height();
currItem->updateClip();
}
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
qApp->restoreOverrideCursor();
}
}
if (iafData.frameType==PageItem::TextFrame)
{
currItem->setColumns(iafData.columnCount);
currItem->setColumnGap(iafData.columnGap/docUnitRatio);
if (i==0 && iafData.linkToExistingFrame && prevItem != NULL)
{
prevItem->link(currItem);
}
if (i!=0 && iafData.linkTextFrames && prevItem != NULL)
{
prevItem->link(currItem);
}
if (!iafData.source.isEmpty() && prevItem == NULL && QFile::exists(iafData.source))
{
gtGetText* gt = new gtGetText(this);
if (iafData.impsetup.runDialog)
gt->launchImporter(iafData.impsetup.importer, iafData.impsetup.filename, iafData.impsetup.textOnly, iafData.impsetup.encoding, true, currItem);
delete gt;
}
prevItem=currItem;
}
}
}
transaction.commit();
setCurrentPage(oldCurrentPage);
changed();
regionsChanged()->update(QRectF());
return z;
}
void ScribusDoc::itemAddDetails(const PageItem::ItemType itemType, const PageItem::ItemFrameType frameType, const int itemNumber)
{
PageItem* newItem=Items->at(itemNumber);
Q_ASSERT(newItem->realItemType()==itemType);
switch( itemType )
{
case PageItem::ImageFrame:
newItem->setImageXYScale(toolSettings.scaleX, toolSettings.scaleY);
newItem->ScaleType = toolSettings.scaleType;
newItem->AspectRatio = toolSettings.aspectRatio;
newItem->IProfile = CMSSettings.DefaultImageRGBProfile;
newItem->IRender = CMSSettings.DefaultIntentImages;
newItem->setFillShade(toolSettings.shadePict);
break;
case PageItem::LatexFrame:
newItem->setFillShade(toolSettings.shadePict);
break;
case PageItem::TextFrame:
// newItem->setFontFillShade(toolSettings.dTextPenShade);
// newItem->setFontStrokeShade(toolSettings.dTextStrokeShade);
newItem->setFillColor(toolSettings.dTextBackGround);
newItem->setFillShade(toolSettings.dTextBackGroundShade);
newItem->setLineColor(toolSettings.dTextLineColor);
newItem->setLineShade(toolSettings.dTextLineShade);
break;
case PageItem::Line:
newItem->PLineArt = Qt::PenStyle(toolSettings.dLstyleLine);
newItem->setLineShade(toolSettings.dShadeLine);
break;
case PageItem::Polygon:
if(frameType!=PageItem::Rectangle && frameType!=PageItem::Ellipse)
{
newItem->ClipEdited = true;
newItem->FrameType = 3;
}
break;
case PageItem::PolyLine:
newItem->ClipEdited = true;
break;
case PageItem::PathText:
//At this point, we cannot create a PathText item like this, only by conversion, do nothing
break;
default:
break;
}
if (frameType==PageItem::Rectangle || itemType==PageItem::TextFrame || itemType==PageItem::ImageFrame || itemType==PageItem::LatexFrame)
{
newItem->SetRectFrame();
//TODO one day hopefully, if(ScCore->usingGUI())
newItem->setRedrawBounding();
//m_View->setRedrawBounding(newItem);
newItem->ContourLine = newItem->PoLine.copy();
}
if (frameType==PageItem::Ellipse)
{
newItem->SetOvalFrame();
//TODO one day hopefully, if(ScCore->usingGUI())
newItem->setRedrawBounding();
//m_View->setRedrawBounding(newItem);
newItem->ContourLine = newItem->PoLine.copy();
}
//ItemType Polygon
if (itemType==PageItem::Polygon || itemType==PageItem::PolyLine)
{
newItem->PLineArt = Qt::PenStyle(toolSettings.dLineArt);
newItem->setFillShade(toolSettings.dShade);
newItem->setLineShade(toolSettings.dShade2);
if (itemType == PageItem::Polygon)
newItem->ContourLine = newItem->PoLine.copy();
}
}
bool ScribusDoc::itemAddCommit(const int /*itemNumber*/)
{
//TODO use the parameter
if (m_itemCreationTransaction && appMode != modeDrawBezierLine)
{
PageItem *createdItem=m_Selection->itemAt(0);
if (createdItem!=NULL)
{
createdItem->checkChanges(true);
QString targetName = Um::ScratchSpace;
if (createdItem->OwnPage > -1)
targetName = Pages->at(createdItem->OwnPage)->getUName();
m_itemCreationTransaction->commit(targetName, createdItem->getUPixmap(),
Um::Create + " " + createdItem->getUName(), "", Um::ICreate);
delete m_itemCreationTransaction;
m_itemCreationTransaction = NULL;
if (!isLoading())
return true;
}
}
return false;
}
uint ScribusDoc::getItemNrfromUniqueID(uint unique)
{
uint ret = 0;
for (int a = 0; a < Items->count(); ++a)
{
if (Items->at(a)->uniqueNr == unique)
{
ret = Items->at(a)->ItemNr;
break;
}
}
return ret;
}
void ScribusDoc::updateFrameItems()
{
uint frameItemsCount=FrameItems.count();
for (uint a = 0; a < frameItemsCount; ++a)
FrameItems.at(a)->ItemNr = a;
}
void ScribusDoc::renumberItemsInListOrder( )
{
m_docUpdater->beginUpdate();
m_updateManager.setUpdatesEnabled(false);
int itemsCount=Items->count();
for (int i = 0; i < itemsCount; ++i)
{
Items->at(i)->ItemNr = i;
Items->at(i)->checkTextFlowInteractions(true);
}
m_updateManager.setUpdatesEnabled(true);
m_docUpdater->endUpdate();
}
void ScribusDoc::rebuildItemLists()
{
// #5826 Rebuild items list in case layer order as been changed
QList<PageItem*> newDocItems, newMasterItems;
Layers.sort();
uint layerCount = this->layerCount();
uint itemIndex = 0, masterIndex = 0;
for (uint la = 0; la < layerCount; ++la)
{
PageItem* currItem;
int layerNr = Layers.at(la).LNr;
for (int it = 0; it < DocItems.count(); ++it)
{
currItem = DocItems.at(it);
if (currItem->LayerNr != layerNr)
continue;
newDocItems.append(currItem);
currItem->ItemNr = itemIndex++;
}
for (int it = 0; it < MasterItems.count(); ++it)
{
currItem = MasterItems.at(it);
if (currItem->LayerNr != layerNr)
continue;
newMasterItems.append(currItem);
currItem->ItemNr = masterIndex++;