aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-03-17 07:09:51 +0100
committerDavid Schulz <david.schulz@qt.io>2022-03-17 11:03:00 +0000
commit2d3d66c115bdc6821e73de112622b8961c94a9d7 (patch)
tree7a0c463b7a2313f0d135c669c3c9fac5ab0d2ddb
parentb822a9462eed10f3b855e8c17c6467c23b5b7d80 (diff)
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 <christian.stenger@qt.io>
-rw-r--r--src/plugins/texteditor/texteditoroverlay.cpp18
-rw-r--r--src/plugins/texteditor/texteditoroverlay.h4
2 files changed, 12 insertions, 10 deletions
diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp
index 4fb7de00a25..5af06eb187b 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 d87a0fe7aab..4c3811b8950 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;