22#include "kformuladefs.h"
23#include "textelement.h"
24#include "identifierelement.h"
25#include "operatorelement.h"
26#include "numberelement.h"
27#include "kformulacommand.h"
28#include "kformulacontainer.h"
29#include "kformuladocument.h"
30#include "formulaelement.h"
31#include "creationstrategy.h"
33KFORMULA_NAMESPACE_BEGIN
35IdentifierElement::IdentifierElement(
BasicElement* parent ) : TokenElement( parent ) {}
43KCommand* IdentifierElement::buildCommand(
Container* container, Request* request )
47 formula()->tell( i18n(
"write protection" ) );
51 if ( *request == req_addText ) {
53 TextRequest* tr =
static_cast<TextRequest*
>( request );
54 for ( uint i = 0; i < tr->text().length(); i++ ) {
55 TextElement* element = creationStrategy->createTextElement( tr->text()[i] );
61 else if ( *request == req_addTextChar ) {
63 TextCharRequest* tr =
static_cast<TextCharRequest*
>( request );
64 TextElement* element = creationStrategy->createTextElement( tr->ch(), tr->isSymbol() );
69 if ( countChildren() == 0 || cursor->getPos() == countChildren() ) {
74 uint pos = parent->childPos(
this );
75 cursor->
setTo( parent, pos + 1);
79 if ( cursor->getPos() == 0 ) {
82 uint pos = parent->childPos(
this );
83 cursor->
setTo( parent, pos );
95 case req_addOperator: {
97 OperatorRequest* opr =
static_cast<OperatorRequest*
>( request );
98 OperatorElement* op = creationStrategy->createOperatorElement();
99 TextElement* text = creationStrategy->createTextElement( opr->ch() );
105 cursor->
setTo( parent, parent->childPos(
this ) + 1 );
109 case req_addNumber: {
111 NumberRequest* nr =
static_cast<NumberRequest*
>( request );
112 NumberElement* num = creationStrategy->createNumberElement();
113 TextElement* text = creationStrategy->createTextElement( nr->ch() );
119 cursor->
setTo( parent, parent->childPos(
this ) + 1 );
123 case req_addEmptyBox:
124 case req_addNameSequence:
127 case req_addFraction:
130 case req_addOneByTwoMatrix:
131 case req_addMatrix: {
132 uint pos =
static_cast<SequenceElement*
>(getParent())->childPos(
this );
133 cursor->
setTo( getParent(), pos + 1);
134 return getParent()->buildCommand( container, request );
142void IdentifierElement::setStyleVariant( StyleAttributes& style )
144 if ( customMathVariant() ) {
145 style.setCustomMathVariant (
true );
146 style.setCustomFontWeight(
false );
147 style.setCustomFontStyle(
false );
148 style.setCustomFont(
false );
149 if ( customMathVariant() ) {
150 style.setCharFamily ( charFamily() );
151 style.setCharStyle( charStyle() );
154 style.setCharFamily( style.charFamily() );
155 style.setCharStyle( style.charStyle() );
159 style.setCustomMathVariant(
false );
160 if ( customFontFamily() ) {
161 style.setCustomFont(
true );
162 style.setFont( TQFont(fontFamily()) );
165 bool fontweight =
false;
166 if ( customFontWeight() || style.customFontWeight() ) {
167 style.setCustomFontWeight(
true );
168 if ( customFontWeight() ) {
169 fontweight = fontWeight();
172 fontweight = style.customFontWeight();
174 style.setFontWeight( fontweight );
177 style.setCustomFontWeight(
false );
181 if ( customFontStyle() ) {
182 fontstyle = fontStyle();
184 else if ( countChildren() == 1 ) {
191 if ( fontweight && fontstyle ) {
192 style.setCharStyle( boldItalicChar );
194 else if ( fontweight && ! fontstyle ) {
195 style.setCharStyle( boldChar );
197 else if ( ! fontweight && fontstyle ) {
198 style.setCharStyle( italicChar );
201 style.setCharStyle( normalChar );
206KFORMULA_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.