kformula/flake

BasicElement Class Reference

The base class for all elements of a formula. More...

#include <BasicElement.h>

Inheritance diagram for BasicElement:

List of all members.

Public Member Functions

 BasicElement (BasicElement *parent=0)
virtual ~BasicElement ()
const QRectF absoluteBoundingRect () const
virtual bool acceptCursor (const FormulaCursor &cursor)
QString attribute (const QString &attribute) const
virtual QString attributesDefaultValue (const QString &attribute) const
double baseLine () const
const QRectFboundingRect () const
BasicElementchildElementAt (const QPointF &p)
virtual const QList
< BasicElement * > 
childElements () const
const QRectFchildrenBoundingRect () const
virtual QLineF cursorLine (int position) const
bool displayStyle () const
virtual BasicElementelementAfter (int position) const
virtual BasicElementelementBefore (int position) const
virtual QList< BasicElement * > elementsBetween (int pos1, int pos2) const
virtual ElementType elementType () const
BasicElementemptyDescendant ()
virtual int endPosition () const
BasicElementformulaElement ()
bool hasDescendant (BasicElement *other) const
double height () const
virtual QString inheritsAttribute (const QString &attribute) const
virtual bool isEmpty () const
virtual bool isInferredRow () const
virtual void layout (const AttributeManager *am)
virtual bool moveCursor (FormulaCursor &newcursor, FormulaCursor &oldcursor)
QPointF origin () const
virtual void paint (QPainter &painter, AttributeManager *am)
virtual void paintEditingHints (QPainter &painter, AttributeManager *am)
BasicElementparentElement () const
TableEntryElementparentTableEntry ()
virtual int positionOfChild (BasicElement *child) const
bool readMathML (const KoXmlElement &element)
virtual bool replaceChild (BasicElement *oldelement, BasicElement *newelement)
double scaleFactor () const
int scaleLevel () const
virtual QPainterPath selectionRegion (const int pos1, const int pos2) const
void setAttribute (const QString &name, const QVariant &value)
void setBaseLine (double baseLine)
void setChildrenBoundingRect (const QRectF &rect)
virtual bool setCursorTo (FormulaCursor &cursor, QPointF point)
void setDisplayStyle (bool displayStyle)
void setHeight (double height)
void setOrigin (QPointF origin)
void setParentElement (BasicElement *parent)
void setScaleFactor (double scaleFactor)
void setScaleLevel (int scaleLevel)
void setWidth (double width)
virtual void stretch ()
double width () const
virtual const QString writeElementContent () const
virtual void writeElementTree (int indent=0, bool wrong=false) const
void writeMathML (KoXmlWriter *writer) const

Protected Member Functions

virtual bool readMathMLAttributes (const KoXmlElement &element)
virtual bool readMathMLContent (const KoXmlElement &element)
virtual void writeMathMLAttributes (KoXmlWriter *writer) const
virtual void writeMathMLContent (KoXmlWriter *writer) const

Static Protected Member Functions

static void cleanElementTree (BasicElement *element)

Detailed Description

The base class for all elements of a formula.

The BasicElement class is constructed with a parent and normally an element in a formula has a parent. The only exception is FormulaElement which is the root of the element tree and has no parent element. Most of the elements have children but the number of it can be fixed or variable and the type of child element is not certain. So with the childElements() method you can obtain a list of all direct children of an element. Note that the returned list can be empty when the element is eg a token. This is also the reason why each class inheriting BasicElement has to implement the childElements() method on its own. With the childElementAt method you can test if the given point is in the element. This method is generically implemented for all element types only once in BasicElement. The BasicElement knows its size and position in the formula. This data is normally only used for drawing and stored in the m_boundingRect attribute. To adapt both variables, size and coordinates, to fit in the formula each and every BasicElement derived class has to implement layoutElement().

For cursor movement, an element has to implement elementBefore, elementAfter, lastCursorPosition and positionOfChild as well as moveCursor (keyboard navigation) and setCursorTo (cursor placement by clicking).

Definition at line 68 of file BasicElement.h.


Constructor & Destructor Documentation

BasicElement::BasicElement ( BasicElement parent = 0  ) 

Definition at line 35 of file BasicElement.cpp.

BasicElement::~BasicElement (  )  [virtual]

The standard destructor.

Definition at line 46 of file BasicElement.cpp.


Member Function Documentation

const QRectF BasicElement::absoluteBoundingRect (  )  const
Returns:
The absoulte bounding rectangle of the element

Definition at line 113 of file BasicElement.cpp.

bool BasicElement::acceptCursor ( const FormulaCursor cursor  )  [virtual]

Implement the cursor behaviour for the element.

Parameters:
cursor the cursor we test
Returns:
true, if the element accepts the cursor

Reimplemented in FixedElement, MultiscriptElement, RowElement, TableElement, TableRowElement, TokenElement, and UnknownElement.

Definition at line 76 of file BasicElement.cpp.

QString BasicElement::attribute ( const QString attribute  )  const
Returns:
The value of the attribute if it is set for this element

Definition at line 176 of file BasicElement.cpp.

QString BasicElement::attributesDefaultValue ( const QString attribute  )  const [virtual]
Returns:
The default value of the attribute for this element

Reimplemented in FencedElement, FractionElement, MultiscriptElement, SpaceElement, SubSupElement, TableElement, TableEntryElement, and UnderOverElement.

Definition at line 190 of file BasicElement.cpp.

double BasicElement::baseLine (  )  const
Returns:
The baseline of the element

Definition at line 275 of file BasicElement.cpp.

const QRectF & BasicElement::boundingRect (  )  const
Returns:
The bounding rectangle of the element

Definition at line 251 of file BasicElement.cpp.

BasicElement * BasicElement::childElementAt ( const QPointF p  ) 

Get the element of the formula at the given point.

Parameters:
p the point to look for
Returns:
a pointer to a BasicElement

Definition at line 145 of file BasicElement.cpp.

const QList< BasicElement * > BasicElement::childElements (  )  const [virtual]

Obtain a list of all child elements of this element - sorted in saving order.

Returns:
a QList with pointers to all child elements

Reimplemented in FractionElement, MultiscriptElement, RootElement, RowElement, SubSupElement, TableElement, TableRowElement, TokenElement, UnderOverElement, and UnknownElement.

Definition at line 139 of file BasicElement.cpp.

const QRectF & BasicElement::childrenBoundingRect (  )  const
Returns:
The bounding rectangle of the children, relative to the element

Definition at line 255 of file BasicElement.cpp.

void BasicElement::cleanElementTree ( BasicElement element  )  [static, protected]

Definition at line 465 of file BasicElement.cpp.

QLineF BasicElement::cursorLine ( int  position  )  const [virtual]

Return the coordinates of the line, where the cursor should be drawn in coordinates relative to the formula element (or the flake shape).

Parameters:
cursor The FormulaCursor specifying the position
Returns:
the cursor line

Reimplemented in FixedElement, RowElement, TableElement, TableRowElement, and TokenElement.

Definition at line 89 of file BasicElement.cpp.

bool BasicElement::displayStyle (  )  const

Whether displaystyle is set.

Definition at line 368 of file BasicElement.cpp.

BasicElement * BasicElement::elementAfter ( int  position  )  const [virtual]
Returns:
the element right after the cursor position position and 0 if there is none

Reimplemented in FixedElement, and RowElement.

Definition at line 353 of file BasicElement.cpp.

BasicElement * BasicElement::elementBefore ( int  position  )  const [virtual]
Returns:
the element right before the cursor position position and 0 if there is none

Reimplemented in FixedElement, and RowElement.

Definition at line 347 of file BasicElement.cpp.

QList< BasicElement * > BasicElement::elementsBetween ( int  pos1,
int  pos2 
) const [virtual]

Reimplemented in FractionElement, and RowElement.

Definition at line 359 of file BasicElement.cpp.

BasicElement * BasicElement::emptyDescendant (  ) 
Returns:
first empty element, that is a descendant of this element, if there is one

Definition at line 392 of file BasicElement.cpp.

int BasicElement::endPosition (  )  const [virtual]
Returns:
The last cusor position (number of available cursor positions - 1)

Reimplemented in FixedElement, FractionElement, RootElement, RowElement, SubSupElement, TableElement, TableRowElement, TokenElement, and UnderOverElement.

Definition at line 319 of file BasicElement.cpp.

BasicElement * BasicElement::formulaElement (  ) 
Returns:
the formula element that is a descendant of this element

Definition at line 407 of file BasicElement.cpp.

bool BasicElement::hasDescendant ( BasicElement other  )  const
Returns:
true, if other is a descendant of this element

Definition at line 378 of file BasicElement.cpp.

double BasicElement::height (  )  const
Returns:
The height of the element

Definition at line 265 of file BasicElement.cpp.

QString BasicElement::inheritsAttribute ( const QString attribute  )  const [virtual]
Returns:
The value of the attribute if it is inherited

Definition at line 185 of file BasicElement.cpp.

bool BasicElement::isEmpty (  )  const [virtual]
Returns:
true, when the element is empty

Reimplemented in RowElement.

Definition at line 416 of file BasicElement.cpp.

bool BasicElement::isInferredRow (  )  const [virtual]
Returns:
true, if the element is an inferred mrow

Reimplemented in RowElement.

Definition at line 460 of file BasicElement.cpp.

void BasicElement::layout ( const AttributeManager am  )  [virtual]

Calculate the minimum size of the element and the positions of its children.

Laying out the items is done in two parts.

First layout() is called for the topmost element, which in turn calls layout() for its children, and so on. This sets the minimum size of all elements.

Then stretch() is called for the topmost element, which in turn calls stretch() for its children, and so on. This stretches elements that are stretchable, up to their maximum size.

Parameters:
am The AttributeManager providing information about attributes values

Reimplemented in EncloseElement, FencedElement, FractionElement, MultiscriptElement, PaddedElement, RootElement, RowElement, SpaceElement, SquareRootElement, SubSupElement, TableElement, TableRowElement, TokenElement, UnderOverElement, and UnknownElement.

Definition at line 65 of file BasicElement.cpp.

bool BasicElement::moveCursor ( FormulaCursor newcursor,
FormulaCursor oldcursor 
) [virtual]

Move the cursor in the direction specified in cursor.

Parameters:
newcursor the cursor we move around
oldcursor the former cursor position
Returns:
true, if we moved the cursor

Reimplemented in FractionElement, MultiscriptElement, RootElement, RowElement, SubSupElement, TableElement, TableEntryElement, TableRowElement, TokenElement, and UnderOverElement.

Definition at line 82 of file BasicElement.cpp.

QPointF BasicElement::origin (  )  const
Returns:
The element's origin

Definition at line 280 of file BasicElement.cpp.

void BasicElement::paint ( QPainter painter,
AttributeManager am 
) [virtual]

Render the element to the given QPainter.

Parameters:
painter The QPainter to paint the element to
am AttributeManager containing style info

Reimplemented in EncloseElement, ErrorElement, FencedElement, FractionElement, MultiscriptElement, RootElement, RowElement, SpaceElement, SquareRootElement, SubSupElement, TableElement, TableRowElement, TokenElement, UnderOverElement, and UnknownElement.

Definition at line 51 of file BasicElement.cpp.

void BasicElement::paintEditingHints ( QPainter painter,
AttributeManager am 
) [virtual]

Render the editing hints of the element to the given QPainter.

Parameters:
painter The QPainter to paint the element to
am AttributeManager containing style info

Reimplemented in RowElement.

Definition at line 59 of file BasicElement.cpp.

BasicElement * BasicElement::parentElement (  )  const
Returns:
The parent element of this BasicElement

Definition at line 285 of file BasicElement.cpp.

TableEntryElement * BasicElement::parentTableEntry (  ) 
Returns:
the first TableEntryElement among the elements ancestors or 0 if there is none

Definition at line 481 of file BasicElement.cpp.

int BasicElement::positionOfChild ( BasicElement child  )  const [virtual]
Returns:
the cursor position before the child in this element and -1 if it isn't a child
Parameters:
child the childelement we are looking for

Definition at line 324 of file BasicElement.cpp.

bool BasicElement::readMathML ( const KoXmlElement &  element  ) 

Read the element from MathML.

Definition at line 195 of file BasicElement.cpp.

bool BasicElement::readMathMLAttributes ( const KoXmlElement &  element  )  [protected, virtual]

Read all attributes loaded and add them to the m_attributes map.

Definition at line 201 of file BasicElement.cpp.

bool BasicElement::readMathMLContent ( const KoXmlElement &  element  )  [protected, virtual]

Read all content from the node - reimplemented by child elements.

Reimplemented in FractionElement, MultiscriptElement, OperatorElement, RootElement, RowElement, SubSupElement, TableElement, TableRowElement, TokenElement, UnderOverElement, and UnknownElement.

Definition at line 211 of file BasicElement.cpp.

bool BasicElement::replaceChild ( BasicElement oldelement,
BasicElement newelement 
) [virtual]

Replace a child element.

Parameters:
oldelement the child to replace
newelement the child oldelement is replaced with

Definition at line 132 of file BasicElement.cpp.

double BasicElement::scaleFactor (  )  const
Returns:
The elements scale factor

Definition at line 290 of file BasicElement.cpp.

int BasicElement::scaleLevel (  )  const
Returns:
The elements scale level

Definition at line 294 of file BasicElement.cpp.

QPainterPath BasicElement::selectionRegion ( const int  pos1,
const int  pos2 
) const [virtual]

Reimplemented in FixedElement, and TableElement.

Definition at line 97 of file BasicElement.cpp.

void BasicElement::setAttribute ( const QString name,
const QVariant value 
)

Set an attribute's value.

Parameters:
name The name of the attribute to be set
value The value to set for the attribute

Definition at line 165 of file BasicElement.cpp.

void BasicElement::setBaseLine ( double  baseLine  ) 

Set the element's baseline to baseLine.

Definition at line 314 of file BasicElement.cpp.

void BasicElement::setChildrenBoundingRect ( const QRectF rect  ) 

Set the bounding rectangle of the children, relative to the element.

Definition at line 259 of file BasicElement.cpp.

bool BasicElement::setCursorTo ( FormulaCursor cursor,
QPointF  point 
) [virtual]

place the cursor at the the given point the point should be placed a the position in the element (or it's child) that is closest to the point in particular the point doesn't have to be within boundingBox()

Parameters:
cursor The FormulaCursor to modify
point The point in coordinates relative to the elements local coordinate system
Returns:
true, iff the cursor could be placed

Reimplemented in FractionElement, MultiscriptElement, RootElement, RowElement, SubSupElement, TableElement, TableRowElement, TokenElement, and UnderOverElement.

Definition at line 124 of file BasicElement.cpp.

void BasicElement::setDisplayStyle ( bool  displayStyle  ) 

Whether displaystyle is set. This is updated by FormulaRenderer.

Definition at line 372 of file BasicElement.cpp.

void BasicElement::setHeight ( double  height  ) 

Set the element's height to height.

Definition at line 304 of file BasicElement.cpp.

void BasicElement::setOrigin ( QPointF  origin  ) 

Set the element's origin inside the m_parentElement to origin.

Definition at line 309 of file BasicElement.cpp.

void BasicElement::setParentElement ( BasicElement parent  ) 

Set the element's m_parentElement to parent.

Definition at line 330 of file BasicElement.cpp.

void BasicElement::setScaleFactor ( double  scaleFactor  ) 

Set the element's m_scaleFactor to scaleFactor.

Definition at line 422 of file BasicElement.cpp.

void BasicElement::setScaleLevel ( int  scaleLevel  ) 

Set the elements scale level and sets the scale factor.

Definition at line 335 of file BasicElement.cpp.

void BasicElement::setWidth ( double  width  ) 

Set the element's width to width.

Definition at line 299 of file BasicElement.cpp.

void BasicElement::stretch (  )  [virtual]

Calculate the stretched size of the element.

This is called after layouting.

Reimplemented in OperatorElement, and RowElement.

Definition at line 68 of file BasicElement.cpp.

double BasicElement::width (  )  const
Returns:
The width of the element

Definition at line 270 of file BasicElement.cpp.

const QString BasicElement::writeElementContent (  )  const [virtual]

return the content of the element to kDebug(), only for debugging

Reimplemented in TokenElement.

Definition at line 454 of file BasicElement.cpp.

void BasicElement::writeElementTree ( int  indent = 0,
bool  wrong = false 
) const [virtual]

writes the child element tree to kDebug() only for debugging purpose

Parameters:
wrong indicates, if the parent is set wrong
indent indention level

Definition at line 427 of file BasicElement.cpp.

void BasicElement::writeMathML ( KoXmlWriter *  writer  )  const

Save the element to MathML.

Definition at line 217 of file BasicElement.cpp.

void BasicElement::writeMathMLAttributes ( KoXmlWriter *  writer  )  const [protected, virtual]

Write all attributes of m_attributes to writer.

Reimplemented in FormulaElement.

Definition at line 235 of file BasicElement.cpp.

void BasicElement::writeMathMLContent ( KoXmlWriter *  writer  )  const [protected, virtual]

Write all content to the KoXmlWriter - reimplemented by the child elements.

Reimplemented in FractionElement, MultiscriptElement, RootElement, RowElement, SubSupElement, TableElement, TableRowElement, TokenElement, UnderOverElement, and UnknownElement.

Definition at line 241 of file BasicElement.cpp.


The documentation for this class was generated from the following files: