fix selection rendering issues if rounding leads to left-out pixels

instead of manual qFloor, use the toAlignedRect() function to get the minimal enclosing rectangle
this will in some cases over-paint one-pixel, which is preferable to under-paint which
leaves gaps inside painting text lines that can not be fixed by the user of the painting routines

Task-number: QTBUG-66036
Change-Id: I8d6c2f7370e55bd544e1ff93d5c07b554b20ffeb
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Reviewed-by: Dominik Haumann <dhaumann@kde.org>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
bb10
Christoph Cullmann 2018-02-11 13:18:29 +01:00 committed by Dominik Haumann
parent 09e212eec0
commit 47904bb08a
1 changed files with 5 additions and 9 deletions

View File

@ -1006,10 +1006,8 @@ static void addSelectedRegionsToPath(QTextEngine *eng, int lineNumber, const QPo
}
if (lastSelectionWidth > 0) {
QRectF rect = boundingRect & QRectF(lastSelectionX.toReal(), selectionY, lastSelectionWidth.toReal(), lineHeight);
rect.moveLeft(qFloor(rect.left()));
rect.moveTop(qFloor(rect.top()));
region->addRect(rect);
const QRectF rect = boundingRect & QRectF(lastSelectionX.toReal(), selectionY, lastSelectionWidth.toReal(), lineHeight);
region->addRect(rect.toAlignedRect());
}
lastSelectionX = selectionX;
@ -1017,10 +1015,8 @@ static void addSelectedRegionsToPath(QTextEngine *eng, int lineNumber, const QPo
}
}
if (lastSelectionWidth > 0) {
QRectF rect = boundingRect & QRectF(lastSelectionX.toReal(), selectionY, lastSelectionWidth.toReal(), lineHeight);
rect.moveLeft(qFloor(rect.left()));
rect.moveTop(qFloor(rect.top()));
region->addRect(rect);
const QRectF rect = boundingRect & QRectF(lastSelectionX.toReal(), selectionY, lastSelectionWidth.toReal(), lineHeight);
region->addRect(rect.toAlignedRect());
}
}
@ -2135,7 +2131,7 @@ static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const Q
QBrush bg = chf.background();
if (bg.style() != Qt::NoBrush && !chf.property(SuppressBackground).toBool())
p->fillRect(QRectF(qFloor(r.x()), qFloor(r.y()), r.width(), r.height()), bg);
p->fillRect(r.toAlignedRect(), bg);
if (c.style() != Qt::NoBrush) {
p->setPen(QPen(c, 0));
}