mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +08:00
JKQTMathTextBraceNode uses an enum to reference brace types, not a QStrig
This commit is contained in:
parent
c8ef57bb66
commit
5c255712ce
@ -1010,7 +1010,7 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, const QString& quitOn
|
|||||||
JKQTMathTextNode* n1=parseLatexString(true);
|
JKQTMathTextNode* n1=parseLatexString(true);
|
||||||
JKQTMathTextNode* n2=nullptr;
|
JKQTMathTextNode* n2=nullptr;
|
||||||
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
|
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 error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(name));
|
||||||
} else if (name=="underbrace") {
|
} else if (name=="underbrace") {
|
||||||
JKQTMathTextNode* n1=parseLatexString(true);
|
JKQTMathTextNode* n1=parseLatexString(true);
|
||||||
@ -1061,12 +1061,12 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, const QString& quitOn
|
|||||||
first=false;
|
first=false;
|
||||||
}
|
}
|
||||||
//std::cout<<" creating matrix-node with "<<items.size()<<" items.\n";
|
//std::cout<<" creating matrix-node with "<<items.size()<<" items.\n";
|
||||||
if (envname=="pmatrix") 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, "{", "", 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, "[", "]", 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, "{", "}", 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, "|", "|", 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, "||", "||", 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));
|
else nl->addNode(new JKQTMathTextMatrixNode(this, items));
|
||||||
//std::cout<<" creating matrix-node ... done!\n";
|
//std::cout<<" creating matrix-node ... done!\n";
|
||||||
} else {
|
} else {
|
||||||
@ -1209,52 +1209,52 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, const QString& quitOn
|
|||||||
if (currentTokenName.size()>0) {
|
if (currentTokenName.size()>0) {
|
||||||
if (currentTokenName[0]=='(') {
|
if (currentTokenName[0]=='(') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1); // we already used the first character from the text token!
|
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]=='[') {
|
} else if (currentTokenName[0]=='[') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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]=='{') {
|
} else if (currentTokenName[0]=='{') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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]=='<') {
|
} else if (currentTokenName[0]=='<') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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]=='|') {
|
} else if (currentTokenName[0]=='|') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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]=='~') {
|
} else if (currentTokenName[0]=='~') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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]=='_') {
|
} else if (currentTokenName[0]=='_') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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]=='#') {
|
} else if (currentTokenName[0]=='#') {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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]=='.') {
|
} else if (currentTokenName[0]=='.') {
|
||||||
showLeftBrace=false;
|
showLeftBrace=false;
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
||||||
JKQTMathTextNode* cn=parseLatexString(currentTokenName.size()<=0, "any");
|
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 {
|
} else {
|
||||||
getNew=false;
|
getNew=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (currentToken==MTTinstruction && currentTokenName=="langle") {
|
} else if (currentToken==MTTinstruction && currentTokenName=="langle") {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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=="{") {
|
} else if (currentToken==MTTinstruction && currentTokenName=="{") {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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") {
|
} else if (currentToken==MTTinstruction && currentTokenName=="lfloor") {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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") {
|
} else if (currentToken==MTTinstruction && currentTokenName=="lceil") {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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=="|") {
|
} else if (currentToken==MTTinstruction && currentTokenName=="|") {
|
||||||
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
|
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) {
|
} else if (currentToken==MTTinstruction && currentTokenName==quitOnClosingBrace) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -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)
|
JKQTMathTextSingleChildNode(child, _parent)
|
||||||
{
|
{
|
||||||
this->openbrace=openbrace;
|
this->openbrace=openbrace;
|
||||||
@ -112,14 +147,14 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
|
|||||||
const double xbrace1=xnew+lw;
|
const double xbrace1=xnew+lw;
|
||||||
const double xbrace2=qMin(xnew+paren_fraction*bracewidth, xnew+bracewidth-lw/2.0);
|
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);
|
const double xbrace2s=qMin(xnew+brace_fraction*bracewidth, xnew+bracewidth-lw/2.0);
|
||||||
if (openbrace=="(") {
|
if (openbrace==MTBTParenthesis) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-nodeBaselineHeight;
|
const double y2=y-nodeBaselineHeight;
|
||||||
path.moveTo(xbrace2, y1);
|
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);
|
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);
|
painter.drawPath(path);
|
||||||
} else if (openbrace=="[") {
|
} else if (openbrace==JKQTMathTextBraceNode::MTBTSquareBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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(xbrace1, y2);
|
||||||
path.lineTo(xbrace2s, y2);
|
path.lineTo(xbrace2s, y2);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
} else if (openbrace=="{") {
|
} else if (openbrace==JKQTMathTextBraceNode::MTBTCurlyBracket) {
|
||||||
QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*brace_fraction);
|
QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*brace_fraction);
|
||||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||||
painter.translate((xbrace1+xbrace2)/2.0, y-nodeBaselineHeight+nodeOverallHeight/2.0);
|
painter.translate((xbrace1+xbrace2)/2.0, y-nodeBaselineHeight+nodeOverallHeight/2.0);
|
||||||
painter.rotate(90);
|
painter.rotate(90);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
|
|
||||||
} else if (openbrace=="_") {
|
} else if (openbrace==JKQTMathTextBraceNode::MTBTFloorBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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, y1);
|
||||||
path.lineTo(xbrace1, y2);
|
path.lineTo(xbrace1, y2);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
} else if (openbrace=="~") {
|
} else if (openbrace==JKQTMathTextBraceNode::MTBTCeilBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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(xbrace1, y2);
|
||||||
path.lineTo(xbrace2s, y2);
|
path.lineTo(xbrace2s, y2);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
} else if (openbrace=="|") {
|
} else if (openbrace==JKQTMathTextBraceNode::MTBTSingleLine) {
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-nodeBaselineHeight;
|
const double y2=y-nodeBaselineHeight;
|
||||||
const QLineF l(xbrace1, y1, xbrace1, y2);
|
const QLineF l(xbrace1, y1, xbrace1, y2);
|
||||||
if (l.length()>0) painter.drawLine(l);
|
if (l.length()>0) painter.drawLine(l);
|
||||||
} else if (openbrace=="#" || openbrace=="||") {
|
} else if (openbrace==JKQTMathTextBraceNode::MTBTDoubleLine) {
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-nodeBaselineHeight;
|
const double y2=y-nodeBaselineHeight;
|
||||||
const QLineF l(xbrace1, y1, xbrace1, y2);
|
const QLineF l(xbrace1, y1, xbrace1, y2);
|
||||||
if (l.length()>0) painter.drawLine(l);
|
if (l.length()>0) painter.drawLine(l);
|
||||||
const QLineF l2(xbrace1+1.5*lw, y1, xbrace1+1.5*lw, y2);
|
const QLineF l2(xbrace1+1.5*lw, y1, xbrace1+1.5*lw, y2);
|
||||||
if (l2.length()>0) painter.drawLine(l2);
|
if (l2.length()>0) painter.drawLine(l2);
|
||||||
} else if (openbrace=="<") {
|
} else if (openbrace==JKQTMathTextBraceNode::MTBTAngleBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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 xbrace1s=qMax(xnew+bracewidth-brace_fraction*bracewidth, xnew+lw/2.0);
|
||||||
const double xbrace2=xnew+bracewidth-lw;
|
const double xbrace2=xnew+bracewidth-lw;
|
||||||
painter.setPen(p);
|
painter.setPen(p);
|
||||||
if (closebrace==")") {
|
if (closebrace==JKQTMathTextBraceNode::MTBTParenthesis) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-nodeBaselineHeight;
|
const double y2=y-nodeBaselineHeight;
|
||||||
path.moveTo(xbrace1, y1);
|
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);
|
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);
|
painter.drawPath(path);
|
||||||
} else if (closebrace=="]") {
|
} else if (closebrace==JKQTMathTextBraceNode::MTBTSquareBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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(xbrace2, y2);
|
||||||
path.lineTo(xbrace1s, y2);
|
path.lineTo(xbrace1s, y2);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
} else if (closebrace=="}") {
|
} else if (closebrace==JKQTMathTextBraceNode::MTBTCurlyBracket) {
|
||||||
QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*brace_fraction);
|
QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*brace_fraction);
|
||||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||||
painter.translate((xbrace1+xbrace2)/2.0, y-nodeBaselineHeight+nodeOverallHeight/2.0);
|
painter.translate((xbrace1+xbrace2)/2.0, y-nodeBaselineHeight+nodeOverallHeight/2.0);
|
||||||
painter.rotate(270);
|
painter.rotate(270);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
|
|
||||||
} else if (closebrace=="_") {
|
} else if (closebrace==JKQTMathTextBraceNode::MTBTFloorBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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, y1);
|
||||||
path.lineTo(xbrace2, y2);
|
path.lineTo(xbrace2, y2);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
} else if (closebrace=="~") {
|
} else if (closebrace==JKQTMathTextBraceNode::MTBTCeilBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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(xbrace2, y2);
|
||||||
path.lineTo(xbrace1s, y2);
|
path.lineTo(xbrace1s, y2);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
} else if (closebrace=="|") {
|
} else if (closebrace==JKQTMathTextBraceNode::MTBTSingleLine) {
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-nodeBaselineHeight;
|
const double y2=y-nodeBaselineHeight;
|
||||||
const QLineF l(xbrace2, y1, xbrace2, y2);
|
const QLineF l(xbrace2, y1, xbrace2, y2);
|
||||||
if (l.length()>0) painter.drawLine(l);
|
if (l.length()>0) painter.drawLine(l);
|
||||||
} else if (closebrace=="#" || closebrace=="||") {
|
} else if (closebrace==JKQTMathTextBraceNode::MTBTDoubleLine) {
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-nodeBaselineHeight;
|
const double y2=y-nodeBaselineHeight;
|
||||||
const QLineF l(xbrace2, y1, xbrace2, y2);
|
const QLineF l(xbrace2, y1, xbrace2, y2);
|
||||||
if (l.length()>0) painter.drawLine(l);
|
if (l.length()>0) painter.drawLine(l);
|
||||||
const QLineF l2(xbrace2-1.5*lw, y1, xbrace2-1.5*lw, y2);
|
const QLineF l2(xbrace2-1.5*lw, y1, xbrace2-1.5*lw, y2);
|
||||||
if (l2.length()>0) painter.drawLine(l2);
|
if (l2.length()>0) painter.drawLine(l2);
|
||||||
} else if (closebrace==">") {
|
} else if (closebrace==JKQTMathTextBraceNode::MTBTAngleBracket) {
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
|
||||||
const double y2=y-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) {
|
bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
|
||||||
QString ob=openbrace;
|
QString ob;
|
||||||
QString cb=closebrace;
|
QString cb;
|
||||||
if (ob=="<") ob="⟨";
|
if (openbrace==JKQTMathTextBraceNode::MTBTAngleBracket) ob="⟨";
|
||||||
else if (ob=="_") ob="⌊";
|
else if (openbrace==JKQTMathTextBraceNode::MTBTFloorBracket) ob="⌊";
|
||||||
else if (ob=="~") ob="⌈";
|
else if (openbrace==JKQTMathTextBraceNode::MTBTCeilBracket) ob="⌈";
|
||||||
else if (ob=="||" || ob=="#") ob="||";
|
else if (openbrace==JKQTMathTextBraceNode::MTBTParenthesis) ob="(";
|
||||||
if (cb=="<") cb="⟩";
|
else if (openbrace==JKQTMathTextBraceNode::MTBTSquareBracket) ob="[";
|
||||||
else if (cb=="_") cb="⌋";
|
else if (openbrace==JKQTMathTextBraceNode::MTBTCurlyBracket) ob="{";
|
||||||
else if (cb=="~") cb="⌉";
|
else if (openbrace==JKQTMathTextBraceNode::MTBTSingleLine) ob="|";
|
||||||
else if (cb=="||" || cb=="#") cb="||";
|
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;
|
html=html+ob;
|
||||||
@ -276,14 +319,14 @@ bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment curren
|
|||||||
|
|
||||||
QString JKQTMathTextBraceNode::getTypeName() const
|
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;
|
return this->openbrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JKQTMathTextBraceNode::getClosebrace() const {
|
JKQTMathTextBraceNode::BraceType JKQTMathTextBraceNode::getClosebrace() const {
|
||||||
return this->closebrace;
|
return this->closebrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +344,7 @@ void JKQTMathTextBraceNode::getBraceSize(QPainter &/*painter*/, JKQTMathTextEnvi
|
|||||||
const double lw=qMax(0.25,ceil(ev.fontSize/12.0));
|
const double lw=qMax(0.25,ceil(ev.fontSize/12.0));
|
||||||
braceheight=overallHeight*parentMathText->getBraceFactor();
|
braceheight=overallHeight*parentMathText->getBraceFactor();
|
||||||
bracewidth=0.6*pow(braceheight, 0.6);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,23 @@ class JKQTMathText; // forward
|
|||||||
*/
|
*/
|
||||||
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleChildNode {
|
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleChildNode {
|
||||||
public:
|
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;
|
virtual ~JKQTMathTextBraceNode() override;
|
||||||
/** \copydoc JKQTMathTextNode::draw() */
|
/** \copydoc JKQTMathTextNode::draw() */
|
||||||
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
|
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() */
|
/** \copydoc JKQTMathTextNode::getTypeName() */
|
||||||
virtual QString getTypeName() const override;
|
virtual QString getTypeName() const override;
|
||||||
/** \copydoc openbrace */
|
/** \copydoc openbrace */
|
||||||
QString getOpenbrace() const;
|
BraceType getOpenbrace() const;
|
||||||
/** \copydoc closebrace */
|
/** \copydoc closebrace */
|
||||||
QString getClosebrace() const;
|
BraceType getClosebrace() const;
|
||||||
/** \copydoc showRightBrace */
|
/** \copydoc showRightBrace */
|
||||||
bool getShowClosingBrace() const;
|
bool getShowClosingBrace() const;
|
||||||
/** \copydoc showOpeningBrace */
|
/** \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 */
|
/** 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);
|
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 */
|
/**\brief opening brace */
|
||||||
QString openbrace;
|
BraceType openbrace;
|
||||||
/**\brief closing brace */
|
/**\brief closing brace */
|
||||||
QString closebrace;
|
BraceType closebrace;
|
||||||
/**\brief if \c true, the closing (right hand side) brace is drawn */
|
/**\brief if \c true, the closing (right hand side) brace is drawn */
|
||||||
bool showClosingBrace;
|
bool showClosingBrace;
|
||||||
/**\brief if \c true, the opening (left hand side) brace is drawn */
|
/**\brief if \c true, the opening (left hand side) brace is drawn */
|
||||||
|
Loading…
Reference in New Issue
Block a user