26#include "elementvisitor.h"
27#include "indexelement.h"
28#include "formulacursor.h"
29#include "formulaelement.h"
30#include "kformulacommand.h"
31#include "sequenceelement.h"
34KFORMULA_NAMESPACE_BEGIN
42 virtual IndexSequenceElement* clone() {
43 return new IndexSequenceElement( * this );
58KCommand* IndexSequenceElement::buildCommand( Container* container, Request* request )
69 ( cursor->getPos() > 0 && cursor->getPos() < countChildren() ) ) {
73 IndexRequest* ir = static_cast<IndexRequest* >( request );
74 ElementIndexPtr index = element-> getIndex( ir->index() );
75 if ( !index->hasIndex() ) {
80 index->moveToIndex( cursor, afterCursor );
82 formula()->cursorHasMoved( cursor );
89 return inherited::buildCommand( container, request );
95 m_subScriptShiftType( NoSize ),
96 m_superScriptShiftType( NoSize ),
97 m_customAccentUnder( false ),
98 m_customAccent ( false )
100 content = new IndexSequenceElement( this );
110IndexElement::~IndexElement()
124 m_subScriptShiftType( other.m_subScriptShiftType ),
125 m_subScriptShift( other.m_subScriptShift ),
126 m_superScriptShiftType( other.m_superScriptShiftType ),
127 m_superScriptShift( other.m_superScriptShift ),
128 m_customAccentUnder( other.m_customAccentUnder ),
129 m_accentUnder( other.m_accentUnder ),
130 m_customAccent ( other.m_customAccent ),
131 m_accent( other.m_accent )
133 content = new IndexSequenceElement( * dynamic_cast<IndexSequenceElement* >( other.content ) );
135 if ( other.upperLeft ) {
137 upperLeft->setParent( this );
142 if ( other.upperMiddle ) {
144 upperMiddle->setParent( this );
149 if ( other.upperRight ) {
151 upperRight->setParent( this );
157 if ( other.lowerLeft ) {
159 lowerLeft->setParent( this );
164 if ( other.lowerMiddle ) {
166 lowerMiddle->setParent( this );
171 if ( other.lowerRight ) {
173 lowerRight->setParent( this );
183 return visitor->visit( this );
193 if ( hasUpperRight() && !upperRight-> isTextOnly() ) {
196 if ( hasUpperMiddle() && !upperMiddle-> isTextOnly() ) {
199 if ( hasUpperLeft() && !upperLeft-> isTextOnly() ) {
202 if ( hasLowerRight() && !lowerRight-> isTextOnly() ) {
205 if ( hasLowerMiddle() && !lowerMiddle-> isTextOnly() ) {
208 if ( hasLowerLeft() && !lowerLeft-> isTextOnly() ) {
217 if ( child == content ) {
230 const LuPixelPoint& point, const LuPixelPoint& parentOrigin )
234 LuPixelPoint myPos(parentOrigin.x()+getX(), parentOrigin.y()+getY());
235 e = content-> goToPos(cursor, handled, point, myPos);
236 if (e != 0) return e;
238 if (hasUpperRight()) {
239 e = upperRight-> goToPos(cursor, handled, point, myPos);
240 if (e != 0) return e;
242 if (hasUpperMiddle()) {
243 e = upperMiddle-> goToPos(cursor, handled, point, myPos);
244 if (e != 0) return e;
246 if (hasUpperLeft()) {
247 e = upperLeft-> goToPos(cursor, handled, point, myPos);
248 if (e != 0) return e;
250 if (hasLowerRight()) {
251 e = lowerRight-> goToPos(cursor, handled, point, myPos);
252 if (e != 0) return e;
254 if (hasLowerMiddle()) {
255 e = lowerMiddle-> goToPos(cursor, handled, point, myPos);
256 if (e != 0) return e;
258 if (hasLowerLeft()) {
259 e = lowerLeft-> goToPos(cursor, handled, point, myPos);
260 if (e != 0) return e;
263 luPixel dx = point.x() - myPos.x();
264 luPixel dy = point.y() - myPos.y();
267 if (dx < content->getX()+content->getWidth()) {
268 if (dy < content->getY()) {
269 if (hasUpperMiddle() && (dx > upperMiddle->getX())) {
270 upperMiddle-> moveLeft(cursor, this);
274 if (hasUpperLeft() && (dx > upperLeft->getX())) {
280 else if (dy > content->getY()+content->getHeight()) {
281 if (hasLowerMiddle() && (dx > lowerMiddle->getX())) {
282 lowerMiddle-> moveLeft(cursor, this);
286 if (hasLowerLeft() && (dx > lowerLeft->getX())) {
295 if (dy < content->getY()) {
296 if (hasUpperRight()) {
302 else if (dy > content->getY()+content->getHeight()) {
303 if (hasLowerRight()) {
330void IndexElement::setMiddleX( int xOffset, int middleWidth)
332 content->setX(xOffset + (middleWidth - content->getWidth()) / 2);
333 if (hasUpperMiddle()) {
334 upperMiddle->setX(xOffset + (middleWidth - upperMiddle->getWidth()) / 2);
336 if (hasLowerMiddle()) {
337 lowerMiddle->setX(xOffset + (middleWidth - lowerMiddle->getWidth()) / 2);
348 ContextStyle::IndexStyle istyle,
349 StyleAttributes& style )
351 double factor = style.sizeFactor();
352 luPixel distY = context.ptToPixelY( context.getThinSpace( tstyle, factor ) );
359 luPixel ulWidth = 0, ulHeight = 0, ulMidline = 0;
360 if (hasUpperLeft()) {
361 upperLeft-> calcSizes( context, i_tstyle, u_istyle, style );
362 ulWidth = upperLeft->getWidth();
363 ulHeight = upperLeft->getHeight();
364 ulMidline = upperLeft->axis( context, i_tstyle, factor );
367 luPixel umWidth = 0, umHeight = 0, umMidline = 0;
368 if (hasUpperMiddle()) {
369 upperMiddle-> calcSizes( context, i_tstyle, u_istyle, style );
370 umWidth = upperMiddle->getWidth();
371 umHeight = upperMiddle->getHeight() + distY;
372 umMidline = upperMiddle->axis( context, i_tstyle, factor );
375 luPixel urWidth = 0, urHeight = 0, urMidline = 0;
376 if (hasUpperRight()) {
377 upperRight-> calcSizes( context, i_tstyle, u_istyle, style );
378 urWidth = upperRight->getWidth();
379 urHeight = upperRight->getHeight();
380 urMidline = upperRight->axis( context, i_tstyle, factor );
383 luPixel llWidth = 0, llHeight = 0, llMidline = 0;
384 if (hasLowerLeft()) {
385 lowerLeft-> calcSizes( context, i_tstyle, l_istyle, style );
386 llWidth = lowerLeft->getWidth();
387 llHeight = lowerLeft->getHeight();
388 llMidline = lowerLeft->axis( context, i_tstyle, factor );
391 luPixel lmWidth = 0, lmHeight = 0, lmMidline = 0;
392 if (hasLowerMiddle()) {
393 lowerMiddle-> calcSizes( context, i_tstyle, l_istyle, style );
394 lmWidth = lowerMiddle->getWidth();
395 lmHeight = lowerMiddle->getHeight() + distY;
396 lmMidline = lowerMiddle->axis( context, i_tstyle, factor );
399 luPixel lrWidth = 0, lrHeight = 0, lrMidline = 0;
400 if (hasLowerRight()) {
401 lowerRight-> calcSizes( context, i_tstyle, l_istyle, style );
402 lrWidth = lowerRight->getWidth();
403 lrHeight = lowerRight->getHeight();
404 lrMidline = lowerRight->axis( context, i_tstyle, factor );
408 content-> calcSizes( context, tstyle, istyle, style );
409 luPixel width = TQMAX(content->getWidth(), TQMAX(umWidth, lmWidth));
410 luPixel toMidline = content->axis( context, tstyle, factor );
411 luPixel fromMidline = content->getHeight() - toMidline;
414 if (ulWidth > llWidth) {
416 if (hasLowerLeft()) {
417 lowerLeft->setX(ulWidth - llWidth);
419 setMiddleX(ulWidth, width);
423 if (hasUpperLeft()) {
424 upperLeft->setX(llWidth - ulWidth);
426 if (hasLowerLeft()) {
429 setMiddleX(llWidth, width);
433 if (hasUpperRight()) {
434 upperRight->setX(width);
436 if (hasLowerRight()) {
437 lowerRight->setX(width);
439 width += TQMAX(urWidth, lrWidth);
442 luPixel ulOffset = 0;
443 luPixel urOffset = 0;
444 luPixel llOffset = 0;
445 luPixel lrOffset = 0;
448 TQFont font = context.getDefaultFont();
449 font.setPointSizeFloat( context.layoutUnitPtToPt( mySize ) );
451 TQFontMetrics fm(font);
452 LuPixelRect bound = fm.boundingRect( 'x');
457 ulOffset = ulHeight + exBaseline - content->getBaseline();
458 urOffset = urHeight + exBaseline - content->getBaseline();
461 llOffset = lrOffset = content->getBaseline();
466 ulOffset = TQMAX(ulMidline, ulHeight-toMidline);
467 urOffset = TQMAX(urMidline, urHeight-toMidline);
470 llOffset = TQMAX(content->getHeight()-llMidline, toMidline);
471 lrOffset = TQMAX(content->getHeight()-lrMidline, toMidline);
475 switch ( m_superScriptShiftType ) {
480 urOffset += urOffset * m_superScriptShift;
483 urOffset += context.pixelToLayoutUnitY( m_superScriptShift );
489 switch ( m_subScriptShiftType ) {
494 lrOffset += lrOffset * m_subScriptShift;
497 lrOffset += context.pixelToLayoutUnitY( m_subScriptShift );
503 luPixel height = TQMAX(umHeight, TQMAX(ulOffset, urOffset));
506 content->setY(height);
508 if (hasUpperLeft()) {
509 upperLeft->setY(height-ulOffset);
511 if (hasUpperMiddle()) {
512 upperMiddle->setY(height-umHeight);
514 if (hasUpperRight()) {
515 upperRight->setY( height - urOffset );
519 if (hasLowerLeft()) {
520 lowerLeft->setY(height+llOffset);
522 if (hasLowerMiddle()) {
523 lowerMiddle->setY(height+content->getHeight()+distY);
525 if (hasLowerRight()) {
526 lowerRight->setY( height + lrOffset );
529 fromMidline += TQMAX(TQMAX(llHeight+llOffset, lrHeight+lrOffset) - content->getHeight(), lmHeight);
533 setHeight(toMidline+fromMidline);
535 setBaseline(content->getY() + content->getBaseline());
540 setBaseline(content->getBaseline() + content->getY());
552 ContextStyle::IndexStyle istyle,
553 StyleAttributes& style,
554 const LuPixelPoint& parentOrigin )
556 LuPixelPoint myPos( parentOrigin.x()+getX(), parentOrigin.y()+getY() );
564 content-> draw(painter, r, context, tstyle, istyle, style, myPos);
565 if (hasUpperLeft()) {
566 upperLeft-> draw(painter, r, context, i_tstyle, u_istyle, style, myPos);
568 if (hasUpperMiddle()) {
569 upperMiddle-> draw(painter, r, context, i_tstyle, u_istyle, style, myPos);
571 if (hasUpperRight()) {
572 upperRight-> draw(painter, r, context, i_tstyle, u_istyle, style, myPos);
574 if (hasLowerLeft()) {
575 lowerLeft-> draw(painter, r, context, i_tstyle, l_istyle, style, myPos);
577 if (hasLowerMiddle()) {
578 lowerMiddle-> draw(painter, r, context, i_tstyle, l_istyle, style, myPos);
580 if (hasLowerRight()) {
581 lowerRight-> draw(painter, r, context, i_tstyle, l_istyle, style, myPos);
596 if (hasUpperLeft()) {
599 if (hasUpperMiddle()) {
602 if (hasUpperRight()) {
605 if (hasLowerLeft()) {
608 if (hasLowerMiddle()) {
611 if (hasLowerRight()) {
627 if (from == lowerRight) {
628 return lowerRightPos;
630 else if (from == upperRight) {
631 return upperRightPos;
633 else if (from == lowerMiddle) {
634 return lowerMiddlePos;
636 else if (from == content) {
639 else if (from == upperMiddle) {
640 return upperMiddlePos;
642 else if (from == lowerLeft) {
645 else if (from == upperLeft) {
659 getParent()-> moveLeft(cursor, this);
662 bool linear = cursor->getLinearMovement();
663 int fromPos = getFromPos(from);
665 if ((fromPos == lowerRightPos) && hasLowerMiddle()) {
666 lowerMiddle-> moveLeft(cursor, this);
669 else if ((fromPos == upperRightPos) && hasUpperMiddle()) {
670 upperMiddle-> moveLeft(cursor, this);
673 else if ((fromPos == lowerMiddlePos) && hasLowerLeft()) {
677 else if ((fromPos == upperMiddlePos) && hasUpperLeft()) {
684 if (hasLowerRight() && linear) {
689 if (hasUpperRight() && linear) {
694 if (hasLowerMiddle() && linear) {
695 lowerMiddle-> moveLeft(cursor, this);
702 if (hasUpperMiddle() && linear) {
703 upperMiddle-> moveLeft(cursor, this);
707 if (hasLowerLeft() && linear) {
712 if (hasUpperLeft() && linear) {
717 getParent()-> moveLeft(cursor, this);
733 bool linear = cursor->getLinearMovement();
734 int fromPos = getFromPos(from);
736 if ((fromPos == lowerLeftPos) && hasLowerMiddle()) {
740 else if ((fromPos == upperLeftPos) && hasUpperMiddle()) {
744 else if ((fromPos == lowerMiddlePos) && hasLowerRight()) {
748 else if ((fromPos == upperMiddlePos) && hasUpperRight()) {
755 if (hasUpperLeft() && linear) {
760 if (hasLowerLeft() && linear) {
765 if (hasUpperMiddle() && linear) {
773 if (hasLowerMiddle() && linear) {
778 if (hasUpperRight() && linear) {
783 if (hasLowerRight() && linear) {
801 getParent()-> moveUp(cursor, this);
804 if (from == content) {
805 if ((cursor->getPos() == 0) && (cursor-> getElement() == from)) {
806 if (hasUpperLeft()) {
810 else if (hasUpperMiddle()) {
815 if (hasUpperRight()) {
818 else if (hasUpperMiddle()) {
819 upperMiddle-> moveLeft(cursor, this);
821 else if (hasUpperLeft()) {
825 getParent()-> moveUp(cursor, this);
828 else if ((from == upperLeft) || (from == upperMiddle) || (from == upperRight)) {
829 getParent()-> moveUp(cursor, this);
831 else if ((from == getParent()) || (from == lowerLeft) || (from == lowerMiddle)) {
834 else if (from == lowerRight) {
848 getParent()-> moveDown(cursor, this);
851 if (from == content) {
852 if ((cursor->getPos() == 0) && (cursor-> getElement() == from)) {
853 if (hasLowerLeft()) {
857 else if (hasLowerMiddle()) {
862 if (hasLowerRight()) {
865 else if (hasLowerMiddle()) {
866 lowerMiddle-> moveLeft(cursor, this);
868 else if (hasLowerLeft()) {
872 getParent()-> moveDown(cursor, this);
875 else if ((from == lowerLeft) || (from == lowerMiddle) || (from == lowerRight)) {
876 getParent()-> moveDown(cursor, this);
878 else if ((from == getParent()) || (from == upperLeft) || (from == upperMiddle)) {
881 if (from == upperRight) {
915 TQPtrList<BasicElement>& newChildren,
919 index->setParent( this);
921 switch (cursor->getPos()) {
945 if (direction == beforeCursor) {
968 TQPtrList<BasicElement>& removedChildren,
971 int pos = cursor->getPos();
974 removedChildren.append(upperLeft);
977 setToUpperLeft(cursor);
980 removedChildren.append(lowerLeft);
983 setToLowerLeft(cursor);
988 parent-> remove(cursor, removedChildren, direction);
992 removedChildren.append(upperMiddle);
995 setToUpperMiddle(cursor);
998 removedChildren.append(lowerMiddle);
1001 setToLowerMiddle(cursor);
1004 removedChildren.append(upperRight);
1007 setToUpperRight(cursor);
1010 removedChildren.append(lowerRight);
1013 setToLowerRight(cursor);
1025 if (direction == beforeCursor) {
1040 return !hasUpperLeft() && !hasUpperRight() && !hasUpperMiddle() &&
1041 !hasLowerLeft() && !hasLowerRight() && !hasLowerMiddle();
1050 int pos = cursor->getPos();
1064 case upperMiddlePos:
1066 case lowerMiddlePos:
1083 if (child == content) {
1084 setToContent(cursor);
1086 else if (child == upperLeft) {
1087 setToUpperLeft(cursor);
1089 else if (child == lowerLeft) {
1090 setToLowerLeft(cursor);
1092 else if (child == upperMiddle) {
1093 setToUpperMiddle(cursor);
1095 else if (child == lowerMiddle) {
1096 setToLowerMiddle(cursor);
1098 else if (child == upperRight) {
1099 setToUpperRight(cursor);
1101 else if (child == lowerRight) {
1102 setToLowerRight(cursor);
1115 cursor-> setTo( this, contentPos);
1123 cursor-> setTo( this, upperLeftPos);
1128 cursor-> setTo( this, upperMiddlePos);
1133 cursor-> setTo( this, upperRightPos);
1138 cursor-> setTo( this, lowerLeftPos);
1143 cursor-> setTo( this, lowerMiddlePos);
1148 cursor-> setTo( this, lowerRightPos);
1154void IndexElement::moveToUpperLeft( FormulaCursor* cursor, Direction direction)
1156 if (hasUpperLeft()) {
1157 if (direction == beforeCursor) {
1166void IndexElement::moveToUpperMiddle( FormulaCursor* cursor, Direction direction)
1168 if (hasUpperMiddle()) {
1169 if (direction == beforeCursor) {
1170 upperMiddle-> moveLeft(cursor, this);
1178void IndexElement::moveToUpperRight( FormulaCursor* cursor, Direction direction)
1180 if (hasUpperRight()) {
1181 if (direction == beforeCursor) {
1182 upperRight-> moveLeft(cursor, this);
1190void IndexElement::moveToLowerLeft( FormulaCursor* cursor, Direction direction)
1192 if (hasLowerLeft()) {
1193 if (direction == beforeCursor) {
1202void IndexElement::moveToLowerMiddle( FormulaCursor* cursor, Direction direction)
1204 if (hasLowerMiddle()) {
1205 if (direction == beforeCursor) {
1206 lowerMiddle-> moveLeft(cursor, this);
1214void IndexElement::moveToLowerRight( FormulaCursor* cursor, Direction direction)
1216 if (hasLowerRight()) {
1217 if (direction == beforeCursor) {
1218 lowerRight-> moveLeft(cursor, this);
1234 TQDomDocument doc = element.ownerDocument();
1236 TQDomElement cont = doc.createElement( "CONTENT");
1238 element.appendChild(cont);
1240 if (hasUpperLeft()) {
1241 TQDomElement ind = doc.createElement( "UPPERLEFT");
1243 element.appendChild(ind);
1245 if (hasUpperMiddle()) {
1246 TQDomElement ind = doc.createElement( "UPPERMIDDLE");
1248 element.appendChild(ind);
1250 if (hasUpperRight()) {
1251 TQDomElement ind = doc.createElement( "UPPERRIGHT");
1253 element.appendChild(ind);
1255 if (hasLowerLeft()) {
1256 TQDomElement ind = doc.createElement( "LOWERLEFT");
1258 element.appendChild(ind);
1260 if (hasLowerMiddle()) {
1261 TQDomElement ind = doc.createElement( "LOWERMIDDLE");
1263 element.appendChild(ind);
1265 if (hasLowerRight()) {
1266 TQDomElement ind = doc.createElement( "LOWERRIGHT");
1268 element.appendChild(ind);
1295 if ( ! buildChild( content, node, "CONTENT" ) ) {
1296 kdWarning( DEBUGID ) << "Empty content in IndexElement." << endl;
1299 node = node.nextSibling();
1301 bool upperLeftRead = false;
1302 bool upperMiddleRead = false;
1303 bool upperRightRead = false;
1304 bool lowerLeftRead = false;
1305 bool lowerMiddleRead = false;
1306 bool lowerRightRead = false;
1308 while (!node.isNull() &&
1309 !(upperLeftRead && upperMiddleRead && upperRightRead &&
1310 lowerLeftRead && lowerMiddleRead && lowerRightRead)) {
1312 if (!upperLeftRead && (node.nodeName().upper() == "UPPERLEFT")) {
1314 if ( !upperLeftRead ) return false;
1317 if (!upperMiddleRead && (node.nodeName().upper() == "UPPERMIDDLE")) {
1319 if ( !upperMiddleRead ) return false;
1322 if (!upperRightRead && (node.nodeName().upper() == "UPPERRIGHT")) {
1324 if ( !upperRightRead ) return false;
1327 if (!lowerLeftRead && (node.nodeName().upper() == "LOWERLEFT")) {
1329 if ( !lowerLeftRead ) return false;
1332 if (!lowerMiddleRead && (node.nodeName().upper() == "LOWERMIDDLE")) {
1334 if ( !lowerMiddleRead ) return false;
1337 if (!lowerRightRead && (node.nodeName().upper() == "LOWERRIGHT")) {
1339 if ( !lowerRightRead ) return false;
1342 node = node.nextSibling();
1344 return upperLeftRead || upperMiddleRead || upperRightRead ||
1345 lowerLeftRead || lowerMiddleRead || lowerRightRead;
1354 TQString tag = element.tagName().stripWhiteSpace().lower();
1355 if ( tag == "msub" || tag == "msubsup" ) {
1356 TQString subscriptshiftStr = element.attribute( "subscriptshift" ).stripWhiteSpace().lower();
1357 if ( ! subscriptshiftStr.isNull() ) {
1358 m_subScriptShift = getSize( subscriptshiftStr, &m_subScriptShiftType );
1361 if ( tag == "msup" || tag == "msubsup" ) {
1362 TQString superscriptshiftStr = element.attribute( "superscriptshift" ).stripWhiteSpace().lower();
1363 if ( ! superscriptshiftStr.isNull() ) {
1364 m_superScriptShift = getSize( superscriptshiftStr, &m_superScriptShiftType );
1368 if ( tag == "munder" || tag == "munderover" ) {
1369 TQString accentunderStr = element.attribute( "accentunder" ).stripWhiteSpace().lower();
1370 if ( ! accentunderStr.isNull() ) {
1371 if ( accentunderStr == "true" ) {
1372 m_customAccentUnder = true;
1373 m_accentUnder = true;
1375 else if ( accentunderStr == "false" ) {
1376 m_customAccentUnder = true;
1377 m_accentUnder = false;
1380 kdWarning( DEBUGID ) << "Invalid value for attribute `accentunder': "
1381 << accentunderStr << endl;
1385 if ( tag == "mover" || tag == "munderover" ) {
1386 TQString accentStr = element.attribute( "accent" ).stripWhiteSpace().lower();
1387 if ( ! accentStr.isNull() ) {
1388 if ( accentStr == "true" ) {
1389 m_customAccent = true;
1392 else if ( accentStr == "false" ) {
1393 m_customAccent = true;
1397 kdWarning( DEBUGID ) << "Invalid value for attribute `accent': "
1398 << accentStr << endl;
1417 int contentNumber = content->buildMathMLChild( node );
1418 if ( contentNumber == -1 ) {
1419 kdWarning( DEBUGID ) << "Empty base in Script" << endl;
1422 for ( int i = 0; i < contentNumber; i++ ) {
1423 if ( node.isNull() ) {
1426 node = node.nextSibling();
1429 TQString indexType = node.parentNode().toElement().tagName().lower();
1430 if ( indexType == "msub" ) {
1432 int lowerRightNumber = lowerRight->buildMathMLChild( node );
1433 if ( lowerRightNumber == -1 ) {
1434 kdWarning( DEBUGID ) << "Empty subscript in Script" << endl;
1437 for ( int i = 0; i < lowerRightNumber; i++ ) {
1438 if ( node.isNull() ) {
1441 node = node.nextSibling();
1447 if ( indexType == "msup" ) {
1449 int upperRightNumber = upperRight->buildMathMLChild( node );
1450 if ( upperRightNumber == -1 ) {
1451 kdWarning( DEBUGID ) << "Empty superscript in Script" << endl;
1454 for ( int i = 0; i < upperRightNumber; i++ ) {
1455 if ( node.isNull() ) {
1458 node = node.nextSibling();
1464 if ( indexType == "msubsup" ) {
1466 int lowerRightNumber = lowerRight->buildMathMLChild( node );
1467 if ( lowerRightNumber == -1 ) {
1468 kdWarning( DEBUGID ) << "Empty subscript in Script" << endl;
1471 for ( int i = 0; i < lowerRightNumber; i++ ) {
1472 if ( node.isNull() ) {
1475 node = node.nextSibling();
1479 int upperRightNumber = upperRight->buildMathMLChild( node );
1480 if ( upperRightNumber == -1 ) {
1481 kdWarning( DEBUGID ) << "Empty superscript in Script" << endl;
1484 for ( int i = 0; i < upperRightNumber; i++ ) {
1485 if ( node.isNull() ) {
1488 node = node.nextSibling();
1493 if ( indexType == "munder" ) {
1495 int lowerMiddleNumber = lowerMiddle->buildMathMLChild( node );
1496 if ( lowerMiddleNumber == -1 ) {
1497 kdWarning( DEBUGID ) << "Empty underscript in Script" << endl;
1500 for ( int i = 0; i < lowerMiddleNumber; i++ ) {
1501 if ( node.isNull() ) {
1504 node = node.nextSibling();
1510 if ( indexType == "mover" ) {
1512 int upperMiddleNumber = upperMiddle->buildMathMLChild( node );
1513 if ( upperMiddleNumber == -1 ) {
1514 kdWarning( DEBUGID ) << "Empty overscript in Script" << endl;
1517 for ( int i = 0; i < upperMiddleNumber; i++ ) {
1518 if ( node.isNull() ) {
1521 node = node.nextSibling();
1527 if ( indexType == "munderover" ) {
1529 int lowerMiddleNumber = lowerMiddle->buildMathMLChild( node );
1530 if ( lowerMiddleNumber == -1 ) {
1531 kdWarning( DEBUGID ) << "Empty underscript in Script" << endl;
1534 for ( int i = 0; i < lowerMiddleNumber; i++ ) {
1535 if ( node.isNull() ) {
1538 node = node.nextSibling();
1543 int upperMiddleNumber = upperMiddle->buildMathMLChild( node );
1544 if ( upperMiddleNumber == -1 ) {
1545 kdWarning( DEBUGID ) << "Empty overscript in Script" << endl;
1548 for ( int i = 0; i < upperMiddleNumber; i++ ) {
1549 if ( node.isNull() ) {
1552 node = node.nextSibling();
1566 return getUpperRight();
1568 return getLowerRight();
1569 case lowerMiddlePos:
1570 return getLowerMiddle();
1571 case upperMiddlePos:
1572 return getUpperMiddle();
1574 return getLowerLeft();
1576 return getUpperLeft();
1578 return getUpperRight();
1587 if ( hasUpperMiddle() ) {
1588 index += "\\overset{" + upperMiddle-> toLatex() + "}{";
1591 if ( hasLowerMiddle() ) {
1592 index += "\\underset{" + lowerMiddle-> toLatex() + "}{";
1595 if ( hasUpperLeft() || hasUpperRight() ) {
1606 if ( hasUpperRight() || hasLowerRight() ) {
1607 if ( hasUpperRight() )
1608 index += "^{" + upperRight-> toLatex() + "}";
1609 if ( hasLowerRight() )
1610 index += "_{" + lowerRight-> toLatex() + "}";
1614 if ( hasLowerMiddle() ) {
1618 if ( hasUpperMiddle() ) {
1625TQString IndexElement::formulaString()
1627 TQString index = "(" + content->formulaString() + ")";
1628 if ( hasLowerRight() ) {
1629 index += "_(" + lowerRight->formulaString() + ")";
1631 if ( hasUpperRight() ) {
1632 index += "**(" + upperRight->formulaString() + ")";
1637TQString IndexElement::getElementName() const
1639 if ( hasUpperMiddle() && hasLowerMiddle() )
1640 return "munderover";
1641 if ( hasUpperMiddle() )
1643 if ( hasLowerMiddle() )
1645 if ( hasLowerLeft() || hasUpperLeft() )
1646 return "mmultiscripts";
1647 if ( hasLowerRight() || hasUpperRight() ) {
1648 if ( ! hasUpperRight() )
1650 if ( ! hasLowerRight() )
1656void IndexElement::writeMathMLAttributes( TQDomElement& element ) const
1658 TQString tag = getElementName();
1659 if ( tag == "msub" || tag == "msubsup" ) {
1660 switch ( m_subScriptShiftType ) {
1662 element.setAttribute( "subscriptshift", TQString( "%1pt" ).arg( m_subScriptShift ) );
1665 element.setAttribute( "subscriptshift", TQString( "%1%" ).arg( m_subScriptShift * 100.0 ) );
1668 element.setAttribute( "subscriptshift", TQString( "%1px" ).arg( m_subScriptShift ) );
1674 if ( tag == "msup" || tag == "msubsup" ) {
1675 switch ( m_superScriptShiftType ) {
1677 element.setAttribute( "superscriptshift", TQString( "%1pt" ).arg( m_superScriptShift ) );
1680 element.setAttribute( "superscriptshift", TQString( "%1%" ).arg( m_superScriptShift * 100.0 ) );
1683 element.setAttribute( "superscriptshift", TQString( "%1px" ).arg( m_superScriptShift ) );
1689 if ( tag == "munder" || tag == "munderover" ) {
1690 if ( m_customAccentUnder ) {
1691 element.setAttribute( "accentunder", m_accentUnder ? "true" : "false" );
1694 if ( tag == "mover" || tag == "munderover" ) {
1695 if ( m_customAccent ) {
1696 element.setAttribute( "accent", m_accent ? "true" : "false" );
1702void IndexElement::writeMathMLContent( TQDomDocument& doc,
1703 TQDomElement& element,
1704 bool oasisFormat ) const
1708 content-> writeMathML( doc, element, oasisFormat );
1709 if ( hasUpperMiddle() && hasLowerMiddle() )
1711 lowerMiddle-> writeMathML( doc, element, oasisFormat );
1712 upperMiddle-> writeMathML( doc, element,oasisFormat );
1714 else if ( hasUpperMiddle() )
1716 upperMiddle-> writeMathML( doc, element,oasisFormat );
1718 else if ( hasLowerMiddle() )
1720 lowerMiddle-> writeMathML( doc, element,oasisFormat );
1723 if ( hasLowerLeft() || hasUpperLeft() )
1725 if ( hasLowerRight() )
1726 lowerRight-> writeMathML( doc, element, oasisFormat );
1728 element.appendChild( doc.createElement( "none" ) );
1730 if ( hasUpperRight() )
1731 upperRight-> writeMathML( doc, element, oasisFormat );
1733 element.appendChild( doc.createElement( "none" ) );
1735 element.appendChild( doc.createElement( "mprescripts" ) );
1737 if ( hasLowerLeft() )
1738 lowerLeft-> writeMathML( doc, element, oasisFormat );
1740 element.appendChild( doc.createElement( "none" ) );
1742 if ( hasUpperLeft() )
1743 upperLeft-> writeMathML( doc, element, oasisFormat );
1745 element.appendChild( doc.createElement( "none" ) );
1747 else if ( hasLowerRight() || hasUpperRight() )
1749 if ( !hasUpperRight() ) {
1750 lowerRight-> writeMathML( doc, element, oasisFormat );
1752 else if ( !hasLowerRight() ) {
1753 upperRight-> writeMathML( doc, element, oasisFormat );
1757 lowerRight-> writeMathML( doc, element, oasisFormat );
1758 upperRight-> writeMathML( doc, element,oasisFormat );
1763KFORMULA_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 readAttributesFromMathMLDom(const TQDomElement &element) Reads our attributes from the MathML element.
virtual bool readContentFromDom(TQDomNode &node) Reads our content from the node.
virtual int readContentFromMathMLDom(TQDomNode &node) Reads our content from the MathML 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.
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 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.
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 element with up to four indexes in the four corners.
virtual void moveDown(FormulaCursor *cursor, BasicElement *from) Enters this element while moving down starting inside the element ‘from’.
virtual bool isSenseless() Moves the cursor away from the given child.
virtual int readContentFromMathMLDom(TQDomNode &node) Reads our content from the MathML node.
virtual void normalize(FormulaCursor *, Direction) Moves the cursor to a normal place where new elements might be inserted.
virtual bool accept(ElementVisitor *visitor) Visit this element.
virtual TQString toLatex()
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction) Inserts all new children at the cursor position.
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 void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction) Removes all selected children and returns them.
virtual void selectChild(FormulaCursor *cursor, BasicElement *child) Sets the cursor to select the child.
ElementIndexPtr getIndex(int position) Returns the index at the position.
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 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 writeDom(TQDomElement element) Appends our attributes to the dom element.
virtual void dispatchFontCommand(FontCommand *cmd) Dispatch this FontCommand to all our TextElement children.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from) Enters this element while moving to the left starting inside the element ‘from’.
virtual void entered(SequenceElement *child) The cursor has entered one of our child sequences.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from) Enters this element while moving to the right 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 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 bool readAttributesFromDom(TQDomElement element) Reads our attributes from the element.
virtual TQChar getCharacter() const
static double ptToLayoutUnitPt(double pt) Not zoom dependent.
The element that contains a number of children.
virtual TQString toLatex()
virtual bool isTextOnly() const
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.
|