Commit 739795ce authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

TextEditor: Optimize TextEditorOverlay::createSelectionPath

Change-Id: I9a0eca133a5a56fabab1ab51b91ca9db594a4f27
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 40fb9492
......@@ -245,40 +245,53 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co
const int margin = m_borderWidth/2;
const int extra = 0;
points += (selection.at(0).topLeft() + selection.at(0).topRight()) / 2 + QPointF(0, -margin);
points += selection.at(0).topRight() + QPointF(margin+1, -margin);
points += selection.at(0).bottomRight() + QPointF(margin+1, 0);
for (int i = 1; i < selection.count()-1; ++i) {
#define MAX3(a,b,c) qMax(a, qMax(b,c))
qreal x = MAX3(selection.at(i-1).right(),
selection.at(i).right(),
selection.at(i+1).right()) + margin;
points += QPointF(x+1, selection.at(i).top());
points += QPointF(x+1, selection.at(i).bottom());
const QRectF &firstSelection = selection.at(0);
points += (firstSelection.topLeft() + firstSelection.topRight()) / 2 + QPointF(0, -margin);
points += firstSelection.topRight() + QPointF(margin+1, -margin);
points += firstSelection.bottomRight() + QPointF(margin+1, 0);
const int count = selection.count();
if (count > 2) {
const QRectF *prev = &selection.at(0);
const QRectF *current = &selection.at(1);
const QRectF *next = &selection.at(2);
for (int i = 0; i < count; ++i) {
#define MAX3(a,b,c) qMax(a, qMax(b,c))
qreal x = MAX3(prev->right(), current->right(), next->right()) + margin;
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);
points += selection.at(selection.count()-1).bottomRight() + QPointF(margin+1, margin+extra);
points += selection.at(selection.count()-1).bottomLeft() + QPointF(-margin, margin+extra);
points += selection.at(selection.count()-1).topLeft() + QPointF(-margin, 0);
for (int i = selection.count()-2; i > 0; --i) {
const QRectF &lastSelection = selection.at(count-1);
points += lastSelection.topRight() + QPointF(margin+1, 0);
points += lastSelection.bottomRight() + QPointF(margin+1, margin+extra);
points += lastSelection.bottomLeft() + QPointF(-margin, margin+extra);
points += lastSelection.topLeft() + QPointF(-margin, 0);
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))
qreal x = MIN3(selection.at(i-1).left(),
selection.at(i).left(),
selection.at(i+1).left()) - margin;
points += QPointF(x, selection.at(i).bottom()+extra);
points += QPointF(x, selection.at(i).top());
qreal x = MIN3(prev->left(), current->left(), next->left()) - margin;
points += QPointF(x, current->bottom()+extra);
points += QPointF(x, current->top());
next = current;
current = prev;
if (i > 0)
prev = &selection.at(i);
}
}
points += selection.at(0).bottomLeft() + QPointF(-margin, extra);
points += selection.at(0).topLeft() + QPointF(-margin, -margin);
points += firstSelection.bottomLeft() + QPointF(-margin, extra);
points += firstSelection.topLeft() + QPointF(-margin, -margin);
QPainterPath path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment