Rev 1185 | Rev 1394 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
364 | Franz | 1 | /*************************************************************************** |
2 | * Copyright (C) 2004 by Riku Leino * |
||
1184 | tsoots | 3 | * tsoots@gmail.com * |
364 | Franz | 4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
||
6 | * it under the terms of the GNU General Public License as published by * |
||
7 | * the Free Software Foundation; either version 2 of the License, or * |
||
8 | * (at your option) any later version. * |
||
9 | * * |
||
10 | * This program is distributed in the hope that it will be useful, * |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
13 | * GNU General Public License for more details. * |
||
14 | * * |
||
15 | * You should have received a copy of the GNU General Public License * |
||
16 | * along with this program; if not, write to the * |
||
17 | * Free Software Foundation, Inc., * |
||
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
19 | ***************************************************************************/ |
||
20 | |||
713 | cbradney | 21 | #include "missing.h" |
364 | Franz | 22 | #include "gtaction.h" |
759 | cbradney | 23 | #include "mpalette.h" |
766 | cbradney | 24 | #include "scribus.h" |
415 | Franz | 25 | #include <qcursor.h> |
833 | tsoots | 26 | #include <qstringlist.h> |
27 | #include "color.h" |
||
364 | Franz | 28 | |
29 | extern ScribusApp* ScApp; |
||
30 | |||
31 | gtAction::gtAction(bool append) |
||
32 | { |
||
456 | fschmid | 33 | textFrame = ScApp->view->SelItem.at(0); |
364 | Franz | 34 | it = textFrame; |
35 | lastParagraphStyle = -1; |
||
411 | Franz | 36 | inPara = false; |
418 | Franz | 37 | isFirstWrite = true; |
364 | Franz | 38 | lastCharWasLineChange = false; |
375 | Franz | 39 | currentFrameStyle = ""; |
418 | Franz | 40 | doAppend = append; |
411 | Franz | 41 | updateParagraphStyles = false; |
418 | Franz | 42 | overridePStyleFont = true; |
364 | Franz | 43 | } |
44 | |||
45 | void gtAction::setProgressInfo() |
||
46 | { |
||
47 | ScApp->FMess->setText(QObject::tr("Importing text")); |
||
48 | ScApp->FProg->reset(); |
||
49 | ScApp->FProg->setTotalSteps(0); |
||
50 | } |
||
51 | |||
52 | void gtAction::setProgressInfoDone() |
||
53 | { |
||
54 | ScApp->FMess->setText(""); |
||
55 | ScApp->FProg->reset(); |
||
56 | } |
||
57 | |||
58 | void gtAction::setInfo(QString infoText) |
||
59 | { |
||
60 | ScApp->FMess->setText(infoText); |
||
61 | } |
||
62 | |||
63 | void gtAction::clearFrame() |
||
64 | { |
||
1065 | cbradney | 65 | textFrame->itemText.clear(); |
364 | Franz | 66 | textFrame->CPos = 0; |
67 | } |
||
68 | |||
411 | Franz | 69 | void gtAction::write(const QString& text, gtStyle *style) |
364 | Franz | 70 | { |
418 | Franz | 71 | if (isFirstWrite) |
72 | { |
||
73 | if (!doAppend) |
||
74 | { |
||
75 | if (it->NextBox != 0) |
||
76 | { |
||
77 | PageItem *nb = it->NextBox; |
||
78 | while (nb != 0) |
||
79 | { |
||
1065 | cbradney | 80 | nb->itemText.clear(); |
418 | Franz | 81 | nb->CPos = 0; |
82 | nb = nb->NextBox; |
||
83 | } |
||
84 | } |
||
1065 | cbradney | 85 | it->itemText.clear(); |
418 | Franz | 86 | it->CPos = 0; |
87 | } |
||
88 | } |
||
411 | Franz | 89 | int paragraphStyle = -1; |
364 | Franz | 90 | if (style->target() == "paragraph") |
91 | { |
||
92 | gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style); |
||
93 | paragraphStyle = applyParagraphStyle(pstyle); |
||
418 | Franz | 94 | if (isFirstWrite) |
95 | inPara = true; |
||
364 | Franz | 96 | } |
97 | else if (style->target() == "frame") |
||
98 | { |
||
99 | gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style); |
||
100 | applyFrameStyle(fstyle); |
||
101 | } |
||
411 | Franz | 102 | |
103 | if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1)) |
||
104 | paragraphStyle = lastParagraphStyle; |
||
105 | |||
106 | |||
107 | if (paragraphStyle == -1) |
||
1065 | cbradney | 108 | paragraphStyle = ScApp->doc->currentParaStyle; |
411 | Franz | 109 | |
364 | Franz | 110 | gtFont* font = style->getFont(); |
375 | Franz | 111 | QString fontName = validateFont(font); |
418 | Franz | 112 | gtFont* font2 = new gtFont(*font); |
1065 | cbradney | 113 | font2->setName(ScApp->doc->docParagraphStyles[paragraphStyle].Font); |
418 | Franz | 114 | QString fontName2 = validateFont(font2); |
364 | Franz | 115 | for (uint a = 0; a < text.length(); ++a) |
116 | { |
||
117 | if ((text.at(a) == QChar(0)) || (text.at(a) == QChar(13))) |
||
118 | continue; |
||
1065 | cbradney | 119 | struct ScText *hg = new ScText; |
364 | Franz | 120 | hg->ch = text.at(a); |
121 | if ((hg->ch == QChar(10)) || (hg->ch == QChar(5))) |
||
122 | hg->ch = QChar(13); |
||
418 | Franz | 123 | if ((inPara) && (!overridePStyleFont)) |
124 | { |
||
1065 | cbradney | 125 | if (ScApp->doc->docParagraphStyles[paragraphStyle].Font == "") |
418 | Franz | 126 | hg->cfont = fontName2; |
127 | else |
||
1065 | cbradney | 128 | hg->cfont = ScApp->doc->docParagraphStyles[paragraphStyle].Font; |
129 | hg->csize = ScApp->doc->docParagraphStyles[paragraphStyle].FontSize; |
||
130 | hg->ccolor = ScApp->doc->docParagraphStyles[paragraphStyle].FColor; |
||
131 | hg->cshade = ScApp->doc->docParagraphStyles[paragraphStyle].FShade; |
||
132 | hg->cstroke = ScApp->doc->docParagraphStyles[paragraphStyle].SColor; |
||
133 | hg->cshade2 = ScApp->doc->docParagraphStyles[paragraphStyle].SShade; |
||
134 | hg->cstyle = ScApp->doc->docParagraphStyles[paragraphStyle].FontEffect; |
||
418 | Franz | 135 | } |
136 | else |
||
137 | { |
||
138 | hg->cfont = fontName; |
||
139 | hg->csize = font->getSize(); |
||
833 | tsoots | 140 | hg->ccolor = parseColor(font->getColor()); |
418 | Franz | 141 | hg->cshade = font->getShade(); |
833 | tsoots | 142 | hg->cstroke = parseColor(font->getStrokeColor()); |
418 | Franz | 143 | hg->cshade2 = font->getStrokeShade(); |
144 | hg->cstyle = font->getEffectsValue(); |
||
145 | } |
||
364 | Franz | 146 | hg->cscale = font->getHscale(); |
147 | hg->cextra = font->getKerning(); |
||
148 | hg->cselect = false; |
||
411 | Franz | 149 | hg->cab = paragraphStyle; |
364 | Franz | 150 | hg->xp = 0; |
151 | hg->yp = 0; |
||
152 | hg->PtransX = 0; |
||
153 | hg->PtransY = 0; |
||
1065 | cbradney | 154 | it->itemText.append(hg); |
364 | Franz | 155 | } |
411 | Franz | 156 | lastCharWasLineChange = text.right(1) == "\n"; |
157 | inPara = style->target() == "paragraph"; |
||
158 | lastParagraphStyle = paragraphStyle; |
||
418 | Franz | 159 | if (isFirstWrite) |
160 | isFirstWrite = false; |
||
364 | Franz | 161 | } |
162 | |||
163 | int gtAction::findParagraphStyle(gtParagraphStyle* pstyle) |
||
164 | { |
||
411 | Franz | 165 | return findParagraphStyle(pstyle->getName()); |
166 | } |
||
167 | |||
168 | int gtAction::findParagraphStyle(const QString& name) |
||
169 | { |
||
364 | Franz | 170 | int pstyleIndex = -1; |
1065 | cbradney | 171 | for (uint i = 0; i < ScApp->doc->docParagraphStyles.size(); ++i) |
364 | Franz | 172 | { |
1065 | cbradney | 173 | if (ScApp->doc->docParagraphStyles[i].Vname == name) |
411 | Franz | 174 | { |
364 | Franz | 175 | pstyleIndex = i; |
176 | break; |
||
177 | } |
||
178 | } |
||
179 | return pstyleIndex; |
||
180 | } |
||
181 | |||
182 | int gtAction::applyParagraphStyle(gtParagraphStyle* pstyle) |
||
183 | { |
||
184 | int pstyleIndex = findParagraphStyle(pstyle); |
||
185 | if (pstyleIndex == -1) |
||
186 | { |
||
187 | createParagraphStyle(pstyle); |
||
1065 | cbradney | 188 | pstyleIndex = ScApp->doc->docParagraphStyles.size() - 1; |
364 | Franz | 189 | } |
411 | Franz | 190 | else if (updateParagraphStyles) |
191 | { |
||
192 | updateParagraphStyle(pstyleIndex, pstyle); |
||
193 | } |
||
364 | Franz | 194 | return pstyleIndex; |
195 | } |
||
196 | |||
197 | void gtAction::applyFrameStyle(gtFrameStyle* fstyle) |
||
198 | { |
||
375 | Franz | 199 | textFrame->Cols = fstyle->getColumns(); |
200 | textFrame->ColGap = fstyle->getColumnsGap(); |
||
833 | tsoots | 201 | textFrame->Pcolor = parseColor(fstyle->getBgColor()); |
375 | Franz | 202 | textFrame->Shade = fstyle->getBgShade(); |
387 | Franz | 203 | textFrame->TabValues = QValueList<double>(*(fstyle->getTabValues())); |
375 | Franz | 204 | |
411 | Franz | 205 | // gtParagraphStyle* pstyle = new gtParagraphStyle(*fstyle); |
206 | // int pstyleIndex = findParagraphStyle(pstyle); |
||
207 | // if (pstyleIndex == -1) |
||
208 | // pstyleIndex = 0; |
||
1065 | cbradney | 209 | // textFrame->Doc->currentParaStyle = pstyleIndex; |
375 | Franz | 210 | |
411 | Franz | 211 | double linesp; |
212 | if (fstyle->getAutoLineSpacing()) |
||
213 | linesp = getLineSpacing(fstyle->getFont()->getSize()); |
||
214 | else |
||
215 | linesp = fstyle->getLineSpacing(); |
||
216 | textFrame->LineSp = linesp; |
||
217 | |||
375 | Franz | 218 | gtFont* font = fstyle->getFont(); |
219 | QString fontName = validateFont(font); |
||
220 | textFrame->IFont = fontName; |
||
221 | textFrame->ISize = font->getSize(); |
||
833 | tsoots | 222 | textFrame->TxtFill = parseColor(font->getColor()); |
375 | Franz | 223 | textFrame->ShTxtFill = font->getShade(); |
833 | tsoots | 224 | textFrame->TxtStroke = parseColor(font->getStrokeColor()); |
375 | Franz | 225 | textFrame->ShTxtStroke = font->getStrokeShade(); |
226 | textFrame->TxtScale = font->getHscale(); |
||
411 | Franz | 227 | textFrame->ExtraV = font->getKerning(); |
364 | Franz | 228 | } |
229 | |||
230 | void gtAction::getFrameFont(gtFont *font) |
||
231 | { |
||
232 | font->setName(textFrame->IFont); |
||
233 | font->setSize(textFrame->ISize); |
||
234 | font->setColor(textFrame->TxtFill); |
||
235 | font->setShade(textFrame->ShTxtFill); |
||
236 | font->setStrokeColor(textFrame->TxtStroke); |
||
237 | font->setStrokeShade(textFrame->ShTxtStroke); |
||
238 | font->setHscale(textFrame->TxtScale); |
||
239 | font->setKerning(0); |
||
240 | } |
||
241 | |||
242 | void gtAction::getFrameStyle(gtFrameStyle *fstyle) |
||
243 | { |
||
244 | fstyle->setColumns(textFrame->Cols); |
||
245 | fstyle->setColumnsGap(textFrame->ColGap); |
||
246 | fstyle->setBgColor(textFrame->Pcolor); |
||
247 | fstyle->setBgShade(textFrame->Shade); |
||
248 | |||
1065 | cbradney | 249 | struct ParagraphStyle vg = textFrame->Doc->docParagraphStyles[textFrame->Doc->currentParaStyle]; |
364 | Franz | 250 | fstyle->setName(vg.Vname); |
251 | fstyle->setLineSpacing(vg.LineSpa); |
||
1065 | cbradney | 252 | fstyle->setAlignment(vg.textAlignment); |
364 | Franz | 253 | fstyle->setIndent(vg.Indent); |
254 | fstyle->setFirstLineIndent(vg.First); |
||
1065 | cbradney | 255 | fstyle->setSpaceAbove(vg.gapBefore); |
256 | fstyle->setSpaceBelow(vg.gapAfter); |
||
364 | Franz | 257 | fstyle->setDropCap(vg.Drop); |
258 | fstyle->setDropCapHeight(vg.DropLin); |
||
259 | fstyle->setAdjToBaseline(vg.BaseAdj); |
||
260 | |||
261 | gtFont font; |
||
262 | getFrameFont(&font); |
||
263 | fstyle->setFont(font); |
||
387 | Franz | 264 | fstyle->setName("Default frame style"); |
364 | Franz | 265 | } |
266 | |||
267 | void gtAction::createParagraphStyle(gtParagraphStyle* pstyle) |
||
268 | { |
||
1065 | cbradney | 269 | if (textFrame->Doc->docParagraphStyles.size() > 5) |
364 | Franz | 270 | { |
1065 | cbradney | 271 | for (uint i = 5; i < textFrame->Doc->docParagraphStyles.size(); ++i) |
364 | Franz | 272 | { |
1065 | cbradney | 273 | if (textFrame->Doc->docParagraphStyles[i].Vname == pstyle->getName()) |
364 | Franz | 274 | return; |
275 | } |
||
411 | Franz | 276 | } |
364 | Franz | 277 | gtFont* font = pstyle->getFont(); |
1065 | cbradney | 278 | struct ParagraphStyle vg; |
364 | Franz | 279 | vg.Vname = pstyle->getName(); |
411 | Franz | 280 | double linesp; |
281 | if (pstyle->getAutoLineSpacing()) |
||
282 | linesp = getLineSpacing(pstyle->getFont()->getSize()); |
||
283 | else |
||
284 | linesp = pstyle->getLineSpacing(); |
||
285 | vg.LineSpa = linesp; |
||
1065 | cbradney | 286 | vg.textAlignment = pstyle->getAlignment(); |
364 | Franz | 287 | vg.Indent = pstyle->getIndent(); |
288 | vg.First = pstyle->getFirstLineIndent(); |
||
1065 | cbradney | 289 | vg.gapBefore = pstyle->getSpaceAbove(); |
290 | vg.gapAfter = pstyle->getSpaceBelow(); |
||
403 | Franz | 291 | vg.Font = validateFont(font); |
364 | Franz | 292 | vg.FontSize = font->getSize(); |
293 | vg.TabValues.clear(); |
||
375 | Franz | 294 | QValueList<double> *tabs = pstyle->getTabValues(); |
295 | for (uint i = 0; i < tabs->size(); ++i) |
||
296 | { |
||
297 | double tmp = (*tabs)[i]; |
||
298 | vg.TabValues.append(tmp); |
||
299 | } |
||
364 | Franz | 300 | vg.Drop = pstyle->hasDropCap(); |
301 | vg.DropLin = pstyle->getDropCapHeight(); |
||
302 | vg.FontEffect = font->getEffectsValue(); |
||
833 | tsoots | 303 | vg.FColor = parseColor(font->getColor()); |
364 | Franz | 304 | vg.FShade = font->getShade(); |
833 | tsoots | 305 | vg.SColor = parseColor(font->getStrokeColor()); |
364 | Franz | 306 | vg.SShade = font->getStrokeShade(); |
307 | vg.BaseAdj = pstyle->isAdjToBaseline(); |
||
1065 | cbradney | 308 | textFrame->Doc->docParagraphStyles.append(vg); |
716 | cbradney | 309 | ScApp->Mpal->Spal->updateFormatList(); |
364 | Franz | 310 | } |
311 | |||
411 | Franz | 312 | void gtAction::removeParagraphStyle(const QString& name) |
313 | { |
||
314 | int index = findParagraphStyle(name); |
||
315 | if (index != -1) |
||
316 | removeParagraphStyle(index); |
||
317 | } |
||
318 | |||
319 | void gtAction::removeParagraphStyle(int index) |
||
320 | { |
||
1065 | cbradney | 321 | QValueList<ParagraphStyle>::iterator it = ScApp->doc->docParagraphStyles.at(index); |
322 | ScApp->doc->docParagraphStyles.remove(it); |
||
411 | Franz | 323 | } |
324 | |||
1185 | tsoots | 325 | void gtAction::updateParagraphStyle(const QString&, gtParagraphStyle* pstyle) |
411 | Franz | 326 | { |
327 | int pstyleIndex = findParagraphStyle(pstyle->getName()); |
||
328 | if (pstyleIndex != -1) |
||
329 | updateParagraphStyle(pstyleIndex, pstyle); |
||
330 | } |
||
331 | |||
332 | void gtAction::updateParagraphStyle(int pstyleIndex, gtParagraphStyle* pstyle) |
||
333 | { |
||
334 | gtFont* font = pstyle->getFont(); |
||
1065 | cbradney | 335 | struct ParagraphStyle vg; |
411 | Franz | 336 | vg.Vname = pstyle->getName(); |
337 | double linesp; |
||
338 | if (pstyle->getAutoLineSpacing()) |
||
339 | linesp = getLineSpacing(pstyle->getFont()->getSize()); |
||
340 | else |
||
341 | linesp = pstyle->getLineSpacing(); |
||
342 | vg.LineSpa = linesp; |
||
1065 | cbradney | 343 | vg.textAlignment = pstyle->getAlignment(); |
411 | Franz | 344 | vg.Indent = pstyle->getIndent(); |
345 | vg.First = pstyle->getFirstLineIndent(); |
||
1065 | cbradney | 346 | vg.gapBefore = pstyle->getSpaceAbove(); |
347 | vg.gapAfter = pstyle->getSpaceBelow(); |
||
411 | Franz | 348 | vg.Font = validateFont(font); |
349 | vg.FontSize = font->getSize(); |
||
350 | vg.TabValues.clear(); |
||
351 | QValueList<double> *tabs = pstyle->getTabValues(); |
||
352 | for (uint i = 0; i < tabs->size(); ++i) |
||
353 | { |
||
354 | double tmp = (*tabs)[i]; |
||
355 | vg.TabValues.append(tmp); |
||
356 | } |
||
357 | vg.Drop = pstyle->hasDropCap(); |
||
358 | vg.DropLin = pstyle->getDropCapHeight(); |
||
359 | vg.FontEffect = font->getEffectsValue(); |
||
833 | tsoots | 360 | vg.FColor = parseColor(font->getColor()); |
411 | Franz | 361 | vg.FShade = font->getShade(); |
833 | tsoots | 362 | vg.SColor = parseColor(font->getStrokeColor()); |
411 | Franz | 363 | vg.SShade = font->getStrokeShade(); |
364 | vg.BaseAdj = pstyle->isAdjToBaseline(); |
||
1065 | cbradney | 365 | ScApp->doc->docParagraphStyles[pstyleIndex] = vg; |
411 | Franz | 366 | } |
367 | |||
375 | Franz | 368 | QString gtAction::validateFont(gtFont* font) |
364 | Franz | 369 | { |
411 | Franz | 370 | // Dirty hack for family Times New Roman |
371 | if (font->getFamily() == "Times New") |
||
372 | { |
||
373 | font->setFamily("Times New Roman"); |
||
374 | if (font->getWeight() == "Roman") |
||
375 | font->setWeight("Regular"); |
||
376 | } |
||
377 | |||
375 | Franz | 378 | QString useFont = font->getName(); |
379 | if ((useFont == NULL) || (useFont == "")) |
||
380 | useFont = textFrame->IFont; |
||
381 | else if (ScApp->Prefs.AvailFonts[font->getName()] == 0) |
||
364 | Franz | 382 | { |
387 | Franz | 383 | bool found = false; |
411 | Franz | 384 | useFont == NULL; |
387 | Franz | 385 | QString tmpName = findFontName(font); |
386 | if (tmpName != NULL) |
||
375 | Franz | 387 | { |
387 | Franz | 388 | useFont = tmpName; |
389 | found = true; |
||
375 | Franz | 390 | } |
387 | Franz | 391 | if (!found) |
392 | { |
||
393 | if (font->getSlant() == gtFont::fontSlants[ITALIC]) |
||
394 | { |
||
395 | gtFont* tmp = new gtFont(*font); |
||
396 | tmp->setSlant(OBLIQUE); |
||
397 | tmpName = findFontName(tmp); |
||
398 | if (tmpName != NULL) |
||
399 | { |
||
400 | useFont = tmpName; |
||
401 | found = true; |
||
402 | } |
||
403 | delete tmp; |
||
404 | } |
||
405 | else if (font->getSlant() == gtFont::fontSlants[OBLIQUE]) |
||
406 | { |
||
407 | gtFont* tmp = new gtFont(*font); |
||
408 | tmp->setSlant(ITALIC); |
||
409 | tmpName = findFontName(tmp); |
||
410 | if (tmpName != NULL) |
||
411 | { |
||
412 | useFont = tmpName; |
||
413 | found = true; |
||
414 | } |
||
415 | delete tmp; |
||
416 | } |
||
417 | if (!found) |
||
418 | { |
||
419 | if (!ScApp->Prefs.GFontSub.contains(font->getName())) |
||
420 | { |
||
1143 | fschmid | 421 | MissingFont *dia = new MissingFont(0, useFont, &ScApp->Prefs, ScApp->doc); |
387 | Franz | 422 | dia->exec(); |
713 | cbradney | 423 | useFont = dia->getReplacementFont(); |
387 | Franz | 424 | ScApp->Prefs.GFontSub[font->getName()] = useFont; |
425 | delete dia; |
||
426 | } |
||
427 | else |
||
428 | useFont = ScApp->Prefs.GFontSub[font->getName()]; |
||
429 | } |
||
430 | } |
||
364 | Franz | 431 | } |
411 | Franz | 432 | |
375 | Franz | 433 | if(!ScApp->doc->UsedFonts.contains(useFont)) |
434 | ScApp->doc->AddFont(useFont, ScApp->Prefs.AvailFonts[useFont]->Font); |
||
435 | return useFont; |
||
364 | Franz | 436 | } |
437 | |||
387 | Franz | 438 | QString gtAction::findFontName(gtFont* font) |
439 | { |
||
440 | QString ret = NULL; |
||
441 | for (uint i = 0; i < static_cast<uint>(gtFont::NAMECOUNT); ++i) |
||
442 | { |
||
443 | QString nname = font->getName(i); |
||
444 | if (ScApp->Prefs.AvailFonts[nname] != 0) |
||
445 | { |
||
446 | ret = nname; |
||
447 | break; |
||
448 | } |
||
449 | } |
||
450 | return ret; |
||
451 | } |
||
452 | |||
411 | Franz | 453 | double gtAction::getLineSpacing(int fontSize) |
454 | { |
||
823 | fschmid | 455 | return ((fontSize / 10.0) * static_cast<double>(ScApp->doc->typographicSetttings.autoLineSpacing) / 100) + (fontSize / 10.0); |
411 | Franz | 456 | } |
457 | |||
375 | Franz | 458 | double gtAction::getFrameWidth() |
459 | { |
||
460 | return textFrame->Width; |
||
461 | } |
||
462 | |||
463 | QString gtAction::getFrameName() |
||
464 | { |
||
1361 | tsoots | 465 | return QString(textFrame->itemName()); |
375 | Franz | 466 | } |
467 | |||
411 | Franz | 468 | bool gtAction::getUpdateParagraphStyles() |
469 | { |
||
470 | return updateParagraphStyles; |
||
471 | } |
||
472 | |||
473 | void gtAction::setUpdateParagraphStyles(bool newUPS) |
||
474 | { |
||
475 | updateParagraphStyles = newUPS; |
||
476 | } |
||
477 | |||
418 | Franz | 478 | bool gtAction::getOverridePStyleFont() |
479 | { |
||
480 | return overridePStyleFont; |
||
481 | } |
||
482 | void gtAction::setOverridePStyleFont(bool newOPSF) |
||
483 | { |
||
484 | overridePStyleFont = newOPSF; |
||
485 | } |
||
486 | |||
833 | tsoots | 487 | QString gtAction::parseColor(const QString &s) |
488 | { |
||
489 | QString ret = "None"; |
||
490 | if (s == "None") |
||
491 | return ret; // don't want None to become Black or any color |
||
492 | bool found = false; |
||
1065 | cbradney | 493 | ColorList::Iterator it; |
833 | tsoots | 494 | for (it = ScApp->doc->PageColors.begin(); it != ScApp->doc->PageColors.end(); ++it) |
495 | { |
||
496 | if (it.key() == s) |
||
497 | { |
||
498 | ret = it.key(); |
||
499 | found = true; |
||
500 | } |
||
501 | } |
||
502 | if (!found) |
||
503 | { |
||
504 | QColor c; |
||
505 | if( s.startsWith( "rgb(" ) ) |
||
506 | { |
||
507 | QString parse = s.stripWhiteSpace(); |
||
508 | QStringList colors = QStringList::split( ',', parse ); |
||
509 | QString r = colors[0].right( ( colors[0].length() - 4 ) ); |
||
510 | QString g = colors[1]; |
||
511 | QString b = colors[2].left( ( colors[2].length() - 1 ) ); |
||
512 | if( r.contains( "%" ) ) |
||
513 | { |
||
514 | r = r.left( r.length() - 1 ); |
||
515 | r = QString::number( static_cast<int>( ( static_cast<double>( 255 * r.toDouble() ) / 100.0 ) ) ); |
||
516 | } |
||
517 | if( g.contains( "%" ) ) |
||
518 | { |
||
519 | g = g.left( g.length() - 1 ); |
||
520 | g = QString::number( static_cast<int>( ( static_cast<double>( 255 * g.toDouble() ) / 100.0 ) ) ); |
||
521 | } |
||
522 | if( b.contains( "%" ) ) |
||
523 | { |
||
524 | b = b.left( b.length() - 1 ); |
||
525 | b = QString::number( static_cast<int>( ( static_cast<double>( 255 * b.toDouble() ) / 100.0 ) ) ); |
||
526 | } |
||
527 | c = QColor(r.toInt(), g.toInt(), b.toInt()); |
||
528 | } |
||
529 | else |
||
530 | { |
||
531 | QString rgbColor = s.stripWhiteSpace(); |
||
532 | if( rgbColor.startsWith( "#" ) ) |
||
533 | c.setNamedColor( rgbColor ); |
||
534 | else |
||
535 | c = parseColorN( rgbColor ); |
||
536 | } |
||
537 | found = false; |
||
538 | for (it = ScApp->doc->PageColors.begin(); it != ScApp->doc->PageColors.end(); ++it) |
||
539 | { |
||
540 | if (c == ScApp->doc->PageColors[it.key()].getRGBColor()) |
||
541 | { |
||
542 | ret = it.key(); |
||
543 | found = true; |
||
544 | } |
||
545 | } |
||
546 | if (!found) |
||
547 | { |
||
548 | CMYKColor tmp; |
||
549 | tmp.fromQColor(c); |
||
550 | ScApp->doc->PageColors.insert("FromGetText"+c.name(), tmp); |
||
551 | ScApp->Mpal->Cpal->SetColors(ScApp->doc->PageColors); |
||
552 | ret = "FromGetText"+c.name(); |
||
553 | } |
||
554 | } |
||
555 | return ret; |
||
556 | } |
||
557 | |||
558 | QColor gtAction::parseColorN(const QString &rgbColor) |
||
559 | { |
||
560 | int r, g, b; |
||
561 | keywordToRGB( rgbColor, r, g, b ); |
||
562 | return QColor( r, g, b ); |
||
563 | } |
||
564 | |||
364 | Franz | 565 | void gtAction::finalize() |
566 | { |
||
1065 | cbradney | 567 | if (ScApp->doc->docHyphenator->AutoCheck) |
568 | ScApp->doc->docHyphenator->slotHyphenate(textFrame); |
||
456 | fschmid | 569 | ScApp->view->DrawNew(); |
364 | Franz | 570 | ScApp->slotDocCh(); |
571 | } |
||
572 | |||
573 | gtAction::~gtAction() |
||
574 | { |
||
575 | finalize(); |
||
576 | } |