diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 92de555869f..b686eadf86e 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -4020,8 +4020,13 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data, boundingRect = QRectF(x, boundingRect.top(), q->viewport()->width() - x, boundingRect.height()); if (boundingRect.isEmpty()) break; - if (data.eventRect.intersects(boundingRect.toRect())) - mark->paintAnnotation(painter, &boundingRect, offset, itemOffset / 2, q->contentOffset()); + + mark->paintAnnotation(painter, + data.eventRect, + &boundingRect, + offset, + itemOffset / 2, + q->contentOffset()); x = boundingRect.right(); offset = itemOffset / 2; diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index d2b101ec2dc..09a373f6a27 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -133,23 +133,35 @@ void TextMark::paintIcon(QPainter *painter, const QRect &rect) const icon().paint(painter, rect, Qt::AlignCenter); } -void TextMark::paintAnnotation(QPainter &painter, QRectF *annotationRect, - const qreal fadeInOffset, const qreal fadeOutOffset, +void TextMark::paintAnnotation(QPainter &painter, + const QRect &eventRect, + QRectF *annotationRect, + const qreal fadeInOffset, + const qreal fadeOutOffset, const QPointF &contentOffset) const { QString text = lineAnnotation(); if (text.isEmpty()) return; - const AnnotationRects &rects = annotationRects(*annotationRect, painter.fontMetrics(), - fadeInOffset, fadeOutOffset); + const AnnotationRects &rects = annotationRects(*annotationRect, + painter.fontMetrics(), + fadeInOffset, + fadeOutOffset); + annotationRect->setRight(rects.fadeOutRect.right()); + const QRectF eventRectF(eventRect); + if (!(rects.fadeInRect.intersects(eventRectF) || rects.annotationRect.intersects(eventRectF) + || rects.fadeOutRect.intersects(eventRectF))) { + return; + } + const QColor &markColor = m_color.has_value() ? Utils::creatorTheme()->color(m_color.value()).toHsl() : painter.pen().color(); const FontSettings &fontSettings = m_baseTextDocument->fontSettings(); const AnnotationColors &colors = AnnotationColors::getAnnotationColors( - markColor, fontSettings.toTextCharFormat(C_TEXT).background().color()); + markColor, fontSettings.toTextCharFormat(C_TEXT).background().color()); painter.save(); QLinearGradient grad(rects.fadeInRect.topLeft() - contentOffset, @@ -169,7 +181,6 @@ void TextMark::paintAnnotation(QPainter &painter, QRectF *annotationRect, painter.fillRect(rects.fadeOutRect, grad); } painter.restore(); - annotationRect->setRight(rects.fadeOutRect.right()); } TextMark::AnnotationRects TextMark::annotationRects(const QRectF &boundingRect, diff --git a/src/plugins/texteditor/textmark.h b/src/plugins/texteditor/textmark.h index 0eb47b524ad..2c69592aeed 100644 --- a/src/plugins/texteditor/textmark.h +++ b/src/plugins/texteditor/textmark.h @@ -72,8 +72,11 @@ public: int lineNumber() const; virtual void paintIcon(QPainter *painter, const QRect &rect) const; - virtual void paintAnnotation(QPainter &painter, QRectF *annotationRect, - const qreal fadeInOffset, const qreal fadeOutOffset, + virtual void paintAnnotation(QPainter &painter, + const QRect &eventRect, + QRectF *annotationRect, + const qreal fadeInOffset, + const qreal fadeOutOffset, const QPointF &contentOffset) const; struct AnnotationRects {