summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocumentlayout.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-02-06 17:10:42 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2019-05-02 04:10:21 +0000
commit75256d62d2462103180b368aa79b933acf71f444 (patch)
tree7c45742725ee1ceec2e42ba0594b2a522205b4b3 /src/gui/text/qtextdocumentlayout.cpp
parentdeae75ae093d11714dd2f05a40dcfcdb6bb8e10e (diff)
Render markdown task lists (checkboxes instead of bullets) in QTextEdit
Checkboxes are right-aligned with any bullets that are in the same QTextList so that there is enough space to make them larger than bullets. But hopefully mixing bullets and checkboxes will be a rarely-used feature. Change-Id: I28e274d1f7883aa093df29eb4988e99641e87a71 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/gui/text/qtextdocumentlayout.cpp')
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp
index bed0a2c450..7873faf2cb 100644
--- a/src/gui/text/qtextdocumentlayout.cpp
+++ b/src/gui/text/qtextdocumentlayout.cpp
@@ -1436,6 +1436,21 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p
QBrush brush = context.palette.brush(QPalette::Text);
+ bool marker = bl.blockFormat().marker() != QTextBlockFormat::NoMarker;
+ if (marker) {
+ int adj = fontMetrics.lineSpacing() / 6;
+ r.adjust(-adj, 0, -adj, 0);
+ if (bl.blockFormat().marker() == QTextBlockFormat::Checked) {
+ // ### Qt6: render with QStyle / PE_IndicatorCheckBox. We don't currently
+ // have access to that here, because it would be a widget dependency.
+ painter->setPen(QPen(painter->pen().color(), 2));
+ painter->drawLine(r.topLeft(), r.bottomRight());
+ painter->drawLine(r.topRight(), r.bottomLeft());
+ painter->setPen(QPen(painter->pen().color(), 0));
+ }
+ painter->drawRect(r.adjusted(-adj, -adj, adj, adj));
+ }
+
switch (style) {
case QTextListFormat::ListDecimal:
case QTextListFormat::ListLowerAlpha:
@@ -1456,16 +1471,21 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p
break;
}
case QTextListFormat::ListSquare:
- painter->fillRect(r, brush);
+ if (!marker)
+ painter->fillRect(r, brush);
break;
case QTextListFormat::ListCircle:
- painter->setPen(QPen(brush, 0));
- painter->drawEllipse(r.translated(0.5, 0.5)); // pixel align for sharper rendering
+ if (!marker) {
+ painter->setPen(QPen(brush, 0));
+ painter->drawEllipse(r.translated(0.5, 0.5)); // pixel align for sharper rendering
+ }
break;
case QTextListFormat::ListDisc:
- painter->setBrush(brush);
- painter->setPen(Qt::NoPen);
- painter->drawEllipse(r);
+ if (!marker) {
+ painter->setBrush(brush);
+ painter->setPen(Qt::NoPen);
+ painter->drawEllipse(r);
+ }
break;
case QTextListFormat::ListStyleUndefined:
break;