Back to index

scribus-ng  1.3.4.dfsg+svn20071115
gtaction.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2004 by Riku Leino                                      *
00009  *   tsoots@gmail.com                                                      *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #include "missing.h"
00028 #include "gtaction.h"
00029 #include "mpalette.h"
00030 #include "scribus.h"
00031 #include <qcursor.h>
00032 #include <qstringlist.h>
00033 #include "color.h"
00034 #include "prefsmanager.h"
00035 #include "hyphenator.h"
00036 #include "selection.h"
00037 #include "commonstrings.h"
00038 #include "util.h"
00039 #include "sccolorengine.h"
00040 
00041 // gtAction::gtAction(bool append)
00042 // {
00043 //     prefsManager=PrefsManager::instance();
00044 //     textFrame = ScMW->doc->m_Selection->itemAt(0);
00045 //     it = textFrame;
00046 //     lastParagraphStyle = -1;
00047 //     inPara = false;
00048 //     isFirstWrite = true;
00049 //     lastCharWasLineChange = false;
00050 //     currentFrameStyle = "";
00051 //     doAppend = append;
00052 //     updateParagraphStyles = false;
00053 //     overridePStyleFont = true;
00054 // }
00055 
00056 gtAction::gtAction(bool append, PageItem* pageitem)
00057 {
00058        prefsManager=PrefsManager::instance();
00059        textFrame = pageitem;
00060        m_ScMW=textFrame->doc()->scMW();
00061        it = textFrame;
00062        lastParagraphStyle = -1;
00063        inPara = false;
00064        isFirstWrite = true;
00065        lastCharWasLineChange = false;
00066        currentFrameStyle = "";
00067        doAppend = append;
00068        updateParagraphStyles = false;
00069        overridePStyleFont = true;
00070 }
00071 
00072 void gtAction::setProgressInfo()
00073 {
00074        m_ScMW->setStatusBarInfoText(QObject::tr("Importing text"));
00075        m_ScMW->mainWindowProgressBar->reset();
00076        m_ScMW->mainWindowProgressBar->setTotalSteps(0);
00077 }
00078 
00079 void gtAction::setProgressInfoDone()
00080 {
00081        m_ScMW->setStatusBarInfoText("");
00082        m_ScMW->mainWindowProgressBar->reset();
00083 }
00084 
00085 void gtAction::setInfo(QString infoText)
00086 {
00087        m_ScMW->setStatusBarInfoText(infoText);
00088 }
00089 
00090 void gtAction::clearFrame()
00091 {
00092        textFrame->itemText.clear();
00093        textFrame->CPos = 0;
00094 }
00095 
00096 void gtAction::write(const QString& text, gtStyle *style)
00097 {
00098        if (isFirstWrite)
00099        {
00100               if (!doAppend)
00101               {
00102                      if (it->nextInChain() != 0)
00103                      {
00104                             PageItem *nextItem = it->nextInChain();
00105                             while (nextItem != 0)
00106                             {
00107                                    nextItem->itemText.clear();
00108                                    nextItem->CPos = 0;
00109                                    nextItem = nextItem->nextInChain();
00110                             }
00111                      }
00112                      it->itemText.clear();
00113                      it->CPos = 0;
00114               }
00115        }
00116        int paragraphStyle = -1;
00117        if (style->target() == "paragraph")
00118        {
00119               gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style);
00120               paragraphStyle = applyParagraphStyle(pstyle);
00121               if (isFirstWrite)
00122                      inPara = true;
00123        }
00124        else if (style->target() == "frame")
00125        {
00126               gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style);
00127               applyFrameStyle(fstyle);
00128        }
00129 
00130        if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1))
00131               paragraphStyle = lastParagraphStyle;
00132 
00133 
00134        if (paragraphStyle == -1)
00135               paragraphStyle = 0; // ::findParagraphStyle(textFrame->doc(), textFrame->doc()->currentStyle);
00136 
00137        gtFont* font = style->getFont();
00138        QString fontName = validateFont(font).scName();
00139        gtFont font2(*font);
00140        font2.setName(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().font().scName());
00141        QString fontName2 = validateFont(&font2).scName();
00142        CharStyle lastStyle;
00143        int lastStyleStart = 0;
00144        for (uint a = 0; a < text.length(); ++a)
00145        {
00146               CharStyle newStyle;
00147               if ((text.at(a) == QChar(0)) || (text.at(a) == QChar(13)))
00148                      continue;
00149               QChar ch = text.at(a);
00150               if ((ch == QChar(10)) || (ch == QChar(5)))
00151                      ch = QChar(13);
00152               if ((inPara) && (!overridePStyleFont))
00153               {
00154                      if (textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().font().isNone())
00155                             newStyle.setFont((*textFrame->doc()->AllFonts)[fontName2]);
00156                      else
00157                             newStyle.setFont(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().font());
00158                      newStyle.setFontSize(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().fontSize());
00159                      newStyle.setFillColor(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().fillColor());
00160                      newStyle.setFillShade(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().fillShade());
00161                      newStyle.setStrokeColor(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().strokeColor());
00162                      newStyle.setStrokeShade(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().strokeShade());
00163                      newStyle.setFeatures(textFrame->doc()->paragraphStyles()[paragraphStyle].charStyle().features());
00164               }
00165               else
00166               {
00167                      newStyle.setFont((*textFrame->doc()->AllFonts)[fontName]);
00168                      newStyle.setFontSize(font->getSize());
00169                      newStyle.setFillColor(parseColor(font->getColor()));
00170                      newStyle.setFillShade(font->getShade());
00171                      newStyle.setStrokeColor(parseColor(font->getStrokeColor()));
00172                      newStyle.setStrokeShade(font->getStrokeShade());
00173                      newStyle.setFeatures(static_cast<StyleFlag>(font->getEffectsValue()).featureList());
00174               }
00175               newStyle.setScaleH(font->getHscale());
00176               newStyle.setScaleV(1000);
00177               newStyle.setBaselineOffset(0);
00178               newStyle.setShadowXOffset(50);
00179               newStyle.setShadowYOffset(-50);
00180               newStyle.setOutlineWidth(10);
00181               newStyle.setUnderlineOffset(-1);
00182               newStyle.setUnderlineWidth(-1);
00183               newStyle.setStrikethruOffset(-1);
00184               newStyle.setStrikethruWidth(-1);
00185               newStyle.setTracking(font->getKerning());
00186               int pos = it->itemText.length();
00187               it->itemText.insertChars(pos, QString(ch));
00188               if (newStyle != lastStyle) {
00189                      it->itemText.applyCharStyle(lastStyleStart, pos-lastStyleStart, lastStyle);
00190                      lastStyle = newStyle;
00191                      lastStyleStart = pos;
00192               }
00193               if (ch == SpecialChars::PARSEP) {
00194                      it->itemText.applyStyle(pos, textFrame->doc()->paragraphStyles()[paragraphStyle]);
00195               }
00196        }
00197        it->itemText.applyCharStyle(lastStyleStart, it->itemText.length()-lastStyleStart, lastStyle);
00198        it->itemText.applyStyle(QMAX(0,it->itemText.length()-1), textFrame->doc()->paragraphStyles()[paragraphStyle]);
00199        
00200        lastCharWasLineChange = text.right(1) == "\n";
00201        inPara = style->target() == "paragraph";
00202        lastParagraphStyle = paragraphStyle;
00203        if (isFirstWrite)
00204               isFirstWrite = false;
00205 }
00206 
00207 int gtAction::findParagraphStyle(gtParagraphStyle* pstyle)
00208 {
00209        return findParagraphStyle(pstyle->getName());
00210 }
00211 
00212 int gtAction::findParagraphStyle(const QString& name)
00213 {
00214        int pstyleIndex = -1;
00215        for (uint i = 0; i < textFrame->doc()->paragraphStyles().count(); ++i)
00216        {
00217               if (textFrame->doc()->paragraphStyles()[i].name() == name)
00218               {
00219                      pstyleIndex = i;
00220                      break;
00221               }
00222        }
00223        return pstyleIndex;
00224 }
00225 
00226 int gtAction::applyParagraphStyle(gtParagraphStyle* pstyle)
00227 {
00228        int pstyleIndex = findParagraphStyle(pstyle);
00229        if (pstyleIndex == -1)
00230        {
00231               createParagraphStyle(pstyle);
00232               pstyleIndex = textFrame->doc()->paragraphStyles().count() - 1;
00233        }
00234        else if (updateParagraphStyles)
00235        {
00236               updateParagraphStyle(pstyleIndex, pstyle);
00237        }
00238        return pstyleIndex;
00239 }
00240 
00241 void gtAction::applyFrameStyle(gtFrameStyle* fstyle)
00242 {
00243        textFrame->setColumns(fstyle->getColumns());
00244        textFrame->setColumnGap(fstyle->getColumnsGap());
00245        textFrame->setFillColor(parseColor(fstyle->getBgColor()));
00246        textFrame->setFillShade(fstyle->getBgShade());
00247        ParagraphStyle newTabs(textFrame->itemText.defaultStyle());
00248        newTabs.setTabValues(QValueList<ParagraphStyle::TabRecord>(*(fstyle->getTabValues())));
00249        textFrame->itemText.setDefaultStyle(newTabs);
00250 
00251 //     gtParagraphStyle* pstyle = new gtParagraphStyle(*fstyle);
00252 //     int pstyleIndex = findParagraphStyle(pstyle);
00253 //     if (pstyleIndex == -1)
00254 //            pstyleIndex = 0;
00255 //     textFrame->Doc->currentParaStyle = pstyleIndex;
00256 
00257 /* FIXME
00258        double linesp;
00259        if (fstyle->getAutoLineSpacing())
00260               linesp = getLineSpacing(fstyle->getFont()->getSize());
00261        else
00262               linesp = fstyle->getLineSpacing();
00263        textFrame->setLineSpacing(linesp);
00264        textFrame->setLineSpacingMode(0);
00265        gtFont* font = fstyle->getFont();
00266        Scface* scfont = validateFont(font);
00267        textFrame->setFont(scfont->scName());
00268        textFrame->setFontSize(font->getSize());
00269        textFrame->TxtFill = parseColor(font->getColor());
00270        textFrame->ShTxtFill = font->getShade();
00271        textFrame->TxtStroke = parseColor(font->getStrokeColor());
00272        textFrame->ShTxtStroke = font->getStrokeShade();
00273        textFrame->TxtScale = font->getHscale();
00274        textFrame->TxtScaleV = 1000;
00275        textFrame->TxtBase = 0;
00276        textFrame->TxtShadowX = 50;
00277        textFrame->TxtShadowY = -50;
00278        textFrame->TxtOutline = 10;
00279        textFrame->TxtUnderPos = -1;
00280        textFrame->TxtUnderWidth = -1;
00281        textFrame->TxtStrikePos = -1;
00282        textFrame->TxtStrikeWidth = -1;
00283        textFrame->ExtraV = font->getKerning();
00284        */
00285 }
00286 
00287 void gtAction::getFrameFont(gtFont *font)
00288 {
00289        const CharStyle& style(textFrame->itemText.defaultStyle().charStyle());
00290        
00291        font->setName(style.font().scName());
00292        font->setSize(style.fontSize());
00293        font->setColor(style.fillColor());
00294        font->setShade(style.fillShade());
00295        font->setStrokeColor(style.strokeColor());
00296        font->setStrokeShade(style.strokeShade());
00297        font->setHscale(style.scaleH());
00298        font->setKerning(0);
00299 }
00300 
00301 void gtAction::getFrameStyle(gtFrameStyle *fstyle)
00302 {
00303        fstyle->setColumns(textFrame->Cols);
00304        fstyle->setColumnsGap(textFrame->ColGap);
00305        fstyle->setBgColor(textFrame->fillColor());
00306        fstyle->setBgShade(textFrame->fillShade());
00307 
00308        const ParagraphStyle& vg(textFrame->itemText.defaultStyle());
00309        fstyle->setName(vg.name());
00310        fstyle->setLineSpacing(vg.lineSpacing());
00311        fstyle->setAlignment(vg.alignment());
00312        fstyle->setIndent(vg.leftMargin());
00313        fstyle->setFirstLineIndent(vg.firstIndent());
00314        fstyle->setSpaceAbove(vg.gapBefore());
00315        fstyle->setSpaceBelow(vg.gapAfter());
00316        fstyle->setDropCap(vg.hasDropCap());
00317        fstyle->setDropCapHeight(vg.dropCapLines());
00318        fstyle->setAdjToBaseline(vg.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing);
00319 
00320        gtFont font;
00321        getFrameFont(&font);
00322        fstyle->setFont(font);
00323        fstyle->setName("Default frame style");
00324 }
00325 
00326 void gtAction::createParagraphStyle(gtParagraphStyle* pstyle)
00327 {
00328        ScribusDoc* currDoc=textFrame->doc();
00329        for (uint i = 0; i < currDoc->paragraphStyles().count(); ++i)
00330        {
00331               if (currDoc->paragraphStyles()[i].name() == pstyle->getName())
00332                      return;
00333        }
00334        gtFont* font = pstyle->getFont();
00335        ParagraphStyle vg;
00336        vg.setName(pstyle->getName());
00337        double linesp;
00338        if (pstyle->getAutoLineSpacing())
00339               linesp = getLineSpacing(pstyle->getFont()->getSize());
00340        else
00341               linesp = pstyle->getLineSpacing();
00342        vg.setLineSpacingMode(pstyle->isAdjToBaseline()? ParagraphStyle::BaselineGridLineSpacing : ParagraphStyle::FixedLineSpacing);
00343        vg.setLineSpacing(linesp);
00344        vg.setAlignment(static_cast<ParagraphStyle::AlignmentType>(pstyle->getAlignment()));
00345        vg.setLeftMargin(pstyle->getIndent());
00346        vg.setFirstIndent(pstyle->getFirstLineIndent());
00347        vg.setGapBefore(pstyle->getSpaceAbove());
00348        vg.setGapAfter(pstyle->getSpaceBelow());
00349        vg.charStyle().setFont(validateFont(font));
00350        vg.charStyle().setFontSize(font->getSize());
00351        vg.setTabValues(*pstyle->getTabValues());
00352        vg.setHasDropCap(pstyle->hasDropCap());
00353        vg.setDropCapLines(pstyle->getDropCapHeight());
00354        vg.setDropCapOffset(0);
00355        vg.charStyle().setFeatures(static_cast<StyleFlag>(font->getEffectsValue()).featureList());
00356        vg.charStyle().setFillColor(parseColor(font->getColor()));
00357        vg.charStyle().setFillShade(font->getShade());
00358        vg.charStyle().setStrokeColor(parseColor(font->getStrokeColor()));
00359        vg.charStyle().setStrokeShade(font->getStrokeShade());
00360        vg.charStyle().setShadowXOffset(50);
00361        vg.charStyle().setShadowYOffset(-50);
00362        vg.charStyle().setOutlineWidth(10);
00363        vg.charStyle().setScaleH(1000);
00364        vg.charStyle().setScaleV(1000);
00365        vg.charStyle().setBaselineOffset(0);
00366        vg.charStyle().setTracking(0);
00367        vg.charStyle().setUnderlineOffset(textFrame->doc()->typographicSettings.valueUnderlinePos);
00368        vg.charStyle().setUnderlineWidth(textFrame->doc()->typographicSettings.valueUnderlineWidth);
00369        vg.charStyle().setStrikethruOffset(textFrame->doc()->typographicSettings.valueStrikeThruPos);
00370        vg.charStyle().setStrikethruWidth(textFrame->doc()->typographicSettings.valueStrikeThruPos);
00371 
00372        StyleSet<ParagraphStyle> tmp;
00373        tmp.create(vg);
00374        textFrame->doc()->redefineStyles(tmp, false);
00375        
00376        m_ScMW->propertiesPalette->paraStyleCombo->updateFormatList();
00377 }
00378 
00379 void gtAction::removeParagraphStyle(const QString& name)
00380 {
00381        int index = findParagraphStyle(name);
00382        if (index != -1)
00383               removeParagraphStyle(index);
00384 }
00385 
00386 void gtAction::removeParagraphStyle(int index)
00387 {
00388        QMap<QString, QString> map;
00389        map[textFrame->doc()->paragraphStyles()[index].name()] = "";
00390        textFrame->doc()->replaceStyles(map);
00391 }
00392 
00393 void gtAction::updateParagraphStyle(const QString&, gtParagraphStyle* pstyle)
00394 {
00395        int pstyleIndex = findParagraphStyle(pstyle->getName());
00396        if (pstyleIndex != -1)
00397               updateParagraphStyle(pstyleIndex, pstyle);
00398 }
00399 
00400 void gtAction::updateParagraphStyle(int pstyleIndex, gtParagraphStyle* pstyle)
00401 {
00402        gtFont* font = pstyle->getFont();
00403        ParagraphStyle vg;
00404        vg.setName(pstyle->getName());
00405        double linesp;
00406        if (pstyle->getAutoLineSpacing())
00407               linesp = getLineSpacing(pstyle->getFont()->getSize());
00408        else
00409               linesp = pstyle->getLineSpacing();
00410        vg.setLineSpacingMode(pstyle->isAdjToBaseline()? ParagraphStyle::BaselineGridLineSpacing : ParagraphStyle::FixedLineSpacing);
00411        vg.setLineSpacing(linesp);
00412        vg.setAlignment(static_cast<ParagraphStyle::AlignmentType>(pstyle->getAlignment()));
00413        vg.setLeftMargin(pstyle->getIndent());
00414        vg.setFirstIndent(pstyle->getFirstLineIndent());
00415        vg.setGapBefore(pstyle->getSpaceAbove());
00416        vg.setGapAfter(pstyle->getSpaceBelow());
00417        vg.charStyle().setFont(validateFont(font));
00418        vg.charStyle().setFontSize(font->getSize());
00419        vg.setTabValues(*pstyle->getTabValues());
00420        vg.setHasDropCap(pstyle->hasDropCap());
00421        vg.setDropCapLines(pstyle->getDropCapHeight());
00422        vg.setDropCapOffset(0);
00423        vg.charStyle().setFeatures(static_cast<StyleFlag>(font->getEffectsValue()).featureList());
00424        vg.charStyle().setFillColor(parseColor(font->getColor()));
00425        vg.charStyle().setFillShade(font->getShade());
00426        vg.charStyle().setStrokeColor(parseColor(font->getStrokeColor()));
00427        vg.charStyle().setStrokeShade(font->getStrokeShade());
00428        vg.charStyle().setShadowXOffset(50);
00429        vg.charStyle().setShadowYOffset(-50);
00430        vg.charStyle().setOutlineWidth(10);
00431        vg.charStyle().setScaleH(1000);
00432        vg.charStyle().setScaleV(1000);
00433        vg.charStyle().setBaselineOffset(0);
00434        vg.charStyle().setTracking(0);
00435        vg.charStyle().setUnderlineOffset(textFrame->doc()->typographicSettings.valueUnderlinePos);
00436        vg.charStyle().setUnderlineWidth(textFrame->doc()->typographicSettings.valueUnderlineWidth);
00437        vg.charStyle().setStrikethruOffset(textFrame->doc()->typographicSettings.valueStrikeThruPos);
00438        vg.charStyle().setStrikethruWidth(textFrame->doc()->typographicSettings.valueStrikeThruPos);
00439        StyleSet<ParagraphStyle> tmp;
00440        tmp.create(vg);
00441        textFrame->doc()->redefineStyles(tmp, false);
00442        if (vg.name() != textFrame->doc()->paragraphStyles()[pstyleIndex].name())
00443        {
00444               QMap<QString, QString> map;
00445               map[textFrame->doc()->paragraphStyles()[pstyleIndex].name()] = vg.name();
00446               textFrame->doc()->replaceStyles(map);
00447        }
00448 }
00449 
00450 ScFace gtAction::validateFont(gtFont* font)
00451 {
00452        // Dirty hack for family Times New Roman
00453        if (font->getFamily() == "Times New")
00454        {
00455               font->setFamily("Times New Roman");
00456               if (font->getWeight() == "Roman")
00457                      font->setWeight("Regular");
00458        }
00459 
00460        QString useFont = font->getName();
00461        if ((useFont.isNull()) || (useFont.isEmpty()))
00462               useFont = textFrame->itemText.defaultStyle().charStyle().font().scName();
00463        else if (prefsManager->appPrefs.AvailFonts[font->getName()].isNone())
00464        {
00465               bool found = false;
00466               // Do not empty otherwise user may be asked to replace an empty font 
00467               // by font replacement dialog
00468               // useFont = ""; 
00469               QString tmpName = findFontName(font);
00470               if (!tmpName.isEmpty())
00471               {
00472                      useFont = tmpName;
00473                      found = true;
00474               }
00475               if (!found)
00476               {
00477                      if (font->getSlant() == gtFont::fontSlants[ITALIC])
00478                      {
00479                             gtFont* tmp = new gtFont(*font);
00480                             tmp->setSlant(OBLIQUE);
00481                             tmpName = findFontName(tmp);
00482                             if (!tmpName.isEmpty())
00483                             {
00484                                    useFont = tmpName;
00485                                    found = true;
00486                             }
00487                             delete tmp;
00488                      }
00489                      else if (font->getSlant() == gtFont::fontSlants[OBLIQUE])
00490                      {
00491                             gtFont* tmp = new gtFont(*font);
00492                             tmp->setSlant(ITALIC);
00493                             tmpName = findFontName(tmp);
00494                             if (!tmpName.isEmpty())
00495                             {
00496                                    useFont = tmpName;
00497                                    found = true;
00498                             }
00499                             delete tmp;
00500                      }
00501                      if (!found)
00502                      {
00503                             if (!prefsManager->appPrefs.GFontSub.contains(font->getName()))
00504                             {
00505                                    MissingFont *dia = new MissingFont(0, useFont, textFrame->doc());
00506                                    dia->exec();
00507                                    useFont = dia->getReplacementFont();
00508                                    prefsManager->appPrefs.GFontSub[font->getName()] = useFont;
00509                                    delete dia;
00510                             }
00511                             else
00512                                    useFont = prefsManager->appPrefs.GFontSub[font->getName()];
00513                      }
00514               }
00515        }
00516 
00517        if(!textFrame->doc()->UsedFonts.contains(useFont))
00518               textFrame->doc()->AddFont(useFont);
00519        return prefsManager->appPrefs.AvailFonts[useFont];
00520 }
00521 
00522 QString gtAction::findFontName(gtFont* font)
00523 {
00524        QString ret = NULL;
00525        for (uint i = 0; i < static_cast<uint>(gtFont::NAMECOUNT); ++i)
00526        {
00527               QString nname = font->getName(i);
00528               if (! prefsManager->appPrefs.AvailFonts[nname].isNone())
00529               {
00530                      ret = nname;
00531                      break;
00532               }
00533        }
00534        return ret;
00535 }
00536 
00537 double gtAction::getLineSpacing(int fontSize)
00538 {
00539        return ((fontSize / 10.0) * static_cast<double>(textFrame->doc()->typographicSettings.autoLineSpacing) / 100) + (fontSize / 10.0);
00540 }
00541 
00542 double gtAction::getFrameWidth()
00543 {
00544        return textFrame->width();
00545 }
00546 
00547 QString gtAction::getFrameName()
00548 {
00549        return QString(textFrame->itemName());
00550 }
00551 
00552 bool gtAction::getUpdateParagraphStyles()
00553 {
00554        return updateParagraphStyles;
00555 }
00556 
00557 void gtAction::setUpdateParagraphStyles(bool newUPS)
00558 {
00559        updateParagraphStyles = newUPS;
00560 }
00561 
00562 bool gtAction::getOverridePStyleFont()
00563 {
00564        return overridePStyleFont;
00565 }
00566 void gtAction::setOverridePStyleFont(bool newOPSF)
00567 {
00568        overridePStyleFont = newOPSF;
00569 }
00570 
00571 QString gtAction::parseColor(const QString &s)
00572 {
00573        QString ret = CommonStrings::None;
00574        if (s == CommonStrings::None)
00575               return ret; // don't want None to become Black or any color
00576        bool found = false;
00577        ColorList::Iterator it;
00578        for (it = textFrame->doc()->PageColors.begin(); it != textFrame->doc()->PageColors.end(); ++it)
00579        {
00580               if (it.key() == s)
00581               {
00582                      ret = it.key();
00583                      found = true;
00584               }
00585        }
00586        if (!found)
00587        {
00588               QColor c;
00589               if( s.startsWith( "rgb(" ) )
00590               {
00591                      QString parse = s.stripWhiteSpace();
00592                      QStringList colors = QStringList::split( ',', parse );
00593                      QString r = colors[0].right( ( colors[0].length() - 4 ) );
00594                      QString g = colors[1];
00595                      QString b = colors[2].left( ( colors[2].length() - 1 ) );
00596                      if( r.contains( "%" ) )
00597                      {
00598                             r = r.left( r.length() - 1 );
00599                             r = QString::number( static_cast<int>( ( static_cast<double>( 255 * r.toDouble() ) / 100.0 ) ) );
00600                      }
00601                      if( g.contains( "%" ) )
00602                      {
00603                             g = g.left( g.length() - 1 );
00604                             g = QString::number( static_cast<int>( ( static_cast<double>( 255 * g.toDouble() ) / 100.0 ) ) );
00605                      }
00606                      if( b.contains( "%" ) )
00607                      {
00608                             b = b.left( b.length() - 1 );
00609                             b = QString::number( static_cast<int>( ( static_cast<double>( 255 * b.toDouble() ) / 100.0 ) ) );
00610                      }
00611                      c = QColor(r.toInt(), g.toInt(), b.toInt());
00612               }
00613               else
00614               {
00615                      QString rgbColor = s.stripWhiteSpace();
00616                      if( rgbColor.startsWith( "#" ) )
00617                             c.setNamedColor( rgbColor );
00618                      else
00619                             c = parseColorN( rgbColor );
00620               }
00621               found = false;
00622               for (it = textFrame->doc()->PageColors.begin(); it != textFrame->doc()->PageColors.end(); ++it)
00623               {
00624                      if (c == ScColorEngine::getRGBColor(it.data(), textFrame->doc()))
00625                      {
00626                             ret = it.key();
00627                             found = true;
00628                      }
00629               }
00630               if (!found)
00631               {
00632                      ScColor tmp;
00633                      tmp.fromQColor(c);
00634                      textFrame->doc()->PageColors.insert("FromGetText"+c.name(), tmp);
00635                      m_ScMW->propertiesPalette->updateColorList();
00636                      ret = "FromGetText"+c.name();
00637               }
00638        }
00639        return ret;
00640 }
00641 
00642 QColor gtAction::parseColorN(const QString &rgbColor)
00643 {
00644        int r, g, b;
00645        keywordToRGB( rgbColor, r, g, b );
00646        return QColor( r, g, b );
00647 }
00648 
00649 void gtAction::finalize()
00650 {
00651        if (textFrame->doc()->docHyphenator->AutoCheck)
00652               textFrame->doc()->docHyphenator->slotHyphenate(textFrame);
00653        textFrame->doc()->view()->DrawNew();
00654        textFrame->doc()->changed();
00655 }
00656 
00657 gtAction::~gtAction()
00658 {
00659        finalize();
00660 }