Back to index

scribus-ng  1.3.4.dfsg+svn20071115
gtwriter.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 "gtwriter.h"
00028 //#include "scfonts.h"
00029 #include "pageitem.h"
00030 #include "scribusstructs.h"
00031 
00032 // gtWriter::gtWriter(bool append)
00033 // {
00034 //     action = new gtAction(append, ScMW->doc->m_Selection->itemAt(0));
00035 //     errorSet = false;
00036 //     action->setProgressInfo();
00037 //     setDefaultStyle();
00038 //     unsetCharacterStyle();
00039 //     unsetParagraphStyle();
00040 // //  if (!append)
00041 // //         action->clearFrame();
00042 // //  else
00043 // //         this->append("\n");
00044 // }
00045 
00046 gtWriter::gtWriter(bool append, PageItem *pageitem)
00047 {
00048        action = new gtAction(append, pageitem);
00049        errorSet = false;
00050        action->setProgressInfo();
00051        setDefaultStyle();
00052        unsetCharacterStyle();
00053        unsetParagraphStyle();
00054 }
00055 
00056 gtFrameStyle* gtWriter::getDefaultStyle()
00057 {
00058        return frameStyle;
00059 }
00060 
00061 void gtWriter::setFrameStyle(gtFrameStyle *fStyle)
00062 {
00063        frameStyle = fStyle;
00064        action->applyFrameStyle(fStyle);
00065 }
00066 
00067 void gtWriter::setParagraphStyle(gtParagraphStyle *pStyle)
00068 {
00069        // @todo Start a new paragraph and add the style to the Paragraph Styles
00070        paragraphStyle = pStyle;
00071 }
00072 
00073 void gtWriter::setCharacterStyle(gtStyle *cStyle)
00074 {
00075        characterStyle = cStyle;
00076 }
00077 
00078 void gtWriter::unsetFrameStyle()
00079 {
00080        frameStyle = defaultStyle;
00081 }
00082 
00083 void gtWriter::unsetParagraphStyle()
00084 {
00085        paragraphStyle = NULL;
00086 }
00087 
00088 void gtWriter::unsetCharacterStyle()
00089 {
00090        characterStyle = NULL;
00091 }
00092 
00093 double gtWriter::getPreferredLineSpacing(int fontSize)
00094 {
00095        return action->getLineSpacing(fontSize);
00096 }
00097 
00098 double gtWriter::getPreferredLineSpacing(double fontSize)
00099 {
00100        return getPreferredLineSpacing(static_cast<int>(fontSize * 10));
00101 }
00102 
00103 void gtWriter::append(const QString& text)
00104 {
00105        if (text == NULL)
00106               return;
00107        if (text.length() == 0)
00108               return;
00109        if (characterStyle != NULL)
00110        {
00111               action->write(text, characterStyle);
00112        }
00113        else if (paragraphStyle != NULL)
00114        {
00115               action->write(text, paragraphStyle);
00116        }
00117        else
00118        {
00119               action->write(text, frameStyle);
00120        }
00121 }
00122 
00123 double gtWriter::getFrameWidth()
00124 {
00125        return action->getFrameWidth();
00126 }
00127 
00128 QString gtWriter::getFrameName()
00129 {
00130        return action->getFrameName();
00131 }
00132 
00133 void gtWriter::append(const QString& text, gtStyle *style)
00134 {
00135        if (style == NULL)
00136        {
00137               append(text);
00138               return;
00139        }
00140 
00141        currentStyle = style;
00142        action->write(text, style);
00143        currentStyle = NULL;
00144 }
00145 
00146 void gtWriter::append(const QString& text, gtStyle *style, bool updatePStyle)
00147 {
00148        bool ups = action->getUpdateParagraphStyles();
00149        action->setUpdateParagraphStyles(updatePStyle);
00150        append(text, style);
00151        action->setUpdateParagraphStyles(ups);
00152 }
00153 
00154 void gtWriter::setDefaultStyle()
00155 {
00156        // @todo Get the style of the text frame we are appending to.
00157        defaultStyle = new gtFrameStyle("Default style");
00158        action->getFrameStyle(defaultStyle);
00159        frameStyle = defaultStyle;
00160 }
00161 
00162 bool gtWriter::getUpdateParagraphStyles()
00163 {
00164        return action->getUpdateParagraphStyles();
00165 }
00166 
00167 void gtWriter::setUpdateParagraphStyles(bool newUPS)
00168 {
00169        action->setUpdateParagraphStyles(newUPS);
00170 }
00171 
00172 bool gtWriter::getOverridePStyleFont()
00173 {
00174        return action->getOverridePStyleFont();
00175 }
00176 
00177 void gtWriter::setOverridePStyleFont(bool newOPSF)
00178 {
00179        action->setOverridePStyleFont(newOPSF);
00180 }
00181 
00182 gtWriter::~gtWriter()
00183 {
00184        if (!errorSet)
00185               action->setProgressInfoDone();
00186        delete action;
00187        delete defaultStyle;
00188 }