From 5c255712ce2e0c8392cf11ed74ded1b45a21c920 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Thu, 9 Jun 2022 21:37:06 +0200 Subject: [PATCH] JKQTMathTextBraceNode uses an enum to reference brace types, not a QStrig --- lib/jkqtmathtext/jkqtmathtext.cpp | 42 +++---- .../nodes/jkqtmathtextbracenode.cpp | 105 ++++++++++++------ .../nodes/jkqtmathtextbracenode.h | 26 ++++- 3 files changed, 116 insertions(+), 57 deletions(-) diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp index e36c1b75ed..0d10efa371 100644 --- a/lib/jkqtmathtext/jkqtmathtext.cpp +++ b/lib/jkqtmathtext/jkqtmathtext.cpp @@ -1010,7 +1010,7 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, const QString& quitOn JKQTMathTextNode* n1=parseLatexString(true); JKQTMathTextNode* n2=nullptr; if (getToken()==MTTopenbrace) n2=parseLatexString(true); - if (n1 && n2) nl->addNode(new JKQTMathTextBraceNode(this, "(", ")", new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstackrel))); + if (n1 && n2) nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTParenthesis, JKQTMathTextBraceNode::MTBTParenthesis, new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstackrel))); else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(name)); } else if (name=="underbrace") { JKQTMathTextNode* n1=parseLatexString(true); @@ -1061,12 +1061,12 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, const QString& quitOn first=false; } //std::cout<<" creating matrix-node with "<addNode(new JKQTMathTextBraceNode(this, "(", ")", new JKQTMathTextMatrixNode(this, items))); - else if (envname=="cases") nl->addNode(new JKQTMathTextBraceNode(this, "{", "", new JKQTMathTextMatrixNode(this, items))); - else if (envname=="bmatrix") nl->addNode(new JKQTMathTextBraceNode(this, "[", "]", new JKQTMathTextMatrixNode(this, items))); - else if (envname=="Bmatrix") nl->addNode(new JKQTMathTextBraceNode(this, "{", "}", new JKQTMathTextMatrixNode(this, items))); - else if (envname=="vmatrix") nl->addNode(new JKQTMathTextBraceNode(this, "|", "|", new JKQTMathTextMatrixNode(this, items))); - else if (envname=="Vmatrix") nl->addNode(new JKQTMathTextBraceNode(this, "||", "||", new JKQTMathTextMatrixNode(this, items))); + if (envname=="pmatrix") nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTParenthesis, JKQTMathTextBraceNode::MTBTParenthesis, new JKQTMathTextMatrixNode(this, items))); + else if (envname=="cases") nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTCurlyBracket, JKQTMathTextBraceNode::MTBTNone, new JKQTMathTextMatrixNode(this, items))); + else if (envname=="bmatrix") nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTSquareBracket, JKQTMathTextBraceNode::MTBTSquareBracket, new JKQTMathTextMatrixNode(this, items))); + else if (envname=="Bmatrix") nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTCurlyBracket, JKQTMathTextBraceNode::MTBTCurlyBracket, new JKQTMathTextMatrixNode(this, items))); + else if (envname=="vmatrix") nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTSingleLine, JKQTMathTextBraceNode::MTBTSingleLine, new JKQTMathTextMatrixNode(this, items))); + else if (envname=="Vmatrix") nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTDoubleLine, JKQTMathTextBraceNode::MTBTDoubleLine, new JKQTMathTextMatrixNode(this, items))); else nl->addNode(new JKQTMathTextMatrixNode(this, items)); //std::cout<<" creating matrix-node ... done!\n"; } else { @@ -1209,52 +1209,52 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, const QString& quitOn if (currentTokenName.size()>0) { if (currentTokenName[0]=='(') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); // we already used the first character from the text token! - nl->addNode(new JKQTMathTextBraceNode(this, "(", ")", parseLatexString(currentTokenName.size()<=0, ")"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTParenthesis, JKQTMathTextBraceNode::MTBTParenthesis, parseLatexString(currentTokenName.size()<=0, ")"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='[') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "[", "]", parseLatexString(currentTokenName.size()<=0, "]"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTSquareBracket, JKQTMathTextBraceNode::MTBTSquareBracket, parseLatexString(currentTokenName.size()<=0, "]"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='{') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "{", "}", parseLatexString(currentTokenName.size()<=0, "}"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTCurlyBracket, JKQTMathTextBraceNode::MTBTCurlyBracket, parseLatexString(currentTokenName.size()<=0, "}"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='<') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "<", ">", parseLatexString(currentTokenName.size()<=0, ">"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTAngleBracket, JKQTMathTextBraceNode::MTBTAngleBracket, parseLatexString(currentTokenName.size()<=0, ">"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='|') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "|", "|", parseLatexString(currentTokenName.size()<=0, "|"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTSingleLine, JKQTMathTextBraceNode::MTBTSingleLine, parseLatexString(currentTokenName.size()<=0, "|"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='~') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "~", "~", parseLatexString(currentTokenName.size()<=0, "~"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTCeilBracket, JKQTMathTextBraceNode::MTBTCeilBracket, parseLatexString(currentTokenName.size()<=0, "~"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='_') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "_", "_", parseLatexString(currentTokenName.size()<=0, "_"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTFloorBracket, JKQTMathTextBraceNode::MTBTFloorBracket, parseLatexString(currentTokenName.size()<=0, "_"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='#') { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "#", "#", parseLatexString(currentTokenName.size()<=0, "#"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTDoubleLine, JKQTMathTextBraceNode::MTBTDoubleLine, parseLatexString(currentTokenName.size()<=0, "#"), showLeftBrace, showRightBrace)); } else if (currentTokenName[0]=='.') { showLeftBrace=false; currentTokenName=currentTokenName.right(currentTokenName.size()-1); JKQTMathTextNode* cn=parseLatexString(currentTokenName.size()<=0, "any"); - nl->addNode(new JKQTMathTextBraceNode(this, ".", currentTokenName, cn, showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTNone, JKQTMathTextBraceNode::TokenNameString2TokenType(currentTokenName), cn, showLeftBrace, showRightBrace)); } else { getNew=false; } } } else if (currentToken==MTTinstruction && currentTokenName=="langle") { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "<", ">", parseLatexString(true, ">"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTAngleBracket, JKQTMathTextBraceNode::MTBTAngleBracket, parseLatexString(true, ">"), showLeftBrace, showRightBrace)); } else if (currentToken==MTTinstruction && currentTokenName=="{") { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "{", "}", parseLatexString(currentTokenName.size()<=0, "}"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTCurlyBracket, JKQTMathTextBraceNode::MTBTCurlyBracket, parseLatexString(currentTokenName.size()<=0, "}"), showLeftBrace, showRightBrace)); } else if (currentToken==MTTinstruction && currentTokenName=="lfloor") { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "_", "_", parseLatexString(true, "_"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTFloorBracket, JKQTMathTextBraceNode::MTBTFloorBracket, parseLatexString(true, "_"), showLeftBrace, showRightBrace)); } else if (currentToken==MTTinstruction && currentTokenName=="lceil") { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "~", "~", parseLatexString(true, "~"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTCeilBracket, JKQTMathTextBraceNode::MTBTCeilBracket, parseLatexString(true, "~"), showLeftBrace, showRightBrace)); } else if (currentToken==MTTinstruction && currentTokenName=="|") { currentTokenName=currentTokenName.right(currentTokenName.size()-1); - nl->addNode(new JKQTMathTextBraceNode(this, "#", "#", parseLatexString(currentTokenName.size()<=0, "#"), showLeftBrace, showRightBrace)); + nl->addNode(new JKQTMathTextBraceNode(this, JKQTMathTextBraceNode::MTBTDoubleLine, JKQTMathTextBraceNode::MTBTDoubleLine, parseLatexString(currentTokenName.size()<=0, "#"), showLeftBrace, showRightBrace)); } else if (currentToken==MTTinstruction && currentTokenName==quitOnClosingBrace) { break; } diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp index 73b4f3e56c..2a465d91f3 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp @@ -36,7 +36,42 @@ -JKQTMathTextBraceNode::JKQTMathTextBraceNode(JKQTMathText* _parent, const QString& openbrace, const QString& closebrace, JKQTMathTextNode* child, bool showOpeningBrace, bool showClosingBrace): +QString JKQTMathTextBraceNode::BraceType2String(BraceType type) { + switch(type) { + case MTBTAngleBracket: + return "angle_bracket"; + case MTBTSquareBracket: + return "square_bracket"; + case MTBTCeilBracket: + return "ceil_bracket"; + case MTBTCurlyBracket: + return "curly_bracket"; + case MTBTDoubleLine: + return "double_line"; + case MTBTFloorBracket: + return "floor_bracket"; + case MTBTParenthesis: + return "parenhesis"; + case MTBTSingleLine: + return "single_line"; + } + return "unknown"; +} + +JKQTMathTextBraceNode::BraceType JKQTMathTextBraceNode::TokenNameString2TokenType(const QString &type) +{ + if (type=="(" || type==")") return MTBTParenthesis; + if (type=="[" || type=="]") return MTBTSquareBracket; + if (type=="{" || type=="}") return MTBTCurlyBracket; + if (type=="|") return MTBTSingleLine; + if (type=="||" || type=="#") return MTBTDoubleLine; + if (type=="<" || type==">" || type=="langle" || type=="rangle") return MTBTAngleBracket; + if (type=="_" || type=="lfloor" || type=="rfloor") return MTBTFloorBracket; + if (type=="~" || type=="lceil" || type=="rceil") return MTBTCeilBracket; + return MTBTNone; +} + +JKQTMathTextBraceNode::JKQTMathTextBraceNode(JKQTMathText* _parent, JKQTMathTextBraceNode::BraceType openbrace, JKQTMathTextBraceNode::BraceType closebrace, JKQTMathTextNode* child, bool showOpeningBrace, bool showClosingBrace): JKQTMathTextSingleChildNode(child, _parent) { this->openbrace=openbrace; @@ -112,14 +147,14 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa const double xbrace1=xnew+lw; const double xbrace2=qMin(xnew+paren_fraction*bracewidth, xnew+bracewidth-lw/2.0); const double xbrace2s=qMin(xnew+brace_fraction*bracewidth, xnew+bracewidth-lw/2.0); - if (openbrace=="(") { + if (openbrace==MTBTParenthesis) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; path.moveTo(xbrace2, y1); path.cubicTo(xbrace1, (y1+y2)/2.0+fabs(y1-y2)/6.0, xbrace1, (y1+y2)/2.0-fabs(y1-y2)/6.0 , xbrace2, y2); painter.drawPath(path); - } else if (openbrace=="[") { + } else if (openbrace==JKQTMathTextBraceNode::MTBTSquareBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -128,14 +163,14 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa path.lineTo(xbrace1, y2); path.lineTo(xbrace2s, y2); painter.drawPath(path); - } else if (openbrace=="{") { + } else if (openbrace==JKQTMathTextBraceNode::MTBTCurlyBracket) { QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*brace_fraction); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.translate((xbrace1+xbrace2)/2.0, y-nodeBaselineHeight+nodeOverallHeight/2.0); painter.rotate(90); painter.drawPath(path); - } else if (openbrace=="_") { + } else if (openbrace==JKQTMathTextBraceNode::MTBTFloorBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -143,7 +178,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa path.lineTo(xbrace1, y1); path.lineTo(xbrace1, y2); painter.drawPath(path); - } else if (openbrace=="~") { + } else if (openbrace==JKQTMathTextBraceNode::MTBTCeilBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -151,19 +186,19 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa path.lineTo(xbrace1, y2); path.lineTo(xbrace2s, y2); painter.drawPath(path); - } else if (openbrace=="|") { + } else if (openbrace==JKQTMathTextBraceNode::MTBTSingleLine) { const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; const QLineF l(xbrace1, y1, xbrace1, y2); if (l.length()>0) painter.drawLine(l); - } else if (openbrace=="#" || openbrace=="||") { + } else if (openbrace==JKQTMathTextBraceNode::MTBTDoubleLine) { const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; const QLineF l(xbrace1, y1, xbrace1, y2); if (l.length()>0) painter.drawLine(l); const QLineF l2(xbrace1+1.5*lw, y1, xbrace1+1.5*lw, y2); if (l2.length()>0) painter.drawLine(l2); - } else if (openbrace=="<") { + } else if (openbrace==JKQTMathTextBraceNode::MTBTAngleBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -184,14 +219,14 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa const double xbrace1s=qMax(xnew+bracewidth-brace_fraction*bracewidth, xnew+lw/2.0); const double xbrace2=xnew+bracewidth-lw; painter.setPen(p); - if (closebrace==")") { + if (closebrace==JKQTMathTextBraceNode::MTBTParenthesis) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; path.moveTo(xbrace1, y1); path.cubicTo(xbrace2, (y1+y2)/2.0+fabs(y1-y2)/6.0, xbrace2, (y1+y2)/2.0-fabs(y1-y2)/6.0 , xbrace1, y2); painter.drawPath(path); - } else if (closebrace=="]") { + } else if (closebrace==JKQTMathTextBraceNode::MTBTSquareBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -200,14 +235,14 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa path.lineTo(xbrace2, y2); path.lineTo(xbrace1s, y2); painter.drawPath(path); - } else if (closebrace=="}") { + } else if (closebrace==JKQTMathTextBraceNode::MTBTCurlyBracket) { QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*brace_fraction); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.translate((xbrace1+xbrace2)/2.0, y-nodeBaselineHeight+nodeOverallHeight/2.0); painter.rotate(270); painter.drawPath(path); - } else if (closebrace=="_") { + } else if (closebrace==JKQTMathTextBraceNode::MTBTFloorBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -215,7 +250,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa path.lineTo(xbrace2, y1); path.lineTo(xbrace2, y2); painter.drawPath(path); - } else if (closebrace=="~") { + } else if (closebrace==JKQTMathTextBraceNode::MTBTCeilBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -223,19 +258,19 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa path.lineTo(xbrace2, y2); path.lineTo(xbrace1s, y2); painter.drawPath(path); - } else if (closebrace=="|") { + } else if (closebrace==JKQTMathTextBraceNode::MTBTSingleLine) { const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; const QLineF l(xbrace2, y1, xbrace2, y2); if (l.length()>0) painter.drawLine(l); - } else if (closebrace=="#" || closebrace=="||") { + } else if (closebrace==JKQTMathTextBraceNode::MTBTDoubleLine) { const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; const QLineF l(xbrace2, y1, xbrace2, y2); if (l.length()>0) painter.drawLine(l); const QLineF l2(xbrace2-1.5*lw, y1, xbrace2-1.5*lw, y2); if (l2.length()>0) painter.drawLine(l2); - } else if (closebrace==">") { + } else if (closebrace==JKQTMathTextBraceNode::MTBTAngleBracket) { QPainterPath path; const double y1=y+(nodeOverallHeight-nodeBaselineHeight); const double y2=y-nodeBaselineHeight; @@ -253,16 +288,24 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa } bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) { - QString ob=openbrace; - QString cb=closebrace; - if (ob=="<") ob="⟨"; - else if (ob=="_") ob="⌊"; - else if (ob=="~") ob="⌈"; - else if (ob=="||" || ob=="#") ob="||"; - if (cb=="<") cb="⟩"; - else if (cb=="_") cb="⌋"; - else if (cb=="~") cb="⌉"; - else if (cb=="||" || cb=="#") cb="||"; + QString ob; + QString cb; + if (openbrace==JKQTMathTextBraceNode::MTBTAngleBracket) ob="⟨"; + else if (openbrace==JKQTMathTextBraceNode::MTBTFloorBracket) ob="⌊"; + else if (openbrace==JKQTMathTextBraceNode::MTBTCeilBracket) ob="⌈"; + else if (openbrace==JKQTMathTextBraceNode::MTBTParenthesis) ob="("; + else if (openbrace==JKQTMathTextBraceNode::MTBTSquareBracket) ob="["; + else if (openbrace==JKQTMathTextBraceNode::MTBTCurlyBracket) ob="{"; + else if (openbrace==JKQTMathTextBraceNode::MTBTSingleLine) ob="|"; + else if (openbrace==JKQTMathTextBraceNode::MTBTDoubleLine) ob="||"; + if (closebrace==JKQTMathTextBraceNode::MTBTAngleBracket) cb="⟩"; + else if (closebrace==JKQTMathTextBraceNode::MTBTFloorBracket) cb="⌋"; + else if (closebrace==JKQTMathTextBraceNode::MTBTCeilBracket) cb="⌉"; + else if (closebrace==JKQTMathTextBraceNode::MTBTParenthesis) cb=")"; + else if (closebrace==JKQTMathTextBraceNode::MTBTSquareBracket) cb="]"; + else if (closebrace==JKQTMathTextBraceNode::MTBTCurlyBracket) cb="}"; + else if (closebrace==JKQTMathTextBraceNode::MTBTSingleLine) cb="|"; + else if (closebrace==JKQTMathTextBraceNode::MTBTDoubleLine) cb="||"; html=html+ob; @@ -276,14 +319,14 @@ bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment curren QString JKQTMathTextBraceNode::getTypeName() const { - return QLatin1String("MTbraceNode(")+openbrace+" "+closebrace+")"; + return QLatin1String("MTbraceNode(")+BraceType2String(openbrace)+" "+BraceType2String(closebrace)+")"; } -QString JKQTMathTextBraceNode::getOpenbrace() const { +JKQTMathTextBraceNode::BraceType JKQTMathTextBraceNode::getOpenbrace() const { return this->openbrace; } -QString JKQTMathTextBraceNode::getClosebrace() const { +JKQTMathTextBraceNode::BraceType JKQTMathTextBraceNode::getClosebrace() const { return this->closebrace; } @@ -301,7 +344,7 @@ void JKQTMathTextBraceNode::getBraceSize(QPainter &/*painter*/, JKQTMathTextEnvi const double lw=qMax(0.25,ceil(ev.fontSize/12.0)); braceheight=overallHeight*parentMathText->getBraceFactor(); bracewidth=0.6*pow(braceheight, 0.6); - if (openbrace=="{" || closebrace=="}") bracewidth=qMax(bracewidth, lw*3.5); + if (openbrace==JKQTMathTextBraceNode::MTBTCurlyBracket || closebrace==JKQTMathTextBraceNode::MTBTCurlyBracket) bracewidth=qMax(bracewidth, lw*3.5); } diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h index 132000680e..e952854133 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h +++ b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h @@ -39,7 +39,23 @@ class JKQTMathText; // forward */ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleChildNode { public: - JKQTMathTextBraceNode(JKQTMathText* parent, const QString& openbrace, const QString& closebrace, JKQTMathTextNode* child, bool showOpeningBrace=true, bool showClosingBrace=true); + /** \brief types of available braces */ + enum BraceType { + MTBTParenthesis, /*!< \brief parantheses () \image html jkqtmathtext/jkqtmathtext_brace_round.png */ + MTBTSquareBracket, /*!< \brief brackets [] \image html jkqtmathtext/jkqtmathtext_brace_rect.png */ + MTBTCurlyBracket, /*!< \brief curly braces {} \image html jkqtmathtext/jkqtmathtext_brace_curly.png */ + MTBTAngleBracket, /*!< \brief angle backets <> \image html jkqtmathtext/jkqtmathtext_brace_tri.png */ + MTBTCeilBracket, /*!< \brief ceil brackets \image html jkqtmathtext/jkqtmathtext_brace_ceil.png */ + MTBTFloorBracket, /*!< \brief floor brackets \image html jkqtmathtext/jkqtmathtext_brace_floor.png */ + MTBTDoubleLine, /*!< \brief double-line brackets (norm ||...||) \image html jkqtmathtext/jkqtmathtext_brace_dblline.png */ + MTBTSingleLine, /*!< \brief single-line brackets (abs |...|) \image html jkqtmathtext/jkqtmathtext_brace_oneline.png */ + MTBTNone /*!< \brief no bracket */ + }; + /** \brief convert a BraceType into a string */ + static QString BraceType2String(BraceType type); + /** \brief convert a string describing a LaTeX Token into a BraceType */ + static BraceType TokenNameString2TokenType(const QString& type); + JKQTMathTextBraceNode(JKQTMathText* parent, BraceType openbrace, BraceType closebrace, JKQTMathTextNode* child, bool showOpeningBrace=true, bool showClosingBrace=true); virtual ~JKQTMathTextBraceNode() override; /** \copydoc JKQTMathTextNode::draw() */ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override; @@ -48,9 +64,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleCh /** \copydoc JKQTMathTextNode::getTypeName() */ virtual QString getTypeName() const override; /** \copydoc openbrace */ - QString getOpenbrace() const; + BraceType getOpenbrace() const; /** \copydoc closebrace */ - QString getClosebrace() const; + BraceType getClosebrace() const; /** \copydoc showRightBrace */ bool getShowClosingBrace() const; /** \copydoc showOpeningBrace */ @@ -64,9 +80,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleCh /** calculates the size of this node (also returned by getSizeInternal() ) and of the brace */ void getSizeInternalAndBrace(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, double& bracewidth, double&braceheight, const JKQTMathTextNodeSize* prevNodeSize=nullptr); /**\brief opening brace */ - QString openbrace; + BraceType openbrace; /**\brief closing brace */ - QString closebrace; + BraceType closebrace; /**\brief if \c true, the closing (right hand side) brace is drawn */ bool showClosingBrace; /**\brief if \c true, the opening (left hand side) brace is drawn */