filters
formula.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdlib.h>
00023 #include <kdebug.h>
00024 #include <qptrstack.h>
00025 #include <qdom.h>
00026 #include "formula.h"
00027 #include <kapplication.h>
00028
00029 #include <kformuladocument.h>
00030 #include <kformulamimesource.h>
00031
00032
00033
00034
00035 Formula::Formula()
00036 {
00037 _left = 0;
00038 _right = 0;
00039 _top = 0;
00040 _bottom = 0;
00041 _runaround = TA_NONE;
00042 _runaroundGap = 0;
00043 _autoCreate = TC_EXTEND;
00044 _newFrameBehaviour = TF_RECONNECT;
00045
00046 }
00047
00048
00049
00050
00051 void Formula::analyse(const QDomNode balise)
00052 {
00053
00054
00055
00056
00057 Element::analyse(balise);
00058
00059 kdDebug(30522) << "FRAME ANALYSE (Formula)" << endl;
00060
00061
00062 for(int index= 0; index < getNbChild(balise); index++)
00063 {
00064 if(getChildName(balise, index).compare("FRAME")== 0)
00065 {
00066 analyseParamFrame(balise);
00067 }
00068 else if(getChildName(balise, index).compare("FORMULA")== 0)
00069 {
00070 getFormula(getChild(getChild(balise, "FORMULA"), "FORMULA"), 0);
00071 kdDebug(30522) << _formula << endl;
00072 }
00073
00074 }
00075 kdDebug(30522) << "END OF A FRAME" << endl;
00076 }
00077
00078
00079
00080
00081
00082
00083 void Formula::getFormula(QDomNode p, int indent)
00084 {
00085 switch( p.nodeType() )
00086 {
00087 case QDomNode::TextNode:
00088 _formula = _formula + QString(p.toText().data()) + " ";
00089 break;
00090
00091
00092
00093
00094
00095
00096
00097
00098 case QDomNode::ElementNode:
00099 _formula = _formula + "<" + p.nodeName();
00100 QDomNamedNodeMap attr = p.attributes();
00101 for(unsigned int index = 0; index < attr.length(); index++)
00102 {
00103 _formula = _formula + " " + attr.item(index).nodeName();
00104 _formula = _formula + "=\"" + attr.item(index).nodeValue() + "\"";
00105 }
00106 if(p.childNodes().length() == 0)
00107 _formula = _formula + "/>\n";
00108 else
00109 {
00110 _formula = _formula + ">\n";
00111 QDomNodeList child = p.childNodes();
00112 for(unsigned int index = 0; index < child.length(); index++)
00113 {
00114 getFormula(child.item(index), indent + 3);
00115 }
00116 _formula = _formula + "</" + p.nodeName() + ">\n";
00117 }
00118 break;
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 }
00137 }
00138
00139
00140
00141
00142 void Formula::analyseParamFrame(const QDomNode balise)
00143 {
00144
00145
00146 _left = getAttr(balise, "left").toInt();
00147 _top = getAttr(balise, "top").toInt();
00148 _right = getAttr(balise, "right").toInt();
00149 _bottom = getAttr(balise, "bottom").toInt();
00150 setRunAround(getAttr(balise, "runaround").toInt());
00151 setAroundGap(getAttr(balise, "runaroundGap").toInt());
00152 setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
00153 setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
00154 setSheetSide(getAttr(balise, "sheetside").toInt());
00155 }
00156
00157
00158
00159
00160 void Formula::generate(QTextStream &out)
00161 {
00162 kdDebug(30522) << "FORMULA GENERATION" << endl;
00163 QDomDocument doc;
00164 doc.setContent(_formula);
00165
00166
00167
00168 KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( kapp->config(), 0 );
00169 KFormula::Document* formulaDoc = new KFormula::Document;
00170 wrapper->document( formulaDoc );
00171
00172 KFormula::Container* formula = formulaDoc->createFormula();
00173 if ( !formula->load( doc.documentElement () ) ) {
00174 kdError(30522) << "Failed." << endl;
00175 }
00176
00177 out << "$" << formula->texString() << "$";
00178 delete formula;
00179
00180 delete wrapper;
00181 }
00182
|