/* Copyright (c) 2008-2022 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ #include "jkqtmathtext/nodes/jkqtmathtextmatrixnode.h" #include "jkqtmathtext/nodes/jkqtmathtextnoopnode.h" #include "jkqtmathtext/jkqtmathtexttools.h" #include "jkqtmathtext/jkqtmathtext.h" #include "jkqtcommon/jkqtpcodestructuring.h" #include "jkqtcommon/jkqtpstringtools.h" #include "jkqtcommon/jkqtpdebuggingtools.h" #include #include #include #include #include #include #include JKQTMathTextMatrixNode::JKQTMathTextMatrixNode(JKQTMathText* _parent, const QVector > &children, const QString &columnSpec): JKQTMathTextMultiChildNode(_parent), verticalLineRHSColumn(), verticalLineLeft(LTnone), horizontalLineBottomRow(), horizontalLineTop(LTnone), columns(0), lines(0) { setChildren(children); parseColumnSpec(columnSpec); } JKQTMathTextMatrixNode::JKQTMathTextMatrixNode(JKQTMathText *_parent, const QString &columnSpec): JKQTMathTextMultiChildNode(_parent), verticalLineRHSColumn(), verticalLineLeft(LTnone), horizontalLineBottomRow(), horizontalLineTop(LTnone), columns(0), lines(0) { parseColumnSpec(columnSpec); } JKQTMathTextMatrixNode::~JKQTMathTextMatrixNode() { clearChildrenImpl(true); } void JKQTMathTextMatrixNode::setChildren(const QVector > &children) { this->lines=children.size(); this->columns=0; for (int i=0; ithis->columns) this->columns=children[i].size(); } this->children=children; for (int i=0; isetParentNode(this); } } } void JKQTMathTextMatrixNode::setRowBottomLine(int col, LineType line) { horizontalLineBottomRow[col]=line; } void JKQTMathTextMatrixNode::setTopLine(LineType line) { horizontalLineTop=line; } QString JKQTMathTextMatrixNode::getTypeName() const { return "MTmatrixNode"; } bool JKQTMathTextMatrixNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) const { return false; } QVector > JKQTMathTextMatrixNode::getChildrenMatrix() const { return this->children; } int JKQTMathTextMatrixNode::getColumns() const { return this->columns; } int JKQTMathTextMatrixNode::getLines() const { return this->lines; } QList JKQTMathTextMatrixNode::getChildren() { QList l; for (int i=0; isetParentNode(this); return ; } n++; } } return ; } JKQTMathTextNode *JKQTMathTextMatrixNode::getChild(int nn) { int n=0; for (int i=0; idrawBoxes=draw; for (int i=0; isetDrawBoxes(draw); } } } void JKQTMathTextMatrixNode::drawVLine(QPainter &painter, double x, double y, double height, LineType lt, double linewidth, double linewidthHeavy, QColor color, double doublelineseparation) { if (lt==LTnone) return; QPen p(color, linewidth, Qt::SolidLine); if (lt==LTdashed || lt==LTdoubleDashed) p.setStyle(Qt::DashLine); if (lt==LTheavyline) p.setWidth(linewidthHeavy); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.setPen(p); if (lt==LTline || lt==LTdashed || lt==LTheavyline) { painter.drawLine(QPointF(x,y), QPointF(x,y+height)); } else if (lt==LTdoubleline || lt==LTdoubleDashed) { painter.drawLine(QPointF(x-doublelineseparation/2.0,y), QPointF(x-doublelineseparation/2.0,y+height)); painter.drawLine(QPointF(x+doublelineseparation/2.0,y), QPointF(x+doublelineseparation/2.0,y+height)); } } void JKQTMathTextMatrixNode::drawHLine(QPainter &painter, double x, double y, double width, LineType lt, double linewidth, double linewidthHeavy, QColor color, double doublelineseparation) { if (lt==LTnone) return; QPen p(color, linewidth, Qt::SolidLine); if (lt==LTdashed || lt==LTdoubleDashed) p.setStyle(Qt::DashLine); if (lt==LTheavyline) p.setWidth(linewidthHeavy); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.setPen(p); if (lt==LTline || lt==LTdashed || lt==LTheavyline) { painter.drawLine(QPointF(x,y), QPointF(x+width,y)); } else if (lt==LTdoubleline || lt==LTdoubleDashed) { painter.drawLine(QPointF(x,y-doublelineseparation/2.0), QPointF(x+width,y-doublelineseparation/2.0)); painter.drawLine(QPointF(x,y+doublelineseparation/2.0), QPointF(x+width,y+doublelineseparation/2.0)); } } void JKQTMathTextMatrixNode::parseColumnSpec(const QString &columnSpec) { int i=0; while (igetMatrixXPaddingFactor()*xwidth; const double YPadding=parentMathText->getMatrixYPaddingFactor()*xwidth; const double XSeparation=parentMathText->getMatrixXSeparationFactor()*xwidth; const double YSeparation=parentMathText->getMatrixYSeparationFactor()*xwidth; l.colwidth.resize(columns); for (int i=0; i(columns, 0.0); QVector rowdescent; rowdescent.resize(lines); for (int i=0; igetSize(painter, ev1); l.cellwidth[i].operator[](j)=cs.width; l.colwidth[j]=qMax(l.colwidth[j], cs.width); l.rowascent[i]=qMax(l.rowascent[i], cs.baselineHeight); rowdescent[i]=qMax(rowdescent[i], cs.getDescent()); JKQTMathTextModifyEnvironmentNodeMixIn* modEnvNode=dynamic_cast(children[i].at(j)); if (modEnvNode) { modEnvNode->modifyEnvironment(ev1); } } l.rowheight[i]=l.rowascent[i]+rowdescent[i]; } l.overallHeight=static_cast(lines-1)*YSeparation+l.topPadding+l.bottomPadding; l.width=static_cast(columns-1)*XSeparation+l.leftPadding+l.rightPadding; for (int i=0; igetMatrixXSeparationFactor()*xwidth; const double YSeparation=parentMathText->getMatrixYSeparationFactor()*xwidth; const double yTop=y-l.baselineHeight+l.topPadding; const double xLeft=x+l.leftPadding; const double linewidth=parentMathText->getMatrixLinewidthThinFactor()*fontlw; const double linewidthThick=parentMathText->getMatrixLinewidthHeavyFactor()*fontlw; const double lineSeparation=parentMathText->getMatrixLineSeparationFactor()*fontlw; double leftlineX=xLeft-l.leftPadding/2.0; double rightlineX=x+l.width-l.rightPadding/2.0; double toplineY=yTop-l.topPadding/2.0; double bottomlineY=y+l.getDescent()-l.bottomPadding/2; if (verticalLineLeft==LTdoubleline || verticalLineLeft==LTdoubleDashed) leftlineX-=linewidth; if (horizontalLineTop==LTdoubleline || horizontalLineTop==LTdoubleDashed) toplineY-=linewidth; if (verticalLineRHSColumn.value(lines-1, LTnone)==LTdoubleline || verticalLineRHSColumn.value(lines-1, LTnone)==LTdoubleDashed) rightlineX+=linewidth; if (horizontalLineBottomRow.value(columns-1, LTnone)==LTdoubleline || horizontalLineBottomRow.value(columns-1, LTnone)==LTdoubleDashed) bottomlineY+=linewidth; double xx; double yy=yTop; if (lines>0) yy=yy+l.rowascent[0]; for (int i=0; idraw(painter, xx+xoffset, yy, ev1); xx=xx+l.colwidth[j]+XSeparation; if (i==0 && j(children[i].at(j)); if (modEnvNode) { modEnvNode->modifyEnvironment(ev1); } } if (i