forked from qt-creator/qt-creator
TextEditor: Optimize TextEditorOverlay::createSelectionPath
Change-Id: I9a0eca133a5a56fabab1ab51b91ca9db594a4f27 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
40fb9492a8
commit
739795ce8c
@@ -245,40 +245,53 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co
|
|||||||
const int margin = m_borderWidth/2;
|
const int margin = m_borderWidth/2;
|
||||||
const int extra = 0;
|
const int extra = 0;
|
||||||
|
|
||||||
points += (selection.at(0).topLeft() + selection.at(0).topRight()) / 2 + QPointF(0, -margin);
|
const QRectF &firstSelection = selection.at(0);
|
||||||
points += selection.at(0).topRight() + QPointF(margin+1, -margin);
|
points += (firstSelection.topLeft() + firstSelection.topRight()) / 2 + QPointF(0, -margin);
|
||||||
points += selection.at(0).bottomRight() + QPointF(margin+1, 0);
|
points += firstSelection.topRight() + QPointF(margin+1, -margin);
|
||||||
|
points += firstSelection.bottomRight() + QPointF(margin+1, 0);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 1; i < selection.count()-1; ++i) {
|
const int count = selection.count();
|
||||||
|
if (count > 2) {
|
||||||
#define MAX3(a,b,c) qMax(a, qMax(b,c))
|
const QRectF *prev = &selection.at(0);
|
||||||
qreal x = MAX3(selection.at(i-1).right(),
|
const QRectF *current = &selection.at(1);
|
||||||
selection.at(i).right(),
|
const QRectF *next = &selection.at(2);
|
||||||
selection.at(i+1).right()) + margin;
|
for (int i = 0; i < count; ++i) {
|
||||||
|
#define MAX3(a,b,c) qMax(a, qMax(b,c))
|
||||||
points += QPointF(x+1, selection.at(i).top());
|
qreal x = MAX3(prev->right(), current->right(), next->right()) + margin;
|
||||||
points += QPointF(x+1, selection.at(i).bottom());
|
points += QPointF(x+1, current->top());
|
||||||
|
points += QPointF(x+1, current->bottom());
|
||||||
|
prev = current;
|
||||||
|
current = next;
|
||||||
|
if (i < count-1)
|
||||||
|
next = &selection.at(i+1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
points += selection.at(selection.count()-1).topRight() + QPointF(margin+1, 0);
|
const QRectF &lastSelection = selection.at(count-1);
|
||||||
points += selection.at(selection.count()-1).bottomRight() + QPointF(margin+1, margin+extra);
|
points += lastSelection.topRight() + QPointF(margin+1, 0);
|
||||||
points += selection.at(selection.count()-1).bottomLeft() + QPointF(-margin, margin+extra);
|
points += lastSelection.bottomRight() + QPointF(margin+1, margin+extra);
|
||||||
points += selection.at(selection.count()-1).topLeft() + QPointF(-margin, 0);
|
points += lastSelection.bottomLeft() + QPointF(-margin, margin+extra);
|
||||||
|
points += lastSelection.topLeft() + QPointF(-margin, 0);
|
||||||
|
|
||||||
for (int i = selection.count()-2; i > 0; --i) {
|
if (count > 2) {
|
||||||
|
const QRectF *prev = &selection.at(count-3);
|
||||||
|
const QRectF *current = &selection.at(count-2);
|
||||||
|
const QRectF *next = &selection.at(count-1);
|
||||||
|
for (int i = count-1; i >= 0; --i) {
|
||||||
#define MIN3(a,b,c) qMin(a, qMin(b,c))
|
#define MIN3(a,b,c) qMin(a, qMin(b,c))
|
||||||
qreal x = MIN3(selection.at(i-1).left(),
|
qreal x = MIN3(prev->left(), current->left(), next->left()) - margin;
|
||||||
selection.at(i).left(),
|
points += QPointF(x, current->bottom()+extra);
|
||||||
selection.at(i+1).left()) - margin;
|
points += QPointF(x, current->top());
|
||||||
|
next = current;
|
||||||
points += QPointF(x, selection.at(i).bottom()+extra);
|
current = prev;
|
||||||
points += QPointF(x, selection.at(i).top());
|
if (i > 0)
|
||||||
|
prev = &selection.at(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
points += selection.at(0).bottomLeft() + QPointF(-margin, extra);
|
points += firstSelection.bottomLeft() + QPointF(-margin, extra);
|
||||||
points += selection.at(0).topLeft() + QPointF(-margin, -margin);
|
points += firstSelection.topLeft() + QPointF(-margin, -margin);
|
||||||
|
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
|
|||||||
Reference in New Issue
Block a user