22#include "numberelement.h"
23#include "kformuladefs.h"
24#include "textelement.h"
25#include "identifierelement.h"
26#include "operatorelement.h"
27#include "kformulacommand.h"
28#include "kformulacontainer.h"
29#include "formulaelement.h"
30#include "creationstrategy.h"
32KFORMULA_NAMESPACE_BEGIN
34NumberElement::NumberElement(
BasicElement* parent ) : TokenElement( parent ) {}
46 formula()->tell( i18n(
"write protection" ) );
50 if ( *request == req_addNumber ) {
52 NumberRequest* nr =
static_cast<NumberRequest*
>( request );
53 TextElement* element = creationStrategy->createTextElement( nr->ch(), false );
58 if ( countChildren() == 0 || cursor->getPos() == countChildren() ) {
63 uint pos = parent->childPos(
this );
64 cursor->
setTo( parent, pos + 1);
68 if ( cursor->getPos() == 0 ) {
71 uint pos = parent->childPos(
this );
72 cursor->
setTo( parent, pos );
84 case req_addTextChar: {
86 TextCharRequest* tr =
static_cast<TextCharRequest*
>( request );
87 IdentifierElement*
id = creationStrategy->createIdentifierElement();
88 TextElement* text = creationStrategy->createTextElement( tr->ch() );
94 cursor->
setTo( parent, parent->childPos(
this ) + 1 );
101 TextRequest* tr =
static_cast<TextRequest*
>( request );
102 IdentifierElement*
id = creationStrategy->createIdentifierElement();
105 for ( uint i = 0; i < tr->text().length(); i++ ) {
106 TextElement* text = creationStrategy->createTextElement( tr->text()[i] );
111 cursor->
setTo( parent, parent->childPos(
this ) + 1 );
116 case req_addOperator: {
118 OperatorRequest* opr =
static_cast<OperatorRequest*
>( request );
119 OperatorElement* op = creationStrategy->createOperatorElement();
120 TextElement* text = creationStrategy->createTextElement( opr->ch() );
126 cursor->
setTo( parent, parent->childPos(
this ) + 1 );
130 case req_addEmptyBox:
131 case req_addNameSequence:
134 case req_addFraction:
137 case req_addOneByTwoMatrix:
138 case req_addMatrix: {
141 uint pos = parent->childPos(
this );
142 cursor->
setTo( parent, pos + 1);
153KFORMULA_NAMESPACE_END
Basis of every formula element.
FormulaCursor * activeCursor()
void addContent(BasicElement *element, BasicElement *content)
Collect content for each token.
void addToken(BasicElement *element)
Collect all tokens that are to be added.
void addElement(BasicElement *element)
Collects all elements that are to be added.
Removes the current selection and adds any new elements afterwards.
Add and remove arbitrary token elements and their contents.
void addCursor(FormulaCursor *cursor)
Collect cursor data that will be needed to do the stuff properly.
The element that contains a number of children.
virtual KCommand * buildCommand(Container *, Request *)
This is called by the container to get a command depending on the current cursor position (this is ho...
An element that represents one char.