00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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 KoXmlWriter contentTmpWriter( tmpFile, 1 );
00101
00102
00103 QTextStream stream(tmpFile);
00104 stream.setEncoding( QTextStream::UnicodeUTF8 );
00105 formula->saveMathML( stream, true );
00106
00107 tmpFile->close();
00108 contentWriter->addCompleteElement( tmpFile );
00109 contentTmpFile.close();
00110
00111
00112
00113 contentWriter->endElement();
00114 delete contentWriter;
00115
00116 if(!store->close())
00117 return false;
00118
00119 manifestWriter->addManifestEntry("content.xml", "text/xml");
00120
00121 setModified( false );
00122
00123 return true;
00124 }
00125
00126
00127 QDomDocument KFormulaDoc::saveXML()
00128 {
00129 QDomDocument doc = document->saveXML();
00130 history->documentSaved();
00131 return doc;
00132 }
00133
00134 bool KFormulaDoc::loadOasis( const QDomDocument& doc, KoOasisStyles&, const QDomDocument&, KoStore* )
00135 {
00136
00137
00138
00139
00140 if ( document->loadOasis( doc ) ) {
00141 history->clear();
00142 history->documentSaved();
00143 return true;
00144 }
00145 return false;
00146 }
00147
00148 bool KFormulaDoc::loadXML(QIODevice *, const QDomDocument& doc)
00149 {
00150 if ( document->loadXML( doc ) ) {
00151 history->clear();
00152 history->documentSaved();
00153 return true;
00154 }
00155 return false;
00156 }
00157
00158
00159 KoView* KFormulaDoc::createViewInstance(QWidget* _parent, const char *name)
00160 {
00161 return new KFormulaPartView(this, _parent, name);
00162 }
00163
00164 void KFormulaDoc::commandExecuted()
00165 {
00166 if (formula->isEmpty()) {
00167 setEmpty();
00168 }
00169 setModified(true);
00170 }
00171
00172 void KFormulaDoc::documentRestored()
00173 {
00174 setModified(false);
00175 }
00176
00177
00178 bool KFormulaDoc::initDoc(InitDocFlags , QWidget* )
00179 {
00180
00181 return TRUE;
00182 }
00183
00184 void KFormulaDoc::showStartUpWidget(KoMainWindow* parent, bool )
00185 {
00186 parent->setRootDocument( this );
00187 }
00188
00189 bool KFormulaDoc::showEmbedInitDialog(QWidget* )
00190 {
00191 return true;
00192 }
00193
00194 void KFormulaDoc::paintContent(QPainter& painter, const QRect& rect, bool transparent, double zoomX, double zoomY)
00195 {
00196
00197
00198
00199 bool forPrint = painter.device() && painter.device()->devType() == QInternal::Printer;
00200 document->setZoomAndResolution( 100, zoomX, zoomY, true, forPrint );
00201 if ( !transparent ) {
00202 painter.fillRect( rect, Qt::white );
00203 }
00204 formula->draw( painter, rect );
00205 }
00206
00207 QString KFormulaDoc::configFile() const
00208 {
00209
00210
00211
00212
00213 return QString::null;
00214 }
00215
00216 #include "kformula_doc.moc"