Rev 18084 | Rev 19080 | 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 | */ |
||
364 | Franz | 7 | /*************************************************************************** |
8 | * Copyright (C) 2004 by Riku Leino * |
||
1184 | tsoots | 9 | * tsoots@gmail.com * |
364 | Franz | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * |
||
12 | * it under the terms of the GNU General Public License as published by * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | * This program is distributed in the hope that it will be useful, * |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
19 | * GNU General Public License for more details. * |
||
20 | * * |
||
21 | * You should have received a copy of the GNU General Public License * |
||
22 | * along with this program; if not, write to the * |
||
23 | * Free Software Foundation, Inc., * |
||
18122 | mrdocs | 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
364 | Franz | 25 | ***************************************************************************/ |
26 | |||
13649 | jghali | 27 | #include <QCursor> |
28 | #include <QList> |
||
16546 | jghali | 29 | #include <QProgressBar> |
13649 | jghali | 30 | #include <QStringList> |
31 | |||
13648 | jghali | 32 | #include "gtaction.h" |
13805 | jghali | 33 | #include "gtfont.h" |
34 | #include "gtstyle.h" |
||
35 | #include "gtparagraphstyle.h" |
||
36 | #include "gtframestyle.h" |
||
37 | |||
833 | tsoots | 38 | #include "color.h" |
13805 | jghali | 39 | #include "commonstrings.h" |
18084 | jghali | 40 | #include "hyphenator.h" |
41 | #include "marks.h" |
||
42 | #include "notesstyles.h" |
||
43 | #include "pageitem_textframe.h" |
||
2834 | cbradney | 44 | #include "prefsmanager.h" |
13464 | cbradney | 45 | #include "scclocale.h" |
3934 | cbradney | 46 | #include "selection.h" |
7478 | jghali | 47 | #include "sccolorengine.h" |
13805 | jghali | 48 | #include "scribus.h" |
17641 | craig | 49 | #include "undomanager.h" |
364 | Franz | 50 | |
13805 | jghali | 51 | #include "util_icon.h" |
18084 | jghali | 52 | #include "util_text.h" |
13805 | jghali | 53 | #include "ui/propertiespalette.h" |
16546 | jghali | 54 | #include "ui/propertiespalette_text.h" |
13805 | jghali | 55 | #include "ui/missing.h" |
56 | |||
57 | |||
58 | |||
5781 | cbradney | 59 | // gtAction::gtAction(bool append) |
60 | // { |
||
61 | // prefsManager=PrefsManager::instance(); |
||
62 | // textFrame = ScMW->doc->m_Selection->itemAt(0); |
||
63 | // it = textFrame; |
||
64 | // lastParagraphStyle = -1; |
||
65 | // inPara = false; |
||
66 | // isFirstWrite = true; |
||
67 | // lastCharWasLineChange = false; |
||
68 | // currentFrameStyle = ""; |
||
69 | // doAppend = append; |
||
70 | // updateParagraphStyles = false; |
||
71 | // overridePStyleFont = true; |
||
72 | // } |
||
364 | Franz | 73 | |
1702 | cbradney | 74 | gtAction::gtAction(bool append, PageItem* pageitem) |
75 | { |
||
2950 | cbradney | 76 | prefsManager=PrefsManager::instance(); |
1702 | cbradney | 77 | textFrame = pageitem; |
5781 | cbradney | 78 | m_ScMW=textFrame->doc()->scMW(); |
1702 | cbradney | 79 | it = textFrame; |
80 | lastParagraphStyle = -1; |
||
81 | inPara = false; |
||
82 | isFirstWrite = true; |
||
83 | lastCharWasLineChange = false; |
||
84 | currentFrameStyle = ""; |
||
85 | doAppend = append; |
||
86 | updateParagraphStyles = false; |
||
87 | overridePStyleFont = true; |
||
17641 | craig | 88 | undoManager = UndoManager::instance(); |
18084 | jghali | 89 | noteStory = NULL; |
90 | note = NULL; |
||
1702 | cbradney | 91 | } |
92 | |||
364 | Franz | 93 | void gtAction::setProgressInfo() |
94 | { |
||
5781 | cbradney | 95 | m_ScMW->setStatusBarInfoText(QObject::tr("Importing text")); |
96 | m_ScMW->mainWindowProgressBar->reset(); |
||
9971 | jghali | 97 | m_ScMW->mainWindowProgressBar->setMaximum(0); // 0 shows a busy progressbar |
364 | Franz | 98 | } |
99 | |||
100 | void gtAction::setProgressInfoDone() |
||
101 | { |
||
5781 | cbradney | 102 | m_ScMW->setStatusBarInfoText(""); |
103 | m_ScMW->mainWindowProgressBar->reset(); |
||
9971 | jghali | 104 | m_ScMW->mainWindowProgressBar->setMaximum(1); |
364 | Franz | 105 | } |
106 | |||
107 | void gtAction::setInfo(QString infoText) |
||
108 | { |
||
5781 | cbradney | 109 | m_ScMW->setStatusBarInfoText(infoText); |
364 | Franz | 110 | } |
111 | |||
112 | void gtAction::clearFrame() |
||
113 | { |
||
1065 | cbradney | 114 | textFrame->itemText.clear(); |
364 | Franz | 115 | } |
116 | |||
18084 | jghali | 117 | void gtAction::writeUnstyled(const QString& text, bool isNote) |
12895 | jghali | 118 | { |
17641 | craig | 119 | UndoTransaction* activeTransaction = NULL; |
18084 | jghali | 120 | if (isFirstWrite && it->itemText.length() > 0) |
12895 | jghali | 121 | { |
122 | if (!doAppend) |
||
123 | { |
||
17641 | craig | 124 | if (UndoManager::undoEnabled()) |
125 | activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ImportText, "", Um::IDelete)); |
||
12895 | jghali | 126 | if (it->nextInChain() != 0) |
127 | { |
||
128 | PageItem *nextItem = it->nextInChain(); |
||
129 | while (nextItem != 0) |
||
130 | { |
||
17641 | craig | 131 | nextItem->itemText.selectAll(); |
132 | nextItem->asTextFrame()->deleteSelectedTextFromFrame(); |
||
12895 | jghali | 133 | nextItem = nextItem->nextInChain(); |
134 | } |
||
135 | } |
||
17641 | craig | 136 | it->itemText.selectAll(); |
137 | it->asTextFrame()->deleteSelectedTextFromFrame(); |
||
12895 | jghali | 138 | } |
139 | } |
||
140 | |||
17641 | craig | 141 | QChar ch0(0), ch5(5), ch10(10), ch13(13); |
142 | QString textStr = text; |
||
143 | textStr.remove(ch0); |
||
144 | textStr.remove(ch13); |
||
145 | textStr.replace(ch10,ch13); |
||
146 | textStr.replace(ch5,ch13); |
||
147 | textStr.replace(QString(0x2028),SpecialChars::LINEBREAK); |
||
148 | textStr.replace(QString(0x2029),SpecialChars::PARSEP); |
||
18084 | jghali | 149 | if (isNote) |
12895 | jghali | 150 | { |
18084 | jghali | 151 | if (note == NULL) |
152 | { |
||
153 | note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0)); |
||
154 | Q_ASSERT(noteStory == NULL); |
||
155 | noteStory = new StoryText(it->m_Doc); |
||
156 | } |
||
157 | if (textStr == SpecialChars::OBJECT) |
||
158 | { |
||
159 | NotesStyle* nStyle = note->notesStyle(); |
||
160 | QString label = "NoteMark_" + nStyle->name(); |
||
161 | if (nStyle->range() == NSRsection) |
||
162 | label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1); |
||
163 | else if (nStyle->range() == NSRpage) |
||
164 | label += " on page " + QString::number(it->OwnPage +1); |
||
165 | else if (nStyle->range() == NSRstory) |
||
166 | label += " in " + it->firstInChain()->itemName(); |
||
167 | else if (nStyle->range() == NSRframe) |
||
168 | label += " in frame" + it->itemName(); |
||
169 | if (it->m_Doc->getMarkDefinied(label + "_1", MARKNoteMasterType) != NULL) |
||
170 | getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed |
||
171 | else |
||
172 | label = label + "_1"; |
||
173 | Mark* mrk = it->m_Doc->newMark(); |
||
174 | mrk->label = label; |
||
175 | mrk->setType(MARKNoteMasterType); |
||
176 | mrk->setNotePtr(note); |
||
177 | note->setMasterMark(mrk); |
||
178 | if (noteStory->text(noteStory->length() -1) == SpecialChars::PARSEP) |
||
179 | noteStory->removeChars(noteStory->length() -1, 1); |
||
180 | note->setSaxedText(saxedText(noteStory)); |
||
181 | mrk->setString(""); |
||
182 | mrk->OwnPage = it->OwnPage; |
||
183 | it->itemText.insertMark(mrk); |
||
184 | if (UndoManager::undoEnabled()) |
||
185 | { |
||
186 | ScItemsState* is = new ScItemsState(UndoManager::InsertNote); |
||
187 | is->set("ETEA", mrk->label); |
||
188 | is->set("MARK", QString("new")); |
||
189 | is->set("label", mrk->label); |
||
190 | is->set("type", (int) MARKNoteMasterType); |
||
191 | is->set("strtxt", QString("")); |
||
192 | is->set("nStyle", nStyle->name()); |
||
193 | is->set("at", it->itemText.cursorPosition() -1); |
||
194 | is->insertItem("inItem", it); |
||
195 | undoManager->action(it->m_Doc, is); |
||
196 | } |
||
197 | note = NULL; |
||
198 | delete noteStory; |
||
199 | } |
||
200 | else |
||
201 | noteStory->insertChars(noteStory->length(), textStr); |
||
202 | } |
||
203 | else |
||
204 | { |
||
205 | int pos = it->itemText.length(); |
||
206 | if (UndoManager::undoEnabled()) |
||
207 | { |
||
208 | SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate); |
||
17641 | craig | 209 | ss->set("INSERT_FRAMETEXT", "insert_frametext"); |
210 | ss->set("TEXT_STR",textStr); |
||
211 | ss->set("START", pos); |
||
212 | undoManager->action(it, ss); |
||
18084 | jghali | 213 | } |
214 | it->itemText.insertChars(pos, textStr); |
||
12895 | jghali | 215 | } |
216 | lastCharWasLineChange = text.right(1) == "\n"; |
||
217 | isFirstWrite = false; |
||
17641 | craig | 218 | if (activeTransaction) |
219 | { |
||
220 | activeTransaction->commit(); |
||
221 | delete activeTransaction; |
||
222 | activeTransaction = NULL; |
||
223 | } |
||
12895 | jghali | 224 | } |
225 | |||
18084 | jghali | 226 | void gtAction::write(const QString& text, gtStyle *style, bool isNote) |
364 | Franz | 227 | { |
418 | Franz | 228 | if (isFirstWrite) |
229 | { |
||
230 | if (!doAppend) |
||
231 | { |
||
7994 | avox | 232 | if (it->nextInChain() != 0) |
418 | Franz | 233 | { |
7994 | avox | 234 | PageItem *nextItem = it->nextInChain(); |
1957 | cbradney | 235 | while (nextItem != 0) |
418 | Franz | 236 | { |
1957 | cbradney | 237 | nextItem->itemText.clear(); |
7994 | avox | 238 | nextItem = nextItem->nextInChain(); |
418 | Franz | 239 | } |
240 | } |
||
1065 | cbradney | 241 | it->itemText.clear(); |
418 | Franz | 242 | } |
243 | } |
||
411 | Franz | 244 | int paragraphStyle = -1; |
364 | Franz | 245 | if (style->target() == "paragraph") |
246 | { |
||
247 | gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style); |
||
9810 | avox | 248 | assert(pstyle != NULL); |
364 | Franz | 249 | paragraphStyle = applyParagraphStyle(pstyle); |
418 | Franz | 250 | if (isFirstWrite) |
251 | inPara = true; |
||
364 | Franz | 252 | } |
253 | else if (style->target() == "frame") |
||
254 | { |
||
255 | gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style); |
||
9810 | avox | 256 | assert(fstyle != NULL); |
364 | Franz | 257 | applyFrameStyle(fstyle); |
258 | } |
||
4546 | subik | 259 | |
411 | Franz | 260 | if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1)) |
261 | paragraphStyle = lastParagraphStyle; |
||
262 | |||
263 | if (paragraphStyle == -1) |
||
9730 | jghali | 264 | paragraphStyle = 0; //::findParagraphStyle(textFrame->doc(), textFrame->doc()->currentStyle); |
411 | Franz | 265 | |
9833 | jghali | 266 | const ParagraphStyle& paraStyle = textFrame->doc()->paragraphStyles()[paragraphStyle]; |
267 | |||
364 | Franz | 268 | gtFont* font = style->getFont(); |
5980 | avox | 269 | QString fontName = validateFont(font).scName(); |
12895 | jghali | 270 | CharStyle lastStyle, newStyle; |
5184 | avox | 271 | int lastStyleStart = 0; |
12895 | jghali | 272 | |
9833 | jghali | 273 | if ((inPara) && (!overridePStyleFont)) |
274 | { |
||
12895 | jghali | 275 | if (paraStyle.charStyle().font().isNone()) |
276 | { |
||
277 | gtFont font2(*font); |
||
278 | font2.setName(paraStyle.charStyle().font().scName()); |
||
279 | QString fontName2 = validateFont(&font2).scName(); |
||
9833 | jghali | 280 | newStyle.setFont((*textFrame->doc()->AllFonts)[fontName2]); |
12895 | jghali | 281 | } |
9833 | jghali | 282 | } |
283 | else |
||
284 | { |
||
12895 | jghali | 285 | setCharStyleAttributes(font, newStyle); |
9833 | jghali | 286 | } |
12895 | jghali | 287 | /*newStyle.eraseCharStyle(paraStyle.charStyle());*/ |
9833 | jghali | 288 | |
289 | lastStyle = newStyle; |
||
290 | lastStyleStart = it->itemText.length(); |
||
18084 | jghali | 291 | StoryText* story = NULL; |
292 | if (isNote) |
||
293 | { |
||
294 | if (noteStory == NULL) |
||
295 | { |
||
296 | note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0)); |
||
297 | noteStory = new StoryText(it->m_Doc); |
||
298 | } |
||
299 | story = noteStory; |
||
300 | } |
||
301 | else |
||
302 | story = &it->itemText; |
||
9833 | jghali | 303 | |
304 | QChar ch0(0), ch5(5), ch10(10), ch13(13); |
||
8595 | jghali | 305 | for (int a = 0; a < text.length(); ++a) |
364 | Franz | 306 | { |
9833 | jghali | 307 | if ((text.at(a) == ch0) || (text.at(a) == ch13)) |
364 | Franz | 308 | continue; |
5184 | avox | 309 | QChar ch = text.at(a); |
9833 | jghali | 310 | if ((ch == ch10) || (ch == ch5)) |
311 | ch = ch13; |
||
312 | |||
18084 | jghali | 313 | int pos = story->length(); |
314 | if (isNote && ch == SpecialChars::OBJECT) |
||
315 | { |
||
316 | NotesStyle* nStyle = note->notesStyle(); |
||
317 | QString label = "NoteMark_" + nStyle->name(); |
||
318 | if (nStyle->range() == NSRsection) |
||
319 | label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1); |
||
320 | else if (nStyle->range() == NSRpage) |
||
321 | label += " on page " + QString::number(it->OwnPage +1); |
||
322 | else if (nStyle->range() == NSRstory) |
||
323 | label += " in " + it->firstInChain()->itemName(); |
||
324 | else if (nStyle->range() == NSRframe) |
||
325 | label += " in frame" + it->itemName(); |
||
326 | if (it->m_Doc->getMarkDefinied(label + "_1", MARKNoteMasterType) != NULL) |
||
327 | getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed |
||
328 | else |
||
329 | label = label + "_1"; |
||
330 | Mark* mrk = it->m_Doc->newMark(); |
||
331 | mrk->label = label; |
||
332 | mrk->setType(MARKNoteMasterType); |
||
333 | mrk->setNotePtr(note); |
||
334 | note->setMasterMark(mrk); |
||
335 | mrk->setString(""); |
||
336 | mrk->OwnPage = it->OwnPage; |
||
337 | it->itemText.insertMark(mrk); |
||
338 | story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle); |
||
339 | if (paraStyle.hasName()) |
||
340 | { |
||
341 | ParagraphStyle pStyle; |
||
342 | pStyle.setParent(paraStyle.name()); |
||
343 | story->applyStyle(qMax(0,story->length()-1), pStyle); |
||
344 | } |
||
345 | else |
||
346 | story->applyStyle(qMax(0,story->length()-1), paraStyle); |
||
347 | |||
348 | lastCharWasLineChange = text.right(1) == "\n"; |
||
349 | inPara = style->target() == "paragraph"; |
||
350 | lastParagraphStyle = paragraphStyle; |
||
351 | if (isFirstWrite) |
||
352 | isFirstWrite = false; |
||
353 | if (story->text(pos -1) == SpecialChars::PARSEP) |
||
354 | story->removeChars(pos-1, 1); |
||
355 | note->setSaxedText(saxedText(story)); |
||
356 | note = NULL; |
||
357 | delete noteStory; |
||
358 | noteStory = NULL; |
||
359 | return; |
||
360 | } |
||
361 | else |
||
362 | story->insertChars(pos, QString(ch)); |
||
12895 | jghali | 363 | if (ch == SpecialChars::PARSEP) |
364 | { |
||
365 | if (paraStyle.hasName()) |
||
366 | { |
||
367 | ParagraphStyle pstyle; |
||
368 | pstyle.setParent(paraStyle.name()); |
||
18084 | jghali | 369 | story->applyStyle(pos, pstyle); |
12895 | jghali | 370 | } |
371 | else |
||
18084 | jghali | 372 | story->applyStyle(pos, paraStyle); |
5184 | avox | 373 | } |
364 | Franz | 374 | } |
18084 | jghali | 375 | story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle); |
12895 | jghali | 376 | if (paraStyle.hasName()) |
377 | { |
||
378 | ParagraphStyle pStyle; |
||
379 | pStyle.setParent(paraStyle.name()); |
||
18084 | jghali | 380 | story->applyStyle(qMax(0,story->length()-1), pStyle); |
12895 | jghali | 381 | } |
382 | else |
||
18084 | jghali | 383 | story->applyStyle(qMax(0,story->length()-1), paraStyle); |
5184 | avox | 384 | |
411 | Franz | 385 | lastCharWasLineChange = text.right(1) == "\n"; |
386 | inPara = style->target() == "paragraph"; |
||
387 | lastParagraphStyle = paragraphStyle; |
||
418 | Franz | 388 | if (isFirstWrite) |
389 | isFirstWrite = false; |
||
364 | Franz | 390 | } |
391 | |||
392 | int gtAction::findParagraphStyle(gtParagraphStyle* pstyle) |
||
393 | { |
||
411 | Franz | 394 | return findParagraphStyle(pstyle->getName()); |
395 | } |
||
396 | |||
397 | int gtAction::findParagraphStyle(const QString& name) |
||
398 | { |
||
364 | Franz | 399 | int pstyleIndex = -1; |
10400 | subik | 400 | for (int i = 0; i < textFrame->doc()->paragraphStyles().count(); ++i) |
364 | Franz | 401 | { |
7442 | avox | 402 | if (textFrame->doc()->paragraphStyles()[i].name() == name) |
411 | Franz | 403 | { |
364 | Franz | 404 | pstyleIndex = i; |
405 | break; |
||
406 | } |
||
407 | } |
||
408 | return pstyleIndex; |
||
409 | } |
||
410 | |||
411 | int gtAction::applyParagraphStyle(gtParagraphStyle* pstyle) |
||
412 | { |
||
413 | int pstyleIndex = findParagraphStyle(pstyle); |
||
414 | if (pstyleIndex == -1) |
||
415 | { |
||
416 | createParagraphStyle(pstyle); |
||
7442 | avox | 417 | pstyleIndex = textFrame->doc()->paragraphStyles().count() - 1; |
364 | Franz | 418 | } |
411 | Franz | 419 | else if (updateParagraphStyles) |
420 | { |
||
421 | updateParagraphStyle(pstyleIndex, pstyle); |
||
422 | } |
||
364 | Franz | 423 | return pstyleIndex; |
424 | } |
||
425 | |||
426 | void gtAction::applyFrameStyle(gtFrameStyle* fstyle) |
||
427 | { |
||
5559 | avox | 428 | textFrame->setColumns(fstyle->getColumns()); |
429 | textFrame->setColumnGap(fstyle->getColumnsGap()); |
||
1394 | cbradney | 430 | textFrame->setFillColor(parseColor(fstyle->getBgColor())); |
431 | textFrame->setFillShade(fstyle->getBgShade()); |
||
7994 | avox | 432 | ParagraphStyle newTabs(textFrame->itemText.defaultStyle()); |
9803 | fschmid | 433 | newTabs.setTabValues(QList<ParagraphStyle::TabRecord>(*(fstyle->getTabValues()))); |
7994 | avox | 434 | textFrame->itemText.setDefaultStyle(newTabs); |
4546 | subik | 435 | |
411 | Franz | 436 | // gtParagraphStyle* pstyle = new gtParagraphStyle(*fstyle); |
437 | // int pstyleIndex = findParagraphStyle(pstyle); |
||
438 | // if (pstyleIndex == -1) |
||
439 | // pstyleIndex = 0; |
||
1065 | cbradney | 440 | // textFrame->Doc->currentParaStyle = pstyleIndex; |
375 | Franz | 441 | |
5559 | avox | 442 | /* FIXME |
411 | Franz | 443 | double linesp; |
444 | if (fstyle->getAutoLineSpacing()) |
||
445 | linesp = getLineSpacing(fstyle->getFont()->getSize()); |
||
446 | else |
||
447 | linesp = fstyle->getLineSpacing(); |
||
4584 | cbradney | 448 | textFrame->setLineSpacing(linesp); |
449 | textFrame->setLineSpacingMode(0); |
||
375 | Franz | 450 | gtFont* font = fstyle->getFont(); |
5980 | avox | 451 | Scface* scfont = validateFont(font); |
5184 | avox | 452 | textFrame->setFont(scfont->scName()); |
4073 | cbradney | 453 | textFrame->setFontSize(font->getSize()); |
833 | tsoots | 454 | textFrame->TxtFill = parseColor(font->getColor()); |
375 | Franz | 455 | textFrame->ShTxtFill = font->getShade(); |
833 | tsoots | 456 | textFrame->TxtStroke = parseColor(font->getStrokeColor()); |
375 | Franz | 457 | textFrame->ShTxtStroke = font->getStrokeShade(); |
2254 | fschmid | 458 | textFrame->TxtScale = font->getHscale(); |
459 | textFrame->TxtScaleV = 1000; |
||
2234 | fschmid | 460 | textFrame->TxtBase = 0; |
2247 | fschmid | 461 | textFrame->TxtShadowX = 50; |
462 | textFrame->TxtShadowY = -50; |
||
2257 | fschmid | 463 | textFrame->TxtOutline = 10; |
2262 | fschmid | 464 | textFrame->TxtUnderPos = -1; |
465 | textFrame->TxtUnderWidth = -1; |
||
2272 | fschmid | 466 | textFrame->TxtStrikePos = -1; |
467 | textFrame->TxtStrikeWidth = -1; |
||
411 | Franz | 468 | textFrame->ExtraV = font->getKerning(); |
5559 | avox | 469 | */ |
364 | Franz | 470 | } |
471 | |||
472 | void gtAction::getFrameFont(gtFont *font) |
||
473 | { |
||
5569 | avox | 474 | const CharStyle& style(textFrame->itemText.defaultStyle().charStyle()); |
5559 | avox | 475 | |
12895 | jghali | 476 | if (!style.isInhFont()) |
477 | font->setName(style.font().scName()); |
||
478 | if (!style.isInhFontSize()) |
||
479 | font->setSize(style.fontSize()); |
||
480 | if (!style.isInhFillColor()) |
||
481 | font->setColor(style.fillColor()); |
||
482 | if (!style.isInhFillShade()) |
||
483 | font->setShade(qRound(style.fillShade())); |
||
484 | if (!style.isInhStrokeColor()) |
||
485 | font->setStrokeColor(style.strokeColor()); |
||
486 | if (!style.isInhStrokeShade()) |
||
487 | font->setStrokeShade(qRound(style.strokeShade())); |
||
488 | if (!style.isInhScaleH()) |
||
489 | font->setHscale(qRound(style.scaleH())); |
||
364 | Franz | 490 | font->setKerning(0); |
491 | } |
||
492 | |||
493 | void gtAction::getFrameStyle(gtFrameStyle *fstyle) |
||
494 | { |
||
495 | fstyle->setColumns(textFrame->Cols); |
||
496 | fstyle->setColumnsGap(textFrame->ColGap); |
||
1394 | cbradney | 497 | fstyle->setBgColor(textFrame->fillColor()); |
10510 | fschmid | 498 | fstyle->setBgShade(qRound(textFrame->fillShade())); |
4546 | subik | 499 | |
5569 | avox | 500 | const ParagraphStyle& vg(textFrame->itemText.defaultStyle()); |
5184 | avox | 501 | fstyle->setName(vg.name()); |
502 | fstyle->setLineSpacing(vg.lineSpacing()); |
||
8871 | cbradney | 503 | fstyle->setAdjToBaseline(vg.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing); |
4546 | subik | 504 | |
12895 | jghali | 505 | if (!vg.isInhAlignment()) |
506 | fstyle->setAlignment(vg.alignment()); |
||
507 | if (!vg.isInhLeftMargin()) |
||
508 | fstyle->setIndent(vg.leftMargin()); |
||
509 | if (!vg.isInhFirstIndent()) |
||
510 | fstyle->setFirstLineIndent(vg.firstIndent()); |
||
511 | if (!vg.isInhGapBefore()) |
||
512 | fstyle->setSpaceAbove(vg.gapBefore()); |
||
513 | if (!vg.isInhGapAfter()) |
||
514 | fstyle->setSpaceBelow(vg.gapAfter()); |
||
515 | if (!vg.isInhHasDropCap()) |
||
516 | fstyle->setDropCap(vg.hasDropCap()); |
||
517 | if (!vg.isInhDropCapLines()) |
||
518 | fstyle->setDropCapHeight(vg.dropCapLines()); |
||
18047 | craig | 519 | if (!vg.isInhHasBullet()) |
520 | fstyle->setBullet(vg.hasBullet(), vg.bulletStr()); |
||
521 | if (!vg.isInhHasNum()) |
||
522 | fstyle->setNum(vg.hasNum(),vg.numFormat(),vg.numLevel(), vg.numStart(), vg.numPrefix(), vg.numSuffix()); |
||
12895 | jghali | 523 | |
364 | Franz | 524 | gtFont font; |
525 | getFrameFont(&font); |
||
526 | fstyle->setFont(font); |
||
387 | Franz | 527 | fstyle->setName("Default frame style"); |
364 | Franz | 528 | } |
529 | |||
530 | void gtAction::createParagraphStyle(gtParagraphStyle* pstyle) |
||
531 | { |
||
5781 | cbradney | 532 | ScribusDoc* currDoc=textFrame->doc(); |
10400 | subik | 533 | for (int i = 0; i < currDoc->paragraphStyles().count(); ++i) |
364 | Franz | 534 | { |
7442 | avox | 535 | if (currDoc->paragraphStyles()[i].name() == pstyle->getName()) |
6733 | avox | 536 | return; |
411 | Franz | 537 | } |
364 | Franz | 538 | gtFont* font = pstyle->getFont(); |
12895 | jghali | 539 | |
5184 | avox | 540 | ParagraphStyle vg; |
12895 | jghali | 541 | setParaStyleAttributes(pstyle, vg); |
542 | setCharStyleAttributes(font, vg.charStyle()); |
||
543 | |||
544 | // Maybe set those attributes when target is the frame |
||
545 | /*vg.charStyle().setShadowXOffset(50); |
||
5691 | avox | 546 | vg.charStyle().setShadowYOffset(-50); |
547 | vg.charStyle().setOutlineWidth(10); |
||
548 | vg.charStyle().setScaleH(1000); |
||
549 | vg.charStyle().setScaleV(1000); |
||
550 | vg.charStyle().setBaselineOffset(0); |
||
551 | vg.charStyle().setTracking(0); |
||
5781 | cbradney | 552 | vg.charStyle().setUnderlineOffset(textFrame->doc()->typographicSettings.valueUnderlinePos); |
553 | vg.charStyle().setUnderlineWidth(textFrame->doc()->typographicSettings.valueUnderlineWidth); |
||
554 | vg.charStyle().setStrikethruOffset(textFrame->doc()->typographicSettings.valueStrikeThruPos); |
||
12895 | jghali | 555 | vg.charStyle().setStrikethruWidth(textFrame->doc()->typographicSettings.valueStrikeThruPos);*/ |
7442 | avox | 556 | |
557 | StyleSet<ParagraphStyle> tmp; |
||
558 | tmp.create(vg); |
||
559 | textFrame->doc()->redefineStyles(tmp, false); |
||
560 | |||
16546 | jghali | 561 | m_ScMW->propertiesPalette->textPal->updateParagraphStyles(); |
364 | Franz | 562 | } |
563 | |||
12895 | jghali | 564 | void gtAction:: setCharStyleAttributes(gtFont *font, CharStyle& style) |
565 | { |
||
566 | int flags = font->getFlags(); |
||
567 | style.erase(); |
||
568 | |||
13648 | jghali | 569 | if ((flags & gtFont::familyWasSet) || (flags & gtFont::weightWasSet) || (flags & gtFont::slantWasSet)) |
12895 | jghali | 570 | style.setFont(validateFont(font)); |
571 | if (flags & gtFont::sizeWasSet) |
||
572 | style.setFontSize(font->getSize()); |
||
573 | if (flags & gtFont::effectWasSet) |
||
574 | style.setFeatures(static_cast<StyleFlag>(font->getEffectsValue()).featureList()); |
||
575 | if (flags & gtFont::fillColorWasSet) |
||
576 | style.setFillColor(parseColor(font->getColor())); |
||
577 | if (flags & gtFont::fillShadeWasSet) |
||
578 | style.setFillShade(font->getShade()); |
||
579 | if (flags & gtFont::strokeColorWasSet) |
||
580 | style.setStrokeColor(parseColor(font->getStrokeColor())); |
||
581 | if (flags & gtFont::strokeShadeWasSet) |
||
582 | style.setStrokeShade(font->getStrokeShade()); |
||
583 | if (flags & gtFont::hscaleWasSet) |
||
584 | style.setScaleH(font->getHscale()); |
||
585 | if (flags & gtFont::kerningWasSet) |
||
586 | style.setTracking(font->getKerning()); |
||
587 | } |
||
588 | |||
589 | void gtAction::setParaStyleAttributes(gtParagraphStyle *pstyle, ParagraphStyle& style) |
||
590 | { |
||
591 | double linesp; |
||
592 | int flags = pstyle->getFlags(); |
||
593 | style.erase(); |
||
594 | |||
595 | style.setName(pstyle->getName()); |
||
596 | if (pstyle->getAutoLineSpacing()) |
||
597 | linesp = getLineSpacing(pstyle->getFont()->getSize()); |
||
598 | else |
||
599 | linesp = pstyle->getLineSpacing(); |
||
600 | style.setLineSpacingMode(pstyle->isAdjToBaseline() ? ParagraphStyle::BaselineGridLineSpacing : ParagraphStyle::FixedLineSpacing); |
||
601 | style.setLineSpacing(linesp); |
||
602 | |||
603 | if (flags & gtParagraphStyle::alignmentWasSet) |
||
604 | style.setAlignment(static_cast<ParagraphStyle::AlignmentType>(pstyle->getAlignment())); |
||
605 | if (flags & gtParagraphStyle::indentWasSet) |
||
606 | style.setLeftMargin(pstyle->getIndent()); |
||
607 | if (flags & gtParagraphStyle::firstIndentWasSet) |
||
608 | style.setFirstIndent(pstyle->getFirstLineIndent()); |
||
609 | if (flags & gtParagraphStyle::spaceAboveWasSet) |
||
610 | style.setGapBefore(pstyle->getSpaceAbove()); |
||
611 | if (flags & gtParagraphStyle::spaceBelowWasSet) |
||
612 | style.setGapAfter(pstyle->getSpaceBelow()); |
||
613 | if (flags & gtParagraphStyle::tabValueWasSet) |
||
614 | style.setTabValues(*pstyle->getTabValues()); |
||
615 | if (flags & gtParagraphStyle::dropCapWasSet) |
||
616 | style.setHasDropCap(pstyle->hasDropCap()); |
||
617 | if (flags & gtParagraphStyle::dropCapHeightWasSet) |
||
618 | style.setDropCapLines(pstyle->getDropCapHeight()); |
||
18047 | craig | 619 | if (flags & gtParagraphStyle::bulletWasSet) |
620 | { |
||
621 | style.setHasBullet(pstyle->hasBullet()); |
||
622 | style.setBulletStr(pstyle->getBullet()); |
||
623 | } |
||
624 | if (flags & gtParagraphStyle::numWasSet) |
||
625 | { |
||
626 | style.setHasNum(pstyle->hasNum()); |
||
627 | style.setNumName(pstyle->getName()); |
||
628 | style.setNumFormat(pstyle->getNumFormat()); |
||
629 | style.setNumLevel(pstyle->getNumLevel()); |
||
630 | style.setNumStart(pstyle->getNumStart()); |
||
631 | style.setNumHigher(true); |
||
632 | style.setNumOther(true); |
||
633 | style.setNumPrefix(pstyle->getNumPrefix()); |
||
634 | style.setNumSuffix(pstyle->getNumSuffix()); |
||
635 | } |
||
636 | |||
12895 | jghali | 637 | /*vg.setDropCapOffset(0);*/ |
638 | } |
||
639 | |||
411 | Franz | 640 | void gtAction::removeParagraphStyle(const QString& name) |
641 | { |
||
642 | int index = findParagraphStyle(name); |
||
643 | if (index != -1) |
||
644 | removeParagraphStyle(index); |
||
645 | } |
||
646 | |||
647 | void gtAction::removeParagraphStyle(int index) |
||
648 | { |
||
7442 | avox | 649 | QMap<QString, QString> map; |
650 | map[textFrame->doc()->paragraphStyles()[index].name()] = ""; |
||
651 | textFrame->doc()->replaceStyles(map); |
||
411 | Franz | 652 | } |
653 | |||
1185 | tsoots | 654 | void gtAction::updateParagraphStyle(const QString&, gtParagraphStyle* pstyle) |
411 | Franz | 655 | { |
656 | int pstyleIndex = findParagraphStyle(pstyle->getName()); |
||
657 | if (pstyleIndex != -1) |
||
658 | updateParagraphStyle(pstyleIndex, pstyle); |
||
659 | } |
||
660 | |||
661 | void gtAction::updateParagraphStyle(int pstyleIndex, gtParagraphStyle* pstyle) |
||
662 | { |
||
663 | gtFont* font = pstyle->getFont(); |
||
5184 | avox | 664 | ParagraphStyle vg; |
12895 | jghali | 665 | |
666 | setParaStyleAttributes(pstyle, vg); |
||
667 | setCharStyleAttributes(font, vg.charStyle()); |
||
668 | |||
669 | // Maybe set those attributes when target is the frame |
||
670 | /*vg.charStyle().setShadowXOffset(50); |
||
5691 | avox | 671 | vg.charStyle().setShadowYOffset(-50); |
672 | vg.charStyle().setOutlineWidth(10); |
||
673 | vg.charStyle().setScaleH(1000); |
||
674 | vg.charStyle().setScaleV(1000); |
||
675 | vg.charStyle().setBaselineOffset(0); |
||
676 | vg.charStyle().setTracking(0); |
||
5781 | cbradney | 677 | vg.charStyle().setUnderlineOffset(textFrame->doc()->typographicSettings.valueUnderlinePos); |
678 | vg.charStyle().setUnderlineWidth(textFrame->doc()->typographicSettings.valueUnderlineWidth); |
||
679 | vg.charStyle().setStrikethruOffset(textFrame->doc()->typographicSettings.valueStrikeThruPos); |
||
12895 | jghali | 680 | vg.charStyle().setStrikethruWidth(textFrame->doc()->typographicSettings.valueStrikeThruPos);*/ |
681 | |||
7442 | avox | 682 | StyleSet<ParagraphStyle> tmp; |
683 | tmp.create(vg); |
||
684 | textFrame->doc()->redefineStyles(tmp, false); |
||
685 | if (vg.name() != textFrame->doc()->paragraphStyles()[pstyleIndex].name()) |
||
686 | { |
||
687 | QMap<QString, QString> map; |
||
688 | map[textFrame->doc()->paragraphStyles()[pstyleIndex].name()] = vg.name(); |
||
689 | textFrame->doc()->replaceStyles(map); |
||
690 | } |
||
411 | Franz | 691 | } |
692 | |||
5980 | avox | 693 | ScFace gtAction::validateFont(gtFont* font) |
364 | Franz | 694 | { |
411 | Franz | 695 | // Dirty hack for family Times New Roman |
696 | if (font->getFamily() == "Times New") |
||
697 | { |
||
698 | font->setFamily("Times New Roman"); |
||
699 | if (font->getWeight() == "Roman") |
||
700 | font->setWeight("Regular"); |
||
701 | } |
||
702 | |||
375 | Franz | 703 | QString useFont = font->getName(); |
2877 | cbradney | 704 | if ((useFont.isNull()) || (useFont.isEmpty())) |
5980 | avox | 705 | useFont = textFrame->itemText.defaultStyle().charStyle().font().scName(); |
13955 | cbradney | 706 | else if (prefsManager->appPrefs.fontPrefs.AvailFonts[font->getName()].isNone()) |
364 | Franz | 707 | { |
387 | Franz | 708 | bool found = false; |
9429 | jghali | 709 | // Do not empty otherwise user may be asked to replace an empty font |
710 | // by font replacement dialog |
||
711 | // useFont = ""; |
||
387 | Franz | 712 | QString tmpName = findFontName(font); |
9506 | jghali | 713 | if (!tmpName.isEmpty()) |
375 | Franz | 714 | { |
387 | Franz | 715 | useFont = tmpName; |
716 | found = true; |
||
375 | Franz | 717 | } |
387 | Franz | 718 | if (!found) |
719 | { |
||
720 | if (font->getSlant() == gtFont::fontSlants[ITALIC]) |
||
721 | { |
||
722 | gtFont* tmp = new gtFont(*font); |
||
723 | tmp->setSlant(OBLIQUE); |
||
724 | tmpName = findFontName(tmp); |
||
9506 | jghali | 725 | if (!tmpName.isEmpty()) |
387 | Franz | 726 | { |
727 | useFont = tmpName; |
||
728 | found = true; |
||
729 | } |
||
730 | delete tmp; |
||
731 | } |
||
732 | else if (font->getSlant() == gtFont::fontSlants[OBLIQUE]) |
||
733 | { |
||
734 | gtFont* tmp = new gtFont(*font); |
||
735 | tmp->setSlant(ITALIC); |
||
736 | tmpName = findFontName(tmp); |
||
9506 | jghali | 737 | if (!tmpName.isEmpty()) |
387 | Franz | 738 | { |
739 | useFont = tmpName; |
||
740 | found = true; |
||
741 | } |
||
742 | delete tmp; |
||
743 | } |
||
744 | if (!found) |
||
745 | { |
||
13967 | cbradney | 746 | if (!prefsManager->appPrefs.fontPrefs.GFontSub.contains(font->getName())) |
387 | Franz | 747 | { |
5781 | cbradney | 748 | MissingFont *dia = new MissingFont(0, useFont, textFrame->doc()); |
387 | Franz | 749 | dia->exec(); |
713 | cbradney | 750 | useFont = dia->getReplacementFont(); |
13967 | cbradney | 751 | prefsManager->appPrefs.fontPrefs.GFontSub[font->getName()] = useFont; |
387 | Franz | 752 | delete dia; |
753 | } |
||
754 | else |
||
13967 | cbradney | 755 | useFont = prefsManager->appPrefs.fontPrefs.GFontSub[font->getName()]; |
387 | Franz | 756 | } |
757 | } |
||
364 | Franz | 758 | } |
411 | Franz | 759 | |
5781 | cbradney | 760 | if(!textFrame->doc()->UsedFonts.contains(useFont)) |
761 | textFrame->doc()->AddFont(useFont); |
||
13955 | cbradney | 762 | return prefsManager->appPrefs.fontPrefs.AvailFonts[useFont]; |
364 | Franz | 763 | } |
764 | |||
387 | Franz | 765 | QString gtAction::findFontName(gtFont* font) |
766 | { |
||
8595 | jghali | 767 | QString ret = QString(); |
387 | Franz | 768 | for (uint i = 0; i < static_cast<uint>(gtFont::NAMECOUNT); ++i) |
769 | { |
||
770 | QString nname = font->getName(i); |
||
13955 | cbradney | 771 | if (! prefsManager->appPrefs.fontPrefs.AvailFonts[nname].isNone()) |
387 | Franz | 772 | { |
773 | ret = nname; |
||
774 | break; |
||
775 | } |
||
776 | } |
||
777 | return ret; |
||
778 | } |
||
779 | |||
411 | Franz | 780 | double gtAction::getLineSpacing(int fontSize) |
781 | { |
||
17223 | jghali | 782 | return ((fontSize / 10.0) * (static_cast<double>(textFrame->doc()->typographicPrefs().autoLineSpacing) / 100)); |
411 | Franz | 783 | } |
784 | |||
375 | Franz | 785 | double gtAction::getFrameWidth() |
786 | { |
||
3934 | cbradney | 787 | return textFrame->width(); |
375 | Franz | 788 | } |
789 | |||
790 | QString gtAction::getFrameName() |
||
791 | { |
||
1361 | tsoots | 792 | return QString(textFrame->itemName()); |
375 | Franz | 793 | } |
794 | |||
411 | Franz | 795 | bool gtAction::getUpdateParagraphStyles() |
796 | { |
||
797 | return updateParagraphStyles; |
||
798 | } |
||
799 | |||
800 | void gtAction::setUpdateParagraphStyles(bool newUPS) |
||
801 | { |
||
802 | updateParagraphStyles = newUPS; |
||
803 | } |
||
804 | |||
418 | Franz | 805 | bool gtAction::getOverridePStyleFont() |
806 | { |
||
807 | return overridePStyleFont; |
||
808 | } |
||
809 | void gtAction::setOverridePStyleFont(bool newOPSF) |
||
810 | { |
||
811 | overridePStyleFont = newOPSF; |
||
812 | } |
||
813 | |||
833 | tsoots | 814 | QString gtAction::parseColor(const QString &s) |
815 | { |
||
4546 | subik | 816 | QString ret = CommonStrings::None; |
817 | if (s == CommonStrings::None) |
||
833 | tsoots | 818 | return ret; // don't want None to become Black or any color |
819 | bool found = false; |
||
1065 | cbradney | 820 | ColorList::Iterator it; |
5781 | cbradney | 821 | for (it = textFrame->doc()->PageColors.begin(); it != textFrame->doc()->PageColors.end(); ++it) |
833 | tsoots | 822 | { |
823 | if (it.key() == s) |
||
824 | { |
||
825 | ret = it.key(); |
||
826 | found = true; |
||
827 | } |
||
828 | } |
||
829 | if (!found) |
||
830 | { |
||
831 | QColor c; |
||
832 | if( s.startsWith( "rgb(" ) ) |
||
833 | { |
||
10394 | cbradney | 834 | QString parse = s.trimmed(); |
10603 | fschmid | 835 | QStringList colors = parse.split(',', QString::SkipEmptyParts); |
833 | tsoots | 836 | QString r = colors[0].right( ( colors[0].length() - 4 ) ); |
837 | QString g = colors[1]; |
||
838 | QString b = colors[2].left( ( colors[2].length() - 1 ) ); |
||
839 | if( r.contains( "%" ) ) |
||
840 | { |
||
15498 | jghali | 841 | r.chop(1); |
13464 | cbradney | 842 | r = QString::number( static_cast<int>( ( static_cast<double>( 255 * ScCLocale::toDoubleC(r) ) / 100.0 ) ) ); |
833 | tsoots | 843 | } |
844 | if( g.contains( "%" ) ) |
||
845 | { |
||
15498 | jghali | 846 | g.chop(1); |
13464 | cbradney | 847 | g = QString::number( static_cast<int>( ( static_cast<double>( 255 * ScCLocale::toDoubleC(g) ) / 100.0 ) ) ); |
833 | tsoots | 848 | } |
849 | if( b.contains( "%" ) ) |
||
850 | { |
||
15498 | jghali | 851 | b.chop(1); |
13464 | cbradney | 852 | b = QString::number( static_cast<int>( ( static_cast<double>( 255 * ScCLocale::toDoubleC(b) ) / 100.0 ) ) ); |
833 | tsoots | 853 | } |
854 | c = QColor(r.toInt(), g.toInt(), b.toInt()); |
||
855 | } |
||
856 | else |
||
857 | { |
||
10394 | cbradney | 858 | QString rgbColor = s.trimmed(); |
833 | tsoots | 859 | if( rgbColor.startsWith( "#" ) ) |
860 | c.setNamedColor( rgbColor ); |
||
861 | else |
||
862 | c = parseColorN( rgbColor ); |
||
863 | } |
||
864 | found = false; |
||
5781 | cbradney | 865 | for (it = textFrame->doc()->PageColors.begin(); it != textFrame->doc()->PageColors.end(); ++it) |
833 | tsoots | 866 | { |
10427 | cbradney | 867 | if (c == ScColorEngine::getRGBColor(it.value(), textFrame->doc())) |
833 | tsoots | 868 | { |
869 | ret = it.key(); |
||
870 | found = true; |
||
871 | } |
||
872 | } |
||
873 | if (!found) |
||
874 | { |
||
2886 | fschmid | 875 | ScColor tmp; |
833 | tsoots | 876 | tmp.fromQColor(c); |
5781 | cbradney | 877 | textFrame->doc()->PageColors.insert("FromGetText"+c.name(), tmp); |
878 | m_ScMW->propertiesPalette->updateColorList(); |
||
833 | tsoots | 879 | ret = "FromGetText"+c.name(); |
880 | } |
||
881 | } |
||
882 | return ret; |
||
883 | } |
||
884 | |||
885 | QColor gtAction::parseColorN(const QString &rgbColor) |
||
886 | { |
||
887 | int r, g, b; |
||
888 | keywordToRGB( rgbColor, r, g, b ); |
||
889 | return QColor( r, g, b ); |
||
890 | } |
||
891 | |||
364 | Franz | 892 | void gtAction::finalize() |
893 | { |
||
5781 | cbradney | 894 | if (textFrame->doc()->docHyphenator->AutoCheck) |
895 | textFrame->doc()->docHyphenator->slotHyphenate(textFrame); |
||
10701 | avox | 896 | textFrame->doc()->regionsChanged()->update(QRectF()); |
5781 | cbradney | 897 | textFrame->doc()->changed(); |
364 | Franz | 898 | } |
899 | |||
900 | gtAction::~gtAction() |
||
901 | { |
||
902 | finalize(); |
||
903 | } |