21#include <tqmemarray.h>
28#include "MatrixDialog.h"
29#include "elementvisitor.h"
30#include "formulaelement.h"
31#include "formulacursor.h"
32#include "kformulacontainer.h"
33#include "kformulacommand.h"
34#include "matrixelement.h"
35#include "sequenceelement.h"
36#include "spaceelement.h"
39KFORMULA_NAMESPACE_BEGIN
43 typedef SequenceElement inherited;
46 MatrixSequenceElement( BasicElement* parent = 0 ) : SequenceElement( parent ) {}
47 virtual MatrixSequenceElement* clone() {
48 return new MatrixSequenceElement( *
this );
59 virtual KCommand* buildCommand( Container*, Request* );
63class KFCRemoveRow :
public Command {
65 KFCRemoveRow(
const TQString&
name, Container* document, MatrixElement* m, uint r, uint c );
72 MatrixElement* matrix;
76 TQPtrList<MatrixSequenceElement>* row;
80class KFCInsertRow :
public KFCRemoveRow {
82 KFCInsertRow(
const TQString&
name, Container* document, MatrixElement* m, uint r, uint c );
89class KFCRemoveColumn :
public Command {
91 KFCRemoveColumn(
const TQString&
name, Container* document, MatrixElement* m, uint r, uint c );
98 MatrixElement* matrix;
102 TQPtrList<MatrixSequenceElement>* column;
106class KFCInsertColumn :
public KFCRemoveColumn {
108 KFCInsertColumn(
const TQString&
name, Container* document, MatrixElement* m, uint r, uint c );
115KCommand* MatrixSequenceElement::buildCommand(
Container* container, Request* request )
122 switch ( *request ) {
123 case req_appendColumn:
125 case req_insertColumn:
126 case req_removeColumn:
128 case req_removeRow: {
129 MatrixElement* matrix =
static_cast<MatrixElement*
>( getParent() );
131 for ( uint row = 0; row < matrix->getRows(); row++ ) {
132 for ( uint col = 0; col < matrix->getColumns(); col++ ) {
133 if ( matrix->getElement( row, col ) == cursor->
getElement() ) {
134 switch ( *request ) {
135 case req_appendColumn:
136 return new KFCInsertColumn( i18n(
"Append Column" ), container, matrix, row, matrix->getColumns() );
138 return new KFCInsertRow( i18n(
"Append Row" ), container, matrix, matrix->getRows(), col );
139 case req_insertColumn:
140 return new KFCInsertColumn( i18n(
"Insert Column" ), container, matrix, row, col );
141 case req_removeColumn:
142 if ( matrix->getColumns() > 1 ) {
143 return new KFCRemoveColumn( i18n(
"Remove Column" ), container, matrix, row, col );
147 return new KFCInsertRow( i18n(
"Insert Row" ), container, matrix, row, col );
149 if ( matrix->getRows() > 1 ) {
150 return new KFCRemoveRow( i18n(
"Remove Row" ), container, matrix, row, col );
159 kdWarning( DEBUGID ) <<
"MatrixSequenceElement::buildCommand: Sequence not found." << endl;
170 : Command(
name, document ), matrix( m ), rowPos( r ), colPos( c ), row( 0 )
174KFCRemoveRow::~KFCRemoveRow()
181 FormulaCursor* cursor = getExecuteCursor();
182 row = matrix->content.at( rowPos );
183 FormulaElement* formula = matrix->formula();
184 for ( uint i = matrix->getColumns(); i > 0; i-- ) {
187 matrix->content.take( rowPos );
189 if ( rowPos < matrix->getRows() ) {
190 matrix->getElement( rowPos, colPos )->goInside( cursor );
193 matrix->getElement( rowPos-1, colPos )->goInside( cursor );
200 matrix->content.insert( rowPos, row );
202 FormulaCursor* cursor = getExecuteCursor();
203 matrix->getElement( rowPos, colPos )->goInside( cursor );
204 matrix->formula()->changed();
210 : KFCRemoveRow(
name, document, m, r, c )
212 row =
new TQPtrList< MatrixSequenceElement >;
213 row->setAutoDelete(
true );
214 for ( uint i = 0; i < matrix->getColumns(); i++ ) {
215 row->append(
new MatrixSequenceElement( matrix ) );
220KFCRemoveColumn::KFCRemoveColumn(
const TQString& name,
Container* document,
MatrixElement* m, uint r, uint c )
221 : Command(
name, document ), matrix( m ), rowPos( r ), colPos( c )
223 column =
new TQPtrList< MatrixSequenceElement >;
224 column->setAutoDelete(
true );
227KFCRemoveColumn::~KFCRemoveColumn()
234 FormulaCursor* cursor = getExecuteCursor();
235 FormulaElement* formula = matrix->
formula();
236 for ( uint i = 0; i < matrix->getRows(); i++ ) {
237 column->append( matrix->getElement( i, colPos ) );
239 matrix->content.at( i )->take( colPos );
242 if ( colPos < matrix->getColumns() ) {
243 matrix->getElement( rowPos, colPos )->goInside( cursor );
246 matrix->getElement( rowPos, colPos-1 )->goInside( cursor );
253 for ( uint i = 0; i < matrix->getRows(); i++ ) {
254 matrix->content.at( i )->insert( colPos, column->take( 0 ) );
256 FormulaCursor* cursor = getExecuteCursor();
257 matrix->getElement( rowPos, colPos )->goInside( cursor );
258 matrix->formula()->changed();
263KFCInsertColumn::KFCInsertColumn(
const TQString& name,
Container* document,
MatrixElement* m, uint r, uint c )
264 : KFCRemoveColumn(
name, document, m, r, c )
266 for ( uint i = 0; i < matrix->getRows(); i++ ) {
267 column->append(
new MatrixSequenceElement( matrix ) );
272MatrixElement::MatrixElement(uint rows, uint columns,
BasicElement* parent)
276 m_widthType( NoSize ),
278 m_frameHSpacing( NoSize ),
279 m_frameVSpacing( NoSize ),
281 m_minLabelSpacingType( NoSize ),
282 m_customEqualRows( false ),
283 m_customEqualColumns( false ),
284 m_customDisplayStyle( false )
286 for (uint r = 0; r < rows; r++) {
287 TQPtrList< MatrixSequenceElement >* list =
new TQPtrList< MatrixSequenceElement >;
288 list->setAutoDelete(
true);
289 for (uint c = 0; c < columns; c++) {
290 list->append(
new MatrixSequenceElement(
this));
292 content.append(list);
294 content.setAutoDelete(
true);
297MatrixElement::~MatrixElement()
305 uint rows = other.getRows();
306 uint columns = other.getColumns();
308 TQPtrListIterator< TQPtrList< MatrixSequenceElement > > rowIter( other.content );
309 for (uint r = 0; r < rows; r++) {
311 TQPtrListIterator< MatrixSequenceElement > colIter( *rowIter.current() );
313 TQPtrList< MatrixSequenceElement >* list =
new TQPtrList< MatrixSequenceElement >;
314 list->setAutoDelete(
true);
315 for (uint c = 0; c < columns; c++) {
317 MatrixSequenceElement *mse =
319 new MatrixSequenceElement( *colIter.current() );
321 mse->setParent(
this );
323 content.append(list);
325 content.setAutoDelete(
true);
331 return visitor->visit(
this );
342 const LuPixelPoint& point,
const LuPixelPoint& parentOrigin )
346 LuPixelPoint myPos(parentOrigin.x() + getX(),
347 parentOrigin.y() + getY());
349 uint rows = getRows();
350 uint columns = getColumns();
352 for (uint r = 0; r < rows; r++) {
353 for (uint c = 0; c < columns; c++) {
354 BasicElement* element = getElement(r, c);
355 e = element->
goToPos(cursor, handled, point, myPos);
363 luPixel dx = point.x() - myPos.x();
364 luPixel dy = point.y() - myPos.y();
367 for (uint r = 0; r < rows; r++) {
368 BasicElement* element = getElement(r, 0);
369 if (element->getY() > dy) {
375 BasicElement* element = getParent();
376 element->moveLeft(cursor,
this);
382 uint column = columns;
383 for (uint c = 0; c < columns; c++) {
384 BasicElement* element = getElement(row, c);
385 if (element->getX() > dx) {
391 BasicElement* element = getParent();
392 element->moveLeft(cursor,
this);
400 for (uint r = 0; r < rows; r++) {
401 BasicElement* element = getElement(r, column);
402 if (element->getY() > dy) {
408 BasicElement* element = getParent();
409 element->moveLeft(cursor,
this);
415 BasicElement* element = getElement(row, column);
416 element->moveLeft(cursor,
this);
437 ContextStyle::IndexStyle istyle,
438 StyleAttributes& style )
440 TQMemArray<luPixel> toMidlines(getRows());
441 TQMemArray<luPixel> fromMidlines(getRows());
442 TQMemArray<luPixel> widths(getColumns());
445 fromMidlines.fill(0);
448 uint rows = getRows();
449 uint columns = getColumns();
452 ContextStyle::IndexStyle i_istyle = context.convertIndexStyleUpper(istyle);
453 double factor = style.sizeFactor();
455 for (uint r = 0; r < rows; r++) {
456 TQPtrList< MatrixSequenceElement >* list = content.at(r);
457 for (uint c = 0; c < columns; c++) {
458 SequenceElement* element = list->at(c);
459 element->
calcSizes( context, i_tstyle, i_istyle, style );
460 toMidlines[r] = TQMAX(toMidlines[r], element->axis( context, i_tstyle, factor ));
461 fromMidlines[r] = TQMAX(fromMidlines[r],
462 element->getHeight()-element->axis( context, i_tstyle, factor ));
463 widths[c] = TQMAX(widths[c], element->getWidth());
467 luPixel distX = context.ptToPixelX( context.getThinSpace( tstyle, factor ) );
468 luPixel distY = context.ptToPixelY( context.getThinSpace( tstyle, factor ) );
471 for (uint r = 0; r < rows; r++) {
472 TQPtrList< MatrixSequenceElement >* list = content.at(r);
474 yPos += toMidlines[r];
475 for (uint c = 0; c < columns; c++) {
476 SequenceElement* element = list->at(c);
477 switch (context.getMatrixAlignment()) {
478 case ContextStyle::left:
481 case ContextStyle::center:
482 element->setX(xPos + (widths[c] - element->getWidth())/2);
484 case ContextStyle::right:
485 element->setX(xPos + widths[c] - element->getWidth());
488 element->setY(yPos - element->axis( context, i_tstyle, factor ));
489 xPos += widths[c] + distX;
491 yPos += fromMidlines[r] + distY;
494 luPixel width = distX * (columns - 1);
495 luPixel height = distY * (rows - 1);
497 for (uint r = 0; r < rows; r++) height += toMidlines[r] + fromMidlines[r];
498 for (uint c = 0; c < columns; c++) width += widths[c];
502 if ((rows == 2) && (columns == 1)) {
503 setBaseline(
getMainChild()->getHeight() + distY / 2 + context.axisHeight( tstyle, factor ) );
506 setBaseline( height/2 + context.axisHeight( tstyle, factor ) );
515void MatrixElement::draw( TQPainter& painter,
const LuPixelRect& rect,
518 ContextStyle::IndexStyle istyle,
519 StyleAttributes& style,
520 const LuPixelPoint& parentOrigin )
522 LuPixelPoint myPos( parentOrigin.x()+getX(), parentOrigin.y()+getY() );
526 uint rows = getRows();
527 uint columns = getColumns();
529 for (uint r = 0; r < rows; r++) {
530 for (uint c = 0; c < columns; c++) {
531 getElement(r, c)->draw(painter, rect, context,
532 context.convertTextStyleFraction(tstyle),
533 context.convertIndexStyleUpper(istyle),
547 uint rows = getRows();
548 uint columns = getColumns();
550 for (uint r = 0; r < rows; r++) {
551 for (uint c = 0; c < columns; c++) {
552 getElement(r, c)->dispatchFontCommand( cmd );
574 getParent()->moveLeft(cursor,
this);
577 if (from == getParent()) {
578 getElement(getRows()-1, getColumns()-1)->moveLeft(cursor,
this);
581 bool linear = cursor->getLinearMovement();
584 if (searchElement(from, row, column)) {
586 getElement(row, column-1)->moveLeft(cursor,
this);
588 else if (linear && (row > 0)) {
589 getElement(row-1, getColumns()-1)->moveLeft(cursor,
this);
592 getParent()->moveLeft(cursor,
this);
596 getParent()->moveLeft(cursor,
this);
610 getParent()->moveRight(cursor,
this);
613 if (from == getParent()) {
614 getElement(0, 0)->moveRight(cursor,
this);
617 bool linear = cursor->getLinearMovement();
620 if (searchElement(from, row, column)) {
621 if (column < getColumns()-1) {
622 getElement(row, column+1)->moveRight(cursor,
this);
624 else if (linear && (row < getRows()-1)) {
625 getElement(row+1, 0)->moveRight(cursor,
this);
628 getParent()->moveRight(cursor,
this);
632 getParent()->moveRight(cursor,
this);
646 getParent()->moveUp(cursor,
this);
649 if (from == getParent()) {
650 getElement(0, 0)->moveRight(cursor,
this);
655 if (searchElement(from, row, column)) {
657 getElement(row-1, column)->moveRight(cursor,
this);
660 getParent()->moveUp(cursor,
this);
664 getParent()->moveUp(cursor,
this);
678 getParent()->moveDown(cursor,
this);
681 if (from == getParent()) {
682 getElement(0, 0)->moveRight(cursor,
this);
687 if (searchElement(from, row, column)) {
688 if (row < getRows()-1) {
689 getElement(row+1, column)->moveRight(cursor,
this);
692 getParent()->moveDown(cursor,
this);
696 getParent()->moveDown(cursor,
this);
708 getElement(0, 0)->goInside(cursor);
715 return content.at(0)->at(0);
720 uint rows = getRows();
721 uint columns = getColumns();
722 for (uint r = 0; r < rows; r++) {
723 for (uint c = 0; c < columns; c++) {
724 if (child == getElement(r, c)) {
725 cursor->
setTo(
this, r*columns+c);
731const MatrixSequenceElement* MatrixElement::getElement( uint row, uint column )
const
733 TQPtrListIterator< TQPtrList < MatrixSequenceElement > > rows( content );
735 if ( ! rows.current() )
738 TQPtrListIterator< MatrixSequenceElement > cols ( *rows.current() );
740 return cols.current();
744bool MatrixElement::searchElement(
BasicElement* element, uint& row, uint& column)
746 uint rows = getRows();
747 uint columns = getColumns();
748 for (uint r = 0; r < rows; r++) {
749 for (uint c = 0; c < columns; c++) {
750 if (element == getElement(r, c)) {
768 uint rows = getRows();
769 uint cols = getColumns();
771 element.setAttribute(
"ROWS", rows);
772 element.setAttribute(
"COLUMNS", cols);
774 TQDomDocument doc = element.ownerDocument();
776 for (uint r = 0; r < rows; r++) {
777 for (uint c = 0; c < cols; c++) {
778 TQDomElement tmp = getElement(r,c)->getElementDom(doc);
779 element.appendChild(tmp);
781 element.appendChild(doc.createComment(
"end of row"));
795 TQString rowStr = element.attribute(
"ROWS");
796 if(!rowStr.isNull()) {
797 rows = rowStr.toInt();
800 kdWarning( DEBUGID ) <<
"Rows <= 0 in MatrixElement." << endl;
804 TQString columnStr = element.attribute(
"COLUMNS");
806 if(!columnStr.isNull()) {
807 cols = columnStr.toInt();
810 kdWarning( DEBUGID ) <<
"Columns <= 0 in MatrixElement." << endl;
815 for (uint r = 0; r < rows; r++) {
816 TQPtrList< MatrixSequenceElement >* list =
new TQPtrList< MatrixSequenceElement >;
817 list->setAutoDelete(
true);
818 content.append(list);
819 for (uint c = 0; c < cols; c++) {
820 MatrixSequenceElement* element =
new MatrixSequenceElement(
this);
821 list->append(element);
838 uint rows = getRows();
839 uint cols = getColumns();
843 while ( !node.isNull() && r < rows ) {
844 if ( node.isElement() ) {
845 SequenceElement* element = getElement( r, c );
846 TQDomElement e = node.toElement();
856 node = node.nextSibling();
867 TQString alignStr = element.attribute(
"align" ).lower();
868 if ( ! alignStr.isNull() ) {
869 if ( alignStr.find(
"top" ) != -1 ) {
872 else if ( alignStr.find(
"bottom" ) != -1 ) {
873 m_align = BottomAlign;
875 else if ( alignStr.find(
"center" ) != -1 ) {
876 m_align = CenterAlign;
878 else if ( alignStr.find(
"baseline" ) != -1 ) {
879 m_align = BaselineAlign;
881 else if ( alignStr.find(
"axis" ) != -1 ) {
884 int index = alignStr.findRev(
' ' );
886 m_rowNumber = alignStr.right( index + 1 ).toInt();
889 TQString rowalignStr = element.attribute(
"rowalign" ).lower();
890 if ( ! rowalignStr.isNull() ) {
891 TQStringList list = TQStringList::split(
' ', rowalignStr );
892 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
893 if ( *it ==
"top" ) {
894 m_rowAlign.append( TopAlign );
896 else if ( *it ==
"bottom" ) {
897 m_rowAlign.append( BottomAlign );
899 else if ( *it ==
"center" ) {
900 m_rowAlign.append( CenterAlign );
902 else if ( *it ==
"baseline" ) {
903 m_rowAlign.append( BaselineAlign );
905 else if ( *it ==
"axis" ) {
906 m_rowAlign.append( AxisAlign );
910 TQString columnalignStr = element.attribute(
"columnalign" ).lower();
911 if ( ! columnalignStr.isNull() ) {
912 TQStringList list = TQStringList::split(
' ', columnalignStr );
913 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
914 if ( *it ==
"left" ) {
915 m_columnAlign.append( LeftHorizontalAlign );
917 else if ( *it ==
"center" ) {
918 m_columnAlign.append( CenterHorizontalAlign );
920 else if ( *it ==
"right" ) {
921 m_columnAlign.append( RightHorizontalAlign );
925 TQString alignmentscopeStr = element.attribute(
"alignmentscope" ).lower();
926 if ( ! alignmentscopeStr.isNull() ) {
927 TQStringList list = TQStringList::split(
' ', alignmentscopeStr );
928 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
929 if ( *it ==
"true" ) {
930 m_alignmentScope.append(
true );
932 else if ( *it ==
"false" ) {
933 m_alignmentScope.append(
false );
937 TQString columnwidthStr = element.attribute(
"columnwidth" ).lower();
938 if ( columnwidthStr.isNull() ) {
939 TQStringList list = TQStringList::split(
' ', columnwidthStr );
940 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
941 SizeType type = NoSize;
943 if ( *it ==
"auto" ) {
946 else if ( *it ==
"fit" ) {
950 length =
getSize( columnwidthStr, &type );
951 if ( type == NoSize ) {
952 type = getSpace( columnwidthStr );
955 if ( type != NoSize ) {
956 m_columnWidthType.append( type );
957 if ( type == RelativeSize || type == AbsoluteSize || type == PixelSize ) {
958 m_columnWidth.append( length );
963 TQString widthStr = element.attribute(
"width" ).lower();
964 if ( ! widthStr.isNull() ) {
965 if ( widthStr ==
"auto" ) {
966 m_widthType = AutoSize;
969 m_width =
getSize( widthStr, &m_widthType );
972 TQString rowspacingStr = element.attribute(
"rowspacing" ).lower();
973 if ( ! rowspacingStr.isNull() ) {
974 TQStringList list = TQStringList::split(
' ', rowspacingStr );
975 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
977 double length =
getSize( *it, &type );
978 if ( type != NoSize ) {
979 m_rowSpacingType.append( type );
980 m_rowSpacing.append( length );
984 TQString columnspacingStr = element.attribute(
"columnspacing" ).lower();
985 if ( ! columnspacingStr.isNull() ) {
986 TQStringList list = TQStringList::split(
' ', columnspacingStr );
987 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
989 double length =
getSize( *it, &type );
990 if ( type == NoSize ) {
991 type = getSpace( columnspacingStr );
993 if ( type != NoSize ) {
994 m_columnSpacingType.append( type );
995 if ( type == RelativeSize || type == AbsoluteSize || type == PixelSize ) {
996 m_columnSpacing.append( length );
1001 TQString rowlinesStr = element.attribute(
"rowlines" ).lower();
1002 if ( ! rowlinesStr.isNull() ) {
1003 TQStringList list = TQStringList::split(
' ', rowlinesStr );
1004 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
1005 if ( *it ==
"none" ) {
1006 m_rowLines.append( NoneLine );
1008 else if ( *it ==
"solid" ) {
1009 m_rowLines.append( SolidLine );
1011 else if ( *it ==
"dashed" ) {
1012 m_rowLines.append( DashedLine );
1016 TQString columnlinesStr = element.attribute(
"columnlines" ).lower();
1017 if ( ! columnlinesStr.isNull() ) {
1018 TQStringList list = TQStringList::split(
' ', columnlinesStr );
1019 for ( TQStringList::iterator it = list.begin(); it != list.end(); it++ ) {
1020 if ( *it ==
"none" ) {
1021 m_columnLines.append( NoneLine );
1023 else if ( *it ==
"solid" ) {
1024 m_columnLines.append( SolidLine );
1026 else if ( *it ==
"dashed" ) {
1027 m_columnLines.append( DashedLine );
1031 TQString frameStr = element.attribute(
"frame" ).stripWhiteSpace().lower();
1032 if ( ! frameStr.isNull() ) {
1033 if ( frameStr ==
"none" ) {
1036 else if ( frameStr ==
"solid" ) {
1037 m_frame = SolidLine;
1039 else if ( frameStr ==
"dashed" ) {
1040 m_frame = DashedLine;
1043 TQString framespacingStr = element.attribute(
"framespacing" );
1044 if ( ! framespacingStr.isNull() ) {
1045 TQStringList list = TQStringList::split(
' ', framespacingStr );
1046 m_frameHSpacing =
getSize( list[0], &m_frameHSpacingType );
1047 if ( m_frameHSpacingType == NoSize ) {
1048 m_frameHSpacingType = getSpace( list[0] );
1050 if ( list.count() > 1 ) {
1051 m_frameVSpacing =
getSize( list[1], &m_frameVSpacingType );
1052 if ( m_frameVSpacingType == NoSize ) {
1053 m_frameVSpacingType = getSpace( list[1] );
1057 TQString equalrowsStr = element.attribute(
"equalrows" ).stripWhiteSpace().lower();
1058 if ( ! equalrowsStr.isNull() ) {
1059 m_customEqualRows =
true;
1060 if ( equalrowsStr ==
"false" ) {
1061 m_equalRows =
false;
1067 TQString equalcolumnsStr = element.attribute(
"equalcolumns" ).stripWhiteSpace().lower();
1068 if ( ! equalcolumnsStr.isNull() ) {
1069 m_customEqualColumns =
true;
1070 if ( equalcolumnsStr ==
"false" ) {
1071 m_equalColumns =
false;
1074 m_equalColumns =
true;
1077 TQString displaystyleStr = element.attribute(
"displaystyle" ).stripWhiteSpace().lower();
1078 if ( ! displaystyleStr.isNull() ) {
1079 m_customDisplayStyle =
true;
1080 if ( displaystyleStr ==
"false" ) {
1081 m_displayStyle =
false;
1084 m_displayStyle =
true;
1087 TQString sideStr = element.attribute(
"side" ).stripWhiteSpace().lower();
1088 if ( ! sideStr.isNull() ) {
1089 if ( sideStr ==
"left" ) {
1092 else if ( sideStr ==
"right" ) {
1095 else if ( sideStr ==
"leftoverlap" ) {
1096 m_side = LeftOverlapSide;
1098 else if ( sideStr ==
"rightoverlap" ) {
1099 m_side = RightOverlapSide;
1102 TQString minlabelspacingStr = element.attribute(
"minlabelspacing" ).stripWhiteSpace().lower();
1103 if ( ! minlabelspacingStr.isNull() ) {
1104 m_minLabelSpacing =
getSize( minlabelspacingStr, &m_minLabelSpacingType );
1105 if ( m_minLabelSpacingType == NoSize ) {
1106 m_minLabelSpacingType = getSpace( minlabelspacingStr );
1130 while ( !n.isNull() ) {
1131 if ( n.isElement() ) {
1132 TQDomElement e = n.toElement();
1133 if ( e.tagName().lower() ==
"mtr" || e.tagName().lower() ==
"mlabeledtr" )
1138 TQDomNode cellnode = e.firstChild();
1141 while ( !cellnode.isNull() ) {
1142 if ( cellnode.isElement() )
1144 cellnode = cellnode.nextSibling();
1146 if ( cc > 0 && e.tagName().lower() ==
"mlabeledtr" )
1152 n = n.nextSibling();
1157 for (uint r = 0; r < rows; r++) {
1158 TQPtrList< MatrixSequenceElement >* list =
new TQPtrList< MatrixSequenceElement >;
1159 list->setAutoDelete(
true);
1160 content.append(list);
1161 for (uint c = 0; c < cols; c++) {
1162 MatrixSequenceElement* element =
new MatrixSequenceElement(
this);
1163 list->append(element);
1170 while ( !node.isNull() ) {
1171 if ( node.isElement() ) {
1172 TQDomElement e = node.toElement();
1173 if ( e.tagName().lower() ==
"mtr" || e.tagName().lower() ==
"mlabeledtr" ) {
1174 TQDomNode cellnode = e.firstChild();
1175 if ( e.tagName().lower() ==
"mlabeledtr" ) {
1176 while ( ! cellnode.isNull() && ! cellnode.isElement() )
1177 cellnode = cellnode.nextSibling();
1178 if ( ! cellnode.isNull() )
1179 cellnode = cellnode.nextSibling();
1181 while ( !cellnode.isNull() ) {
1182 if ( cellnode.isElement() ) {
1183 TQDomElement cellelement = cellnode.toElement();
1184 if ( cellelement.tagName().lower() !=
"mtd" ) {
1186 kdWarning( DEBUGID ) <<
"Unsupported tag "
1187 << cellelement.tagName()
1188 <<
" inside matrix row\n";
1191 SequenceElement* element = getElement(r, c);
1197 cellnode = cellnode.nextSibling();
1203 node = node.nextSibling();
1213 uint cols=getColumns();
1214 uint rows=getRows();
1216 matrix=
"\\begin{array}{ ";
1217 for(uint i=0;i<cols;i++)
1222 for (uint r = 0; r < rows; r++) {
1223 for (uint c = 0; c < cols; c++) {
1224 matrix+=getElement(r, c)->toLatex();
1225 if( c < cols-1) matrix+=
" & ";
1227 if(r < rows-1 ) matrix+=
" \\\\ ";
1230 matrix+=
" \\end{array}";
1235TQString MatrixElement::formulaString()
1237 TQString matrix =
"[";
1238 uint cols=getColumns();
1239 uint rows=getRows();
1240 for (uint r = 0; r < rows; r++) {
1242 for (uint c = 0; c < cols; c++) {
1243 matrix+=getElement(r, c)->formulaString();
1244 if ( c < cols-1 ) matrix+=
", ";
1247 if ( r < rows-1 ) matrix +=
", ";
1256 return getElement( row, column );
1259void MatrixElement::writeMathMLAttributes( TQDomElement& element )
const
1262 if ( m_rowNumber ) {
1263 rownumber = TQString(
" %1" ).arg( m_rowNumber );
1265 switch ( m_align ) {
1267 element.setAttribute(
"align",
"top" + rownumber );
1270 element.setAttribute(
"align",
"bottom" + rownumber );
1273 element.setAttribute(
"align",
"center" + rownumber );
1276 element.setAttribute(
"align",
"baseline" + rownumber );
1279 element.setAttribute(
"align",
"axis" + rownumber );
1285 for ( TQValueList<VerticalAlign >::const_iterator it = m_rowAlign.begin(); it != m_rowAlign.end(); it++ )
1289 rowalign.append(
"top " );
1292 rowalign.append(
"bottom " );
1295 rowalign.append(
"center " );
1298 rowalign.append(
"baseline " );
1301 rowalign.append(
"axis " );
1307 if ( ! rowalign.isNull() ) {
1308 element.setAttribute(
"rowalign", rowalign.stripWhiteSpace() );
1310 TQString columnalign;
1311 for ( TQValueList<HorizontalAlign >::const_iterator it = m_columnAlign.begin(); it != m_columnAlign.end(); it++ )
1314 case LeftHorizontalAlign:
1315 rowalign.append(
"left " );
1317 case CenterHorizontalAlign:
1318 rowalign.append(
"center " );
1320 case RightHorizontalAlign:
1321 rowalign.append(
"right " );
1327 if ( ! columnalign.isNull() ) {
1328 element.setAttribute(
"columnalign", columnalign.stripWhiteSpace() );
1330 TQString alignmentscope;
1331 for ( TQValueList< bool >::const_iterator it = m_alignmentScope.begin(); it != m_alignmentScope.end(); it++ )
1334 alignmentscope.append(
"true " );
1337 alignmentscope.append(
"false " );
1340 if ( ! alignmentscope.isNull() ) {
1341 element.setAttribute(
"alignmentscope", alignmentscope.stripWhiteSpace() );
1343 TQString columnwidth;
1344 TQValueList< double >::const_iterator lengthIt = m_columnWidth.begin();
1345 for ( TQValueList< SizeType >::const_iterator typeIt = m_columnWidthType.begin();
1346 typeIt != m_columnWidthType.end(); typeIt ++ ) {
1347 switch ( *typeIt ) {
1349 columnwidth.append(
"auto " );
1352 columnwidth.append(
"fit " );
1355 columnwidth.append( TQString(
"%1pt " ).arg( *lengthIt ) );
1359 columnwidth.append( TQString(
"%1% " ).arg( *lengthIt * 100.0 ) );
1363 columnwidth.append( TQString(
"%1px " ).arg( *lengthIt ) );
1366 case NegativeVeryVeryThinMathSpace:
1367 columnwidth.append(
"negativeveryverythinmathspace " );
1369 case NegativeVeryThinMathSpace:
1370 columnwidth.append(
"negativeverythinmathspace " );
1372 case NegativeThinMathSpace:
1373 columnwidth.append(
"negativethinmathspace " );
1375 case NegativeMediumMathSpace:
1376 columnwidth.append(
"negativemediummathspace " );
1378 case NegativeThickMathSpace:
1379 columnwidth.append(
"negativethickmathspace " );
1381 case NegativeVeryThickMathSpace:
1382 columnwidth.append(
"negativeverythickmathspace " );
1384 case NegativeVeryVeryThickMathSpace:
1385 columnwidth.append(
"negativeveryverythickmathspace " );
1387 case VeryVeryThinMathSpace:
1388 columnwidth.append(
"veryverythinmathspace " );
1390 case VeryThinMathSpace:
1391 columnwidth.append(
"verythinmathspace " );
1394 columnwidth.append(
"thinmathspace " );
1396 case MediumMathSpace:
1397 columnwidth.append(
"mediummathspace " );
1399 case ThickMathSpace:
1400 columnwidth.append(
"thickmathspace " );
1402 case VeryThickMathSpace:
1403 columnwidth.append(
"verythickmathspace " );
1405 case VeryVeryThickMathSpace:
1406 columnwidth.append(
"veryverythickmathspace " );
1412 if ( ! columnwidth.isNull() ) {
1413 element.setAttribute(
"columnwidth", columnwidth.stripWhiteSpace() );
1415 switch ( m_widthType ) {
1417 element.setAttribute(
"width",
"auto" );
1420 element.setAttribute(
"width", TQString(
"%1pt" ).arg( m_width ) );
1423 element.setAttribute(
"width", TQString(
"%1% " ).arg( m_width * 100.0 ) );
1426 element.setAttribute(
"width", TQString(
"%1px " ).arg( m_width ) );
1431 TQString rowspacing;
1432 lengthIt = m_rowSpacing.begin();
1433 for ( TQValueList< SizeType >::const_iterator typeIt = m_rowSpacingType.begin();
1434 typeIt != m_rowSpacingType.end(); typeIt++, lengthIt++ ) {
1435 switch ( *typeIt ) {
1437 rowspacing.append( TQString(
"%1pt " ).arg( *lengthIt ) );
1440 rowspacing.append( TQString(
"%1% " ).arg( *lengthIt * 100.0 ) );
1443 rowspacing.append( TQString(
"%1px " ).arg( *lengthIt ) );
1449 if ( ! rowspacing.isNull() ) {
1450 element.setAttribute(
"rowspacing", rowspacing.stripWhiteSpace() );
1452 TQString columnspacing;
1453 lengthIt = m_columnSpacing.begin();
1454 for ( TQValueList< SizeType >::const_iterator typeIt = m_columnSpacingType.begin();
1455 typeIt != m_columnSpacingType.end(); typeIt++ ) {
1456 switch ( *typeIt ) {
1458 columnspacing.append( TQString(
"%1pt " ).arg( *lengthIt ) );
1462 columnspacing.append( TQString(
"%1% " ).arg( *lengthIt * 100.0 ) );
1466 columnspacing.append( TQString(
"%1px " ).arg( *lengthIt ) );
1469 case NegativeVeryVeryThinMathSpace:
1470 columnspacing.append(
"negativeveryverythinmathspace " );
1472 case NegativeVeryThinMathSpace:
1473 columnspacing.append(
"negativeverythinmathspace " );
1475 case NegativeThinMathSpace:
1476 columnspacing.append(
"negativethinmathspace " );
1478 case NegativeMediumMathSpace:
1479 columnspacing.append(
"negativemediummathspace " );
1481 case NegativeThickMathSpace:
1482 columnspacing.append(
"negativethickmathspace " );
1484 case NegativeVeryThickMathSpace:
1485 columnspacing.append(
"negativeverythickmathspace " );
1487 case NegativeVeryVeryThickMathSpace:
1488 columnspacing.append(
"negativeveryverythickmathspace " );
1490 case VeryVeryThinMathSpace:
1491 columnspacing.append(
"veryverythinmathspace " );
1493 case VeryThinMathSpace:
1494 columnspacing.append(
"verythinmathspace " );
1497 columnspacing.append(
"thinmathspace " );
1499 case MediumMathSpace:
1500 columnspacing.append(
"mediummathspace " );
1502 case ThickMathSpace:
1503 columnspacing.append(
"thickmathspace " );
1505 case VeryThickMathSpace:
1506 columnspacing.append(
"verythickmathspace " );
1508 case VeryVeryThickMathSpace:
1509 columnspacing.append(
"veryverythickmathspace " );
1515 if ( ! rowspacing.isNull() ) {
1516 element.setAttribute(
"rowspacing", rowspacing.stripWhiteSpace() );
1519 for ( TQValueList< LineType >::const_iterator it = m_rowLines.begin(); it != m_rowLines.end(); it++ )
1523 rowlines.append(
"none " );
1526 rowlines.append(
"solid " );
1529 rowlines.append(
"dashed " );
1535 if ( ! rowlines.isNull() ) {
1536 element.setAttribute(
"rowlines", rowlines.stripWhiteSpace() );
1538 TQString columnlines;
1539 for ( TQValueList< LineType >::const_iterator it = m_columnLines.begin(); it != m_columnLines.end(); it++ )
1543 columnlines.append(
"none " );
1546 columnlines.append(
"solid " );
1549 columnlines.append(
"dashed " );
1555 if ( ! columnlines.isNull() ) {
1556 element.setAttribute(
"columnlines", columnlines.stripWhiteSpace() );
1558 switch ( m_frame ) {
1560 element.setAttribute(
"frame",
"none" );
1563 element.setAttribute(
"frame",
"solid" );
1566 element.setAttribute(
"frame",
"dashed" );
1571 TQString framespacing;
1572 switch ( m_frameHSpacingType ) {
1574 framespacing.append( TQString(
"%1pt " ).arg( m_frameHSpacing ) );
1577 framespacing.append( TQString(
"%1% " ).arg( m_frameHSpacing * 100.0 ) );
1580 framespacing.append( TQString(
"%1px " ).arg( m_frameHSpacing ) );
1582 case NegativeVeryVeryThinMathSpace:
1583 framespacing.append(
"negativeveryverythinmathspace " );
1585 case NegativeVeryThinMathSpace:
1586 framespacing.append(
"negativeverythinmathspace " );
1588 case NegativeThinMathSpace:
1589 framespacing.append(
"negativethinmathspace " );
1591 case NegativeMediumMathSpace:
1592 framespacing.append(
"negativemediummathspace " );
1594 case NegativeThickMathSpace:
1595 framespacing.append(
"negativethickmathspace " );
1597 case NegativeVeryThickMathSpace:
1598 framespacing.append(
"negativeverythickmathspace " );
1600 case NegativeVeryVeryThickMathSpace:
1601 framespacing.append(
"negativeveryverythickmathspace " );
1603 case VeryVeryThinMathSpace:
1604 framespacing.append(
"veryverythinmathspace " );
1606 case VeryThinMathSpace:
1607 framespacing.append(
"verythinmathspace " );
1610 framespacing.append(
"thinmathspace " );
1612 case MediumMathSpace:
1613 framespacing.append(
"mediummathspace " );
1615 case ThickMathSpace:
1616 framespacing.append(
"thickmathspace " );
1618 case VeryThickMathSpace:
1619 framespacing.append(
"verythickmathspace " );
1621 case VeryVeryThickMathSpace:
1622 framespacing.append(
"veryverythickmathspace " );
1627 switch ( m_frameVSpacingType ) {
1629 framespacing.append( TQString(
"%1pt " ).arg( m_frameVSpacing ) );
1632 framespacing.append( TQString(
"%1% " ).arg( m_frameVSpacing * 100.0 ) );
1635 framespacing.append( TQString(
"%1px " ).arg( m_frameVSpacing ) );
1637 case NegativeVeryVeryThinMathSpace:
1638 framespacing.append(
"negativeveryverythinmathspace " );
1640 case NegativeVeryThinMathSpace:
1641 framespacing.append(
"negativeverythinmathspace " );
1643 case NegativeThinMathSpace:
1644 framespacing.append(
"negativethinmathspace " );
1646 case NegativeMediumMathSpace:
1647 framespacing.append(
"negativemediummathspace " );
1649 case NegativeThickMathSpace:
1650 framespacing.append(
"negativethickmathspace " );
1652 case NegativeVeryThickMathSpace:
1653 framespacing.append(
"negativeverythickmathspace " );
1655 case NegativeVeryVeryThickMathSpace:
1656 framespacing.append(
"negativeveryverythickmathspace " );
1658 case VeryVeryThinMathSpace:
1659 framespacing.append(
"veryverythinmathspace " );
1661 case VeryThinMathSpace:
1662 framespacing.append(
"verythinmathspace " );
1665 framespacing.append(
"thinmathspace " );
1667 case MediumMathSpace:
1668 framespacing.append(
"mediummathspace " );
1670 case ThickMathSpace:
1671 framespacing.append(
"thickmathspace " );
1673 case VeryThickMathSpace:
1674 framespacing.append(
"verythickmathspace " );
1676 case VeryVeryThickMathSpace:
1677 framespacing.append(
"veryverythickmathspace " );
1682 if ( ! framespacing.isNull() ) {
1683 element.setAttribute(
"framespacing", framespacing.stripWhiteSpace() );
1685 if ( m_customEqualRows ) {
1686 element.setAttribute(
"equalrows", m_equalRows ?
"true" :
"false" );
1688 if ( m_customEqualColumns ) {
1689 element.setAttribute(
"equalcolumns", m_equalColumns ?
"true" :
"false" );
1691 if ( m_customDisplayStyle ) {
1692 element.setAttribute(
"displaystyle", m_displayStyle ?
"true" :
"false" );
1696 element.setAttribute(
"side",
"left" );
1699 element.setAttribute(
"side",
"right" );
1701 case LeftOverlapSide:
1702 element.setAttribute(
"side",
"leftoverlap" );
1704 case RightOverlapSide:
1705 element.setAttribute(
"side",
"rightoverlap" );
1710 switch ( m_minLabelSpacingType ) {
1712 element.setAttribute(
"minlabelspacing", TQString(
"%1pt" ).arg( m_minLabelSpacing ) );
1715 element.setAttribute(
"minlabelspacing", TQString(
"%1%" ).arg( m_minLabelSpacing * 100.0 ) );
1718 element.setAttribute(
"minlabelspacing", TQString(
"%1px" ).arg( m_minLabelSpacing ) );
1720 case NegativeVeryVeryThinMathSpace:
1721 element.setAttribute(
"minlabelspacing",
"negativeveryverythinmathspace" );
1723 case NegativeVeryThinMathSpace:
1724 element.setAttribute(
"minlabelspacing",
"negativeverythinmathspace" );
1726 case NegativeThinMathSpace:
1727 element.setAttribute(
"minlabelspacing",
"negativethinmathspace" );
1729 case NegativeMediumMathSpace:
1730 element.setAttribute(
"minlabelspacing",
"negativemediummathspace" );
1732 case NegativeThickMathSpace:
1733 element.setAttribute(
"minlabelspacing",
"negativethickmathspace" );
1735 case NegativeVeryThickMathSpace:
1736 element.setAttribute(
"minlabelspacing",
"negativeverythickmathspace" );
1738 case NegativeVeryVeryThickMathSpace:
1739 element.setAttribute(
"minlabelspacing",
"negativeveryverythickmathspace" );
1741 case VeryVeryThinMathSpace:
1742 element.setAttribute(
"minlabelspacing",
"veryverythinmathspace" );
1744 case VeryThinMathSpace:
1745 element.setAttribute(
"minlabelspacing",
"verythinmathspace" );
1748 element.setAttribute(
"minlabelspacing",
"thinmathspace" );
1750 case MediumMathSpace:
1751 element.setAttribute(
"minlabelspacing",
"mediummathspace" );
1753 case ThickMathSpace:
1754 element.setAttribute(
"minlabelspacing",
"thickmathspace" );
1756 case VeryThickMathSpace:
1757 element.setAttribute(
"minlabelspacing",
"verythickmathspace" );
1759 case VeryVeryThickMathSpace:
1760 element.setAttribute(
"minlabelspacing",
"veryverythickmathspace" );
1767void MatrixElement::writeMathMLContent( TQDomDocument& doc,
1768 TQDomElement& element,
1769 bool oasisFormat )
const
1774 uint rows = getRows();
1775 uint cols = getColumns();
1777 for ( uint r = 0; r < rows; r++ )
1779 row = doc.createElement( oasisFormat ?
"math:mtr" :
"mtr" );
1780 element.appendChild( row );
1781 for ( uint c = 0; c < cols; c++ )
1783 cell = doc.createElement( oasisFormat ?
"math:mtd" :
"mtd" );
1784 row.appendChild( cell );
1785 getElement(r,c)->writeMathML( doc, cell, oasisFormat );
1799 typedef SequenceElement inherited;
1802 MultilineSequenceElement( BasicElement* parent = 0 );
1804 virtual MultilineSequenceElement* clone() {
1805 return new MultilineSequenceElement( *
this );
1808 virtual BasicElement* goToPos( FormulaCursor*,
bool& handled,
1809 const LuPixelPoint& point,
const LuPixelPoint& parentOrigin );
1815 virtual void calcSizes(
const ContextStyle& context,
1817 ContextStyle::IndexStyle istyle,
1818 StyleAttributes& style );
1820 virtual void registerTab( BasicElement* tab );
1830 virtual KCommand* buildCommand( Container*, Request* );
1832 virtual KCommand* input( Container* container, TQKeyEvent* event );
1834 virtual KCommand* input( Container* container, TQChar ch );
1836 uint tabCount()
const {
return tabs.count(); }
1838 BasicElement* tab( uint i ) {
return tabs.at( i ); }
1841 void moveTabTo( uint i, luPixel pos );
1844 int tabBefore( uint pos );
1847 int tabPos( uint i );
1849 virtual void writeMathML( TQDomDocument& doc, TQDomNode& parent,
bool oasisFormat =
false )
const ;
1853 TQPtrList<BasicElement> tabs;
1858class KFCNewLine :
public Command {
1860 KFCNewLine(
const TQString&
name, Container* document,
1861 MultilineSequenceElement* line, uint pos );
1863 virtual ~KFCNewLine();
1869 MultilineSequenceElement* m_line;
1870 MultilineSequenceElement* m_newline;
1875KFCNewLine::KFCNewLine(
const TQString& name,
Container* document,
1876 MultilineSequenceElement* line, uint pos )
1877 : Command(
name, document ),
1878 m_line( line ), m_pos( pos )
1880 m_newline =
new MultilineSequenceElement( m_line->getParent() );
1884KFCNewLine::~KFCNewLine()
1892 FormulaCursor* cursor = getExecuteCursor();
1893 MultilineElement* parent =
static_cast<MultilineElement*
>( m_line->getParent() );
1894 int linePos = parent->content.find( m_line );
1895 parent->content.insert( linePos+1, m_newline );
1898 if ( m_line->countChildren() >
static_cast<int>( m_pos ) ) {
1901 m_line->selectAllChildren( cursor );
1902 cursor->setMark( m_pos );
1903 TQPtrList<BasicElement> elementList;
1904 m_line->remove( cursor, elementList, beforeCursor );
1907 m_newline->goInside( cursor );
1908 m_newline->insert( cursor, elementList, beforeCursor );
1909 cursor->setPos( cursor->getMark() );
1912 m_newline->goInside( cursor );
1919 FormulaElement* formula = m_line->
formula();
1927 FormulaCursor* cursor = getExecuteCursor();
1928 MultilineElement* parent =
static_cast<MultilineElement*
>( m_line->getParent() );
1929 int linePos = parent->content.find( m_line );
1932 m_newline = parent->content.at( linePos+1 );
1935 FormulaElement* formula = m_line->
formula();
1939 if ( m_newline->countChildren() > 0 ) {
1942 m_newline->selectAllChildren( cursor );
1943 TQPtrList<BasicElement> elementList;
1944 m_newline->remove( cursor, elementList, beforeCursor );
1947 m_line->moveEnd( cursor );
1948 m_line->insert( cursor, elementList, beforeCursor );
1949 cursor->setPos( cursor->getMark() );
1952 m_line->moveEnd( cursor );
1954 parent->content.take( linePos+1 );
1962MultilineSequenceElement::MultilineSequenceElement(
BasicElement* parent )
1965 tabs.setAutoDelete(
false );
1970 const LuPixelPoint& point,
const LuPixelPoint& parentOrigin )
1978 if ( ( point.x() > getX()+getWidth() ) &&
1979 ( point.y() >= getY() ) &&
1980 ( point.y() < getY()+getHeight() ) ) {
1990void MultilineSequenceElement::calcSizes(
const ContextStyle& context,
1992 ContextStyle::IndexStyle istyle,
1993 StyleAttributes& style )
2000void MultilineSequenceElement::registerTab(
BasicElement* tab )
2006KCommand* MultilineSequenceElement::buildCommand(
Container* container, Request* request )
2013 switch ( *request ) {
2019 case req_addNewline: {
2021 return new KFCNewLine( i18n(
"Add Newline" ), container,
this, cursor->getPos() );
2023 case req_addTabMark: {
2024 KFCReplace* command =
new KFCReplace( i18n(
"Add Tabmark"), container );
2025 SpaceElement* element =
new SpaceElement( THIN,
true );
2036KCommand* MultilineSequenceElement::input(
Container* container, TQKeyEvent* event )
2038 int action =
event->key();
2043 case TQt::Key_Enter:
2044 case TQt::Key_Return: {
2045 Request newline( req_addNewline );
2046 return buildCommand( container, &newline );
2048 case TQt::Key_Tab: {
2049 Request r( req_addTabMark );
2050 return buildCommand( container, &r );
2059 int latin1 = ch.latin1();
2062 Request r( req_addTabMark );
2063 return buildCommand( container, &r );
2070void MultilineSequenceElement::moveTabTo( uint i, luPixel pos )
2072 BasicElement* marker = tab( i );
2073 luPixel diff = pos - marker->getX();
2074 marker->setWidth( marker->getWidth() + diff );
2076 for (
int p = childPos( marker )+1; p <
countChildren(); ++p ) {
2077 BasicElement* child =
getChild( p );
2078 child->setX( child->getX() + diff );
2081 setWidth( getWidth()+diff );
2085int MultilineSequenceElement::tabBefore( uint pos )
2087 if ( tabs.isEmpty() ) {
2091 for ( uint i=0; i<pos; ++i ) {
2092 BasicElement* child =
getChild( i );
2093 if ( tabs.at( tabNum ) == child ) {
2094 if ( tabNum+1 == tabs.count() ) {
2100 return static_cast<int>( tabNum )-1;
2104int MultilineSequenceElement::tabPos( uint i )
2106 if ( i < tabs.count() ) {
2107 return childPos( tabs.at( i ) );
2113void MultilineSequenceElement::writeMathML( TQDomDocument& doc,
2114 TQDomNode& parent,
bool oasisFormat )
const
2118 TQDomElement tmp = doc.createElement(
"TMP" );
2127 TQDomElement mtd = doc.createElement( oasisFormat ?
"math:mtd" :
"mtd" );
2130 TQDomNode n = tmp.firstChild().firstChild();
2131 while ( !n.isNull() ) {
2133 if ( n.isElement() && n.toElement().tagName() ==
"TAB" ) {
2134 parent.appendChild( mtd );
2135 mtd = doc.createElement( oasisFormat ?
"math:mtd" :
"mtd" );
2138 mtd.appendChild( n.cloneNode() );
2140 n = n.nextSibling();
2143 parent.appendChild( mtd );
2148 : BasicElement( parent )
2150 content.setAutoDelete(
true );
2151 content.append(
new MultilineSequenceElement(
this ) );
2154MultilineElement::~MultilineElement()
2161 content.setAutoDelete(
true );
2162 uint count = other.content.count();
2163 for (uint i = 0; i < count; i++) {
2164 MultilineSequenceElement* line = content.at(i)->clone();
2165 line->setParent(
this );
2166 content.append( line );
2173 return visitor->visit(
this );
2187 const LuPixelPoint& point,
const LuPixelPoint& parentOrigin )
2191 LuPixelPoint myPos(parentOrigin.x() + getX(),
2192 parentOrigin.y() + getY());
2194 uint count = content.count();
2195 for ( uint i = 0; i < count; ++i ) {
2196 MultilineSequenceElement* line = content.at(i);
2197 e = line->goToPos(cursor, handled, point, myPos);
2209 content.at( 0 )->goInside( cursor );
2217 getParent()->moveLeft(cursor,
this);
2222 if (from == getParent()) {
2223 content.at( content.count()-1 )->moveLeft(cursor,
this);
2228 int pos = content.find(
static_cast<MultilineSequenceElement*
>( from ) );
2231 content.at( pos-1 )->moveLeft( cursor,
this );
2234 getParent()->moveLeft(cursor,
this);
2238 kdDebug( DEBUGID ) << k_funcinfo << endl;
2239 kdDebug( DEBUGID ) <<
"Serious confusion. Must never happen." << endl;
2248 getParent()->moveRight(cursor,
this);
2251 if (from == getParent()) {
2252 content.at( 0 )->moveRight(cursor,
this);
2255 int pos = content.find(
static_cast<MultilineSequenceElement*
>( from ) );
2258 if ( upos < content.count() ) {
2259 if ( upos < content.count()-1 ) {
2260 content.at( upos+1 )->moveRight( cursor,
this );
2263 getParent()->moveRight(cursor,
this);
2268 kdDebug( DEBUGID ) << k_funcinfo << endl;
2269 kdDebug( DEBUGID ) <<
"Serious confusion. Must never happen." << endl;
2279 getParent()->moveLeft(cursor,
this);
2284 if (from == getParent()) {
2285 content.at( content.count()-1 )->moveLeft(cursor,
this);
2290 int pos = content.find(
static_cast<MultilineSequenceElement*
>( from ) );
2296 int cursorPos = cursor->getPos();
2297 MultilineSequenceElement* current = content.at( pos );
2298 MultilineSequenceElement* newLine = content.at( pos-1 );
2299 int tabNum = current->tabBefore( cursorPos );
2300 if ( tabNum > -1 ) {
2301 int oldTabPos = current->tabPos( tabNum );
2302 int newTabPos = newLine->tabPos( tabNum );
2303 if ( newTabPos > -1 ) {
2304 cursorPos += newTabPos-oldTabPos;
2305 int nextNewTabPos = newLine->tabPos( tabNum+1 );
2306 if ( nextNewTabPos > -1 ) {
2307 cursorPos = TQMIN( cursorPos, nextNewTabPos );
2315 int nextNewTabPos = newLine->tabPos( 0 );
2316 if ( nextNewTabPos > -1 ) {
2317 cursorPos = TQMIN( cursorPos, nextNewTabPos );
2320 cursor->
setTo( newLine,
2325 getParent()->moveLeft(cursor,
this);
2329 kdDebug( DEBUGID ) << k_funcinfo << endl;
2330 kdDebug( DEBUGID ) <<
"Serious confusion. Must never happen." << endl;
2339 getParent()->moveRight(cursor,
this);
2342 if (from == getParent()) {
2343 content.at( 0 )->moveRight(cursor,
this);
2346 int pos = content.find(
static_cast<MultilineSequenceElement*
>( from ) );
2349 if ( upos < content.count() ) {
2350 if ( upos < content.count()-1 ) {
2354 int cursorPos = cursor->getPos();
2355 MultilineSequenceElement* current = content.at( upos );
2356 MultilineSequenceElement* newLine = content.at( upos+1 );
2357 int tabNum = current->tabBefore( cursorPos );
2358 if ( tabNum > -1 ) {
2359 int oldTabPos = current->tabPos( tabNum );
2360 int newTabPos = newLine->tabPos( tabNum );
2361 if ( newTabPos > -1 ) {
2362 cursorPos += newTabPos-oldTabPos;
2363 int nextNewTabPos = newLine->tabPos( tabNum+1 );
2364 if ( nextNewTabPos > -1 ) {
2365 cursorPos = TQMIN( cursorPos, nextNewTabPos );
2373 int nextNewTabPos = newLine->tabPos( 0 );
2374 if ( nextNewTabPos > -1 ) {
2375 cursorPos = TQMIN( cursorPos, nextNewTabPos );
2378 cursor->
setTo( newLine,
2383 getParent()->moveRight(cursor,
this);
2388 kdDebug( DEBUGID ) << k_funcinfo << endl;
2389 kdDebug( DEBUGID ) <<
"Serious confusion. Must never happen." << endl;
2397 ContextStyle::IndexStyle istyle,
2398 StyleAttributes& style )
2400 double factor = style.sizeFactor();
2401 luPt mySize = context.getAdjustedSize( tstyle, factor );
2402 TQFont font = context.getDefaultFont();
2403 font.setPointSizeFloat( context.layoutUnitPtToPt( mySize ) );
2404 TQFontMetrics fm( font );
2405 luPixel leading = context.ptToLayoutUnitPt( fm.leading() );
2406 luPixel distY = context.ptToPixelY( context.getThinSpace( tstyle, factor ) );
2408 uint count = content.count();
2409 luPixel height = -leading;
2412 for ( uint i = 0; i < count; ++i ) {
2413 MultilineSequenceElement* line = content.at(i);
2414 line->calcSizes( context, tstyle, istyle, style );
2415 tabCount = TQMAX( tabCount, line->tabCount() );
2419 line->setY( height );
2420 height += line->getHeight() + distY;
2421 width = TQMAX( line->getWidth(), width );
2425 for ( uint t = 0; t < tabCount; ++t ) {
2427 for ( uint i = 0; i < count; ++i ) {
2428 MultilineSequenceElement* line = content.at(i);
2429 if ( t < line->tabCount() ) {
2430 pos = TQMAX( pos, line->tab( t )->getX() );
2433 pos = TQMAX( pos, line->getWidth() );
2436 for ( uint i = 0; i < count; ++i ) {
2437 MultilineSequenceElement* line = content.at(i);
2438 if ( t < line->tabCount() ) {
2439 line->moveTabTo( t, pos );
2440 width = TQMAX( width, line->getWidth() );
2445 setHeight( height );
2448 setBaseline( content.at( 0 )->getBaseline() );
2452 setBaseline( height/2 + context.axisHeight( tstyle, factor ) );
2456void MultilineElement::draw( TQPainter& painter,
const LuPixelRect& r,
2459 ContextStyle::IndexStyle istyle,
2460 StyleAttributes& style,
2461 const LuPixelPoint& parentOrigin )
2463 LuPixelPoint myPos( parentOrigin.x() + getX(), parentOrigin.y() + getY() );
2464 uint count = content.count();
2466 if ( context.edit() ) {
2468 painter.setPen( context.getHelpColor() );
2469 for ( uint i = 0; i < count; ++i ) {
2470 MultilineSequenceElement* line = content.at(i);
2471 if ( tabCount < line->tabCount() ) {
2472 for ( uint t = tabCount; t < line->tabCount(); ++t ) {
2474 painter.drawLine( context.layoutUnitToPixelX( myPos.x()+marker->getX() ),
2475 context.layoutUnitToPixelY( myPos.y() ),
2476 context.layoutUnitToPixelX( myPos.x()+marker->getX() ),
2477 context.layoutUnitToPixelY( myPos.y()+getHeight() ) );
2479 tabCount = line->tabCount();
2484 for ( uint i = 0; i < count; ++i ) {
2485 MultilineSequenceElement* line = content.at(i);
2486 line->draw( painter, r, context, tstyle, istyle, style, myPos );
2493 uint count = content.count();
2494 for ( uint i = 0; i < count; ++i ) {
2495 MultilineSequenceElement* line = content.at(i);
2501 TQPtrList<BasicElement>& newChildren,
2502 Direction direction )
2504 MultilineSequenceElement* e =
static_cast<MultilineSequenceElement*
>(newChildren.take(0));
2506 content.insert( cursor->getPos(), e );
2508 if (direction == beforeCursor) {
2509 e->moveLeft(cursor,
this);
2512 e->moveRight(cursor,
this);
2519 TQPtrList<BasicElement>& removedChildren,
2520 Direction direction )
2522 if ( content.count() == 1 ) {
2523 getParent()->selectChild(cursor,
this);
2524 getParent()->remove(cursor, removedChildren, direction);
2527 MultilineSequenceElement* e = content.take( cursor->getPos() );
2528 removedChildren.append( e );
2537 int pos = cursor->getPos();
2539 ( pos > -1 ) && (
static_cast<unsigned>( pos ) <= content.count() ) ) {
2540 switch ( direction ) {
2543 content.at( pos-1 )->moveLeft( cursor,
this );
2548 if (
static_cast<unsigned>( pos ) < content.count() ) {
2549 content.at( pos )->moveRight( cursor,
this );
2552 content.at( pos-1 )->moveLeft( cursor,
this );
2564 return content.at( 0 );
2569 int pos = content.find(
dynamic_cast<MultilineSequenceElement*
>( child ) );
2571 cursor->
setTo(
this, pos );
2584 uint lineCount = content.count();
2585 element.setAttribute(
"LINES", lineCount );
2587 TQDomDocument doc = element.ownerDocument();
2588 for ( uint i = 0; i < lineCount; ++i ) {
2589 TQDomElement tmp = content.at( i )->getElementDom(doc);
2590 element.appendChild(tmp);
2596 TQDomElement de = doc.createElement( oasisFormat ?
"math:mtable" :
"mtable" );
2597 TQDomElement row; TQDomElement cell;
2599 for ( TQPtrListIterator < MultilineSequenceElement > it( content ); it.current(); ++it ) {
2600 row = doc.createElement( oasisFormat ?
"math:mtr" :
"mtr" );
2601 de.appendChild( row );
2606 it.current()->writeMathML( doc, row, oasisFormat );
2609 parent.appendChild( de );
2622 TQString lineCountStr = element.attribute(
"LINES");
2623 if(!lineCountStr.isNull()) {
2624 lineCount = lineCountStr.toInt();
2626 if (lineCount == 0) {
2627 kdWarning( DEBUGID ) <<
"lineCount <= 0 in MultilineElement." << endl;
2632 for ( uint i = 0; i < lineCount; ++i ) {
2633 MultilineSequenceElement* element =
new MultilineSequenceElement(
this);
2634 content.append(element);
2650 uint lineCount = content.count();
2652 while ( !node.isNull() && i < lineCount ) {
2653 if ( node.isElement() ) {
2654 SequenceElement* element = content.at( i );
2655 TQDomElement e = node.toElement();
2661 node = node.nextSibling();
2668 uint lineCount = content.count();
2669 TQString muliline =
"\\begin{split} ";
2670 for ( uint i = 0; i < lineCount; ++i ) {
2671 muliline += content.at( i )->toLatex();
2672 muliline +=
" \\\\ ";
2674 muliline +=
"\\end{split}";
2679TQString MultilineElement::formulaString()
2681 uint lineCount = content.count();
2682 TQString muliline =
"";
2683 for ( uint i = 0; i < lineCount; ++i ) {
2684 muliline += content.at( i )->formulaString();
2692KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual FormulaElement * formula()
Provide fast access to the rootElement for each 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.
int buildFromMathMLDom(TQDomElement element)
Set this element attribute, build children and call their builFromMathMLDom.
bool buildFromDom(TQDomElement element)
Set this element attribute, build children and call their buildFromDom.
virtual void normalize(FormulaCursor *, Direction)
Moves the cursor to a normal place where new elements might be inserted.
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 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
Textstyles like in TeX.
Base for all font commands that act on the current selection.
virtual TQString name() const=0
virtual void unexecute()=0
void addElement(BasicElement *element)
Collects all elements that are to be added.
virtual int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual void selectChild(FormulaCursor *, BasicElement *)
Inserts all new children at the cursor position.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual TQString toLatex()
Moves the cursor away from the given child.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
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 SequenceElement * getMainChild()
We define the Main Child of a matrix to be the first row/column.
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 BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual void dispatchFontCommand(FontCommand *cmd)
Draws the whole element including its children.
virtual void goInside(FormulaCursor *cursor)
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 writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Inserts all new children at the cursor position.
BasicElement * goToPos(FormulaCursor *cursor, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Returns the element the point is in.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
virtual void goInside(FormulaCursor *cursor)
Sets the cursor inside this element to its start position.
virtual void calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Enters this element while moving to the left starting inside the element `from'.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
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 selectChild(FormulaCursor *cursor, BasicElement *child)
Sets the cursor to select the child.
virtual void dispatchFontCommand(FontCommand *cmd)
Draws the whole element including its children.
virtual SequenceElement * getMainChild()
Removes the child.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
MultilineElement(BasicElement *parent=0)
The container this FormulaElement belongs to must not be 0, except you really know what you are doing...
virtual TQString toLatex()
The element that contains a number of children.
virtual KCommand * input(Container *container, TQChar ch)
Parses the input.
uint countChildren() 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 BasicElement * getChild(FormulaCursor *, Direction=beforeCursor)
Returns the child at the cursor.
virtual void dispatchFontCommand(FontCommand *cmd)
Draws the whole element including its 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 BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
TDEAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0L)
const char * name(StdAction id)