Skip to content

Commit c5d2dd2

Browse files
committed
display ellipsis variants in QtSLiM's status bar
1 parent 4c9a755 commit c5d2dd2

2 files changed

Lines changed: 78 additions & 11 deletions

File tree

QtSLiM/QtSLiMScriptTextEdit.cpp

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,14 @@ void QtSLiMTextEdit::updateStatusFieldFromSelection(void)
10181018
}
10191019
}
10201020

1021+
double signaturePointSize;
1022+
1023+
#ifdef __linux__
1024+
signaturePointSize = 9;
1025+
#else
1026+
signaturePointSize = 11;
1027+
#endif
1028+
10211029
QString displayString;
10221030

10231031
if (signature)
@@ -1034,30 +1042,88 @@ void QtSLiMTextEdit::updateStatusFieldFromSelection(void)
10341042

10351043
td.setPlainText(displayString);
10361044

1037-
if (signature)
1045+
// hanging indent for multiline wrapping aesthetics
10381046
{
10391047
QTextCursor tc(&td);
10401048
tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
10411049
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
10421050

1043-
#ifdef __linux__
1044-
ColorizeCallSignature(signature.get(), 9, tc);
1045-
#else
1046-
ColorizeCallSignature(signature.get(), 11, tc);
1047-
#endif
1051+
QTextBlockFormat blockFormat;
1052+
blockFormat.setLeftMargin(30);
1053+
blockFormat.setTextIndent(-30);
1054+
1055+
tc.setBlockFormat(blockFormat);
10481056
}
10491057

1050-
// hanging indent for multiline wrapping aesthetics
1058+
if (signature)
10511059
{
10521060
QTextCursor tc(&td);
10531061
tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
10541062
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
10551063

1056-
QTextBlockFormat blockFormat;
1057-
blockFormat.setLeftMargin(30);
1058-
blockFormat.setTextIndent(-30);
1064+
QTextCharFormat plainTextFormat = tc.charFormat();
1065+
plainTextFormat.setFontPointSize(signaturePointSize);
10591066

1060-
tc.setBlockFormat(blockFormat);
1067+
ColorizeCallSignature(signature.get(), signaturePointSize, tc);
1068+
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
1069+
1070+
QTextCharFormat codeTextFormat = tc.charFormat();
1071+
1072+
int indexOfEllipsis = displayString.indexOf("...");
1073+
const std::vector<EidosCallSignature *> &variants = signature->ellipsis_variants_;
1074+
int variantCount = (int)variants.size();
1075+
1076+
if (signature->has_ellipsis_ && (indexOfEllipsis > 0) && (variantCount > 0))
1077+
{
1078+
// we insert a newline in anticipation of each new variant; this allows the text coloring to work correctly below
1079+
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
1080+
tc.insertText("\n"); // one extra newline for separation
1081+
1082+
// display ellipsis variants, showing only the variant portion as in the doc
1083+
for (int variantIndex = 1; variantIndex <= variantCount; ++variantIndex)
1084+
{
1085+
EidosCallSignature *variant = variants[variantIndex - 1];
1086+
1087+
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
1088+
tc.setCharFormat(plainTextFormat);
1089+
tc.insertText(QString("variant %1: ").arg(variantIndex));
1090+
tc.setCharFormat(codeTextFormat);
1091+
tc.insertText("...");
1092+
tc.setCharFormat(plainTextFormat);
1093+
tc.insertText(" conforms to ");
1094+
1095+
int sigStart = tc.position();
1096+
QString variantString = QString::fromStdString(variant->SignatureString());
1097+
tc.insertText(variantString);
1098+
1099+
tc.setPosition(sigStart, QTextCursor::MoveAnchor);
1100+
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
1101+
ColorizeCallSignature(variant, signaturePointSize, tc);
1102+
1103+
// insert a newline in anticipation of the next variant; this way the (black) color of the end paren carries forward
1104+
if (variantIndex < variantCount) {
1105+
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
1106+
tc.insertText("\n");
1107+
}
1108+
1109+
// then delete the prefix and suffix shared between the base signature and this variant
1110+
tc.setPosition(sigStart, QTextCursor::MoveAnchor);
1111+
tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, indexOfEllipsis);
1112+
tc.removeSelectedText();
1113+
1114+
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
1115+
tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, (variantIndex < variantCount) ? 1 : 0); // back through newline
1116+
tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, displayString.length() - indexOfEllipsis - 3);
1117+
tc.removeSelectedText();
1118+
}
1119+
1120+
// fix the height of the top margin of the block, to provide a bit of space between the base signature and variants
1121+
tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
1122+
tc.select(QTextCursor::BlockUnderCursor);
1123+
QTextBlockFormat blockFormat = tc.blockFormat();
1124+
blockFormat.setBottomMargin(6);
1125+
tc.setBlockFormat(blockFormat);
1126+
}
10611127
}
10621128

10631129
QString htmlString = td.toHtml();

VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ multitrait branch:
205205
shift to require a minimum of Qt 5.15.2 on all platforms; Ubuntu 18.04 LTS preinstalled Qt 5.9.5, so we are now abandoning Ubuntu 18.04 LTS (no change for macOS and Windows, I think)
206206
add a function/method overloading mechanism to Eidos, "ellipsis variants"; allows better documentation/handling of arguments for calls with multiple signatures
207207
add ellipsis variants for constructors: Dictionary(...), DataFrame(...), Image(...), Palette(...)
208+
add QtSLiM support for displaying ellipsis variants in the status bar
208209
switch SpatialMap over to using a Palette for its colors
209210
add a defineSpatialMap() ellipsis variant that takes a Palette object to define its colors
210211
add a changeColors() ellipsis variant that takes a Palette object to define its colors

0 commit comments

Comments
 (0)