From 2d3d66c115bdc6821e73de112622b8961c94a9d7 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 17 Mar 2022 07:09:51 +0100 Subject: Editor: limit painter path calculation for overlay selections Only calculate a painter path if it is inside the paint event rect. Task-number: QTCREATORBUG-26812 Change-Id: I9e7026b70251347fe8c38fc5b9278de943786956 Reviewed-by: Christian Stenger --- src/plugins/texteditor/texteditoroverlay.cpp | 18 ++++++++++-------- src/plugins/texteditor/texteditoroverlay.h | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp index 4fb7de00a2..5af06eb187 100644 --- a/src/plugins/texteditor/texteditoroverlay.cpp +++ b/src/plugins/texteditor/texteditoroverlay.cpp @@ -312,7 +312,8 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co } void TextEditorOverlay::paintSelection(QPainter *painter, - const OverlaySelection &selection) + const OverlaySelection &selection, + const QRect &clip) { QTextCursor begin = selection.m_cursor_begin; @@ -325,7 +326,7 @@ void TextEditorOverlay::paintSelection(QPainter *painter, if (begin.isNull() || end.isNull() || begin.position() > end.position() || !bg.isValid()) return; - QPainterPath path = createSelectionPath(begin, end, m_editor->viewport()->rect()); + QPainterPath path = createSelectionPath(begin, end, clip); painter->save(); QColor penColor = fg; @@ -374,14 +375,15 @@ void TextEditorOverlay::paintSelection(QPainter *painter, void TextEditorOverlay::fillSelection(QPainter *painter, const OverlaySelection &selection, - const QColor &color) + const QColor &color, + const QRect &clip) { const QTextCursor &begin = selection.m_cursor_begin; const QTextCursor &end= selection.m_cursor_end; if (begin.isNull() || end.isNull() || begin.position() > end.position()) return; - QPainterPath path = createSelectionPath(begin, end, m_editor->viewport()->rect()); + QPainterPath path = createSelectionPath(begin, end, clip); painter->save(); painter->translate(-.5, -.5); @@ -402,7 +404,7 @@ void TextEditorOverlay::paint(QPainter *painter, const QRect &clip) != selection.m_fixedLength) continue; - paintSelection(painter, selection); + paintSelection(painter, selection, clip); } for (int i = m_selections.size()-1; i >= 0; --i) { const OverlaySelection &selection = m_selections.at(i); @@ -413,7 +415,7 @@ void TextEditorOverlay::paint(QPainter *painter, const QRect &clip) != selection.m_fixedLength) continue; - paintSelection(painter, selection); + paintSelection(painter, selection, clip); } } @@ -444,7 +446,7 @@ void TextEditorOverlay::fill(QPainter *painter, const QColor &color, const QRect != selection.m_fixedLength) continue; - fillSelection(painter, selection, color); + fillSelection(painter, selection, color, clip); } for (int i = m_selections.size()-1; i >= 0; --i) { const OverlaySelection &selection = m_selections.at(i); @@ -455,7 +457,7 @@ void TextEditorOverlay::fill(QPainter *painter, const QColor &color, const QRect != selection.m_fixedLength) continue; - fillSelection(painter, selection, color); + fillSelection(painter, selection, color, clip); } } diff --git a/src/plugins/texteditor/texteditoroverlay.h b/src/plugins/texteditor/texteditoroverlay.h index d87a0fe7aa..4c3811b895 100644 --- a/src/plugins/texteditor/texteditoroverlay.h +++ b/src/plugins/texteditor/texteditoroverlay.h @@ -100,8 +100,8 @@ protected: private: QPainterPath createSelectionPath(const QTextCursor &begin, const QTextCursor &end, const QRect& clip); - void paintSelection(QPainter *painter, const OverlaySelection &selection); - void fillSelection(QPainter *painter, const OverlaySelection &selection, const QColor &color); + void paintSelection(QPainter *painter, const OverlaySelection &selection, const QRect &clip); + void fillSelection(QPainter *painter, const OverlaySelection &selection, const QColor &color, const QRect &clip); bool m_visible; bool m_alpha; -- cgit v1.2.1