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