kformula

kformula_doc.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                   Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 
00022 #include "kformula_doc.h"
00023 #include "kformula_view.h"
00024 #include "kformula_factory.h"
00025 
00026 #include <qbitmap.h>
00027 #include <qcolor.h>
00028 #include <qdom.h>
00029 #include <qpainter.h>
00030 #include <qpopupmenu.h>
00031 #include <qprinter.h>
00032 #include <qstring.h>
00033 #include <qwmatrix.h>
00034 #include <qfile.h>
00035 
00036 #include <config.h>
00037 #include <unistd.h>
00038 
00039 #include <kaboutdialog.h>
00040 #include <kaction.h>
00041 #include <kapplication.h>
00042 #include <kdebug.h>
00043 #include <KoGlobal.h>
00044 #include <kiconloader.h>
00045 #include <klocale.h>
00046 #include <kstdaction.h>
00047 #include <kstandarddirs.h>
00048 #include <kurl.h>
00049 #include <KoXmlWriter.h>
00050 #include <KoStoreDevice.h>
00051 #include <ktempfile.h>
00052 #include <KoMainWindow.h>
00053 
00054 #include <kformulacontainer.h>
00055 #include <kformuladocument.h>
00056 
00057 
00058 KFormulaDoc::KFormulaDoc(QWidget *parentWidget, const char *widgetName, QObject* parent, const char* name, bool singleViewMode)
00059         : KoDocument(parentWidget, widgetName, parent, name, singleViewMode)
00060 {
00061     setInstance(KFormulaFactory::global(), false);
00062     //kdDebug(39001) << "General Settings" << endl;
00063 
00064     history = new KoCommandHistory( actionCollection() );
00065     wrapper = new KFormula::DocumentWrapper( kapp->config(),
00066                                              actionCollection(),
00067                                              history );
00068     document = new KFormula::Document;
00069     wrapper->document( document );
00070     formula = document->createFormula();
00071 
00072     document->setEnabled( true );
00073 
00074     // the modify flag
00075     connect(history, SIGNAL(commandExecuted()), this, SLOT(commandExecuted()));
00076     connect(history, SIGNAL(documentRestored()), this, SLOT(documentRestored()));
00077     dcopObject();
00078 }
00079 
00080 
00081 KFormulaDoc::~KFormulaDoc()
00082 {
00083     delete history;
00084     delete wrapper;
00085 }
00086 
00087 
00088 bool KFormulaDoc::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
00089 {
00090     if ( !store->open( "content.xml" ) )
00091         return false;
00092 
00093     KoStoreDevice dev( store );
00094     KoXmlWriter* contentWriter = createOasisXmlWriter( &dev, "math:math" );
00095 
00096 
00097     KTempFile contentTmpFile;
00098     contentTmpFile.setAutoDelete( true );
00099     QFile* tmpFile = contentTmpFile.file();
00100 
00101     //todo save content
00102     QTextStream stream(tmpFile);
00103     stream.setEncoding( QTextStream::UnicodeUTF8 );
00104     formula->saveMathML( stream, true );
00105 
00106     tmpFile->close();
00107     contentWriter->addCompleteElement( tmpFile );
00108     contentTmpFile.close();
00109 
00110 
00111 
00112     contentWriter->endElement();
00113     delete contentWriter;
00114 
00115     if(!store->close())
00116         return false;
00117 
00118     manifestWriter->addManifestEntry("content.xml", "text/xml");
00119 
00120     setModified( false );
00121 
00122     return true;
00123 }
00124 
00125 
00126 QDomDocument KFormulaDoc::saveXML()
00127 {
00128     QDomDocument doc = document->saveXML();
00129     history->documentSaved();
00130     return doc;
00131 }
00132 
00133 bool KFormulaDoc::loadOasis( const QDomDocument& doc, KoOasisStyles&, const QDomDocument&, KoStore* )
00134 {
00135     // we don't have style into this format
00136     // we don't have settings into kformula (for the moment)
00137     // necessary to adapt kformula code to load MathML format with Oasis Extension.
00138     
00139     if ( document->loadOasis( doc ) ) {
00140         history->clear();
00141         history->documentSaved();
00142         return true;
00143     }
00144     return false;
00145 }
00146 
00147 bool KFormulaDoc::loadXML(QIODevice *, const QDomDocument& doc)
00148 {
00149     if ( document->loadXML( doc ) ) {
00150         history->clear();
00151         history->documentSaved();
00152         return true;
00153     }
00154     return false;
00155 }
00156 
00157 
00158 KoView* KFormulaDoc::createViewInstance(QWidget* _parent, const char *name)
00159 {
00160     return new KFormulaPartView(this, _parent, name);
00161 }
00162 
00163 void KFormulaDoc::commandExecuted()
00164 {
00165     if (formula->isEmpty()) {
00166         setEmpty();
00167     }
00168     setModified(true);
00169 }
00170 
00171 void KFormulaDoc::documentRestored()
00172 {
00173     setModified(false);
00174 }
00175 
00176 
00177 bool KFormulaDoc::initDoc(InitDocFlags /*flags*/, QWidget* /*parentWidget*/)
00178 {
00179     // If nothing is loaded, do initialize here
00180     return TRUE;
00181 }
00182 
00183 void KFormulaDoc::showStartUpWidget(KoMainWindow* parent, bool /*alwaysShow*/)
00184 {
00185     parent->setRootDocument( this );
00186 }
00187 
00188 bool KFormulaDoc::showEmbedInitDialog(QWidget* /*parent*/)
00189 {
00190   return true;
00191 }
00192 
00193 void KFormulaDoc::paintContent(QPainter& painter, const QRect& rect, bool transparent, double zoomX, double zoomY)
00194 {
00195     // ####### handle transparency and zoom
00196     // Need to draw only the document rectangle described in the parameter rect.
00197 
00198     bool forPrint = painter.device() && painter.device()->devType() == QInternal::Printer;
00199     document->setZoomAndResolution( 100, zoomX, zoomY, true, forPrint );
00200     if ( !transparent ) {
00201         painter.fillRect( rect, Qt::white );
00202     }
00203     formula->draw( painter, rect );
00204 }
00205 
00206 QString KFormulaDoc::configFile() const
00207 {
00208 //    return readConfigFile( locate( "data", "kformula/kformula.rc",
00209 //                                 KFormulaFactory::global() ) );
00210 
00211 //    return readConfigFile( "kformula.rc" );
00212     return QString::null;
00213 }
00214 
00215 #include "kformula_doc.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys