symbolelement.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqpainter.h>
22
23#include <kdebug.h>
24
25#include "elementvisitor.h"
26#include "formulacursor.h"
27#include "formulaelement.h"
28#include "kformulacommand.h"
29#include "sequenceelement.h"
30#include "symbolelement.h"
31
32KFORMULA_NAMESPACE_BEGIN
33
34
35class SymbolSequenceElement : public SequenceElement {
36 typedef SequenceElement inherited;
37public:
38
39 SymbolSequenceElement( BasicElement* parent = 0 ) : SequenceElement( parent ) {}
40
49 virtual KCommand* buildCommand( Container*, Request* );
50};
51
52
53KCommand* SymbolSequenceElement::buildCommand( Container* container, Request* request )
54{
55 FormulaCursor* cursor = container->activeCursor();
56 if ( cursor->isReadOnly() ) {
57 return 0;
58 }
59
60 switch ( *request ) {
61 case req_addIndex: {
62 FormulaCursor* cursor = container->activeCursor();
63 if ( cursor->isSelection() ||
64 ( cursor->getPos() > 0 && cursor->getPos() < countChildren() ) ) {
65 break;
66 }
67 IndexRequest* ir = static_cast<IndexRequest*>( request );
68 if ( ( ir->index() == upperMiddlePos ) || ( ir->index() == lowerMiddlePos ) ) {
69 SymbolElement* element = static_cast<SymbolElement*>( getParent() );
70 ElementIndexPtr index = element->getIndex( ir->index() );
71 if ( !index->hasIndex() ) {
72 KFCAddGenericIndex* command = new KFCAddGenericIndex( container, index );
73 return command;
74 }
75 else {
76 index->moveToIndex( cursor, afterCursor );
77 cursor->setSelection( false );
78 formula()->cursorHasMoved( cursor );
79 return 0;
80 }
81 }
82 }
83 default:
84 break;
85 }
86 return inherited::buildCommand( container, request );
87}
88
89
90SymbolElement::SymbolElement(SymbolType type, BasicElement* parent)
91 : BasicElement(parent), symbol( 0 ), symbolType( type )
92{
93 content = new SymbolSequenceElement( this );
94 upper = 0;
95 lower = 0;
96}
97
98SymbolElement::~SymbolElement()
99{
100 delete lower;
101 delete upper;
102 delete content;
103 delete symbol;
104}
105
106
107SymbolElement::SymbolElement( const SymbolElement& other )
108 : BasicElement( other ), symbol( 0 ), symbolType( other.symbolType )
109{
110 content = new SymbolSequenceElement( *dynamic_cast<SymbolSequenceElement*>( other.content ) );
111 content->setParent( this );
112
113 if ( other.upper ) {
114 upper = new SequenceElement( *( other.upper ) );
115 upper->setParent( this );
116 }
117 else {
118 upper = 0;
119 }
120 if ( other.lower ) {
121 lower = new SequenceElement( *( other.lower ) );
122 lower->setParent( this );
123 }
124 else {
125 lower = 0;
126 }
127}
128
129
131{
132 return visitor->visit( this );
133}
134
135
137 const LuPixelPoint& point, const LuPixelPoint& parentOrigin )
138{
139 BasicElement* e = BasicElement::goToPos(cursor, handled, point, parentOrigin);
140 if (e != 0) {
141 LuPixelPoint myPos(parentOrigin.x() + getX(),
142 parentOrigin.y() + getY());
143
144 e = content->goToPos(cursor, handled, point, myPos);
145 if (e != 0) {
146 return e;
147 }
148 if (hasLower()) {
149 e = lower->goToPos(cursor, handled, point, myPos);
150 if (e != 0) {
151 return e;
152 }
153 }
154 if (hasUpper()) {
155 e = upper->goToPos(cursor, handled, point, myPos);
156 if (e != 0) {
157 return e;
158 }
159 }
160
161 // the positions after the indexes.
162 luPixel dx = point.x() - myPos.x();
163 luPixel dy = point.y() - myPos.y();
164 if (dy < symbol->getY()) {
165 if (hasUpper() && (dx > upper->getX())) {
166 upper->moveLeft(cursor, this);
167 handled = true;
168 return upper;
169 }
170 }
171 else if (dy > symbol->getY()+symbol->getHeight()) {
172 if (hasLower() && (dx > lower->getX())) {
173 lower->moveLeft(cursor, this);
174 handled = true;
175 return lower;
176 }
177 }
178
179 // Have the cursor jump behind the integral.
180 if ( ( dx < symbol->getX()+symbol->getWidth() ) &&
181 ( dx > symbol->getX()+symbol->getWidth()/2 ) ) {
182 content->moveRight( cursor, this );
183 handled = true;
184 return content;
185 }
186
187 return this;
188 }
189 return 0;
190}
191
192
199 ContextStyle::IndexStyle istyle,
200 StyleAttributes& style )
201{
202 double factor = style.sizeFactor();
203 luPt mySize = context.getAdjustedSize( tstyle, factor );
204 luPixel distX = context.ptToPixelX( context.getThinSpace( tstyle, factor ) );
205 luPixel distY = context.ptToPixelY( context.getThinSpace( tstyle, factor ) );
206
207 //if ( symbol == 0 ) {
208 delete symbol;
209 symbol = context.fontStyle().createArtwork( symbolType );
210 //}
211
212 symbol->calcSizes(context, tstyle, factor, mySize);
213 content->calcSizes( context, tstyle, istyle, style );
214
215 //symbol->scale(((double)parentSize)/symbol->getHeight()*2);
216
217 luPixel upperWidth = 0;
218 luPixel upperHeight = 0;
219 if (hasUpper()) {
220 upper->calcSizes( context, context.convertTextStyleIndex( tstyle ),
221 context.convertIndexStyleUpper( istyle ), style );
222 upperWidth = upper->getWidth();
223 upperHeight = upper->getHeight() + distY;
224 }
225
226 luPixel lowerWidth = 0;
227 luPixel lowerHeight = 0;
228 if (hasLower()) {
229 lower->calcSizes( context, context.convertTextStyleIndex( tstyle ),
230 context.convertIndexStyleLower( istyle ), style );
231 lowerWidth = lower->getWidth();
232 lowerHeight = lower->getHeight() + distY;
233 }
234
235 // widths
236 luPixel xOffset = TQMAX(symbol->getWidth(), TQMAX(upperWidth, lowerWidth));
237 if (context.getCenterSymbol()) {
238 symbol->setX((xOffset - symbol->getWidth()) / 2);
239 }
240 else {
241 symbol->setX(xOffset - symbol->getWidth());
242 }
243 // ???
244 content->setX(xOffset +
245 static_cast<luPixel>( symbol->slant()*symbol->getHeight()/2 ) +
246 distX/2);
247
248 setWidth(TQMAX(content->getX() + content->getWidth(),
249 TQMAX(upperWidth, lowerWidth)));
250
251 // heights
252 //int toMidline = TQMAX(content->getHeight() / 2,
253 luPixel toMidline = TQMAX(content->axis( context, tstyle, factor ),
254 upperHeight + symbol->getHeight()/2);
255 //int fromMidline = TQMAX(content->getHeight() / 2,
256 luPixel fromMidline = TQMAX(content->getHeight() - content->axis( context, tstyle, factor ),
257 lowerHeight + symbol->getHeight()/2);
258 setHeight(toMidline + fromMidline);
259 //setMidline(toMidline);
260
261 symbol->setY(toMidline - symbol->getHeight()/2);
262 //content->setY(toMidline - content->getHeight()/2);
263 content->setY(toMidline - content->axis( context, tstyle, factor ));
264
265 if (hasUpper()) {
266 luPixel slant =
267 static_cast<luPixel>( symbol->slant()*( symbol->getHeight()+distY ) );
268 if (context.getCenterSymbol()) {
269 upper->setX((xOffset - upperWidth) / 2 + slant );
270 }
271 else {
272 if (upperWidth < symbol->getWidth()) {
273 upper->setX(symbol->getX() +
274 (symbol->getWidth() - upperWidth) / 2 + slant );
275 }
276 else {
277 upper->setX(xOffset - upperWidth);
278 }
279 }
280 upper->setY(toMidline - upperHeight - symbol->getHeight()/2);
281 }
282 if (hasLower()) {
283 luPixel slant = static_cast<luPixel>( -symbol->slant()*distY );
284 if (context.getCenterSymbol()) {
285 lower->setX((xOffset - lowerWidth) / 2 + slant);
286 }
287 else {
288 if (lowerWidth < symbol->getWidth()) {
289 lower->setX(symbol->getX() +
290 (symbol->getWidth() - lowerWidth) / 2 + slant );
291 }
292 else {
293 lower->setX(xOffset - lowerWidth);
294 }
295 }
296 lower->setY(toMidline + symbol->getHeight()/2 + distY);
297 }
298 setBaseline(content->getBaseline() + content->getY());
299}
300
306void SymbolElement::draw( TQPainter& painter, const LuPixelRect& r,
307 const ContextStyle& context,
309 ContextStyle::IndexStyle istyle,
310 StyleAttributes& style,
311 const LuPixelPoint& parentOrigin )
312{
313 LuPixelPoint myPos( parentOrigin.x()+getX(), parentOrigin.y()+getY() );
314 //if ( !LuPixelRect( myPos.x(), myPos.y(), getWidth(), getHeight() ).intersects( r ) )
315 // return;
316
317 luPt mySize = context.getAdjustedSize( tstyle, style.sizeFactor() );
318 symbol->draw( painter, r, context, tstyle, style, mySize, myPos );
319 content->draw( painter, r, context, tstyle, istyle, style, myPos );
320 if ( hasUpper() ) {
321 upper->draw( painter, r, context, context.convertTextStyleIndex( tstyle ),
322 context.convertIndexStyleUpper( istyle ), style, myPos );
323 }
324 if ( hasLower() ) {
325 lower->draw( painter, r, context, context.convertTextStyleIndex( tstyle ),
326 context.convertIndexStyleLower( istyle ), style, myPos );
327 }
328
329 // Debug
330#if 0
331 painter.setBrush(TQt::NoBrush);
332 painter.setPen(TQt::red);
333// painter.drawRect( context.layoutUnitToPixelX( myPos.x() ),
334// context.layoutUnitToPixelY( myPos.y() ),
335// context.layoutUnitToPixelX( getWidth() ),
336// context.layoutUnitToPixelY( getHeight() ) );
337 painter.drawRect( context.layoutUnitToPixelX( myPos.x()+symbol->getX() ),
338 context.layoutUnitToPixelY( myPos.y()+symbol->getY() ),
339 context.layoutUnitToPixelX( symbol->getWidth() ),
340 context.layoutUnitToPixelY( symbol->getHeight() ) );
341 painter.setPen(TQt::green);
342 painter.drawLine( context.layoutUnitToPixelX( myPos.x() ),
343 context.layoutUnitToPixelY( myPos.y()+axis(context, tstyle) ),
344 context.layoutUnitToPixelX( myPos.x()+getWidth() ),
345 context.layoutUnitToPixelY( myPos.y()+axis(context, tstyle) ) );
346#endif
347}
348
349
351{
352 content->dispatchFontCommand( cmd );
353 if ( hasUpper() ) {
354 upper->dispatchFontCommand( cmd );
355 }
356 if ( hasLower() ) {
357 lower->dispatchFontCommand( cmd );
358 }
359}
360
361// navigation
362//
363// The elements are responsible to handle cursor movement themselves.
364// To do this they need to know the direction the cursor moves and
365// the element it comes from.
366//
367// The cursor might be in normal or in selection mode.
368
375{
376 if (cursor->isSelectionMode()) {
377 getParent()->moveLeft(cursor, this);
378 }
379 else {
380 bool linear = cursor->getLinearMovement();
381 if (from == getParent()) {
382 content->moveLeft(cursor, this);
383 }
384 else if (from == content) {
385 if (linear && hasLower()) {
386 lower->moveLeft(cursor, this);
387 }
388 else if (linear && hasUpper()) {
389 upper->moveLeft(cursor, this);
390 }
391 else {
392 getParent()->moveLeft(cursor, this);
393 }
394 }
395 else if (from == lower) {
396 if (linear && hasUpper()) {
397 upper->moveLeft(cursor, this);
398 }
399 else {
400 getParent()->moveLeft(cursor, this);
401 }
402 }
403 else if (from == upper) {
404 getParent()->moveLeft(cursor, this);
405 }
406 }
407}
408
415{
416 if (cursor->isSelectionMode()) {
417 getParent()->moveRight(cursor, this);
418 }
419 else {
420 bool linear = cursor->getLinearMovement();
421 if (from == getParent()) {
422 if (linear && hasUpper()) {
423 upper->moveRight(cursor, this);
424 }
425 else if (linear && hasLower()) {
426 lower->moveRight(cursor, this);
427 }
428 else {
429 content->moveRight(cursor, this);
430 }
431 }
432 else if (from == upper) {
433 if (linear && hasLower()) {
434 lower->moveRight(cursor, this);
435 }
436 else {
437 content->moveRight(cursor, this);
438 }
439 }
440 else if (from == lower) {
441 content->moveRight(cursor, this);
442 }
443 else if (from == content) {
444 getParent()->moveRight(cursor, this);
445 }
446 }
447}
448
455{
456 if (cursor->isSelectionMode()) {
457 getParent()->moveUp(cursor, this);
458 }
459 else {
460 if (from == content) {
461 if (hasUpper()) {
462 upper->moveLeft(cursor, this);
463 }
464 else {
465 getParent()->moveUp(cursor, this);
466 }
467 }
468 else if (from == upper) {
469 getParent()->moveUp(cursor, this);
470 }
471 else if ((from == getParent()) || (from == lower)) {
472 content->moveRight(cursor, this);
473 }
474 }
475}
476
483{
484 if (cursor->isSelectionMode()) {
485 getParent()->moveDown(cursor, this);
486 }
487 else {
488 if (from == content) {
489 if (hasLower()) {
490 lower->moveLeft(cursor, this);
491 }
492 else {
493 getParent()->moveDown(cursor, this);
494 }
495 }
496 else if (from == lower) {
497 getParent()->moveDown(cursor, this);
498 }
499 else if ((from == getParent()) || (from == upper)) {
500 content->moveRight(cursor, this);
501 }
502 }
503}
504
505// children
506
507// main child
508//
509// If an element has children one has to become the main one.
510
511// void SymbolElement::setMainChild(SequenceElement* child)
512// {
513// formula()->elementRemoval(content);
514// content = child;
515// content->setParent(this);
516// formula()->changed();
517// }
518
519
531 TQPtrList<BasicElement>& newChildren,
532 Direction direction)
533{
534 SequenceElement* index = static_cast<SequenceElement*>(newChildren.take(0));
535 index->setParent(this);
536
537 switch (cursor->getPos()) {
538 case upperMiddlePos:
539 upper = index;
540 break;
541 case lowerMiddlePos:
542 lower = index;
543 break;
544 default:
545 // this is an error!
546 return;
547 }
548
549 if (direction == beforeCursor) {
550 index->moveLeft(cursor, this);
551 }
552 else {
553 index->moveRight(cursor, this);
554 }
555 cursor->setSelection(false);
556 formula()->changed();
557}
558
571 TQPtrList<BasicElement>& removedChildren,
572 Direction direction)
573{
574 int pos = cursor->getPos();
575 switch (pos) {
576 case upperMiddlePos:
577 removedChildren.append(upper);
578 formula()->elementRemoval(upper);
579 upper = 0;
580 setToUpper(cursor);
581 break;
582 case lowerMiddlePos:
583 removedChildren.append(lower);
584 formula()->elementRemoval(lower);
585 lower = 0;
586 setToLower(cursor);
587 break;
588 case contentPos: {
589 BasicElement* parent = getParent();
590 parent->selectChild(cursor, this);
591 parent->remove(cursor, removedChildren, direction);
592 break;
593 }
594 }
595 formula()->changed();
596}
597
602void SymbolElement::normalize(FormulaCursor* cursor, Direction direction)
603{
604 if (direction == beforeCursor) {
605 content->moveLeft(cursor, this);
606 }
607 else {
608 content->moveRight(cursor, this);
609 }
610}
611
616{
617 int pos = cursor->getPos();
618 switch (pos) {
619 case contentPos:
620 return content;
621 case upperMiddlePos:
622 return upper;
623 case lowerMiddlePos:
624 return lower;
625 }
626 return 0;
627}
628
634{
635 if (child == content) {
636 setToContent(cursor);
637 }
638 else if (child == upper) {
639 setToUpper(cursor);
640 }
641 else if (child == lower) {
642 setToLower(cursor);
643 }
644}
645
646void SymbolElement::setToUpper(FormulaCursor* cursor)
647{
648 cursor->setTo(this, upperMiddlePos);
649}
650
651void SymbolElement::setToLower(FormulaCursor* cursor)
652{
653 cursor->setTo(this, lowerMiddlePos);
654}
655
662void SymbolElement::setToContent(FormulaCursor* cursor)
663{
664 cursor->setTo(this, contentPos);
665}
666
667
668void SymbolElement::moveToUpper(FormulaCursor* cursor, Direction direction)
669{
670 if (hasUpper()) {
671 if (direction == beforeCursor) {
672 upper->moveLeft(cursor, this);
673 }
674 else {
675 upper->moveRight(cursor, this);
676 }
677 }
678}
679
680void SymbolElement::moveToLower(FormulaCursor* cursor, Direction direction)
681{
682 if (hasLower()) {
683 if (direction == beforeCursor) {
684 lower->moveLeft(cursor, this);
685 }
686 else {
687 lower->moveRight(cursor, this);
688 }
689 }
690}
691
692
693ElementIndexPtr SymbolElement::getIndex( int position )
694{
695 switch ( position ) {
696 case lowerMiddlePos:
697 return getLowerIndex();
698 case upperMiddlePos:
699 return getUpperIndex();
700 }
701 return getUpperIndex();
702}
703
704
708void SymbolElement::writeDom(TQDomElement element)
709{
710 BasicElement::writeDom(element);
711
712 element.setAttribute("TYPE", symbolType);
713
714 TQDomDocument doc = element.ownerDocument();
715
716 TQDomElement con = doc.createElement("CONTENT");
717 con.appendChild(content->getElementDom(doc));
718 element.appendChild(con);
719
720 if(hasLower()) {
721 TQDomElement ind = doc.createElement("LOWER");
722 ind.appendChild(lower->getElementDom(doc));
723 element.appendChild(ind);
724 }
725 if(hasUpper()) {
726 TQDomElement ind = doc.createElement("UPPER");
727 ind.appendChild(upper->getElementDom(doc));
728 element.appendChild(ind);
729 }
730}
731
736bool SymbolElement::readAttributesFromDom(TQDomElement element)
737{
739 return false;
740 }
741
742 TQString typeStr = element.attribute("TYPE");
743 if(!typeStr.isNull()) {
744 symbolType = static_cast<SymbolType>(typeStr.toInt());
745 }
746
747 return true;
748}
749
756{
758 return false;
759 }
760
761 if ( !buildChild( content, node, "CONTENT" ) ) {
762 kdWarning( DEBUGID ) << "Empty content in SymbolElement." << endl;
763 return false;
764 }
765 node = node.nextSibling();
766
767 bool lowerRead = false;
768 bool upperRead = false;
769
770 while (!node.isNull() && !(upperRead && lowerRead)) {
771
772 if (!lowerRead && (node.nodeName().upper() == "LOWER")) {
773 lowerRead = buildChild( lower=new SequenceElement( this ), node, "LOWER" );
774 if ( !lowerRead ) return false;
775 }
776
777 if (!upperRead && (node.nodeName().upper() == "UPPER")) {
778 upperRead = buildChild( upper=new SequenceElement( this ), node, "UPPER" );
779 if ( !upperRead ) return false;
780 }
781
782 node = node.nextSibling();
783 }
784 return true;
785}
786
788{
789 TQString sym;
790
791 switch(symbolType) {
792
793 case 1001:
794 sym="\\int";
795 break;
796 case 1002:
797 sym="\\sum";
798 break;
799 case 1003:
800 sym="\\prod";
801 break;
802
803 default:
804 sym=" ";
805
806 }
807
808
809 if(hasLower()) {
810 sym+="_{";
811 sym+=lower->toLatex();
812 sym+="}";
813 }
814
815 if(hasUpper()) {
816 sym+="^{";
817 sym+=upper->toLatex();
818 sym+="} ";
819 }
820
821 sym += " ";
822
823 sym+=content->toLatex();
824
825
826 return sym;
827}
828
829TQString SymbolElement::formulaString()
830{
831 TQString sym;
832 switch ( symbolType ) {
833 case 1001:
834 sym="int(";
835 break;
836 case 1002:
837 sym="sum(";
838 break;
839 case 1003:
840 sym="prod(";
841 break;
842 default:
843 sym="(";
844 }
845 sym += content->formulaString();
846 if ( hasLower() ) {
847 sym += ", " + lower->formulaString();
848 }
849 if ( hasUpper() ) {
850 sym += ", " + upper->formulaString();
851 }
852 return sym + ")";
853}
854
855void SymbolElement::writeMathML( TQDomDocument& doc, TQDomNode& parent, bool oasisFormat ) const
856{
857 TQDomElement de = doc.createElement( oasisFormat ? "math:mrow" : "mrow" );
858 TQDomElement mo = doc.createElement( oasisFormat ? "math:mo" : "mo" );
859
860 TQString value;
861
862 switch( symbolType )
863 {
864 case EmptyBracket: break;
865 case LeftLineBracket: case RightLineBracket:
866 mo.appendChild( doc.createTextNode( "|" ) ); break;
867 case Integral:
868 mo.appendChild( doc.createEntityReference( "int" ) ); break;
869 case Sum:
870 mo.appendChild( doc.createEntityReference( "sum" ) ); break;
871 case Product:
872 mo.appendChild( doc.createEntityReference( "prod" ) ); break;
873 default:
874 mo.appendChild( doc.createTextNode( TQChar( symbolType ) ) );
875 }
876
877 TQDomElement between;
878 if ( hasUpper() && hasLower() )
879 {
880 between = doc.createElement( oasisFormat ? "math:msubsup" : "msubsup" );
881 between.appendChild( mo );
882 lower->writeMathML( doc, between, oasisFormat );
883 upper->writeMathML( doc, between, oasisFormat );
884 }
885 else if ( hasUpper() )
886 {
887 between = doc.createElement( oasisFormat ? "math:msup" : "msup" );
888 between.appendChild( mo );
889 upper->writeMathML( doc, between, oasisFormat );
890 }
891 else if ( hasLower() )
892 {
893 between = doc.createElement( oasisFormat ? "math:msub" : "msub" );
894 between.appendChild( mo );
895 lower->writeMathML( doc, between, oasisFormat );
896 }
897 else
898 between = mo;
899
900 de.appendChild( between );
901 content->writeMathML( doc, de, oasisFormat );
902
903 parent.appendChild( de );
904}
905
906KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual FormulaElement * formula()
Provide fast access to the rootElement for each child.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
bool buildChild(SequenceElement *child, TQDomNode node, TQString name)
Returns if the SequenceElement could be constructed from the nodes first child.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual void moveUp(FormulaCursor *, BasicElement *)
Enters this element while moving up starting inside the element ‘from’.
virtual void selectChild(FormulaCursor *, BasicElement *)
Sets the cursor to select the child.
TQDomElement getElementDom(TQDomDocument &doc)
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.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
virtual void moveDown(FormulaCursor *, BasicElement *)
Enters this element while moving down starting inside the element ‘from’.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
The document.
FormulaCursor * activeCursor()
Contains all the style information for the formela.
TextStyle convertTextStyleIndex(TextStyle tstyle) const
Font-conversions a la TeX.
luPt getAdjustedSize(TextStyle tstyle, double factor) const
Calculates the font size corresponding to the given TextStyle.
TextStyle
Textstyles like in TeX.
IndexStyle convertIndexStyleLower(IndexStyle) const
Index-style-conversions a la TeX.
IndexStyle convertIndexStyleUpper(IndexStyle istyle) const
Index-style-conversions a la TeX.
Base for all font commands that act on the current selection.
The selection.
bool isSelection() const
Returns wether there actually is a selection.
void setSelection(bool selection)
Sets the selection mode.
bool isSelectionMode() const
Returns wether we are in selection mode.
void setTo(BasicElement *element, uint cursor, int mark=-1)
Sets the cursor to a new position.
bool isReadOnly() const
void elementRemoval(BasicElement *child)
Gets called just before the child is removed from the element tree.
virtual void changed()
Gets called whenever something changes and we need to recalc.
int ptToPixelX(double pt) const
Basic pt to pixel and pixel to pt conversions, valid at any zoom level, as well as at the Layout Unit...
int layoutUnitToPixelX(int lupix) const
The "layout unit pixel" -> "[zoomed] view pixel" conversions.
The element that contains a number of children.
virtual TQString toLatex()
virtual KCommand * buildCommand(Container *, Request *)
This is called by the container to get a command depending on the current cursor position (this is ho...
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
virtual void calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
virtual BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
virtual void draw(TQPainter &painter, const LuPixelRect &r, const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style, const LuPixelPoint &parentOrigin)
Draws the whole element including its children.
A symbol is simply a piece of art.
virtual BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
virtual void calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
ElementIndexPtr getIndex(int position)
Returns the index at the position.
virtual void moveUp(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving up starting inside the element ‘from’.
virtual BasicElement * getChild(FormulaCursor *, Direction=beforeCursor)
Returns the child at the cursor.
virtual void moveDown(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving down starting inside the element ‘from’.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual void selectChild(FormulaCursor *cursor, BasicElement *child)
Sets the cursor to select the child.
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Inserts all new children at the cursor position.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual void normalize(FormulaCursor *, Direction)
Moves the cursor to a normal place where new elements might be inserted.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual TQString toLatex()
virtual void draw(TQPainter &painter, const LuPixelRect &r, const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style, const LuPixelPoint &parentOrigin)
Draws the whole element including its children.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
bool hasUpper() const
Moves the cursor away from the given child.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.