22#include "kformula_doc.h"
23#include "kformula_view.h"
24#include "kformula_factory.h"
30#include <tqpopupmenu.h>
39#include <tdeaboutdialog.h>
41#include <tdeapplication.h>
44#include <kiconloader.h>
46#include <kstdaction.h>
47#include <kstandarddirs.h>
49#include <KoXmlWriter.h>
50#include <KoStoreDevice.h>
51#include <tdetempfile.h>
52#include <KoMainWindow.h>
54#include <kformulacontainer.h>
55#include <kformuladocument.h>
58KFormulaDoc::KFormulaDoc(TQWidget *parentWidget,
const char *widgetName, TQObject* parent,
const char* name,
bool singleViewMode)
59 : KoDocument(parentWidget, widgetName, parent, name, singleViewMode)
61 setInstance(KFormulaFactory::global(),
false);
64 history =
new KoCommandHistory( actionCollection() );
65 wrapper =
new KFormula::DocumentWrapper( kapp->config(),
68 document =
new KFormula::Document;
69 wrapper->document( document );
70 formula = document->createFormula();
72 document->setEnabled(
true );
75 connect(history, TQ_SIGNAL(commandExecuted()),
this, TQ_SLOT(commandExecuted()));
76 connect(history, TQ_SIGNAL(documentRestored()),
this, TQ_SLOT(documentRestored()));
81KFormulaDoc::~KFormulaDoc()
88bool KFormulaDoc::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
90 if ( !store->open(
"content.xml" ) )
93 KoStoreDevice dev( store );
94 KoXmlWriter* contentWriter = createOasisXmlWriter( &dev,
"math:math" );
97 KTempFile contentTmpFile;
98 contentTmpFile.setAutoDelete(
true );
99 TQFile* tmpFile = contentTmpFile.file();
102 TQTextStream stream(tmpFile);
103 stream.setEncoding( TQTextStream::UnicodeUTF8 );
104 formula->saveMathML( stream,
true );
107 contentWriter->addCompleteElement( tmpFile );
108 contentTmpFile.close();
112 contentWriter->endElement();
113 delete contentWriter;
118 manifestWriter->addManifestEntry(
"content.xml",
"text/xml");
120 setModified(
false );
126TQDomDocument KFormulaDoc::saveXML()
128 TQDomDocument doc = document->saveXML();
129 history->documentSaved();
133bool KFormulaDoc::loadOasis(
const TQDomDocument& doc, KoOasisStyles&,
const TQDomDocument&, KoStore* )
139 if ( document->loadOasis( doc ) ) {
141 history->documentSaved();
147bool KFormulaDoc::loadXML(TQIODevice *,
const TQDomDocument& doc)
149 if ( doc.doctype().name().lower() ==
"math"
150 || doc.documentElement().tagName().lower() ==
"math" )
151 if ( document->loadOasis( doc ) ) {
153 history->documentSaved();
156 if ( document->loadXML( doc ) ) {
158 history->documentSaved();
171 TQCString mimeType = outputMimeType();
172 bool mathml = !mimeType.isEmpty() && mimeType.contains(
"mathml",
false );
175 if ( f.open( IO_WriteOnly | IO_Translate ) )
177 TQTextStream stream( &f );
178 stream.setEncoding( TQTextStream::UnicodeUTF8 );
179 formula->saveMathML( stream,
false );
187 return KoDocument::saveNativeFormat( file );
190KoView* KFormulaDoc::createViewInstance(TQWidget* _parent,
const char *name)
195void KFormulaDoc::commandExecuted()
197 if (formula->isEmpty()) {
203void KFormulaDoc::documentRestored()
209bool KFormulaDoc::initDoc(InitDocFlags , TQWidget* )
215void KFormulaDoc::showStartUpWidget(KoMainWindow* parent,
bool )
217 parent->setRootDocument(
this );
220bool KFormulaDoc::showEmbedInitDialog(TQWidget* )
225void KFormulaDoc::paintContent(TQPainter& painter,
const TQRect& rect,
bool transparent,
double zoomX,
double zoomY)
230 bool forPrint = painter.device() && painter.device()->devType() == TQInternal::Printer;
231 document->setZoomAndResolution( 100, zoomX, zoomY,
true, forPrint );
232 if ( !transparent ) {
233 painter.fillRect( rect, TQt::white );
235 formula->draw( painter, rect );
238TQString KFormulaDoc::configFile()
const
247#include "kformula_doc.moc"