summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qtextedit.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-10 20:20:00 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-05-24 15:37:04 +0200
commit2c8fa9700cb1eb5f1587bec46b7060ec93c6b1d2 (patch)
tree9a7743c8818999c65193583d92ed10cd1fc3794d /src/widgets/widgets/qtextedit.cpp
parent12e0c7cbe0be22c288413080a1d1bd3beafb3008 (diff)
Support clicking to toggle checkboxes in QTextEdit
Add QAbstractTextDocumentLayout::markerAt(pos) for hit testing. (Qt Quick TextEdit needs it too.) Finds out whether the position corresponds to a marker on a paragraph. I.e. it finds checkboxes in GitHub-flavored markdown. This enables editor classes to toggle checkboxes by clicking them. Use it in QTextEdit to add the checkbox toggling feature. Also show the "pointing finger" cursor when hovering a toggleable checkbox. Change-Id: I036c967ab45e14c836272eac2cc7c7d652543c89 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/widgets/widgets/qtextedit.cpp')
-rw-r--r--src/widgets/widgets/qtextedit.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index 5f734258b2..01f7c34f93 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -167,6 +167,7 @@ void QTextEditPrivate::init(const QString &html)
QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool)));
QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged()));
QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged()));
+ QObject::connect(control, SIGNAL(blockMarkerHovered(QTextBlock)), q, SLOT(_q_hoveredBlockWithMarkerChanged(QTextBlock)));
QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus()));
@@ -187,6 +188,7 @@ void QTextEditPrivate::init(const QString &html)
vbar->setSingleStep(20);
viewport->setBackgroundRole(QPalette::Base);
+ q->setMouseTracking(true);
q->setAcceptDrops(true);
q->setFocusPolicy(Qt::StrongFocus);
q->setAttribute(Qt::WA_KeyCompression);
@@ -228,6 +230,21 @@ void QTextEditPrivate::_q_cursorPositionChanged()
#endif
}
+void QTextEditPrivate::_q_hoveredBlockWithMarkerChanged(const QTextBlock &block)
+{
+ Q_Q(QTextEdit);
+ Qt::CursorShape cursor = cursorToRestoreAfterHover;
+ if (block.isValid() && !q->isReadOnly()) {
+ QTextBlockFormat::MarkerType marker = block.blockFormat().marker();
+ if (marker != QTextBlockFormat::NoMarker) {
+ if (viewport->cursor().shape() != Qt::PointingHandCursor)
+ cursorToRestoreAfterHover = viewport->cursor().shape();
+ cursor = Qt::PointingHandCursor;
+ }
+ }
+ viewport->setCursor(cursor);
+}
+
void QTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode)
{
QTextCursor cursor = control->textCursor();