Editor: avoid relayouting of annotation text for each paint event

Change-Id: Icabf033a43922bb9ebafd1a7973dcac851e9369e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2023-06-20 15:00:08 +02:00
parent b42bdc0e4f
commit 4da2d288d8
2 changed files with 5 additions and 1 deletions

View File

@@ -138,6 +138,8 @@ void TextMark::paintAnnotation(QPainter &painter,
painter.fontMetrics(),
fadeInOffset,
fadeOutOffset);
if (m_staticAnnotationText.text() != rects.text)
m_staticAnnotationText.setText(rects.text);
annotationRect->setRight(rects.fadeOutRect.right());
const QRectF eventRectF(eventRect);
if (!(rects.fadeInRect.intersects(eventRectF) || rects.annotationRect.intersects(eventRectF)
@@ -161,7 +163,7 @@ void TextMark::paintAnnotation(QPainter &painter,
painter.fillRect(rects.annotationRect, colors.rectColor);
painter.setPen(colors.textColor);
paintIcon(&painter, rects.iconRect.toAlignedRect());
painter.drawText(rects.textRect, Qt::AlignLeft, rects.text);
painter.drawStaticText(rects.textRect.topLeft(), m_staticAnnotationText);
if (rects.fadeOutRect.isValid()) {
grad = QLinearGradient(rects.fadeOutRect.topLeft() - contentOffset,
rects.fadeOutRect.topRight() - contentOffset);

View File

@@ -11,6 +11,7 @@
#include <QCoreApplication>
#include <QIcon>
#include <QStaticText>
#include <QVector>
#include <optional>
@@ -139,6 +140,7 @@ private:
bool m_visible = false;
TextMarkCategory m_category;
QString m_lineAnnotation;
mutable QStaticText m_staticAnnotationText;
QString m_toolTip;
std::function<QString()> m_toolTipProvider;
QString m_defaultToolTip;