From e79a0ab49b79f959467409069db080eff83f271e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 3 Jan 2023 08:33:37 +0100 Subject: [PATCH] Editor: increase text cursor visibility on indentation depth mark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce the alpha of the marker if a cursor is at the same position as the marker. Fixes: QTCREATORBUG-28645 Change-Id: I01b1825fd3f393dcc75cc58d64a31f22e50e2648 Reviewed-by: André Hartmann --- src/plugins/texteditor/texteditor.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index c192249862c..9ce003e8537 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -4477,7 +4477,6 @@ void TextEditorWidgetPrivate::paintIndentDepth(PaintEventData &data, const qreal indentAdvance = singleAdvance * data.tabSettings.m_indentSize; painter.save(); - painter.setPen(data.visualWhitespaceFormat.foreground().color()); const QTextLine textLine = blockData.layout->lineAt(0); const QRectF rect = textLine.naturalTextRect(); @@ -4485,6 +4484,16 @@ void TextEditorWidgetPrivate::paintIndentDepth(PaintEventData &data, + singleAdvance * m_visualIndentOffset; int paintColumn = 0; + QList cursorPositions; + for (const QTextCursor & cursor : m_cursors) { + if (cursor.block() == data.block) + cursorPositions << cursor.positionInBlock(); + } + + const QColor normalColor = data.visualWhitespaceFormat.foreground().color(); + QColor cursorColor = normalColor; + cursorColor.setAlpha(cursorColor.alpha() / 2); + const QString text = data.block.text().mid(m_visualIndentOffset); while (paintColumn < depth) { if (x >= 0) { @@ -4493,6 +4502,10 @@ void TextEditorWidgetPrivate::paintIndentDepth(PaintEventData &data, && blockData.layout->lineForTextPosition(paintPosition).lineNumber() != 0) { break; } + if (cursorPositions.contains(paintPosition)) + painter.setPen(cursorColor); + else + painter.setPen(normalColor); const QPointF top(x, blockData.boundingRect.top()); const QPointF bottom(x, blockData.boundingRect.top() + rect.height()); const QLineF line(top, bottom);