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
00086
00087 switch( p.nodeType() )
00088 {
00089 case QDomNode::TextNode:
00090 _formula = _formula + QString(p.toText().data()) + " ";
00091 break;
00092
00093
00094
00095
00096
00097
00098
00099
00100 case QDomNode::ElementNode:
00101 _formula = _formula + "<" + p.nodeName();
00102 QDomNamedNodeMap attr = p.attributes();
00103 for(unsigned int index = 0; index < attr.length(); index++)
00104 {
00105 _formula = _formula + " " + attr.item(index).nodeName();
00106 _formula = _formula + "=\"" + attr.item(index).nodeValue() + "\"";
00107 }
00108 if(p.childNodes().length() == 0)
00109 _formula = _formula + "/>\n";
00110 else
00111 {
00112 _formula = _formula + ">\n";
00113 QDomNodeList child = p.childNodes();
00114 for(unsigned int index = 0; index < child.length(); index++)
00115 {
00116 getFormula(child.item(index), indent+3);
00117 }
00118 _formula = _formula + "</" + p.nodeName() + ">\n";
00119 }
00120 break;
00121
00122
00123
00124 }
00125
00126
00127 }
00128
00129
00130
00131
00132 void Formula::analyseParamFrame(const QDomNode balise)
00133 {
00134
00135
00136 _left = getAttr(balise, "left").toInt();
00137 _top = getAttr(balise, "top").toInt();
00138 _right = getAttr(balise, "right").toInt();
00139 _bottom = getAttr(balise, "bottom").toInt();
00140 setRunAround(getAttr(balise, "runaround").toInt());
00141 setAroundGap(getAttr(balise, "runaroundGap").toInt());
00142 setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
00143 setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
00144 setSheetSide(getAttr(balise, "sheetside").toInt());
00145 }
00146
00147
00148
00149
00150 void Formula::generate(QTextStream &out)
00151 {
00152 kdDebug(30522) << "FORMULA GENERATION" << endl;
00153 QDomDocument doc;
00154 doc.setContent(_formula);
00155
00156
00157
00158 KFormula::Document formulaDoc( kapp->sessionConfig() );
00159
00160 KFormula::Container* formula = new KFormula::Container( &formulaDoc );
00161 if ( !formula->load( doc ) ) {
00162 kdError(30522) << "Failed." << endl;
00163 }
00164
00165 out << "$" << formula->texString() << "$";
00166 delete formula;
00167 }
00168
|