forked from qt-creator/qt-creator
Editor: filter text marks in paintAnnotation
Calculate the correct width for the annotation and decide inside TextMark whether it can be painted or not. This will also make sure that all annotation rectangles are correctly saved in TextEditorWidgetPrivate::updateLineAnnotation. Change-Id: I7e6c606e615b1673a34000618e106efb14184b10 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -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;
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user