24#include "contextstyle.h"
25#include "basicelement.h"
26#include "formulacursor.h"
27#include "formulaelement.h"
28#include "sequenceelement.h"
30KFORMULA_NAMESPACE_BEGIN
34int BasicElement::evilDestructionCount = 0;
37 : parent( p ), m_baseline( 0 ), elementType( 0 )
43 evilDestructionCount++;
46BasicElement::~BasicElement()
48 evilDestructionCount--;
53 m_baseline( other.m_baseline ),
54 elementType( other.elementType )
58 setWidth( other.getWidth() );
59 setHeight( other.getHeight() );
60 evilDestructionCount++;
66 return parent->readOnly(
this );
83 const LuPixelPoint& point,
const LuPixelPoint& parentOrigin )
85 luPixel x = point.x() - (parentOrigin.x() + getX());
86 if ((x >= 0) && (x < getWidth())) {
87 luPixel y = point.y() - (parentOrigin.y() + getY());
88 if ((y >= 0) && (y < getHeight())) {
102 for (BasicElement* element =
this; element != 0; element = element->parent) {
103 x += element->getX();
104 y += element->getY();
106 return LuPixelPoint(x, y);
117 if (mainChild != 0) {
136 getParent()->moveLeft(cursor,
this);
147 getParent()->moveRight(cursor,
this);
159 if (direction == beforeCursor) {
160 element->moveLeft(cursor,
this);
163 element->moveRight(cursor,
this);
171 TQDomElement de = doc.createElement(
getTagName());
179 TQDomElement de = doc.createElement( oasisFormat ?
"math:" + getElementName() : getElementName() );
180 writeMathMLAttributes( de );
181 writeMathMLContent( doc, de, oasisFormat );
182 parent.appendChild( de );
188 kdWarning( DEBUGID ) <<
"Wrong tag name " << element.tagName().latin1() <<
" for " <<
getTagName().latin1() <<
".\n";
194 TQDomNode node = element.firstChild();
207 TQDomNode node = element.firstChild();
243 if (node.isElement()) {
244 TQDomElement e = node.toElement();
245 if (e.tagName().upper() == name) {
246 TQDomNode nodeInner = e.firstChild();
247 if (nodeInner.isElement()) {
248 TQDomElement element = nodeInner.toElement();
292 int index = str.find(
"%" );
294 return str2size( str, st, index, RelativeSize ) / 100.0;
296 index = str.find(
"pt", 0,
false );
298 return str2size( str, st, index, AbsoluteSize );
300 index = str.find(
"mm", 0,
false );
302 return str2size( str, st, index, AbsoluteSize ) * 72.0 / 20.54;
304 index = str.find(
"cm", 0,
false );
306 return str2size( str, st, index, AbsoluteSize ) * 72.0 / 2.54;
308 index = str.find(
"in", 0,
false );
310 return str2size( str, st, index, AbsoluteSize ) * 72.0;
312 index = str.find(
"em", 0,
false );
314 return str2size( str, st, index, RelativeSize );
316 index = str.find(
"ex", 0,
false );
318 return str2size( str, st, index, RelativeSize );
320 index = str.find(
"pc", 0,
false );
322 return str2size( str, st, index, AbsoluteSize ) * 12.0;
324 index = str.find(
"px", 0,
false );
326 return str2size( str, st, index, PixelSize );
329 return str2size( str, st, str.length(),AbsoluteSize );
332SizeType BasicElement::getSpace(
const TQString& str )
334 if ( str ==
"negativeveryverythinmathspace" ) {
335 return NegativeVeryVeryThinMathSpace;
337 if ( str ==
"negativeverythinmathspace" ) {
338 return NegativeVeryThinMathSpace;
340 if ( str ==
"negativethinmathspace" ) {
341 return NegativeThinMathSpace;
343 if ( str ==
"negativemediummathspace" ) {
344 return NegativeMediumMathSpace;
346 if ( str ==
"negativethickmathspace" ) {
347 return NegativeThickMathSpace;
349 if ( str ==
"negativeverythickmathspace" ) {
350 return NegativeVeryThickMathSpace;
352 if ( str ==
"negativeveryverythickmathspace" ) {
353 return NegativeVeryVeryThickMathSpace;
355 if ( str ==
"veryverythinmathspace" ) {
356 return VeryVeryThinMathSpace;
358 if ( str ==
"verythinmathspace" ) {
359 return VeryThinMathSpace;
361 if ( str ==
"thinmathspace" ) {
362 return ThinMathSpace;
364 if ( str ==
"mediummathspace" ) {
365 return MediumMathSpace;
367 if ( str ==
"thickmathspace" ) {
368 return ThickMathSpace;
370 if ( str ==
"verythickmathspace" ) {
371 return VeryThickMathSpace;
373 if ( str ==
"veryverythickmathspace" ) {
374 return VeryVeryThickMathSpace;
383double BasicElement::str2size(
const TQString& str, SizeType *st, uint index, SizeType type )
385 TQString num = str.left( index );
387 double size = num.toDouble( &ok );
400KFORMULA_NAMESPACE_END
Basis of every formula element.
LuPixelPoint widgetPos()
Returns our position inside the widget.
virtual FormulaElement * formula()
Provide fast access to the rootElement for each child.
bool buildChild(SequenceElement *child, TQDomNode node, TQString name)
Returns if the SequenceElement could be constructed from the nodes first child.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual void entered(SequenceElement *)
The cursor has entered one of our child sequences.
virtual int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
int buildFromMathMLDom(TQDomElement element)
Set this element attribute, build children and call their builFromMathMLDom.
virtual bool readOnly(const BasicElement *child) const
virtual TQString getTagName() const
Returns the tag name of this element type.
virtual TQString toLatex()
virtual void goInside(FormulaCursor *cursor)
Sets the cursor inside this element to its start position.
bool buildFromDom(TQDomElement element)
Set this element attribute, build children and call their buildFromDom.
virtual void normalize(FormulaCursor *, Direction)
Moves the cursor to a normal place where new elements might be inserted.
TQDomElement getElementDom(TQDomDocument &doc)
virtual SequenceElement * getMainChild()
Removes the child.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
double getSize(const TQString &str, SizeType *st)
Utility function that sets the size type and returns the size value from a MathML attribute string wi...
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.