Rev 23604 | Rev 23615 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
3 | paul | 7 | /*************************************************************************** |
8 | scribusdoc.cpp - description |
||
9 | ------------------- |
||
10 | begin : Fre Apr 6 21:47:55 CEST 2001 |
||
11 | copyright : (C) 2001 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
13 | ***************************************************************************/ |
||
14 | |||
15 | /*************************************************************************** |
||
16 | * * |
||
17 | * This program is free software; you can redistribute it and/or modify * |
||
18 | * it under the terms of the GNU General Public License as published by * |
||
19 | * the Free Software Foundation; either version 2 of the License, or * |
||
20 | * (at your option) any later version. * |
||
21 | * * |
||
22 | ***************************************************************************/ |
||
10455 | cbradney | 23 | |
15193 | jghali | 24 | #include <memory> |
3670 | cbradney | 25 | #include <utility> |
15239 | jghali | 26 | #include <sstream> |
7736 | cbradney | 27 | |
10749 | cbradney | 28 | #include <QByteArray> |
16856 | craig | 29 | #include <QDebug> |
30 | #include <QDialog> |
||
10749 | cbradney | 31 | #include <QEventLoop> |
10220 | cbradney | 32 | #include <QFile> |
10749 | cbradney | 33 | #include <QList> |
17944 | jghali | 34 | #include <QMessageBox> |
10220 | cbradney | 35 | #include <QPainter> |
10749 | cbradney | 36 | #include <QPixmap> |
16856 | craig | 37 | #include <QPointer> |
9953 | cbradney | 38 | #include <QProgressBar> |
23595 | jghali | 39 | #include <QRegExp> |
17944 | jghali | 40 | #include <QtAlgorithms> |
41 | #include <QTime> |
||
18194 | fschmid | 42 | //#include <qtconcurrentmap.h> |
10011 | fschmid | 43 | |
19495 | craig | 44 | #include "actionmanager.h" |
21107 | craig | 45 | #include "text/boxes.h" |
10749 | cbradney | 46 | #include "canvas.h" |
14150 | fschmid | 47 | #include "colorblind.h" |
10212 | cbradney | 48 | #include "commonstrings.h" |
15239 | jghali | 49 | #include "desaxe/digester.h" |
5642 | cbradney | 50 | #include "fileloader.h" |
3757 | cbradney | 51 | #include "filewatcher.h" |
16856 | craig | 52 | #include "fpoint.h" |
3757 | cbradney | 53 | #include "hyphenator.h" |
21563 | jghali | 54 | #include "langmgr.h" |
17826 | craig | 55 | #include "notesstyles.h" |
18047 | craig | 56 | #include "numeration.h" |
456 | fschmid | 57 | #include "pageitem.h" |
3617 | cbradney | 58 | #include "pageitem_imageframe.h" |
10749 | cbradney | 59 | #include "pageitem_latexframe.h" |
3617 | cbradney | 60 | #include "pageitem_line.h" |
17863 | jghali | 61 | #include "pageitem_noteframe.h" |
3617 | cbradney | 62 | #include "pageitem_pathtext.h" |
63 | #include "pageitem_polygon.h" |
||
64 | #include "pageitem_polyline.h" |
||
16856 | craig | 65 | #include "pageitem_table.h" |
3617 | cbradney | 66 | #include "pageitem_textframe.h" |
13845 | jghali | 67 | #ifdef HAVE_OSG |
68 | #include "pageitem_osgframe.h" |
||
69 | #endif |
||
19093 | craig | 70 | #include "colormgmt/sccolormgmtenginefactory.h" |
71 | #include "pageitem_arc.h" |
||
16105 | fschmid | 72 | #include "pageitem_group.h" |
16191 | fschmid | 73 | #include "pageitem_regularpolygon.h" |
16311 | fschmid | 74 | #include "pageitem_spiral.h" |
19093 | craig | 75 | #include "pageitem_symbol.h" |
10749 | cbradney | 76 | #include "pagesize.h" |
3757 | cbradney | 77 | #include "pagestructs.h" |
21744 | jghali | 78 | #include "pdfwriter.h" |
6124 | cbradney | 79 | #include "prefsfile.h" |
3757 | cbradney | 80 | #include "prefsmanager.h" |
8455 | avox | 81 | #include "resourcecollection.h" |
14744 | fschmid | 82 | #include "scclocale.h" |
19093 | craig | 83 | #include "sccolorengine.h" |
15023 | jghali | 84 | #include "sclimits.h" |
16729 | fschmid | 85 | #include "scpage.h" |
16736 | jghali | 86 | #include "scpainter.h" |
4688 | cbradney | 87 | #include "scraction.h" |
5642 | cbradney | 88 | #include "scribusXml.h" |
10749 | cbradney | 89 | #include "scribuscore.h" |
90 | #include "scribusdoc.h" |
||
91 | #include "scribusview.h" |
||
92 | #include "scribuswin.h" |
||
3903 | cbradney | 93 | #include "selection.h" |
12407 | pierre | 94 | #include "serializer.h" |
16856 | craig | 95 | #include "tableborder.h" |
21107 | craig | 96 | #include "text/textlayoutpainter.h" |
21563 | jghali | 97 | #include "text/textshaper.h" |
98 | #include "ui/guidemanager.h" |
||
19093 | craig | 99 | #include "ui/hruler.h" |
21563 | jghali | 100 | #include "ui/inserttablecolumnsdialog.h" |
101 | #include "ui/inserttablerowsdialog.h" |
||
19093 | craig | 102 | #include "ui/layers.h" |
103 | #include "ui/mark2item.h" |
||
104 | #include "ui/mark2mark.h" |
||
105 | #include "ui/markanchor.h" |
||
106 | #include "ui/markinsert.h" |
||
107 | #include "ui/marksmanager.h" |
||
108 | #include "ui/markvariabletext.h" |
||
21563 | jghali | 109 | #include "ui/notesstyleseditor.h" |
110 | #include "ui/outlinepalette.h" |
||
19093 | craig | 111 | #include "ui/pagepalette.h" |
112 | #include "ui/storyeditor.h" |
||
16856 | craig | 113 | #include "ui/tablecolumnwidthsdialog.h" |
114 | #include "ui/tablerowheightsdialog.h" |
||
1179 | tsoots | 115 | #include "undomanager.h" |
2965 | cbradney | 116 | #include "units.h" |
3809 | cbradney | 117 | #include "util.h" |
10203 | cbradney | 118 | #include "util_math.h" |
410 | Franz | 119 | |
3205 | craig | 120 | |
10684 | fschmid | 121 | // static const bool FRAMESELECTION_EDITS_DEFAULTSTYLE = false; |
9607 | avox | 122 | |
10532 | avox | 123 | |
124 | |||
125 | /** |
||
126 | This class forwards change events for pages and pageitems to |
||
127 | the region occupied by this page or pageitem. |
||
128 | */ |
||
16729 | fschmid | 129 | class DocUpdater : public Observer<ScPage*>, public Observer<PageItem*> |
10532 | avox | 130 | { |
131 | ScribusDoc* doc; |
||
14283 | jghali | 132 | int m_updateEnabled; |
133 | bool m_docChangeNeeded; |
||
10532 | avox | 134 | public: |
14283 | jghali | 135 | DocUpdater(ScribusDoc* d) : doc(d), m_updateEnabled(0), m_docChangeNeeded(false) {} |
136 | |||
14370 | jghali | 137 | bool inUpdateSession() const |
138 | { |
||
139 | return m_updateEnabled > 0; |
||
140 | } |
||
141 | |||
22652 | craig | 142 | void beginUpdate() |
14283 | jghali | 143 | { |
144 | if (m_updateEnabled == 0) |
||
145 | m_docChangeNeeded = false; |
||
146 | ++m_updateEnabled; |
||
147 | } |
||
148 | |||
22652 | craig | 149 | void endUpdate() |
14283 | jghali | 150 | { |
151 | --m_updateEnabled; |
||
152 | if (m_updateEnabled <= 0) |
||
153 | { |
||
154 | if (m_docChangeNeeded) |
||
155 | { |
||
156 | doc->changed(); |
||
157 | m_docChangeNeeded = false; |
||
158 | } |
||
159 | } |
||
160 | } |
||
10532 | avox | 161 | |
23041 | craig | 162 | void changed(ScPage* pg, bool /*doLayout*/) override |
10532 | avox | 163 | { |
11046 | avox | 164 | QRectF pagebox(pg->xOffset(), pg->yOffset(), pg->width(), pg->height()); |
165 | doc->invalidateRegion(pagebox); |
||
166 | doc->regionsChanged()->update(pagebox); |
||
14283 | jghali | 167 | if (m_updateEnabled <= 0) |
168 | { |
||
169 | doc->changed(); |
||
170 | return; |
||
171 | } |
||
172 | m_docChangeNeeded = true; |
||
10532 | avox | 173 | } |
174 | |||
23041 | craig | 175 | void changed(PageItem* it, bool doLayout) override |
10532 | avox | 176 | { |
11046 | avox | 177 | it->invalidateLayout(); |
16639 | jghali | 178 | if (doLayout) |
179 | it->layout(); |
||
17124 | fschmid | 180 | double x, y, w, h; |
20061 | craig | 181 | QTransform t = it->getTransform(); |
17124 | fschmid | 182 | w = it->visualWidth(); |
183 | h = it->visualHeight(); |
||
184 | x = -it->visualLineWidth() / 2.0; |
||
185 | y = -it->visualLineWidth() / 2.0; |
||
186 | QRectF upRect = t.mapRect(QRectF(x, y, w, h)); |
||
187 | doc->regionsChanged()->update(upRect); |
||
14283 | jghali | 188 | if (m_updateEnabled <= 0) |
189 | { |
||
190 | doc->changed(); |
||
191 | return; |
||
192 | } |
||
193 | m_docChangeNeeded = true; |
||
10532 | avox | 194 | } |
19286 | jghali | 195 | |
196 | void setDocChangeNeeded(bool changeNeeded = true) |
||
197 | { |
||
198 | m_docChangeNeeded = changeNeeded; |
||
199 | } |
||
10532 | avox | 200 | }; |
201 | |||
202 | |||
203 | |||
204 | |||
22518 | craig | 205 | ScribusDoc::ScribusDoc() : UndoObject( tr("Document")), Observable<ScribusDoc>(nullptr), |
23060 | craig | 206 | m_appPrefsData(PrefsManager::instance().appPrefs), |
207 | m_docPrefsData(PrefsManager::instance().appPrefs), |
||
20691 | craig | 208 | m_undoManager(UndoManager::instance()), |
22631 | craig | 209 | m_automaticTextFrames(false), |
7906 | jghali | 210 | m_guardedObject(this), |
23179 | jghali | 211 | m_documentFileName( tr("Document") + "-"), |
3983 | craig | 212 | minCanvasCoordinate(FPoint(0, 0)), |
4847 | cbradney | 213 | m_Selection(new Selection(this, true)), |
3983 | craig | 214 | PageSp(1), PageSpa(0), |
215 | FirstPnum(1), |
||
5892 | jghali | 216 | PageColors(this, true), |
20691 | craig | 217 | AllFonts(&m_appPrefsData.fontPrefs.AvailFonts), |
14170 | jghali | 218 | colorEngine(ScCore->defaultEngine), |
3983 | craig | 219 | autoSaveTimer(new QTimer(this)), |
22505 | craig | 220 | m_itemCreationTransaction(nullptr), |
23041 | craig | 221 | m_alignTransaction(nullptr) |
3 | paul | 222 | { |
20691 | craig | 223 | m_docUnitRatio=unitGetRatioFromIndex(m_docPrefsData.docSetupPrefs.docUnitIndex); |
224 | m_docPrefsData.docSetupPrefs.pageHeight=0; |
||
225 | m_docPrefsData.docSetupPrefs.pageWidth=0; |
||
226 | m_docPrefsData.docSetupPrefs.pagePositioning=0; |
||
227 | maxCanvasCoordinate=(FPoint(m_docPrefsData.displayPrefs.scratch.left() + m_docPrefsData.displayPrefs.scratch.right(), m_docPrefsData.displayPrefs.scratch.top() + m_docPrefsData.displayPrefs.scratch.bottom())), |
||
5789 | cbradney | 228 | init(); |
20691 | craig | 229 | m_docPrefsData.pdfPrefs.bleeds = m_docPrefsData.docSetupPrefs.bleeds; |
230 | m_docPrefsData.pdfPrefs.useDocBleeds = true; |
||
7104 | fschmid | 231 | Print_Options.firstUse = true; |
18047 | craig | 232 | //create default numeration |
22832 | craig | 233 | auto* numS = new NumStruct; |
18047 | craig | 234 | numS->m_name = "default"; |
235 | Numeration newNum; |
||
236 | numS->m_nums.insert(0, newNum); |
||
237 | numS->m_counters.insert(0, 0); |
||
238 | numS->m_lastlevel = -1; |
||
239 | numerations.insert("default", numS); |
||
5789 | cbradney | 240 | } |
241 | |||
10532 | avox | 242 | |
5789 | cbradney | 243 | ScribusDoc::ScribusDoc(const QString& docName, int unitindex, const PageSize& pagesize, const MarginStruct& margins, const DocPagesSetup& pagesSetup) : UndoObject( tr("Document")), |
23060 | craig | 244 | m_appPrefsData(PrefsManager::instance().appPrefs), |
245 | m_docPrefsData(PrefsManager::instance().appPrefs), |
||
20691 | craig | 246 | m_undoManager(UndoManager::instance()), |
247 | m_docUnitRatio(unitGetRatioFromIndex(m_appPrefsData.docSetupPrefs.docUnitIndex)), |
||
248 | m_automaticTextFrames(pagesSetup.autoTextFrames), |
||
7906 | jghali | 249 | m_guardedObject(this), |
23179 | jghali | 250 | m_documentFileName(docName), |
5789 | cbradney | 251 | minCanvasCoordinate(FPoint(0, 0)), |
252 | m_Selection(new Selection(this, true)), |
||
253 | PageSp(pagesSetup.columnCount), PageSpa(pagesSetup.columnDistance), |
||
254 | FirstPnum(pagesSetup.firstPageNumber), |
||
5892 | jghali | 255 | PageColors(this, true), |
20691 | craig | 256 | AllFonts(&m_appPrefsData.fontPrefs.AvailFonts), |
14170 | jghali | 257 | colorEngine(ScCore->defaultEngine), |
5789 | cbradney | 258 | autoSaveTimer(new QTimer(this)), |
22505 | craig | 259 | m_itemCreationTransaction(nullptr), |
23041 | craig | 260 | m_alignTransaction(nullptr) |
5789 | cbradney | 261 | { |
20691 | craig | 262 | m_docPrefsData.docSetupPrefs.docUnitIndex=unitindex; |
263 | m_docPrefsData.docSetupPrefs.pageHeight=pagesize.height(); |
||
264 | m_docPrefsData.docSetupPrefs.pageWidth=pagesize.width(); |
||
265 | m_docPrefsData.docSetupPrefs.pageSize=pagesize.name(); |
||
266 | m_docPrefsData.docSetupPrefs.margins=margins; |
||
267 | maxCanvasCoordinate=(FPoint(m_docPrefsData.displayPrefs.scratch.left() + m_docPrefsData.displayPrefs.scratch.right(), m_docPrefsData.displayPrefs.scratch.top() + m_docPrefsData.displayPrefs.scratch.bottom())), |
||
14924 | cbradney | 268 | setPageSetFirstPage(pagesSetup.pageArrangement, pagesSetup.firstPageLocation); |
5789 | cbradney | 269 | init(); |
20691 | craig | 270 | m_docPrefsData.pdfPrefs.bleeds = m_docPrefsData.docSetupPrefs.bleeds; |
271 | m_docPrefsData.pdfPrefs.useDocBleeds = true; |
||
272 | m_docPrefsData.docSetupPrefs.pageOrientation=pagesSetup.orientation; |
||
273 | m_docPrefsData.docSetupPrefs.pagePositioning=pagesSetup.pageArrangement; |
||
7104 | fschmid | 274 | Print_Options.firstUse = true; |
5789 | cbradney | 275 | } |
276 | |||
10532 | avox | 277 | |
5789 | cbradney | 278 | void ScribusDoc::init() |
279 | { |
||
4847 | cbradney | 280 | Q_CHECK_PTR(m_Selection); |
3983 | craig | 281 | Q_CHECK_PTR(autoSaveTimer); |
282 | |||
20691 | craig | 283 | m_docPrefsData.colorPrefs.DCMSset.CMSinUse = false; |
6464 | jghali | 284 | |
14170 | jghali | 285 | colorEngine = ScCore->defaultEngine; |
10338 | jghali | 286 | SetDefaultCMSParams(); |
5880 | jghali | 287 | |
10532 | avox | 288 | // init update change management |
289 | setUpdateManager(&m_updateManager); |
||
290 | m_itemsChanged.setUpdateManager(&m_updateManager); |
||
291 | m_pagesChanged.setUpdateManager(&m_updateManager); |
||
292 | m_regionsChanged.setUpdateManager(&m_updateManager); |
||
293 | nodeEdit.setUpdateManager(&m_updateManager); |
||
294 | |||
295 | // setup update() event chains |
||
296 | m_docUpdater = new DocUpdater(this); |
||
297 | m_itemsChanged.connectObserver(m_docUpdater); |
||
298 | m_pagesChanged.connectObserver(m_docUpdater); |
||
299 | |||
23060 | craig | 300 | PrefsManager& prefsManager = PrefsManager::instance(); |
301 | m_docPrefsData.colorPrefs.DCMSset = prefsManager.appPrefs.colorPrefs.DCMSset; |
||
20691 | craig | 302 | m_docPrefsData.pdfPrefs.SolidProf = m_docPrefsData.colorPrefs.DCMSset.DefaultSolidColorRGBProfile; |
303 | m_docPrefsData.pdfPrefs.ImageProf = m_docPrefsData.colorPrefs.DCMSset.DefaultImageRGBProfile; |
||
304 | m_docPrefsData.pdfPrefs.PrintProf = m_docPrefsData.colorPrefs.DCMSset.DefaultPrinterProfile; |
||
305 | m_docPrefsData.pdfPrefs.Intent = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentColors; |
||
306 | m_docPrefsData.pdfPrefs.Intent2 = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentImages; |
||
6464 | jghali | 307 | |
20691 | craig | 308 | AddFont(m_appPrefsData.itemToolPrefs.textFont);//, prefsData.AvailFonts[prefsData.itemToolPrefs.textFont]->Font); |
14932 | cbradney | 309 | //FIXME: aren't we doing this now anyway with prefs struct copy? |
20691 | craig | 310 | m_docPrefsData.itemToolPrefs.textFont = m_appPrefsData.itemToolPrefs.textFont; |
311 | m_docPrefsData.itemToolPrefs.textSize = m_appPrefsData.itemToolPrefs.textSize; |
||
312 | m_docPrefsData.itemToolPrefs.textTabFillChar = m_appPrefsData.itemToolPrefs.textTabFillChar; |
||
313 | m_docPrefsData.opToolPrefs.dispX = m_appPrefsData.opToolPrefs.dispX; |
||
314 | m_docPrefsData.opToolPrefs.dispY = m_appPrefsData.opToolPrefs.dispY; |
||
315 | m_docPrefsData.opToolPrefs.constrain = m_appPrefsData.opToolPrefs.constrain; |
||
5880 | jghali | 316 | |
15912 | jghali | 317 | PageColors.ensureDefaultColors(); |
20691 | craig | 318 | if (m_appPrefsData.itemToolPrefs.shapeLineColor != CommonStrings::None) |
319 | PageColors.insert(m_appPrefsData.itemToolPrefs.shapeLineColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.shapeLineColor]); |
||
320 | m_docPrefsData.itemToolPrefs.shapeLineColor = m_appPrefsData.itemToolPrefs.shapeLineColor; |
||
321 | if (m_appPrefsData.itemToolPrefs.lineColor != CommonStrings::None) |
||
322 | PageColors.insert(m_appPrefsData.itemToolPrefs.lineColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.lineColor]); |
||
323 | m_docPrefsData.itemToolPrefs.lineColor = m_appPrefsData.itemToolPrefs.lineColor; |
||
324 | if (m_appPrefsData.itemToolPrefs.textColor != CommonStrings::None) |
||
325 | PageColors.insert(m_appPrefsData.itemToolPrefs.textColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.textColor]); |
||
326 | m_docPrefsData.itemToolPrefs.textColor = m_appPrefsData.itemToolPrefs.textColor; |
||
327 | if (m_appPrefsData.itemToolPrefs.textStrokeColor != CommonStrings::None) |
||
328 | PageColors.insert(m_appPrefsData.itemToolPrefs.textStrokeColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.textStrokeColor]); |
||
329 | m_docPrefsData.itemToolPrefs.textStrokeColor = m_appPrefsData.itemToolPrefs.textStrokeColor; |
||
330 | if (m_appPrefsData.itemToolPrefs.shapeFillColor != CommonStrings::None) |
||
331 | PageColors.insert(m_appPrefsData.itemToolPrefs.shapeFillColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.shapeFillColor]); |
||
332 | m_docPrefsData.itemToolPrefs.shapeFillColor = m_appPrefsData.itemToolPrefs.shapeFillColor; |
||
333 | if (m_appPrefsData.itemToolPrefs.imageFillColor != CommonStrings::None) |
||
334 | PageColors.insert(m_appPrefsData.itemToolPrefs.imageFillColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.imageFillColor]); |
||
335 | m_docPrefsData.itemToolPrefs.imageFillColor = m_appPrefsData.itemToolPrefs.imageFillColor; |
||
336 | if (m_appPrefsData.itemToolPrefs.imageStrokeColor != CommonStrings::None) |
||
337 | PageColors.insert(m_appPrefsData.itemToolPrefs.imageStrokeColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.imageStrokeColor]); |
||
338 | m_docPrefsData.itemToolPrefs.imageStrokeColor = m_appPrefsData.itemToolPrefs.imageStrokeColor; |
||
339 | if (m_appPrefsData.itemToolPrefs.textFillColor != CommonStrings::None) |
||
340 | PageColors.insert(m_appPrefsData.itemToolPrefs.textFillColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.textFillColor]); |
||
341 | m_docPrefsData.itemToolPrefs.textFillColor = m_appPrefsData.itemToolPrefs.textFillColor; |
||
342 | if (m_appPrefsData.itemToolPrefs.textLineColor != CommonStrings::None) |
||
343 | PageColors.insert(m_appPrefsData.itemToolPrefs.textLineColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.textLineColor]); |
||
344 | if (m_appPrefsData.itemToolPrefs.calligraphicPenFillColor != CommonStrings::None) |
||
345 | PageColors.insert(m_appPrefsData.itemToolPrefs.calligraphicPenFillColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.calligraphicPenFillColor]); |
||
346 | if (m_appPrefsData.itemToolPrefs.calligraphicPenLineColor != CommonStrings::None) |
||
347 | PageColors.insert(m_appPrefsData.itemToolPrefs.calligraphicPenLineColor, m_appPrefsData.colorPrefs.DColors[m_appPrefsData.itemToolPrefs.calligraphicPenLineColor]); |
||
6733 | avox | 348 | |
349 | |||
7059 | avox | 350 | ParagraphStyle pstyle; |
12283 | cbradney | 351 | pstyle.setDefaultStyle(true); |
352 | pstyle.setName(CommonStrings::DefaultParagraphStyle); |
||
7059 | avox | 353 | pstyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing); |
354 | pstyle.setLineSpacing(15); |
||
23126 | jghali | 355 | pstyle.setAlignment(ParagraphStyle::LeftAligned); |
21563 | jghali | 356 | pstyle.setDirection(ParagraphStyle::LTR); |
7059 | avox | 357 | pstyle.setLeftMargin(0); |
358 | pstyle.setFirstIndent(0); |
||
359 | pstyle.setRightMargin(0); |
||
360 | pstyle.setGapBefore(0); |
||
361 | pstyle.setGapAfter(0); |
||
362 | pstyle.setHasDropCap(false); |
||
18047 | craig | 363 | pstyle.setHasBullet(false); |
364 | pstyle.setHasNum(false); |
||
21563 | jghali | 365 | pstyle.setHyphenConsecutiveLines(2); |
7059 | avox | 366 | pstyle.setDropCapLines(2); |
18047 | craig | 367 | pstyle.setParEffectOffset(0); |
20632 | fschmid | 368 | pstyle.setBackgroundColor(CommonStrings::None); |
369 | pstyle.setBackgroundShade(100); |
||
7095 | avox | 370 | pstyle.charStyle().setParent(""); |
6733 | avox | 371 | |
7059 | avox | 372 | CharStyle cstyle; |
12283 | cbradney | 373 | cstyle.setDefaultStyle(true); |
374 | cstyle.setName(CommonStrings::DefaultCharacterStyle); |
||
20691 | craig | 375 | cstyle.setFont(m_appPrefsData.fontPrefs.AvailFonts[m_docPrefsData.itemToolPrefs.textFont]); |
376 | cstyle.setFontSize(m_docPrefsData.itemToolPrefs.textSize); |
||
21563 | jghali | 377 | cstyle.setFontFeatures(""); |
9607 | avox | 378 | cstyle.setFeatures(QStringList(CharStyle::INHERIT)); |
21563 | jghali | 379 | cstyle.setHyphenWordMin(3); |
20691 | craig | 380 | cstyle.setFillColor(m_docPrefsData.itemToolPrefs.textColor); |
381 | cstyle.setFillShade(m_docPrefsData.itemToolPrefs.textShade); |
||
382 | cstyle.setStrokeColor(m_docPrefsData.itemToolPrefs.textStrokeColor); |
||
383 | cstyle.setStrokeShade(m_docPrefsData.itemToolPrefs.textStrokeShade); |
||
20636 | fschmid | 384 | cstyle.setBackColor(CommonStrings::None); |
385 | cstyle.setBackShade(100); |
||
6733 | avox | 386 | cstyle.setBaselineOffset(0); |
387 | cstyle.setShadowXOffset(50); |
||
388 | cstyle.setShadowYOffset(-50); |
||
389 | cstyle.setOutlineWidth(10); |
||
20691 | craig | 390 | cstyle.setUnderlineOffset(m_docPrefsData.typoPrefs.valueUnderlinePos); |
391 | cstyle.setUnderlineWidth(m_docPrefsData.typoPrefs.valueUnderlineWidth); |
||
392 | cstyle.setStrikethruOffset(m_docPrefsData.typoPrefs.valueStrikeThruPos); |
||
393 | cstyle.setStrikethruWidth(m_docPrefsData.typoPrefs.valueStrikeThruPos); |
||
6733 | avox | 394 | cstyle.setScaleH(1000); |
395 | cstyle.setScaleV(1000); |
||
396 | cstyle.setTracking(0); |
||
23060 | craig | 397 | cstyle.setLanguage(PrefsManager::instance().appPrefs.docSetupPrefs.language); |
6733 | avox | 398 | |
20691 | craig | 399 | m_docParagraphStyles.create(pstyle); |
400 | m_docParagraphStyles.makeDefault( &(m_docParagraphStyles[0]) ); |
||
8058 | avox | 401 | |
20691 | craig | 402 | m_docCharStyles.create(cstyle); |
403 | m_docCharStyles.makeDefault( &(m_docCharStyles[0]) ); |
||
8058 | avox | 404 | |
20691 | craig | 405 | m_docParagraphStyles[0].breakImplicitCharStyleInheritance(); |
406 | m_docParagraphStyles[0].charStyle().setContext( & m_docCharStyles ); |
||
20681 | craig | 407 | // docParagraphStyles[0].charStyle().setName( "cdocdefault" ); // DON'T TRANSLATE |
7059 | avox | 408 | |
409 | currentStyle = pstyle; |
||
16856 | craig | 410 | |
411 | // Create default table style. |
||
412 | // TODO: We should have preferences for the default values. |
||
413 | TableStyle defaultTableStyle; |
||
17318 | fschmid | 414 | defaultTableStyle.setDefaultStyle(true); |
16856 | craig | 415 | defaultTableStyle.setName(CommonStrings::DefaultTableStyle); |
416 | defaultTableStyle.setFillColor(CommonStrings::None); |
||
17311 | fschmid | 417 | defaultTableStyle.setFillShade(100); |
418 | defaultTableStyle.setLeftBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
419 | defaultTableStyle.setRightBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
420 | defaultTableStyle.setTopBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
421 | defaultTableStyle.setBottomBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
20691 | craig | 422 | m_docTableStyles.create(defaultTableStyle); |
423 | m_docTableStyles.makeDefault(&(m_docTableStyles[0])); |
||
16856 | craig | 424 | |
425 | // Create default table cell style. |
||
426 | // TODO: We should have preferences for the default values. |
||
427 | CellStyle defaultCellStyle; |
||
17318 | fschmid | 428 | defaultCellStyle.setDefaultStyle(true); |
16856 | craig | 429 | defaultCellStyle.setName(CommonStrings::DefaultCellStyle); |
430 | defaultCellStyle.setFillColor(CommonStrings::None); |
||
17311 | fschmid | 431 | defaultCellStyle.setFillShade(100); |
432 | defaultCellStyle.setLeftBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
433 | defaultCellStyle.setRightBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
434 | defaultCellStyle.setTopBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
435 | defaultCellStyle.setBottomBorder(TableBorder(1.0, Qt::SolidLine, "Black", 100)); |
||
16856 | craig | 436 | defaultCellStyle.setLeftPadding(1.0); |
437 | defaultCellStyle.setRightPadding(1.0); |
||
438 | defaultCellStyle.setTopPadding(1.0); |
||
439 | defaultCellStyle.setBottomPadding(1.0); |
||
20691 | craig | 440 | m_docCellStyles.create(defaultCellStyle); |
441 | m_docCellStyles.makeDefault(&(m_docCellStyles[0])); |
||
5698 | avox | 442 | |
10146 | jghali | 443 | Layers.addLayer( tr("Background") ); |
14925 | cbradney | 444 | // FIXME: Check PDF version input |
445 | //TODO: Check if this is needed now we ue appPrefsData --> docPrefsData |
||
23548 | jghali | 446 | pdfOptions().Version = m_appPrefsData.pdfPrefs.Version; |
3201 | subik | 447 | |
14925 | cbradney | 448 | pdfOptions().firstUse = true; |
6368 | fschmid | 449 | docPatterns.clear(); |
14150 | fschmid | 450 | docGradients.clear(); |
6368 | fschmid | 451 | |
14925 | cbradney | 452 | if (autoSave() && ScCore->usingGUI()) |
453 | autoSaveTimer->start(autoSaveTime()); |
||
3724 | cbradney | 454 | //Do this after all the collections have been created and cleared! |
455 | m_masterPageMode=true; // quick hack to force the change of pointers in setMasterPageMode(); |
||
456 | setMasterPageMode(false); |
||
2891 | cbradney | 457 | addSymbols(); |
17826 | craig | 458 | //for loading old documents where default notes style is not saved |
459 | if (m_docNotesStylesList.isEmpty()) |
||
460 | m_docNotesStylesList.append(new NotesStyle()); |
||
3 | paul | 461 | } |
462 | |||
10532 | avox | 463 | |
3 | paul | 464 | ScribusDoc::~ScribusDoc() |
465 | { |
||
7906 | jghali | 466 | m_guardedObject.nullify(); |
9616 | jghali | 467 | CloseCMSProfiles(); |
14662 | fschmid | 468 | ScCore->fileWatcher->stop(); |
22832 | craig | 469 | ScCore->fileWatcher->removeFile(m_documentFileName); |
16105 | fschmid | 470 | QList<PageItem*> allItems; |
21394 | craig | 471 | for (int i = 0; i < DocItems.count(); ++i) |
14662 | fschmid | 472 | { |
21394 | craig | 473 | PageItem *currItem = DocItems.at(i); |
16105 | fschmid | 474 | if (currItem->isGroup()) |
22224 | jghali | 475 | allItems = currItem->getAllChildren(); |
16105 | fschmid | 476 | else |
477 | allItems.append(currItem); |
||
21394 | craig | 478 | for (int j = 0; j < allItems.count(); j++) |
14662 | fschmid | 479 | { |
21394 | craig | 480 | currItem = allItems.at(j); |
19834 | craig | 481 | if (currItem->imageIsAvailable) |
16105 | fschmid | 482 | ScCore->fileWatcher->removeFile(currItem->Pfile); |
483 | if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty())) |
||
484 | { |
||
485 | QFileInfo fi(currItem->Pfile); |
||
486 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
487 | } |
||
14662 | fschmid | 488 | } |
16148 | fschmid | 489 | allItems.clear(); |
14662 | fschmid | 490 | } |
21394 | craig | 491 | for (int i = 0; i < MasterItems.count(); ++i) |
14662 | fschmid | 492 | { |
21394 | craig | 493 | PageItem *currItem = MasterItems.at(i); |
16105 | fschmid | 494 | if (currItem->isGroup()) |
22224 | jghali | 495 | allItems = currItem->getAllChildren(); |
16105 | fschmid | 496 | else |
497 | allItems.append(currItem); |
||
21394 | craig | 498 | for (int j = 0; j < allItems.count(); j++) |
14662 | fschmid | 499 | { |
21394 | craig | 500 | currItem = allItems.at(j); |
19834 | craig | 501 | if (currItem->imageIsAvailable) |
16105 | fschmid | 502 | ScCore->fileWatcher->removeFile(currItem->Pfile); |
503 | if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty())) |
||
504 | { |
||
505 | QFileInfo fi(currItem->Pfile); |
||
506 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
507 | } |
||
14662 | fschmid | 508 | } |
16148 | fschmid | 509 | allItems.clear(); |
14662 | fschmid | 510 | } |
22509 | jghali | 511 | for (auto itf = FrameItems.begin(); itf != FrameItems.end(); ++itf) |
14662 | fschmid | 512 | { |
17407 | fschmid | 513 | PageItem *currItem = itf.value(); |
16105 | fschmid | 514 | if (currItem->isGroup()) |
22224 | jghali | 515 | allItems = currItem->getAllChildren(); |
16105 | fschmid | 516 | else |
517 | allItems.append(currItem); |
||
518 | for (int ii = 0; ii < allItems.count(); ii++) |
||
14662 | fschmid | 519 | { |
16105 | fschmid | 520 | currItem = allItems.at(ii); |
19834 | craig | 521 | if (currItem->imageIsAvailable) |
16105 | fschmid | 522 | ScCore->fileWatcher->removeFile(currItem->Pfile); |
523 | if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty())) |
||
524 | { |
||
525 | QFileInfo fi(currItem->Pfile); |
||
526 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
527 | } |
||
14662 | fschmid | 528 | } |
16148 | fschmid | 529 | allItems.clear(); |
14662 | fschmid | 530 | } |
531 | QStringList patterns = docPatterns.keys(); |
||
21394 | craig | 532 | for (int i = 0; i < patterns.count(); ++i) |
14662 | fschmid | 533 | { |
21394 | craig | 534 | ScPattern pa = docPatterns[patterns[i]]; |
535 | for (int j = 0; j < pa.items.count(); j++) |
||
14662 | fschmid | 536 | { |
21394 | craig | 537 | PageItem *currItem = pa.items.at(j); |
16105 | fschmid | 538 | if (currItem->isGroup()) |
22224 | jghali | 539 | allItems = currItem->getAllChildren(); |
16105 | fschmid | 540 | else |
541 | allItems.append(currItem); |
||
21394 | craig | 542 | for (int k = 0; k < allItems.count(); k++) |
14662 | fschmid | 543 | { |
21394 | craig | 544 | currItem = allItems.at(k); |
16105 | fschmid | 545 | if (currItem->itemType() == PageItem::ImageFrame) |
16016 | fschmid | 546 | { |
19834 | craig | 547 | if ((currItem->imageIsAvailable) && (!currItem->Pfile.isEmpty())) |
16105 | fschmid | 548 | { |
549 | ScCore->fileWatcher->removeFile(currItem->Pfile); |
||
550 | QFileInfo fi(currItem->Pfile); |
||
551 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
552 | } |
||
16016 | fschmid | 553 | } |
14662 | fschmid | 554 | } |
16148 | fschmid | 555 | allItems.clear(); |
14662 | fschmid | 556 | } |
16016 | fschmid | 557 | while (!pa.items.isEmpty()) |
558 | { |
||
559 | delete pa.items.takeFirst(); |
||
560 | } |
||
14662 | fschmid | 561 | } |
17826 | craig | 562 | //deleting resources alocated for marks and notes |
563 | while (! m_docNotesList.isEmpty()) |
||
564 | delete m_docNotesList.takeFirst(); |
||
565 | while (!m_docMarksList.isEmpty()) |
||
566 | delete m_docMarksList.takeFirst(); |
||
567 | while (! m_docNotesStylesList.isEmpty()) |
||
568 | delete m_docNotesStylesList.takeFirst(); |
||
16016 | fschmid | 569 | docPatterns.clear(); |
570 | docGradients.clear(); |
||
18047 | craig | 571 | foreach (NumStruct* ns, numerations.values()) |
572 | delete ns; |
||
573 | numerations.clear(); |
||
9856 | fschmid | 574 | while (!DocItems.isEmpty()) |
575 | { |
||
576 | delete DocItems.takeFirst(); |
||
577 | } |
||
17407 | fschmid | 578 | QList<PageItem*> tmList = FrameItems.values(); |
579 | while (!tmList.isEmpty()) |
||
16016 | fschmid | 580 | { |
17407 | fschmid | 581 | delete tmList.takeFirst(); |
16016 | fschmid | 582 | } |
17407 | fschmid | 583 | FrameItems.clear(); |
10013 | cbradney | 584 | |
585 | while (!MasterPages.isEmpty()) |
||
586 | { |
||
587 | delete MasterPages.takeFirst(); |
||
588 | } |
||
589 | while (!DocPages.isEmpty()) |
||
590 | { |
||
591 | delete DocPages.takeFirst(); |
||
592 | } |
||
9856 | fschmid | 593 | while (!MasterItems.isEmpty()) |
594 | { |
||
595 | delete MasterItems.takeFirst(); |
||
596 | } |
||
3544 | avox | 597 | QMap<QString,int>::Iterator it3; |
494 | fschmid | 598 | for (it3 = UsedFonts.begin(); it3 != UsedFonts.end(); ++it3) |
599 | { |
||
5980 | avox | 600 | if (!(*AllFonts)[it3.key()].localForDocument().isEmpty()) |
494 | fschmid | 601 | (*AllFonts).removeFont(it3.key()); |
5559 | avox | 602 | else |
5980 | avox | 603 | (*AllFonts)[it3.key()].decreaseUsage(); |
494 | fschmid | 604 | } |
22631 | craig | 605 | delete docHyphenator; |
606 | delete m_serializer; |
||
607 | delete m_tserializer; |
||
608 | delete m_docUpdater; |
||
21079 | fschmid | 609 | if (!m_docPrefsData.docSetupPrefs.AutoSaveKeep) |
610 | { |
||
611 | if (autoSaveFiles.count() != 0) |
||
612 | { |
||
21394 | craig | 613 | for (int i = 0; i < autoSaveFiles.count(); i++) |
21079 | fschmid | 614 | { |
21394 | craig | 615 | QFile f(autoSaveFiles[i]); |
21079 | fschmid | 616 | f.remove(); |
617 | } |
||
618 | autoSaveFiles.clear(); |
||
619 | } |
||
620 | } |
||
14662 | fschmid | 621 | ScCore->fileWatcher->start(); |
3 | paul | 622 | } |
623 | |||
19568 | jghali | 624 | bool ScribusDoc::inAnEditMode() const |
625 | { |
||
22639 | craig | 626 | return appMode == modeDrawBezierLine || |
627 | appMode == modeEdit || |
||
628 | appMode == modeEditArc || |
||
629 | appMode == modeEditClip || |
||
630 | appMode == modeEditGradientVectors || |
||
631 | appMode == modeEditMeshGradient || |
||
632 | appMode == modeEditMeshPatch || |
||
633 | appMode == modeEditPolygon || |
||
634 | appMode == modeEditSpiral || |
||
635 | appMode == modeEditTable || |
||
636 | appMode == modeEditWeldPoint; |
||
19568 | jghali | 637 | } |
638 | |||
19760 | jghali | 639 | bool ScribusDoc::inASpecialEditMode() const |
640 | { // #12897, modes that use setSpecialEditMode() function in appmodehelper.cpp |
||
22631 | craig | 641 | return appMode == modeDrawBezierLine || |
642 | appMode == modeEditArc || |
||
643 | appMode == modeEditGradientVectors || |
||
644 | appMode == modeEditMeshGradient || |
||
645 | appMode == modeEditMeshPatch || |
||
646 | appMode == modeEditPolygon || |
||
647 | appMode == modeEditSpiral || |
||
648 | appMode == modeEditWeldPoint; |
||
19760 | jghali | 649 | } |
650 | |||
16105 | fschmid | 651 | QList<PageItem*> ScribusDoc::getAllItems(QList<PageItem*> &items) |
652 | { |
||
653 | QList<PageItem*> ret; |
||
654 | for (int em = 0; em < items.count(); ++em) |
||
655 | { |
||
656 | PageItem* embedded = items.at(em); |
||
657 | ret.append(embedded); |
||
658 | if (embedded->isGroup()) |
||
22224 | jghali | 659 | ret += embedded->getAllChildren(); |
16105 | fschmid | 660 | } |
661 | return ret; |
||
662 | } |
||
10532 | avox | 663 | |
16594 | fschmid | 664 | QList<PageItem*> *ScribusDoc::parentGroup(PageItem* item, QList<PageItem*> *list) |
665 | { |
||
22505 | craig | 666 | QList<PageItem*> *retList = nullptr; |
16594 | fschmid | 667 | if (list->contains(item)) |
668 | retList = list; |
||
669 | else |
||
670 | { |
||
21394 | craig | 671 | for (int i = 0; i < list->count(); ++i) |
16594 | fschmid | 672 | { |
21394 | craig | 673 | PageItem* embedded = list->at(i); |
16594 | fschmid | 674 | if (embedded->isGroup()) |
675 | { |
||
676 | retList = parentGroup(item, &embedded->asGroupFrame()->groupItemList); |
||
22505 | craig | 677 | if (retList != nullptr) |
16594 | fschmid | 678 | break; |
679 | } |
||
680 | } |
||
681 | } |
||
682 | return retList; |
||
683 | } |
||
684 | |||
23185 | jghali | 685 | void ScribusDoc::setup(int unitIndex, int fp, int firstLeft, int orientation, int firstPageNumber, const QString& defaultPageSize, const QString& documentName) |
2891 | cbradney | 686 | { |
20691 | craig | 687 | m_docPrefsData.docSetupPrefs.docUnitIndex=unitIndex; |
14924 | cbradney | 688 | setPageSetFirstPage(fp, firstLeft); |
20691 | craig | 689 | m_docPrefsData.docSetupPrefs.pageOrientation = orientation; |
690 | m_docPrefsData.docSetupPrefs.pageSize = defaultPageSize; |
||
2891 | cbradney | 691 | FirstPnum = firstPageNumber; |
20691 | craig | 692 | m_docPrefsData.docSetupPrefs.pagePositioning = fp; |
22832 | craig | 693 | setDocumentFileName(documentName); |
5880 | jghali | 694 | HasCMS = false; |
14925 | cbradney | 695 | if (!pdfOptions().UseLPI) |
4039 | fschmid | 696 | { |
14925 | cbradney | 697 | pdfOptions().LPISettings.clear(); |
4039 | fschmid | 698 | struct LPIData lpo; |
11726 | cbradney | 699 | lpo.Frequency = 133; |
11720 | cbradney | 700 | lpo.SpotFunc = 3; |
4039 | fschmid | 701 | lpo.Angle = 105; |
14925 | cbradney | 702 | pdfOptions().LPISettings.insert("Cyan", lpo); |
4039 | fschmid | 703 | lpo.Angle = 75; |
14925 | cbradney | 704 | pdfOptions().LPISettings.insert("Magenta", lpo); |
4039 | fschmid | 705 | lpo.Angle = 90; |
14925 | cbradney | 706 | pdfOptions().LPISettings.insert("Yellow", lpo); |
4039 | fschmid | 707 | lpo.Angle = 45; |
14925 | cbradney | 708 | pdfOptions().LPISettings.insert("Black", lpo); |
20691 | craig | 709 | m_ActiveLayer = 0; |
4039 | fschmid | 710 | } |
3201 | subik | 711 | |
2891 | cbradney | 712 | appMode = modeNormal; |
23060 | craig | 713 | PrefsManager& prefsManager=PrefsManager::instance(); |
14150 | fschmid | 714 | |
23060 | craig | 715 | m_docPrefsData.colorPrefs.DCMSset = prefsManager.appPrefs.colorPrefs.DCMSset; |
20691 | craig | 716 | m_docPrefsData.pdfPrefs.SolidProf = m_docPrefsData.colorPrefs.DCMSset.DefaultSolidColorRGBProfile; |
717 | m_docPrefsData.pdfPrefs.ImageProf = m_docPrefsData.colorPrefs.DCMSset.DefaultImageRGBProfile; |
||
718 | m_docPrefsData.pdfPrefs.PrintProf = m_docPrefsData.colorPrefs.DCMSset.DefaultPrinterProfile; |
||
719 | m_docPrefsData.pdfPrefs.Intent = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentColors; |
||
720 | m_docPrefsData.pdfPrefs.Intent2 = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentImages; |
||
721 | BlackPoint = m_docPrefsData.colorPrefs.DCMSset.BlackPoint; |
||
722 | SoftProofing = m_docPrefsData.colorPrefs.DCMSset.SoftProofOn; |
||
723 | Gamut = m_docPrefsData.colorPrefs.DCMSset.GamutCheck; |
||
724 | IntentColors = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentColors; |
||
725 | IntentImages = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentImages; |
||
726 | if (ScCore->haveCMS() && m_docPrefsData.colorPrefs.DCMSset.CMSinUse) |
||
2891 | cbradney | 727 | { |
5345 | mrdocs | 728 | if (OpenCMSProfiles(ScCore->InputProfiles, ScCore->InputProfilesCMYK, ScCore->MonitorProfiles, ScCore->PrinterProfiles)) |
5178 | mrdocs | 729 | { |
5880 | jghali | 730 | HasCMS = true; |
20691 | craig | 731 | pdfOptions().SComp = m_docPrefsData.colorPrefs.DCMSset.ComponentsInput2; |
5178 | mrdocs | 732 | } |
733 | else |
||
10338 | jghali | 734 | { |
735 | SetDefaultCMSParams(); |
||
5880 | jghali | 736 | HasCMS = false; |
10338 | jghali | 737 | } |
2891 | cbradney | 738 | } |
739 | } |
||
740 | |||
10532 | avox | 741 | |
5824 | cbradney | 742 | void ScribusDoc::setGUI(bool hasgui, ScribusMainWindow* mw, ScribusView* view) |
5781 | cbradney | 743 | { |
5824 | cbradney | 744 | m_hasGUI = hasgui; |
14681 | fschmid | 745 | m_ScMW = mw; |
10532 | avox | 746 | //FIXME: stop using m_View |
14681 | fschmid | 747 | m_View = view; |
20497 | jghali | 748 | } |
749 | |||
750 | void ScribusDoc::createHyphenator() |
||
751 | { |
||
14681 | fschmid | 752 | if (m_hasGUI) |
753 | { |
||
20497 | jghali | 754 | if (docHyphenator) |
20535 | jghali | 755 | return; |
14681 | fschmid | 756 | docHyphenator = new Hyphenator(m_ScMW, this); |
757 | Q_CHECK_PTR(docHyphenator); |
||
758 | } |
||
759 | else |
||
22505 | craig | 760 | docHyphenator = nullptr; |
5781 | cbradney | 761 | } |
762 | |||
10532 | avox | 763 | |
23185 | jghali | 764 | void ScribusDoc::setLoading(bool docLoading) |
2891 | cbradney | 765 | { |
20691 | craig | 766 | m_loading = docLoading; |
2891 | cbradney | 767 | } |
768 | |||
10532 | avox | 769 | |
3985 | cbradney | 770 | bool ScribusDoc::isLoading() const |
2891 | cbradney | 771 | { |
20691 | craig | 772 | return m_loading; |
2891 | cbradney | 773 | } |
774 | |||
10532 | avox | 775 | |
776 | //AV: eeks. That should not be used |
||
4320 | cbradney | 777 | ScribusView* ScribusDoc::view() const |
778 | { |
||
5781 | cbradney | 779 | return m_View; |
4320 | cbradney | 780 | } |
781 | |||
10532 | avox | 782 | |
7906 | jghali | 783 | const ScGuardedPtr<ScribusDoc>& ScribusDoc::guardedPtr() const |
784 | { |
||
785 | return m_guardedObject; |
||
786 | } |
||
787 | |||
10532 | avox | 788 | |
1330 | fschmid | 789 | void ScribusDoc::CloseCMSProfiles() |
790 | { |
||
5880 | jghali | 791 | HasCMS = false; |
10338 | jghali | 792 | SetDefaultCMSParams(); |
1330 | fschmid | 793 | } |
794 | |||
10338 | jghali | 795 | void ScribusDoc::SetDefaultCMSParams() |
796 | { |
||
797 | BlackPoint = true; |
||
798 | SoftProofing = false; |
||
799 | Gamut = false; |
||
14170 | jghali | 800 | IntentColors = Intent_Relative_Colorimetric; |
801 | IntentImages = Intent_Relative_Colorimetric; |
||
10338 | jghali | 802 | DocInputRGBProf = ScCore->defaultRGBProfile; |
803 | DocInputCMYKProf = ScCore->defaultCMYKProfile; |
||
804 | DocInputImageRGBProf = ScCore->defaultRGBProfile; |
||
805 | DocInputImageCMYKProf = ScCore->defaultCMYKProfile; |
||
14281 | jghali | 806 | DocDisplayProf = ScCore->defaultRGBProfile; |
10338 | jghali | 807 | DocPrinterProf = ScCore->defaultCMYKProfile; |
808 | stdTransRGBMon = ScCore->defaultRGBToScreenSolidTrans; |
||
809 | stdTransCMYKMon = ScCore->defaultCMYKToRGBTrans; |
||
10393 | jghali | 810 | stdTransRGB = ScCore->defaultCMYKToRGBTrans; |
811 | stdTransCMYK = ScCore->defaultRGBToCMYKTrans; |
||
10338 | jghali | 812 | stdProof = ScCore->defaultRGBToScreenSolidTrans; |
813 | stdProofGC = ScCore->defaultRGBToScreenSolidTrans; |
||
814 | stdProofCMYK = ScCore->defaultCMYKToRGBTrans; |
||
815 | stdProofCMYKGC = ScCore->defaultCMYKToRGBTrans; |
||
816 | stdTransImg = ScCore->defaultRGBToScreenImageTrans; |
||
817 | stdProofImg = ScCore->defaultRGBToScreenImageTrans; |
||
818 | stdProofImgCMYK = ScCore->defaultCMYKToScreenImageTrans; |
||
20145 | fschmid | 819 | stdLabToRGBTrans = ScCore->defaultLabToRGBTrans; |
820 | stdLabToCMYKTrans = ScCore->defaultLabToCMYKTrans; |
||
22473 | jghali | 821 | stdLabToScreenTrans = ScCore->defaultLabToScreenTrans; |
20145 | fschmid | 822 | stdProofLab = ScCore->defaultLabToRGBTrans; |
823 | stdProofLabGC = ScCore->defaultLabToRGBTrans; |
||
10338 | jghali | 824 | } |
825 | |||
23272 | craig | 826 | bool ScribusDoc::OpenCMSProfiles(ProfilesL InPo, ProfilesL InPoCMYK, ProfilesL /*MoPo*/, ProfilesL PrPo) |
1330 | fschmid | 827 | { |
5880 | jghali | 828 | HasCMS = false; |
14170 | jghali | 829 | ScColorProfile inputProf; |
830 | |||
14491 | jghali | 831 | colorEngine = colorMgmtEngineFactory.createDefaultEngine(); |
832 | ScColorMgmtStrategy colorStrategy; |
||
23272 | craig | 833 | colorStrategy.setUseBlackPointCompensation(m_docPrefsData.colorPrefs.DCMSset.BlackPoint); |
834 | colorStrategy.setUseBlackPreservation(false); |
||
14170 | jghali | 835 | colorEngine.setStrategy(colorStrategy); |
836 | |||
14281 | jghali | 837 | DocDisplayProf = ScCore->monitorProfile; |
20691 | craig | 838 | DocInputRGBProf = colorEngine.openProfileFromFile( InPo[m_docPrefsData.colorPrefs.DCMSset.DefaultSolidColorRGBProfile] ); |
839 | DocInputCMYKProf = colorEngine.openProfileFromFile( InPoCMYK[m_docPrefsData.colorPrefs.DCMSset.DefaultSolidColorCMYKProfile] ); |
||
840 | DocPrinterProf = colorEngine.openProfileFromFile( PrPo[m_docPrefsData.colorPrefs.DCMSset.DefaultPrinterProfile] ); |
||
841 | DocInputImageRGBProf = colorEngine.openProfileFromFile( InPo[m_docPrefsData.colorPrefs.DCMSset.DefaultImageRGBProfile] ); |
||
842 | DocInputImageCMYKProf = colorEngine.openProfileFromFile( InPoCMYK[m_docPrefsData.colorPrefs.DCMSset.DefaultImageCMYKProfile] ); |
||
14281 | jghali | 843 | if ((!DocDisplayProf) || (!DocInputRGBProf) || (!DocInputCMYKProf) || (!DocPrinterProf) || (!DocInputImageCMYKProf) || (!DocInputImageRGBProf)) |
1330 | fschmid | 844 | { |
20691 | craig | 845 | m_docPrefsData.colorPrefs.DCMSset.CMSinUse = false; |
5178 | mrdocs | 846 | return false; |
1330 | fschmid | 847 | } |
14170 | jghali | 848 | |
849 | int dcmsFlags = 0; |
||
5369 | mrdocs | 850 | int dcmsFlagsGC = 0; |
20691 | craig | 851 | if (m_docPrefsData.colorPrefs.DCMSset.GamutCheck) |
14170 | jghali | 852 | dcmsFlagsGC |= Ctf_GamutCheck; |
20691 | craig | 853 | if (m_docPrefsData.colorPrefs.DCMSset.BlackPoint) |
1330 | fschmid | 854 | { |
14170 | jghali | 855 | dcmsFlags |= Ctf_BlackPointCompensation; |
856 | dcmsFlagsGC |= Ctf_BlackPointCompensation; |
||
1330 | fschmid | 857 | } |
14170 | jghali | 858 | stdTransRGBMon = colorEngine.createTransform(DocInputRGBProf, Format_RGB_16, |
14281 | jghali | 859 | DocDisplayProf, Format_RGB_16, |
14170 | jghali | 860 | IntentColors, dcmsFlags); |
861 | stdTransCMYKMon = colorEngine.createTransform(DocInputCMYKProf, Format_CMYK_16, |
||
14281 | jghali | 862 | DocDisplayProf, Format_RGB_16, |
14170 | jghali | 863 | IntentColors, dcmsFlags); |
5345 | mrdocs | 864 | // TODO : check input profiles used for images |
15128 | jghali | 865 | stdProofImg = colorEngine.createProofingTransform(DocInputImageRGBProf, Format_BGRA_8, |
866 | DocDisplayProf, Format_BGRA_8, DocPrinterProf, |
||
14170 | jghali | 867 | IntentImages, Intent_Relative_Colorimetric, dcmsFlagsGC); |
868 | stdProofImgCMYK = colorEngine.createProofingTransform(DocInputImageCMYKProf, Format_CMYK_8, |
||
15128 | jghali | 869 | DocDisplayProf, Format_BGRA_8, DocPrinterProf, |
14170 | jghali | 870 | IntentImages, Intent_Relative_Colorimetric, dcmsFlagsGC); |
15128 | jghali | 871 | stdTransImg = colorEngine.createTransform(DocInputRGBProf, Format_BGRA_8, |
872 | DocDisplayProf, Format_BGRA_8, |
||
14170 | jghali | 873 | IntentImages, dcmsFlags); |
874 | stdTransRGB = colorEngine.createTransform(DocInputCMYKProf, Format_CMYK_16, |
||
875 | DocInputRGBProf, Format_RGB_16, |
||
876 | IntentColors, dcmsFlags); |
||
877 | stdTransCMYK = colorEngine.createTransform(DocInputRGBProf, Format_RGB_16, |
||
878 | DocInputCMYKProf, Format_CMYK_16, |
||
879 | IntentColors, dcmsFlags); |
||
880 | |||
881 | ScColorProfile inputProfRGB; |
||
882 | ScColorProfile inputProfCMYK; |
||
14772 | jghali | 883 | if (DocPrinterProf.colorSpace() == ColorSpace_Cmyk) |
1491 | fschmid | 884 | { |
20691 | craig | 885 | inputProf = (m_docPrefsData.colorPrefs.DCMSset.SoftProofOn && m_docPrefsData.colorPrefs.DCMSset.SoftProofFullOn) ? DocInputCMYKProf : DocPrinterProf; |
6070 | jghali | 886 | inputProfRGB = DocInputRGBProf; |
887 | inputProfCMYK = inputProf; |
||
1491 | fschmid | 888 | } |
889 | else |
||
890 | { |
||
20691 | craig | 891 | inputProf = (m_docPrefsData.colorPrefs.DCMSset.SoftProofOn && m_docPrefsData.colorPrefs.DCMSset.SoftProofFullOn) ? DocInputRGBProf : DocPrinterProf; |
6070 | jghali | 892 | inputProfRGB = inputProf; |
893 | inputProfCMYK = DocInputCMYKProf; |
||
1491 | fschmid | 894 | } |
14170 | jghali | 895 | stdProof = colorEngine.createProofingTransform(inputProfRGB, Format_RGB_16, |
21394 | craig | 896 | DocDisplayProf, Format_RGB_16, |
897 | DocPrinterProf, |
||
898 | IntentColors, |
||
899 | Intent_Relative_Colorimetric, dcmsFlags); |
||
14170 | jghali | 900 | stdProofGC = colorEngine.createProofingTransform(inputProfRGB, Format_RGB_16, |
21394 | craig | 901 | DocDisplayProf, Format_RGB_16, |
902 | DocPrinterProf, IntentColors, |
||
903 | Intent_Relative_Colorimetric, dcmsFlags| Ctf_GamutCheck); |
||
14170 | jghali | 904 | stdProofCMYK = colorEngine.createProofingTransform(inputProfCMYK, Format_CMYK_16, |
14281 | jghali | 905 | DocDisplayProf, Format_RGB_16, |
14170 | jghali | 906 | DocPrinterProf, IntentColors, |
907 | Intent_Relative_Colorimetric, dcmsFlags); |
||
908 | stdProofCMYKGC = colorEngine.createProofingTransform(inputProfCMYK, Format_CMYK_16, |
||
14281 | jghali | 909 | DocDisplayProf, Format_RGB_16, |
6070 | jghali | 910 | DocPrinterProf, |
911 | IntentColors, |
||
14179 | jghali | 912 | Intent_Relative_Colorimetric, dcmsFlags | Ctf_GamutCheck); |
20145 | fschmid | 913 | stdProofLab = colorEngine.createProofingTransform(ScCore->defaultLabProfile, Format_Lab_Dbl, |
914 | DocDisplayProf, Format_RGB_16, |
||
915 | DocPrinterProf, |
||
916 | IntentColors, |
||
917 | Intent_Relative_Colorimetric, dcmsFlags); |
||
918 | stdProofLabGC = colorEngine.createProofingTransform(ScCore->defaultLabProfile, Format_Lab_Dbl, |
||
919 | DocDisplayProf, Format_RGB_16, |
||
920 | DocPrinterProf, IntentColors, |
||
921 | Intent_Relative_Colorimetric, dcmsFlags| Ctf_GamutCheck); |
||
6464 | jghali | 922 | |
14772 | jghali | 923 | if (DocInputRGBProf.colorSpace() == ColorSpace_Rgb) |
20691 | craig | 924 | m_docPrefsData.colorPrefs.DCMSset.ComponentsInput2 = 3; |
14772 | jghali | 925 | if (DocInputRGBProf.colorSpace() == ColorSpace_Cmyk) |
20691 | craig | 926 | m_docPrefsData.colorPrefs.DCMSset.ComponentsInput2 = 4; |
14772 | jghali | 927 | if (DocInputRGBProf.colorSpace() == ColorSpace_Cmy) |
20691 | craig | 928 | m_docPrefsData.colorPrefs.DCMSset.ComponentsInput2 = 3; |
6464 | jghali | 929 | |
22473 | jghali | 930 | stdLabToRGBTrans = colorEngine.createTransform(ScCore->defaultLabProfile, Format_Lab_Dbl, DocInputRGBProf, Format_RGB_16, Intent_Absolute_Colorimetric, dcmsFlags); |
931 | stdLabToCMYKTrans = colorEngine.createTransform(ScCore->defaultLabProfile, Format_Lab_Dbl, DocInputCMYKProf, Format_CMYK_16, Intent_Absolute_Colorimetric, dcmsFlags); |
||
932 | stdLabToScreenTrans = colorEngine.createTransform(ScCore->defaultLabProfile, Format_Lab_Dbl, DocDisplayProf, Format_RGB_16, Intent_Absolute_Colorimetric, dcmsFlags); |
||
933 | |||
21394 | craig | 934 | bool success = (stdTransRGBMon && stdTransCMYKMon && stdProofImg && stdProofImgCMYK && |
935 | stdTransImg && stdTransRGB && stdTransCMYK && stdProof && |
||
936 | stdProofGC && stdProofCMYK && stdProofCMYKGC && |
||
22473 | jghali | 937 | stdLabToRGBTrans && stdLabToCMYKTrans && stdLabToScreenTrans && stdProofLab && stdProofLabGC); |
14179 | jghali | 938 | if (!success) |
939 | { |
||
940 | CloseCMSProfiles(); |
||
20691 | craig | 941 | m_docPrefsData.colorPrefs.DCMSset.CMSinUse = false; |
14179 | jghali | 942 | QString message = tr("An error occurred while opening ICC profiles, color management is not enabled." ); |
19605 | jghali | 943 | ScMessageBox::warning(m_ScMW, CommonStrings::trWarning, message); |
14179 | jghali | 944 | } |
5178 | mrdocs | 945 | return true; |
1330 | fschmid | 946 | } |
947 | |||
10532 | avox | 948 | |
6726 | fschmid | 949 | void ScribusDoc::enableCMS(bool enable) |
950 | { |
||
951 | m_ScMW->setStatusBarInfoText( tr("Adjusting Colors")); |
||
952 | m_ScMW->mainWindowProgressBar->reset(); |
||
21394 | craig | 953 | int progressBarCount = PageColors.count() + MasterItems.count() + DocItems.count() + FrameItems.count(); |
954 | m_ScMW->mainWindowProgressBar->setMaximum(progressBarCount); |
||
18181 | fschmid | 955 | qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); |
20691 | craig | 956 | bool oldCM = m_docPrefsData.colorPrefs.DCMSset.CMSinUse; |
10726 | jghali | 957 | bool newCM = enable; |
958 | CloseCMSProfiles(); |
||
20691 | craig | 959 | m_docPrefsData.colorPrefs.DCMSset.CMSinUse = newCM; |
960 | HasCMS = m_docPrefsData.colorPrefs.DCMSset.CMSinUse; |
||
961 | BlackPoint = m_docPrefsData.colorPrefs.DCMSset.BlackPoint; |
||
962 | SoftProofing = m_docPrefsData.colorPrefs.DCMSset.SoftProofOn; |
||
963 | Gamut = m_docPrefsData.colorPrefs.DCMSset.GamutCheck; |
||
964 | IntentColors = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentColors; |
||
965 | IntentImages = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentImages; |
||
966 | if (!m_docPrefsData.colorPrefs.DCMSset.CMSinUse) |
||
6726 | fschmid | 967 | { |
968 | HasCMS = false; |
||
21394 | craig | 969 | if (oldCM) |
6726 | fschmid | 970 | { |
22561 | craig | 971 | m_ScMW->recalcColors(); |
6726 | fschmid | 972 | RecalcPictures(&ScCore->InputProfiles, &ScCore->InputProfilesCMYK, m_ScMW->mainWindowProgressBar); |
973 | } |
||
974 | } |
||
975 | else if (OpenCMSProfiles(ScCore->InputProfiles, ScCore->InputProfilesCMYK, ScCore->MonitorProfiles, ScCore->PrinterProfiles) ) |
||
976 | { |
||
977 | HasCMS = true; |
||
20691 | craig | 978 | m_docPrefsData.pdfPrefs.SComp = m_docPrefsData.colorPrefs.DCMSset.ComponentsInput2; |
979 | m_docPrefsData.pdfPrefs.SolidProf = m_docPrefsData.colorPrefs.DCMSset.DefaultSolidColorRGBProfile; |
||
980 | m_docPrefsData.pdfPrefs.ImageProf = m_docPrefsData.colorPrefs.DCMSset.DefaultImageRGBProfile; |
||
981 | m_docPrefsData.pdfPrefs.PrintProf = m_docPrefsData.colorPrefs.DCMSset.DefaultPrinterProfile; |
||
982 | m_docPrefsData.pdfPrefs.Intent = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentColors; |
||
983 | m_docPrefsData.pdfPrefs.Intent2 = m_docPrefsData.colorPrefs.DCMSset.DefaultIntentImages; |
||
22561 | craig | 984 | m_ScMW->recalcColors(); |
6726 | fschmid | 985 | RecalcPictures(&ScCore->InputProfiles, &ScCore->InputProfilesCMYK, m_ScMW->mainWindowProgressBar); |
986 | } |
||
987 | else |
||
10338 | jghali | 988 | { |
989 | SetDefaultCMSParams(); |
||
6726 | fschmid | 990 | HasCMS = false; |
10338 | jghali | 991 | } |
21394 | craig | 992 | m_ScMW->mainWindowProgressBar->setValue(progressBarCount); |
18181 | fschmid | 993 | qApp->restoreOverrideCursor(); |
6726 | fschmid | 994 | m_ScMW->setStatusBarInfoText(""); |
995 | m_ScMW->mainWindowProgressBar->reset(); |
||
996 | } |
||
7442 | avox | 997 | |
998 | |||
8455 | avox | 999 | void ScribusDoc::getNamedResources(ResourceCollection& lists) const |
1000 | { |
||
8776 | cbradney | 1001 | lists.availableFonts = AllFonts; |
8775 | cbradney | 1002 | lists.availableColors = const_cast<ColorList*>(& PageColors); |
1003 | |||
9856 | fschmid | 1004 | const QList<PageItem*> * itemlist = & MasterItems; |
22505 | craig | 1005 | while (itemlist != nullptr) |
8455 | avox | 1006 | { |
9856 | fschmid | 1007 | for (int i=0; i < itemlist->count(); ++i) |
8455 | avox | 1008 | { |
9856 | fschmid | 1009 | const PageItem * currItem = const_cast<QList<PageItem*>*>(itemlist)->at(i); |
8455 | avox | 1010 | if (currItem) |
9296 | jghali | 1011 | currItem->getNamedResources(lists); |
8455 | avox | 1012 | } |
1013 | if (itemlist == &MasterItems) |
||
1014 | itemlist = &DocItems; |
||
1015 | else |
||
22505 | craig | 1016 | itemlist = nullptr; |
8455 | avox | 1017 | } |
17407 | fschmid | 1018 | for (QHash<int, PageItem*>::const_iterator itf = FrameItems.begin(); itf != FrameItems.end(); ++itf) |
1019 | { |
||
1020 | PageItem *currItem = itf.value(); |
||
1021 | if (currItem) |
||
1022 | currItem->getNamedResources(lists); |
||
1023 | } |
||
20691 | craig | 1024 | for (int i = 0; i < m_docParagraphStyles.count(); ++i) |
1025 | m_docParagraphStyles[i].getNamedResources(lists); |
||
1026 | for (int i = 0; i < m_docCharStyles.count(); ++i) |
||
1027 | m_docCharStyles[i].getNamedResources(lists); |
||
1028 | for (int i = 0; i < m_docTableStyles.count(); ++i) |
||
1029 | m_docTableStyles[i].getNamedResources(lists); |
||
1030 | for (int i = 0; i < m_docCellStyles.count(); ++i) |
||
1031 | m_docCellStyles[i].getNamedResources(lists); |
||
8455 | avox | 1032 | |
17400 | fschmid | 1033 | QHash<QString,ScPattern>::ConstIterator it; |
8455 | avox | 1034 | for (it = docPatterns.begin(); it != docPatterns.end(); ++it) |
1035 | { |
||
1036 | ScPattern pa = *it; |
||
9856 | fschmid | 1037 | for (int o = 0; o < pa.items.count(); o++) |
8455 | avox | 1038 | { |
1039 | pa.items.at(o)->getNamedResources(lists); |
||
1040 | } |
||
14813 | fschmid | 1041 | } |
17400 | fschmid | 1042 | QHash<QString,VGradient>::ConstIterator itg; |
14813 | fschmid | 1043 | for (itg = docGradients.begin(); itg != docGradients.end(); ++itg) |
1044 | { |
||
1045 | QList<VColorStop*> cstops = itg.value().colorStops(); |
||
22725 | jghali | 1046 | for (int cst = 0; cst < itg.value().stops(); ++cst) |
14813 | fschmid | 1047 | { |
1048 | lists.collectColor(cstops.at(cst)->name); |
||
1049 | } |
||
1050 | } |
||
8455 | avox | 1051 | } |
1052 | |||
22553 | craig | 1053 | bool ScribusDoc::styleExists(const QString& styleName) |
16386 | fschmid | 1054 | { |
19582 | craig | 1055 | for (int i = 0; i < paragraphStyles().count(); ++i) |
16386 | fschmid | 1056 | { |
19582 | craig | 1057 | if (paragraphStyles()[i].name() == styleName) |
16386 | fschmid | 1058 | return true; |
1059 | } |
||
1060 | return false; |
||
1061 | } |
||
8455 | avox | 1062 | |
16396 | fschmid | 1063 | QList<int> ScribusDoc::getSortedStyleList() |
1064 | { |
||
1065 | QList<int> retList; |
||
20691 | craig | 1066 | for (int i = 0; i < m_docParagraphStyles.count(); ++i) |
16396 | fschmid | 1067 | { |
20691 | craig | 1068 | if (m_docParagraphStyles[i].parent().isEmpty()) |
16396 | fschmid | 1069 | { |
19582 | craig | 1070 | if (!retList.contains(i)) |
1071 | retList.append(i); |
||
16692 | jghali | 1072 | continue; |
16396 | fschmid | 1073 | } |
16692 | jghali | 1074 | |
1075 | QList<int> retList2; |
||
20691 | craig | 1076 | QString name = m_docParagraphStyles[i].name(); |
1077 | QString par = m_docParagraphStyles[i].parent(); |
||
19582 | craig | 1078 | retList2.prepend(i); |
16692 | jghali | 1079 | while ((!par.isEmpty()) && (par != name)) |
16396 | fschmid | 1080 | { |
20691 | craig | 1081 | int pp = m_docParagraphStyles.find(par); |
16692 | jghali | 1082 | if ((pp >= 0) && (!retList2.contains(pp))) |
1083 | retList2.prepend(pp); |
||
20691 | craig | 1084 | par = (pp >= 0) ? m_docParagraphStyles[pp].parent() : QString(); |
16396 | fschmid | 1085 | } |
16692 | jghali | 1086 | for (int r = 0; r < retList2.count(); ++r) |
1087 | { |
||
1088 | if (!retList.contains(retList2[r])) |
||
1089 | retList.append(retList2[r]); |
||
1090 | } |
||
16396 | fschmid | 1091 | } |
1092 | return retList; |
||
1093 | } |
||
16386 | fschmid | 1094 | |
16396 | fschmid | 1095 | QList<int> ScribusDoc::getSortedCharStyleList() |
1096 | { |
||
1097 | QList<int> retList; |
||
20691 | craig | 1098 | for (int i = 0; i < m_docCharStyles.count(); ++i) |
16396 | fschmid | 1099 | { |
20691 | craig | 1100 | if (m_docCharStyles[i].parent().isEmpty()) |
16396 | fschmid | 1101 | { |
19582 | craig | 1102 | if (!retList.contains(i)) |
1103 | retList.append(i); |
||
16692 | jghali | 1104 | continue; |
16396 | fschmid | 1105 | } |
16692 | jghali | 1106 | |
1107 | QList<int> retList2; |
||
20691 | craig | 1108 | QString name = m_docCharStyles[i].name(); |
1109 | QString par = m_docCharStyles[i].parent(); |
||
19582 | craig | 1110 | retList2.prepend(i); |
16692 | jghali | 1111 | while ((!par.isEmpty()) && (par != name)) |
16396 | fschmid | 1112 | { |
20691 | craig | 1113 | int pp = m_docCharStyles.find(par); |
16692 | jghali | 1114 | if ((pp >= 0) && (!retList2.contains(pp))) |
1115 | retList2.prepend(pp); |
||
20691 | craig | 1116 | par = (pp >= 0) ? m_docCharStyles[pp].parent() : QString(); |
16396 | fschmid | 1117 | } |
16692 | jghali | 1118 | for (int r = 0; r < retList2.count(); ++r) |
1119 | { |
||
1120 | if (!retList.contains(retList2[r])) |
||
1121 | retList.append(retList2[r]); |
||
1122 | } |
||
16396 | fschmid | 1123 | } |
1124 | return retList; |
||
1125 | } |
||
1126 | |||
16859 | craig | 1127 | QList<int> ScribusDoc::getSortedTableStyleList() |
1128 | { |
||
1129 | QList<int> retList; |
||
20691 | craig | 1130 | for (int i = 0; i < m_docTableStyles.count(); ++i) |
16859 | craig | 1131 | { |
20691 | craig | 1132 | if (m_docTableStyles[i].parent().isEmpty()) |
16859 | craig | 1133 | { |
19582 | craig | 1134 | if (!retList.contains(i)) |
1135 | retList.append(i); |
||
16859 | craig | 1136 | continue; |
1137 | } |
||
1138 | |||
1139 | QList<int> retList2; |
||
20691 | craig | 1140 | QString name = m_docTableStyles[i].name(); |
1141 | QString par = m_docTableStyles[i].parent(); |
||
19582 | craig | 1142 | retList2.prepend(i); |
16859 | craig | 1143 | while ((!par.isEmpty()) && (par != name)) |
1144 | { |
||
20691 | craig | 1145 | int pp = m_docTableStyles.find(par); |
16859 | craig | 1146 | if ((pp >= 0) && (!retList2.contains(pp))) |
1147 | retList2.prepend(pp); |
||
20691 | craig | 1148 | par = (pp >= 0) ? m_docTableStyles[pp].parent() : QString(); |
16859 | craig | 1149 | } |
1150 | for (int r = 0; r < retList2.count(); ++r) |
||
1151 | { |
||
1152 | if (!retList.contains(retList2[r])) |
||
1153 | retList.append(retList2[r]); |
||
1154 | } |
||
1155 | } |
||
1156 | return retList; |
||
1157 | } |
||
1158 | |||
1159 | QList<int> ScribusDoc::getSortedCellStyleList() |
||
1160 | { |
||
1161 | QList<int> retList; |
||
20691 | craig | 1162 | for (int i = 0; i < m_docCellStyles.count(); ++i) |
16859 | craig | 1163 | { |
20691 | craig | 1164 | if (m_docCellStyles[i].parent().isEmpty()) |
16859 | craig | 1165 | { |
19582 | craig | 1166 | if (!retList.contains(i)) |
1167 | retList.append(i); |
||
16859 | craig | 1168 | continue; |
1169 | } |
||
1170 | |||
1171 | QList<int> retList2; |
||
20691 | craig | 1172 | QString name = m_docCellStyles[i].name(); |
1173 | QString par = m_docCellStyles[i].parent(); |
||
19582 | craig | 1174 | retList2.prepend(i); |
16859 | craig | 1175 | while ((!par.isEmpty()) && (par != name)) |
1176 | { |
||
20691 | craig | 1177 | int pp = m_docCellStyles.find(par); |
16859 | craig | 1178 | if ((pp >= 0) && (!retList2.contains(pp))) |
1179 | retList2.prepend(pp); |
||
20691 | craig | 1180 | par = (pp >= 0) ? m_docCellStyles[pp].parent() : QString(); |
16859 | craig | 1181 | } |
1182 | for (int r = 0; r < retList2.count(); ++r) |
||
1183 | { |
||
1184 | if (!retList.contains(retList2[r])) |
||
1185 | retList.append(retList2[r]); |
||
1186 | } |
||
1187 | } |
||
1188 | return retList; |
||
1189 | } |
||
1190 | |||
7947 | cbradney | 1191 | void ScribusDoc::replaceStyles(const QMap<QString,QString>& newNameForOld) |
7442 | avox | 1192 | { |
8455 | avox | 1193 | ResourceCollection newNames; |
8775 | cbradney | 1194 | newNames.mapStyles(newNameForOld); |
8455 | avox | 1195 | replaceNamedResources(newNames); |
1196 | } |
||
1197 | |||
1198 | void ScribusDoc::replaceNamedResources(ResourceCollection& newNames) |
||
1199 | { |
||
7595 | avox | 1200 | // replace names in items |
9856 | fschmid | 1201 | QList<PageItem*> * itemlist = & MasterItems; |
22505 | craig | 1202 | while (itemlist != nullptr) |
7442 | avox | 1203 | { |
9856 | fschmid | 1204 | for (int i=0; i < itemlist->count(); ++i) |
7442 | avox | 1205 | { |
9433 | jghali | 1206 | PageItem * currItem = itemlist->at(i); |
7442 | avox | 1207 | if (currItem) |
9433 | jghali | 1208 | currItem->replaceNamedResources(newNames); |
7442 | avox | 1209 | } |
1210 | if (itemlist == &MasterItems) |
||
1211 | itemlist = &DocItems; |
||
1212 | else |
||
22505 | craig | 1213 | itemlist = nullptr; |
7442 | avox | 1214 | } |
17826 | craig | 1215 | foreach (NotesStyle* nStyle, m_docNotesStylesList) |
1216 | { //update styles names in notes styles |
||
22505 | craig | 1217 | if (nStyle == nullptr) |
17826 | craig | 1218 | continue; |
1219 | if (newNames.styles().contains(nStyle->notesParStyle())) |
||
1220 | nStyle->setNotesParStyle(newNames.styles().value(nStyle->notesParStyle())); |
||
1221 | if (newNames.charStyles().contains(nStyle->marksChStyle())) |
||
1222 | nStyle->setMarksCharStyle(newNames.charStyles().value(nStyle->marksChStyle())); |
||
1223 | } |
||
22509 | jghali | 1224 | for (auto itf = FrameItems.begin(); itf != FrameItems.end(); ++itf) |
17407 | fschmid | 1225 | { |
1226 | PageItem *currItem = itf.value(); |
||
1227 | if (currItem) |
||
1228 | currItem->replaceNamedResources(newNames); |
||
1229 | } |
||
7595 | avox | 1230 | // replace names in styles... |
20691 | craig | 1231 | for (int i=m_docParagraphStyles.count()-1; i >= 0; --i) |
7595 | avox | 1232 | { |
20691 | craig | 1233 | if (newNames.styles().contains(m_docParagraphStyles[i].name())) |
1234 | m_docParagraphStyles.remove(i); |
||
8814 | cbradney | 1235 | else |
20691 | craig | 1236 | m_docParagraphStyles[i].replaceNamedResources(newNames); |
8455 | avox | 1237 | } |
20691 | craig | 1238 | for (int i=m_docCharStyles.count()-1; i >= 0; --i) |
8455 | avox | 1239 | { |
20691 | craig | 1240 | if (newNames.charStyles().contains(m_docCharStyles[i].name())) |
1241 | m_docCharStyles.remove(i); |
||
8814 | cbradney | 1242 | else |
20691 | craig | 1243 | m_docCharStyles[i].replaceNamedResources(newNames); |
8455 | avox | 1244 | } |
20691 | craig | 1245 | for (int i = m_docTableStyles.count() - 1; i >= 0; --i) |
16856 | craig | 1246 | { |
20691 | craig | 1247 | if (newNames.tableStyles().contains(m_docTableStyles[i].name())) |
1248 | m_docTableStyles.remove(i); |
||
16856 | craig | 1249 | else |
20691 | craig | 1250 | m_docTableStyles[i].replaceNamedResources(newNames); |
16856 | craig | 1251 | } |
20691 | craig | 1252 | for (int i = m_docCellStyles.count() - 1; i >= 0; --i) |
16856 | craig | 1253 | { |
20691 | craig | 1254 | if (newNames.cellStyles().contains(m_docCellStyles[i].name())) |
1255 | m_docCellStyles.remove(i); |
||
16856 | craig | 1256 | else |
20691 | craig | 1257 | m_docCellStyles[i].replaceNamedResources(newNames); |
16856 | craig | 1258 | } |
8455 | avox | 1259 | |
22137 | jghali | 1260 | QHash<QString,ScPattern>::Iterator it = docPatterns.begin(); |
1261 | while (it != docPatterns.end()) |
||
8455 | avox | 1262 | { |
8814 | cbradney | 1263 | if (newNames.patterns().contains(it.key())) |
8455 | avox | 1264 | { |
22137 | jghali | 1265 | it = docPatterns.erase(it); |
1266 | continue; |
||
8058 | avox | 1267 | } |
22137 | jghali | 1268 | |
1269 | ScPattern pa = *it; |
||
1270 | for (int o = 0; o < pa.items.count(); o++) |
||
1271 | { |
||
1272 | pa.items.at(o)->replaceNamedResources(newNames); |
||
1273 | } |
||
1274 | ++it; |
||
8772 | cbradney | 1275 | } |
14150 | fschmid | 1276 | |
22137 | jghali | 1277 | QHash<QString,VGradient>::Iterator itg = docGradients.begin(); |
1278 | while (itg != docGradients.end()) |
||
14150 | fschmid | 1279 | { |
1280 | if (newNames.gradients().contains(itg.key())) |
||
1281 | { |
||
22137 | jghali | 1282 | itg = docGradients.erase(itg); |
1283 | continue; |
||
1284 | } |
||
1285 | |||
1286 | QMap<QString,QString>::ConstIterator itc; |
||
1287 | QList<VColorStop*> cstops = itg.value().colorStops(); |
||
22725 | jghali | 1288 | for (int cst = 0; cst < itg.value().stops(); ++cst) |
22137 | jghali | 1289 | { |
1290 | itc = newNames.colors().find(cstops.at(cst)->name); |
||
1291 | if (itc != newNames.colors().end()) |
||
14150 | fschmid | 1292 | { |
22137 | jghali | 1293 | if (*itc != CommonStrings::None) |
1294 | cstops.at(cst)->name = *itc; |
||
14150 | fschmid | 1295 | } |
1296 | } |
||
22137 | jghali | 1297 | ++itg; |
14150 | fschmid | 1298 | } |
8772 | cbradney | 1299 | |
8783 | cbradney | 1300 | if (newNames.colors().count() > 0 || newNames.fonts().count() > 0) |
1301 | { |
||
20691 | craig | 1302 | m_docCharStyles.invalidate(); |
1303 | m_docParagraphStyles.invalidate(); |
||
1304 | m_docTableStyles.invalidate(); |
||
1305 | m_docCellStyles.invalidate(); |
||
8783 | cbradney | 1306 | } |
1307 | else |
||
1308 | { |
||
1309 | if (newNames.charStyles().count() > 0) |
||
20691 | craig | 1310 | m_docCharStyles.invalidate(); |
8783 | cbradney | 1311 | if (newNames.styles().count() > 0) |
20691 | craig | 1312 | m_docParagraphStyles.invalidate(); |
16856 | craig | 1313 | if (newNames.tableStyles().count() > 0) |
20691 | craig | 1314 | m_docTableStyles.invalidate(); |
16856 | craig | 1315 | if (newNames.cellStyles().count() > 0) |
20691 | craig | 1316 | m_docCellStyles.invalidate(); |
8783 | cbradney | 1317 | } |
8916 | avox | 1318 | if (!isLoading() && !(newNames.colors().isEmpty() && newNames.fonts().isEmpty() && newNames.patterns().isEmpty() |
16856 | craig | 1319 | && newNames.styles().isEmpty() && newNames.charStyles().isEmpty() && newNames.lineStyles().isEmpty() |
1320 | && newNames.tableStyles().isEmpty() && newNames.cellStyles().isEmpty())) |
||
8916 | avox | 1321 | changed(); |
7442 | avox | 1322 | } |
1323 | |||
1324 | |||
7947 | cbradney | 1325 | void ScribusDoc::replaceCharStyles(const QMap<QString,QString>& newNameForOld) |
7442 | avox | 1326 | { |
8455 | avox | 1327 | ResourceCollection newNames; |
8775 | cbradney | 1328 | newNames.mapCharStyles(newNameForOld); |
8455 | avox | 1329 | replaceNamedResources(newNames); |
7442 | avox | 1330 | } |
1331 | |||
16856 | craig | 1332 | void ScribusDoc::replaceTableStyles(const QMap<QString, QString>& newNameForOld) |
1333 | { |
||
1334 | ResourceCollection newNames; |
||
1335 | newNames.mapTableStyles(newNameForOld); |
||
1336 | replaceNamedResources(newNames); |
||
1337 | } |
||
10532 | avox | 1338 | |
16856 | craig | 1339 | void ScribusDoc::replaceCellStyles(const QMap<QString, QString>& newNameForOld) |
1340 | { |
||
1341 | ResourceCollection newNames; |
||
1342 | newNames.mapCellStyles(newNameForOld); |
||
1343 | replaceNamedResources(newNames); |
||
1344 | } |
||
1345 | |||
7595 | avox | 1346 | void ScribusDoc::redefineStyles(const StyleSet<ParagraphStyle>& newStyles, bool removeUnused) |
1347 | { |
||
20691 | craig | 1348 | m_docParagraphStyles.redefine(newStyles, false); |
7595 | avox | 1349 | if (removeUnused) |
1350 | { |
||
1351 | QMap<QString, QString> deletion; |
||
1352 | QString deflt(""); |
||
20691 | craig | 1353 | for (int i=0; i < m_docParagraphStyles.count(); ++i) |
7595 | avox | 1354 | { |
20691 | craig | 1355 | const QString& nam(m_docParagraphStyles[i].name()); |
7595 | avox | 1356 | if (newStyles.find(nam) < 0) |
1357 | deletion[nam] = deflt; |
||
1358 | } |
||
1359 | if (deletion.count() > 0) |
||
1360 | replaceStyles(deletion); |
||
1361 | } |
||
8134 | avox | 1362 | // repair charstyle context: |
20691 | craig | 1363 | for (int i=0; i < m_docParagraphStyles.count(); ++i) |
8058 | avox | 1364 | { |
20691 | craig | 1365 | ParagraphStyle& sty(m_docParagraphStyles[i]); |
1366 | if (m_docParagraphStyles.isDefault(sty)) |
||
8058 | avox | 1367 | { |
1368 | sty.breakImplicitCharStyleInheritance(true); |
||
20691 | craig | 1369 | sty.charStyle().setContext( & m_docCharStyles ); |
8058 | avox | 1370 | } |
1371 | else { |
||
1372 | sty.breakImplicitCharStyleInheritance(false); |
||
1373 | } |
||
1374 | } |
||
20691 | craig | 1375 | m_docParagraphStyles.invalidate(); |
18047 | craig | 1376 | if (!isLoading()) |
1377 | { |
||
1378 | flag_Renumber = true; |
||
1379 | flag_NumUpdateRequest = true; |
||
1380 | } |
||
7595 | avox | 1381 | } |
1382 | |||
1383 | void ScribusDoc::redefineCharStyles(const StyleSet<CharStyle>& newStyles, bool removeUnused) |
||
1384 | { |
||
20691 | craig | 1385 | m_docCharStyles.redefine(newStyles, false); |
7595 | avox | 1386 | if (removeUnused) |
1387 | { |
||
1388 | QMap<QString, QString> deletion; |
||
1389 | QString deflt(""); |
||
20691 | craig | 1390 | for (int i=0; i < m_docCharStyles.count(); ++i) |
7595 | avox | 1391 | { |
20691 | craig | 1392 | const QString& nam(m_docCharStyles[i].name()); |
7595 | avox | 1393 | if (newStyles.find(nam) < 0) |
8772 | cbradney | 1394 | { |
7595 | avox | 1395 | deletion[nam] = deflt; |
8772 | cbradney | 1396 | } |
7595 | avox | 1397 | } |
1398 | if (deletion.count() > 0) |
||
1399 | replaceCharStyles(deletion); |
||
1400 | } |
||
20691 | craig | 1401 | m_docCharStyles.invalidate(); |
7595 | avox | 1402 | } |
1403 | |||
16856 | craig | 1404 | void ScribusDoc::redefineTableStyles(const StyleSet<TableStyle>& newStyles, bool removeUnused) |
1405 | { |
||
20691 | craig | 1406 | m_docTableStyles.redefine(newStyles, false); |
16856 | craig | 1407 | if (removeUnused) |
1408 | { |
||
1409 | QMap<QString, QString> deletion; |
||
1410 | QString deflt(""); |
||
20691 | craig | 1411 | for (int i = 0; i < m_docTableStyles.count(); ++i) |
16856 | craig | 1412 | { |
20691 | craig | 1413 | const QString& nam(m_docTableStyles[i].name()); |
16856 | craig | 1414 | if (newStyles.find(nam) < 0) |
1415 | { |
||
1416 | deletion[nam] = deflt; |
||
1417 | } |
||
1418 | } |
||
1419 | if (deletion.count() > 0) |
||
1420 | replaceTableStyles(deletion); |
||
1421 | } |
||
20691 | craig | 1422 | m_docTableStyles.invalidate(); |
16856 | craig | 1423 | } |
8274 | tsoots | 1424 | |
16856 | craig | 1425 | void ScribusDoc::redefineCellStyles(const StyleSet<CellStyle>& newStyles, bool removeUnused) |
1426 | { |
||
20691 | craig | 1427 | m_docCellStyles.redefine(newStyles, false); |
16856 | craig | 1428 | if (removeUnused) |
1429 | { |
||
1430 | QMap<QString, QString> deletion; |
||
1431 | QString deflt(""); |
||
20691 | craig | 1432 | for (int i = 0; i < m_docCellStyles.count(); ++i) |
16856 | craig | 1433 | { |
20691 | craig | 1434 | const QString& nam(m_docCellStyles[i].name()); |
16856 | craig | 1435 | if (newStyles.find(nam) < 0) |
1436 | { |
||
1437 | deletion[nam] = deflt; |
||
1438 | } |
||
1439 | } |
||
1440 | if (deletion.count() > 0) |
||
1441 | replaceCellStyles(deletion); |
||
1442 | } |
||
20691 | craig | 1443 | m_docCellStyles.invalidate(); |
16856 | craig | 1444 | } |
1445 | |||
456 | fschmid | 1446 | /* |
1447 | * Split out from loadStyles in editFormats.cpp so it's callable from anywhere, |
||
1448 | * including plugins. |
||
1449 | * - 2004-09-14 Craig Ringer |
||
1450 | */ |
||
20681 | craig | 1451 | // don't like this here. could as well be a static method for reading this stuff into temp., then always use redefineXY() - av |
22505 | craig | 1452 | void ScribusDoc::loadStylesFromFile(const QString& fileName) |
12548 | pierre | 1453 | { |
20691 | craig | 1454 | StyleSet<ParagraphStyle> *wrkStyles = &m_docParagraphStyles; |
1455 | StyleSet<CharStyle> *wrkCharStyles = &m_docCharStyles; |
||
17400 | fschmid | 1456 | QHash<QString, multiLine> *wrkLineStyles = &MLineStyles; |
12548 | pierre | 1457 | |
1458 | int oldStyles = wrkStyles->count(); |
||
1459 | int oldCharStyles = wrkCharStyles->count(); |
||
1460 | int oldLineStyles = wrkLineStyles->count(); |
||
1461 | |||
1462 | if (!fileName.isEmpty()) |
||
1463 | { |
||
1464 | FileLoader fl(fileName); |
||
17326 | jghali | 1465 | if (fl.testFile() == -1) |
12548 | pierre | 1466 | //TODO put in nice user warning |
1467 | return; |
||
1468 | |||
17326 | jghali | 1469 | if (!fl.readStyles(this, *wrkStyles)) |
12548 | pierre | 1470 | { |
1471 | //TODO put in nice user warning |
||
1472 | } |
||
1473 | |||
17326 | jghali | 1474 | if (!fl.readCharStyles(this, *wrkCharStyles)) |
12548 | pierre | 1475 | { |
1476 | //TODO put in nice user warning |
||
1477 | } |
||
1478 | |||
17326 | jghali | 1479 | if (!fl.readLineStyles(wrkLineStyles)) |
12548 | pierre | 1480 | { |
1481 | //TODO put in nice user warning |
||
1482 | } |
||
1483 | |||
1484 | if ( !isLoading() && ((wrkStyles->count() > oldStyles) |
||
1485 | || (wrkCharStyles->count() > oldCharStyles) |
||
1486 | || (wrkLineStyles->count() > oldLineStyles) ) ) |
||
1487 | changed(); |
||
1488 | } |
||
1489 | } |
||
1490 | |||
22505 | craig | 1491 | void ScribusDoc::loadStylesFromFile(const QString& fileName, StyleSet<ParagraphStyle> *tempStyles, |
8274 | tsoots | 1492 | StyleSet<CharStyle> *tempCharStyles, |
17400 | fschmid | 1493 | QHash<QString, multiLine> *tempLineStyles) |
456 | fschmid | 1494 | { |
12548 | pierre | 1495 | StyleSet<ParagraphStyle> *wrkStyles = tempStyles; |
1496 | StyleSet<CharStyle> *wrkCharStyles = tempCharStyles; |
||
17400 | fschmid | 1497 | QHash<QString, multiLine> *wrkLineStyles = tempLineStyles; |
8916 | avox | 1498 | |
456 | fschmid | 1499 | if (!fileName.isEmpty()) |
1500 | { |
||
5642 | cbradney | 1501 | FileLoader fl(fileName); |
17326 | jghali | 1502 | if (fl.testFile() == -1) |
5642 | cbradney | 1503 | //TODO put in nice user warning |
1504 | return; |
||
5980 | avox | 1505 | |
17326 | jghali | 1506 | if (!fl.readStyles(this, *wrkStyles)) |
456 | fschmid | 1507 | { |
8274 | tsoots | 1508 | //TODO put in nice user warning |
456 | fschmid | 1509 | } |
8274 | tsoots | 1510 | |
17326 | jghali | 1511 | if (!fl.readCharStyles(this, *wrkCharStyles)) |
8274 | tsoots | 1512 | { |
1513 | //TODO put in nice user warning |
||
1514 | } |
||
1515 | |||
17326 | jghali | 1516 | if (!fl.readLineStyles(wrkLineStyles)) |
8274 | tsoots | 1517 | { |
1518 | //TODO put in nice user warning |
||
1519 | } |
||
12550 | pierre | 1520 | |
1521 | // Which are the default styles |
||
1522 | // Sadly StyleSet is not updated at import |
||
1523 | // and it might break something to do so. |
||
1524 | // We need to loop then - pm |
||
1525 | |||
1526 | QFileInfo fi(fileName); |
||
1527 | QString importPrefix(tr("Imported ","Prefix of imported default style")); |
||
1528 | QString importSuffix(" (" + fi.baseName() + ")"); |
||
1529 | |||
19429 | jghali | 1530 | for (int j(0) ; j < wrkStyles->count() ; ++j) |
12550 | pierre | 1531 | { |
19429 | jghali | 1532 | if ((*wrkStyles)[j].isDefaultStyle()) |
12550 | pierre | 1533 | { |
1534 | ParagraphStyle& parDefault((*wrkStyles)[j]); |
||
1535 | parDefault.setDefaultStyle(false); |
||
1536 | QMap<QString, QString> namesMap; |
||
1537 | namesMap[parDefault.name()] = importPrefix + parDefault.name() + importSuffix; |
||
19429 | jghali | 1538 | for (int i(0) ; i < wrkStyles->count() ; ++i) |
12550 | pierre | 1539 | { |
19429 | jghali | 1540 | if ((*wrkStyles)[i] != parDefault) |
12550 | pierre | 1541 | namesMap[(*wrkStyles)[i].name()] = (*wrkStyles)[i].name(); |
1542 | } |
||
1543 | wrkStyles->rename(namesMap); |
||
1544 | } |
||
1545 | } |
||
19429 | jghali | 1546 | for (int j(0) ; j < wrkCharStyles->count() ; ++j) |
12550 | pierre | 1547 | { |
19429 | jghali | 1548 | if ((*wrkCharStyles)[j].isDefaultStyle()) |
12550 | pierre | 1549 | { |
1550 | CharStyle& charDefault((*wrkCharStyles)[j]); |
||
1551 | charDefault.setDefaultStyle(false); |
||
1552 | QMap<QString, QString> namesMap; |
||
1553 | namesMap[charDefault.name()] = importPrefix + charDefault.name() + importSuffix; |
||
19429 | jghali | 1554 | for (int i(0) ; i < wrkCharStyles->count() ; ++i) |
12550 | pierre | 1555 | { |
19429 | jghali | 1556 | if ((*wrkCharStyles)[i] != charDefault) |
12550 | pierre | 1557 | namesMap[(*wrkCharStyles)[i].name()] = (*wrkCharStyles)[i].name(); |
1558 | } |
||
1559 | wrkCharStyles->rename(namesMap); |
||
1560 | } |
||
1561 | } |
||
456 | fschmid | 1562 | } |
1563 | } |
||
1564 | |||
10532 | avox | 1565 | |
1179 | tsoots | 1566 | void ScribusDoc::lockGuides(bool isLocked) |
1567 | { |
||
1180 | tsoots | 1568 | if (GuideLock == isLocked) |
1569 | return; |
||
1179 | tsoots | 1570 | GuideLock = isLocked; |
1571 | if (UndoManager::undoEnabled()) |
||
1572 | { |
||
1573 | QString name; |
||
1574 | if (isLocked) |
||
1190 | tsoots | 1575 | name = Um::LockGuides; |
1179 | tsoots | 1576 | else |
1190 | tsoots | 1577 | name = Um::UnlockGuides; |
1578 | SimpleState *ss = new SimpleState(name, "", Um::ILockGuides); |
||
1179 | tsoots | 1579 | ss->set("GUIDE_LOCK", isLocked); |
20691 | craig | 1580 | m_undoManager->action(this, ss); |
1179 | tsoots | 1581 | } |
1582 | } |
||
1583 | |||
13349 | jghali | 1584 | void ScribusDoc::undoRedoBegin() |
1585 | { |
||
14370 | jghali | 1586 | m_docUpdater->beginUpdate(); |
13349 | jghali | 1587 | m_Selection->delaySignalsOn(); |
1588 | } |
||
10532 | avox | 1589 | |
13349 | jghali | 1590 | void ScribusDoc::undoRedoDone() |
1591 | { |
||
1592 | m_Selection->delaySignalsOff(); |
||
14370 | jghali | 1593 | m_docUpdater->endUpdate(); |
13349 | jghali | 1594 | } |
1595 | |||
1179 | tsoots | 1596 | void ScribusDoc::restore(UndoState* state, bool isUndo) |
1597 | { |
||
1598 | SimpleState *ss = dynamic_cast<SimpleState*>(state); |
||
22324 | craig | 1599 | if (!ss) |
1600 | return; |
||
1601 | |||
1602 | bool layersUndo=false; |
||
1603 | if (ss->contains("GROUP")) |
||
1604 | restoreGrouping(ss, isUndo); |
||
1605 | else if (ss->contains("UNGROUP")) |
||
1606 | restoreGrouping(ss, !isUndo); |
||
1607 | else if (ss->contains("GUIDE_LOCK")) |
||
1608 | restoreGuideLock(ss, isUndo); |
||
1609 | else if (ss->contains("UP_LAYER")) |
||
1179 | tsoots | 1610 | { |
22324 | craig | 1611 | if (isUndo) |
1612 | lowerLayer(ss->getInt("ACTIVE")); |
||
1613 | else |
||
1614 | raiseLayer(ss->getInt("ACTIVE")); |
||
1615 | layersUndo=true; |
||
1616 | } |
||
1617 | else if (ss->contains("DOWN_LAYER")) |
||
1618 | { |
||
1619 | if (isUndo) |
||
1620 | raiseLayer(ss->getInt("ACTIVE")); |
||
1621 | else |
||
1622 | lowerLayer(ss->getInt("ACTIVE")); |
||
1623 | layersUndo=true; |
||
1624 | } |
||
1625 | else if (ss->contains("PRINT_LAYER")) |
||
1626 | { |
||
1627 | bool print = ss->getBool("PRINT"); |
||
1628 | setLayerPrintable(ss->getInt("ACTIVE"), isUndo ? !print : print); |
||
1629 | layersUndo=true; |
||
1630 | } |
||
1631 | else if (ss->contains("LAYER_FLOW")) |
||
1632 | { |
||
1633 | bool flow = ss->getBool("FLOW"); |
||
1634 | setLayerFlow(ss->getInt("ACTIVE"), isUndo ? !flow : flow); |
||
1635 | layersUndo=true; |
||
1636 | } |
||
1637 | else if (ss->contains("LAYER_LOCK")) |
||
1638 | { |
||
1639 | bool lock = ss->getBool("LOCK"); |
||
1640 | setLayerLocked(ss->getInt("ACTIVE"), isUndo ? !lock : lock); |
||
1641 | layersUndo=true; |
||
1642 | } |
||
1643 | else if (ss->contains("LAYER_TRANSPARENCY")) |
||
1644 | { |
||
1645 | double old_trans = ss->getDouble("OLD_TRANS"); |
||
1646 | double new_trans = ss->getDouble("NEW_TRANS"); |
||
1647 | setLayerTransparency(ss->getInt("ACTIVE"), isUndo ? old_trans : new_trans); |
||
1648 | layersUndo=true; |
||
1649 | } |
||
1650 | else if (ss->contains("LAYER_BLENDMODE")) |
||
1651 | { |
||
1652 | int old_blend = ss->getInt("OLD_BLENDMODE"); |
||
1653 | int new_blend = ss->getInt("NEW_BLENDMODE"); |
||
1654 | setLayerBlendMode(ss->getInt("ACTIVE"), isUndo ? old_blend : new_blend); |
||
1655 | layersUndo=true; |
||
1656 | } |
||
1657 | else if (ss->contains("ADD_LAYER")) |
||
1658 | { |
||
1659 | if (isUndo) |
||
1660 | deleteLayer(ss->getInt("LAYER_NR"), false); |
||
1661 | else |
||
2937 | cbradney | 1662 | { |
22324 | craig | 1663 | int layerID=addLayer( ss->get("NAME"), false ); |
1664 | int newLayerID=ss->getInt("LAYER_NR"); |
||
1665 | bool renumberedOk=renumberLayer(layerID, newLayerID); |
||
1666 | Q_ASSERT(renumberedOk); |
||
2937 | cbradney | 1667 | } |
22324 | craig | 1668 | layersUndo=true; |
1669 | } |
||
1670 | else if (ss->contains("REMOVE_LAYER")) |
||
1671 | { |
||
1672 | if (isUndo) |
||
2937 | cbradney | 1673 | { |
22324 | craig | 1674 | int layerID=addLayer( ss->get("NAME"), false ); |
1675 | int newLayerID=ss->getInt("LAYER_NR"); |
||
1676 | bool renumberedOk=renumberLayer(layerID, newLayerID); |
||
1677 | Q_ASSERT(renumberedOk); |
||
1678 | layerID=newLayerID; |
||
1679 | //Layer is at the top now, lower it until it reaches the old level |
||
1680 | int level = ss->getInt("LEVEL"); |
||
1681 | while (layerLevelFromID(layerID)!=level) |
||
1682 | lowerLayer(layerID); |
||
2937 | cbradney | 1683 | } |
22324 | craig | 1684 | else |
1685 | deleteLayer(ss->getInt("LAYER_NR"), ss->getBool("DELETE")); |
||
1686 | layersUndo=true; |
||
1687 | } |
||
1688 | else if (ss->contains("CHANGE_NAME")) |
||
1689 | { |
||
1690 | QString name = ss->get("OLD_NAME"); |
||
1691 | if (!isUndo) |
||
1692 | name = ss->get("NEW_NAME"); |
||
1693 | changeLayerName(ss->getInt("ACTIVE"), name); |
||
1694 | layersUndo=true; |
||
1695 | } |
||
1696 | else if (ss->contains("MASTERPAGE_ADD")) |
||
1697 | restoreAddMasterPage(ss, isUndo); |
||
1698 | else if (ss->contains("MASTERPAGE_RENAME")) |
||
1699 | restoreMasterPageRenaming(ss, isUndo); |
||
1700 | else if (ss->contains("OLD_MASTERPAGE")) |
||
1701 | restoreMasterPageApplying(ss, isUndo); |
||
1702 | else if (ss->contains("PAGE_COPY")) |
||
1703 | restoreCopyPage(ss, isUndo); |
||
1704 | else if (ss->contains("PAGE_MOVE")) |
||
1705 | restoreMovePage(ss, isUndo); |
||
1706 | else if (ss->contains("PAGE_SWAP")) |
||
1707 | restoreSwapPage(ss, isUndo); |
||
1708 | else if (ss->contains("LEVEL_DOWN")) |
||
1709 | restoreLevelDown(ss,isUndo); |
||
1710 | else if (ss->contains("LEVEL_UP")) |
||
1711 | restoreLevelDown(ss,!isUndo); |
||
1712 | else if (ss->contains("LEVEL_BOTTOM")) |
||
1713 | restoreLevelBottom(ss,isUndo); |
||
1714 | else if (ss->contains("LEVEL_TOP")) |
||
1715 | restoreLevelBottom(ss,!isUndo); |
||
1716 | else if (ss->contains("PAGE_CHANGEPROPS")) |
||
1717 | restoreChangePageProperties(ss,isUndo); |
||
1718 | else if (ss->contains("DELETE_FRAMETEXT")) |
||
1719 | { |
||
1720 | PageItem * nF = getItemFromName(ss->get("noteframeName")); |
||
22505 | craig | 1721 | Q_ASSERT(nF != nullptr); |
22324 | craig | 1722 | nF->asNoteFrame()->restoreDeleteNoteText(ss, isUndo); |
1723 | } |
||
1724 | else if (ss->contains("DELETE_FRAMEPARA")) |
||
1725 | { |
||
1726 | PageItem * nF = getItemFromName(ss->get("noteframeName")); |
||
22505 | craig | 1727 | Q_ASSERT(nF != nullptr); |
22324 | craig | 1728 | nF->asNoteFrame()->restoreDeleteNoteParagraph(ss, isUndo); |
1729 | } |
||
1730 | else if (ss->contains("INSERT_FRAMETEXT")) |
||
1731 | { |
||
1732 | PageItem * nF = getItemFromName(ss->get("noteframeName")); |
||
22505 | craig | 1733 | Q_ASSERT(nF != nullptr); |
22324 | craig | 1734 | nF->asNoteFrame()->restoreInsertNoteText(ss,isUndo); |
1735 | } |
||
1736 | else if (ss->contains("INSERT_FRAMEPARA")) |
||
1737 | { |
||
1738 | PageItem * nF = getItemFromName(ss->get("noteframeName")); |
||
22505 | craig | 1739 | Q_ASSERT(nF != nullptr); |
22324 | craig | 1740 | nF->asNoteFrame()->restoreInsertNoteParagraph(ss,isUndo); |
1741 | } |
||
1742 | else if (ss->contains("NSTYLE")) |
||
1743 | { |
||
22505 | craig | 1744 | NotesStyle* NS = nullptr; |
22324 | craig | 1745 | if ((ss->get("NSTYLE") == "new" && isUndo) || (ss->get("NSTYLE") == "delete" && !isUndo)) |
1746 | deleteNotesStyle(ss->get("name")); |
||
1747 | else if ((ss->get("NSTYLE") == "new" && !isUndo) || (ss->get("NSTYLE") == "delete" && isUndo)) |
||
2937 | cbradney | 1748 | { |
22324 | craig | 1749 | NS = new NotesStyle(); |
1750 | NS->setName(ss->get("name")); |
||
1751 | NS->setStart(ss->getInt("start")); |
||
1752 | NS->setEndNotes(ss->getBool("endNotes")); |
||
1753 | NS->setType((NumFormat) ss->getInt("numFormat")); |
||
1754 | NS->setRange((NumerationRange) ss->getInt("range")); |
||
1755 | NS->setPrefix(ss->get("prefix")); |
||
1756 | NS->setSuffix(ss->get("suffix")); |
||
1757 | NS->setAutoNotesHeight(ss->getBool("autoH")); |
||
1758 | NS->setAutoNotesWidth(ss->getBool("autoW")); |
||
1759 | NS->setAutoWeldNotesFrames(ss->getBool("autoWeld")); |
||
1760 | NS->setAutoRemoveEmptyNotesFrames(ss->getBool("autoRemove")); |
||
1761 | NS->setSuperscriptInMaster(ss->getBool("superMaster")); |
||
1762 | NS->setSuperscriptInNote(ss->getBool("superNote")); |
||
1763 | NS->setMarksCharStyle(ss->get("marksChStyle")); |
||
1764 | NS->setNotesParStyle(ss->get("notesParStyle")); |
||
1765 | m_docNotesStylesList.append(NS); |
||
1766 | scMW()->emitUpdateRequest(reqMarksUpdate); |
||
2937 | cbradney | 1767 | } |
22324 | craig | 1768 | else if (ss->get("NSTYLE") == "edit") |
16492 | craig | 1769 | { |
2937 | cbradney | 1770 | if (isUndo) |
22324 | craig | 1771 | NS = getNotesStyle(ss->get("NEWname")); |
2937 | cbradney | 1772 | else |
22324 | craig | 1773 | NS = getNotesStyle(ss->get("name")); |
22505 | craig | 1774 | Q_ASSERT(NS != nullptr); |
22324 | craig | 1775 | //check if Notes Style change form footnotes to endnotes or range of numeration was changed |
1776 | //if use delete all notes frames with current style |
||
1777 | bool delNF = false; |
||
1778 | if (ss->getBool("NEWendNotes") != ss->getBool("endNotes") |
||
1779 | || ((isUndo && (ss->getBool("endNotes") && (NumerationRange) ss->getInt("range") != (NumerationRange) ss->getInt("NEWrange"))) |
||
1780 | || (!isUndo && (ss->getBool("NEWendNotes") && ((NumerationRange) ss->getInt("NEWrange") != (NumerationRange) ss->getInt("range")))))) |
||
1781 | delNF = true; |
||
1782 | if (delNF) |
||
2937 | cbradney | 1783 | { |
22324 | craig | 1784 | foreach (PageItem_NoteFrame* nF, listNotesFrames(NS)) |
1785 | delNoteFrame(nF, false); |
||
1786 | flag_updateEndNotes = NS->isEndNotes(); |
||
2937 | cbradney | 1787 | } |
1788 | if (isUndo) |
||
1789 | { |
||
17826 | craig | 1790 | NS->setName(ss->get("name")); |
1791 | NS->setStart(ss->getInt("start")); |
||
22324 | craig | 1792 | NS->setRange((NumerationRange) ss->getInt("range")); |
17826 | craig | 1793 | NS->setEndNotes(ss->getBool("endNotes")); |
18047 | craig | 1794 | NS->setType((NumFormat) ss->getInt("numFormat")); |
17826 | craig | 1795 | NS->setPrefix(ss->get("prefix")); |
1796 | NS->setSuffix(ss->get("suffix")); |
||
1797 | NS->setAutoNotesHeight(ss->getBool("autoH")); |
||
1798 | NS->setAutoNotesWidth(ss->getBool("autoW")); |
||
1799 | NS->setAutoWeldNotesFrames(ss->getBool("autoWeld")); |
||
1800 | NS->setAutoRemoveEmptyNotesFrames(ss->getBool("autoRemove")); |
||
1801 | NS->setSuperscriptInMaster(ss->getBool("superMaster")); |
||
1802 | NS->setSuperscriptInNote(ss->getBool("superNote")); |
||
1803 | NS->setMarksCharStyle(ss->get("marksChStyle")); |
||
1804 | NS->setNotesParStyle(ss->get("notesParStyle")); |
||
1805 | } |
||
22324 | craig | 1806 | else |
17826 | craig | 1807 | { |
22324 | craig | 1808 | NS->setName(ss->get("NEWname")); |
1809 | NS->setStart(ss->getInt("NEWstart")); |
||
1810 | NS->setRange((NumerationRange) ss->getInt("NEWrange")); |
||
1811 | NS->setEndNotes(ss->getBool("NEWendNotes")); |
||
1812 | NS->setType((NumFormat) ss->getInt("NEWnumFormat")); |
||
1813 | NS->setPrefix(ss->get("NEWprefix")); |
||
1814 | NS->setSuffix(ss->get("NEWsuffix")); |
||
1815 | NS->setAutoNotesHeight(ss->getBool("NEWautoH")); |
||
1816 | NS->setAutoNotesWidth(ss->getBool("NEWautoW")); |
||
1817 | NS->setAutoWeldNotesFrames(ss->getBool("NEWautoWeld")); |
||
1818 | NS->setAutoRemoveEmptyNotesFrames(ss->getBool("NEWautoRemove")); |
||
1819 | NS->setSuperscriptInMaster(ss->getBool("NEWsuperMaster")); |
||
1820 | NS->setSuperscriptInNote(ss->getBool("NEWsuperNote")); |
||
1821 | NS->setMarksCharStyle(ss->get("NEWmarksChStyle")); |
||
1822 | NS->setNotesParStyle(ss->get("NEWnotesParStyle")); |
||
1823 | } |
||
1824 | setNotesChanged(true); |
||
1825 | if ((ss->get("marksChStyle") != ss->get("NEWmarksChStyle")) |
||
1826 | || (ss->getBool("superMaster") != ss->getBool("NEWsuperMaster"))) |
||
1827 | invalidateMasterFrames(NS); |
||
1828 | updateNotesNums(NS); |
||
1829 | updateNotesFramesSettings(NS); |
||
1830 | if (flag_updateEndNotes) |
||
1831 | updateEndnotesFrames(NS, true); |
||
1832 | updateNotesFramesStyles(NS); |
||
1833 | if (notesChanged()) |
||
1834 | { |
||
1835 | flag_updateMarksLabels = true; |
||
1836 | changed(); |
||
1837 | regionsChanged()->update(QRectF()); |
||
1838 | } |
||
1839 | } |
||
22505 | craig | 1840 | if (NS != nullptr) |
22324 | craig | 1841 | scMW()->nsEditor->setNotesStyle(NS); |
1842 | else |
||
1843 | scMW()->nsEditor->updateNSList(); |
||
1844 | } |
||
1845 | else if (ss->contains("DELETE_NOTE")) |
||
1846 | { |
||
1847 | ScItemsState *is = dynamic_cast<ScItemsState*>(state); |
||
1848 | if (is) |
||
1849 | { |
||
1850 | NotesStyle* nStyle = getNotesStyle(is->get("nStyle")); |
||
22505 | craig | 1851 | PageItem* master = nullptr; |
22324 | craig | 1852 | if (is->contains("noteframeName")) |
1853 | master = getItemFromName(is->get("noteframeName")); |
||
1854 | else |
||
1855 | master = (PageItem*) is->getItem("inItem"); |
||
1856 | if (isUndo) |
||
1857 | { |
||
1858 | TextNote* note = newNote(nStyle); |
||
1859 | Mark* mrk = newMark(); |
||
1860 | mrk->setType(MARKNoteMasterType); |
||
1861 | mrk->setNotePtr(note); |
||
1862 | note->setMasterMark(mrk); |
||
1863 | note->setSaxedText(is->get("noteTXT")); |
||
1864 | master->itemText.insertMark(mrk, is->getInt("at")); |
||
1865 | master->invalid = true; |
||
1866 | if (!nStyle->isAutoRemoveEmptyNotesFrames()) |
||
17826 | craig | 1867 | { |
22324 | craig | 1868 | PageItem_NoteFrame* nF = (PageItem_NoteFrame*) is->getItem("noteframe"); |
22505 | craig | 1869 | Q_ASSERT(nF != nullptr); |
22324 | craig | 1870 | master->asTextFrame()->setNoteFrame(nF); |
17826 | craig | 1871 | } |
1872 | setNotesChanged(true); |
||
22324 | craig | 1873 | if (note->isEndNote()) |
1874 | flag_updateEndNotes = true; |
||
17826 | craig | 1875 | } |
1876 | else |
||
22324 | craig | 1877 | { |
1878 | TextNote* note = master->itemText.mark(is->getInt("at"))->getNotePtr(); |
||
1879 | if (note->isEndNote()) |
||
1880 | flag_updateEndNotes = true; |
||
1881 | deleteNote(note); |
||
1882 | } |
||
1883 | master->invalidateLayout(); |
||
1884 | master->updateLayout(); |
||
17826 | craig | 1885 | } |
22324 | craig | 1886 | } |
1887 | else if (ss->contains("MARK")) |
||
1888 | { |
||
1889 | ScItemsState *is = dynamic_cast<ScItemsState*>(state); |
||
1890 | if (is) |
||
17826 | craig | 1891 | { |
22324 | craig | 1892 | Mark* mrk = getMark(is->get("label"), (MarkType) is->getInt("type")); |
22510 | craig | 1893 | if (mrk == nullptr && is->contains("labelOLD")) |
22324 | craig | 1894 | mrk = getMark(is->get("labelOLD"), (MarkType) is->getInt("type")); |
1895 | int pos = is->getInt("at"); |
||
1896 | bool isAutoNoteFrame = false; |
||
22505 | craig | 1897 | PageItem* currItem = nullptr; |
22324 | craig | 1898 | if (is->contains("noteframeName")) |
17826 | craig | 1899 | { |
22324 | craig | 1900 | currItem = getItemFromName(is->get("noteframeName")); |
22505 | craig | 1901 | if (currItem != nullptr) |
22324 | craig | 1902 | isAutoNoteFrame = currItem->asNoteFrame()->isAutoFrame(); |
1903 | } |
||
1904 | else |
||
1905 | currItem = (PageItem*) is->getItem("inItem"); |
||
1906 | if (isUndo) |
||
1907 | { |
||
1908 | if (is->get("MARK") == "new") |
||
17826 | craig | 1909 | { |
22505 | craig | 1910 | Q_ASSERT(mrk != nullptr); |
22324 | craig | 1911 | if (mrk->isNoteType()) |
17826 | craig | 1912 | { |
22324 | craig | 1913 | TextNote* note = mrk->getNotePtr(); |
1914 | NotesStyle* nStyle = note->notesStyle(); |
||
1915 | if (note->isEndNote()) |
||
1916 | flag_updateEndNotes = true; |
||
1917 | deleteNote(note); |
||
1918 | updateNotesNums(nStyle); |
||
17826 | craig | 1919 | } |
22324 | craig | 1920 | else |
1921 | eraseMark(mrk, true, currItem, true); |
||
17826 | craig | 1922 | } |
22324 | craig | 1923 | else if (is->get("MARK") == "replace") |
17826 | craig | 1924 | { |
22324 | craig | 1925 | Q_ASSERT(pos >= 0); |
22505 | craig | 1926 | Q_ASSERT(currItem != nullptr); |
1927 | Q_ASSERT(mrk != nullptr); |
||
22324 | craig | 1928 | Mark* mrk = getMark(is->get("label"), (MarkType) is->getInt("type")); |
1929 | currItem->itemText.replaceMark(pos, mrk); |
||
1930 | if (is->contains("strtxtOLD")) |
||
1931 | { |
||
1932 | mrk->setString(is->get("strtxtOLD")); |
||
1933 | invalidateVariableTextFrames(mrk, false); |
||
1934 | } |
||
1935 | if (is->contains("labelOLD")) |
||
1936 | mrk->label = is->get("labelOLD"); |
||
17826 | craig | 1937 | } |
22324 | craig | 1938 | else if (is->get("MARK") == "edit") |
17826 | craig | 1939 | { |
22510 | craig | 1940 | Q_ASSERT(mrk != nullptr); |
22324 | craig | 1941 | if (is->contains("labelOLD")) |
1942 | mrk->label = is->get("labelOLD"); |
||
1943 | if (is->contains("strtxtOLD")) |
||
1944 | { |
||
1945 | mrk->setString(is->get("strtxtOLD")); |
||
1946 | invalidateVariableTextFrames(mrk, false); |
||
1947 | } |
||
1948 | if (is->contains("dNameOLD")) |
||
1949 | mrk->setMark(is->get("dNameOLD"), (MarkType) is->getInt("dTypeOLD")); |
||
22510 | craig | 1950 | if (is->getItem("itemPtrOLD") != nullptr) |
22324 | craig | 1951 | mrk->setItemPtr((PageItem*) is->getItem("itemPtrOLD")); |
17826 | craig | 1952 | } |
22324 | craig | 1953 | else if (is->get("MARK") == "insert_existing") |
17826 | craig | 1954 | { |
22324 | craig | 1955 | Q_ASSERT(pos >= 0); |
22505 | craig | 1956 | Q_ASSERT(currItem != nullptr); |
1957 | Q_ASSERT(mrk != nullptr); |
||
23185 | jghali | 1958 | currItem->itemText.removeChars(pos, 1); |
22324 | craig | 1959 | if (is->contains("strOLD")) |
17826 | craig | 1960 | { |
22324 | craig | 1961 | mrk->setString(is->get("strOLD")); |
1962 | invalidateVariableTextFrames(mrk, false); |
||
17826 | craig | 1963 | } |
22324 | craig | 1964 | if (is->contains("labelOLD")) |
1965 | mrk->label = is->get("labelOLD"); |
||
1966 | } |
||
1967 | else if (is->get("MARK") == "delete") |
||
1968 | { |
||
1969 | mrk = newMark(); |
||
1970 | mrk->label = is->get("label"); |
||
1971 | mrk->setType((MarkType) is->getInt("type")); |
||
1972 | Q_ASSERT(pos >= 0); |
||
22505 | craig | 1973 | Q_ASSERT(currItem != nullptr); |
22324 | craig | 1974 | currItem->itemText.insertMark(mrk, pos); |
1975 | if (is->contains("strtxt")) |
||
17826 | craig | 1976 | { |
22324 | craig | 1977 | mrk->setString(is->get("strtxt")); |
1978 | invalidateVariableTextFrames(mrk, false); |
||
17826 | craig | 1979 | } |
22324 | craig | 1980 | if (is->contains("dName")) |
1981 | mrk->setMark(is->get("dName"), (MarkType) is->getInt("dType")); |
||
22505 | craig | 1982 | if (is->getItem("itemPtr") != nullptr) |
22324 | craig | 1983 | mrk->setItemPtr((PageItem*) is->getItem("itemPtrOLD")); |
1984 | } |
||
1985 | else if (is->get("MARK") == "eraseFromText") ////for non-unique marks |
||
1986 | { |
||
1987 | Q_ASSERT(pos >= 0); |
||
22505 | craig | 1988 | Q_ASSERT(mrk != nullptr); |
1989 | Q_ASSERT(currItem != nullptr); |
||
22324 | craig | 1990 | currItem->itemText.insertMark(mrk, pos); |
1991 | if (is->contains("strNew")) |
||
17826 | craig | 1992 | { |
22324 | craig | 1993 | mrk->setString(is->get("strNEW")); |
1994 | invalidateVariableTextFrames(mrk, false); |
||
17826 | craig | 1995 | } |
22324 | craig | 1996 | } |
1997 | else if (is->get("MARK") == "delNonUnique") |
||
1998 | { |
||
1999 | //used if deleting non-unique marks by MarksManager |
||
2000 | mrk = newMark(); |
||
2001 | mrk->label = is->get("label"); |
||
2002 | mrk->setType((MarkType) is->getInt("type")); |
||
2003 | mrk->setString(is->get("strtxt")); |
||
2004 | for (int i=0; i < is->insertItemPos.count(); ++i) |
||
17826 | craig | 2005 | { |
22324 | craig | 2006 | PageItem* item = (PageItem*) is->insertItemPos[i].first; |
2007 | item->itemText.insertMark(mrk, is->insertItemPos[i].second); |
||
2008 | item->invalid = true; |
||
17826 | craig | 2009 | } |
22324 | craig | 2010 | } |
2011 | else |
||
2012 | { |
||
2013 | Q_ASSERT(false); |
||
2014 | qDebug() << "MARK undo - unhandled " << is->get("MARK"); |
||
2015 | } |
||
2016 | } |
||
2017 | else //REDO |
||
2018 | { |
||
2019 | if (is->get("MARK") == "new") |
||
2020 | { |
||