forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user