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