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
00101
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
00136
00137
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 , QWidget* )
00178 {
00179
00180 return TRUE;
00181 }
00182
00183 void KFormulaDoc::showStartUpWidget(KoMainWindow* parent, bool )
00184 {
00185 parent->setRootDocument( this );
00186 }
00187
00188 bool KFormulaDoc::showEmbedInitDialog(QWidget* )
00189 {
00190 return true;
00191 }
00192
00193 void KFormulaDoc::paintContent(QPainter& painter, const QRect& rect, bool transparent, double zoomX, double zoomY)
00194 {
00195
00196
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
00209
00210
00211
00212 return QString::null;
00213 }
00214
00215 #include "kformula_doc.moc"