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());
|
boundingRect = QRectF(x, boundingRect.top(), q->viewport()->width() - x, boundingRect.height());
|
||||||
if (boundingRect.isEmpty())
|
if (boundingRect.isEmpty())
|
||||||
break;
|
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();
|
x = boundingRect.right();
|
||||||
offset = itemOffset / 2;
|
offset = itemOffset / 2;
|
||||||
|
@@ -133,23 +133,35 @@ void TextMark::paintIcon(QPainter *painter, const QRect &rect) const
|
|||||||
icon().paint(painter, rect, Qt::AlignCenter);
|
icon().paint(painter, rect, Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextMark::paintAnnotation(QPainter &painter, QRectF *annotationRect,
|
void TextMark::paintAnnotation(QPainter &painter,
|
||||||
const qreal fadeInOffset, const qreal fadeOutOffset,
|
const QRect &eventRect,
|
||||||
|
QRectF *annotationRect,
|
||||||
|
const qreal fadeInOffset,
|
||||||
|
const qreal fadeOutOffset,
|
||||||
const QPointF &contentOffset) const
|
const QPointF &contentOffset) const
|
||||||
{
|
{
|
||||||
QString text = lineAnnotation();
|
QString text = lineAnnotation();
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const AnnotationRects &rects = annotationRects(*annotationRect, painter.fontMetrics(),
|
const AnnotationRects &rects = annotationRects(*annotationRect,
|
||||||
fadeInOffset, fadeOutOffset);
|
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()
|
const QColor &markColor = m_color.has_value()
|
||||||
? Utils::creatorTheme()->color(m_color.value()).toHsl()
|
? Utils::creatorTheme()->color(m_color.value()).toHsl()
|
||||||
: painter.pen().color();
|
: painter.pen().color();
|
||||||
|
|
||||||
const FontSettings &fontSettings = m_baseTextDocument->fontSettings();
|
const FontSettings &fontSettings = m_baseTextDocument->fontSettings();
|
||||||
const AnnotationColors &colors = AnnotationColors::getAnnotationColors(
|
const AnnotationColors &colors = AnnotationColors::getAnnotationColors(
|
||||||
markColor, fontSettings.toTextCharFormat(C_TEXT).background().color());
|
markColor, fontSettings.toTextCharFormat(C_TEXT).background().color());
|
||||||
|
|
||||||
painter.save();
|
painter.save();
|
||||||
QLinearGradient grad(rects.fadeInRect.topLeft() - contentOffset,
|
QLinearGradient grad(rects.fadeInRect.topLeft() - contentOffset,
|
||||||
@@ -169,7 +181,6 @@ void TextMark::paintAnnotation(QPainter &painter, QRectF *annotationRect,
|
|||||||
painter.fillRect(rects.fadeOutRect, grad);
|
painter.fillRect(rects.fadeOutRect, grad);
|
||||||
}
|
}
|
||||||
painter.restore();
|
painter.restore();
|
||||||
annotationRect->setRight(rects.fadeOutRect.right());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextMark::AnnotationRects TextMark::annotationRects(const QRectF &boundingRect,
|
TextMark::AnnotationRects TextMark::annotationRects(const QRectF &boundingRect,
|
||||||
|
@@ -72,8 +72,11 @@ public:
|
|||||||
int lineNumber() const;
|
int lineNumber() const;
|
||||||
|
|
||||||
virtual void paintIcon(QPainter *painter, const QRect &rect) const;
|
virtual void paintIcon(QPainter *painter, const QRect &rect) const;
|
||||||
virtual void paintAnnotation(QPainter &painter, QRectF *annotationRect,
|
virtual void paintAnnotation(QPainter &painter,
|
||||||
const qreal fadeInOffset, const qreal fadeOutOffset,
|
const QRect &eventRect,
|
||||||
|
QRectF *annotationRect,
|
||||||
|
const qreal fadeInOffset,
|
||||||
|
const qreal fadeOutOffset,
|
||||||
const QPointF &contentOffset) const;
|
const QPointF &contentOffset) const;
|
||||||
struct AnnotationRects
|
struct AnnotationRects
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user