forked from qt-creator/qt-creator
litehtml: Fix selection artifacts with scaled view
If you zoom into a page (Ctrl-+) and then select, artifacts could be left behind when dragging or removing the selection again. Fiddle around with coordinate transformations (with regard to rounding) to fix that. Change-Id: I68c29d8e3559b90dbb3b93550338e483d14731bf Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -998,8 +998,9 @@ QVector<QRect> DocumentContainer::mouseMoveEvent(const QPoint &documentPos,
|
||||
viewportPos,
|
||||
m_selection.mode);
|
||||
if (element.element) {
|
||||
redrawRects.append(
|
||||
m_selection.boundingRect() /*.adjusted(-1, -1, +1, +1)*/); // redraw old selection area
|
||||
m_selection.endElem = element;
|
||||
redrawRects.append(m_selection.boundingRect()); // redraw old selection area
|
||||
m_selection.update();
|
||||
redrawRects.append(m_selection.boundingRect());
|
||||
}
|
||||
|
@@ -664,21 +664,11 @@ QPoint QLiteHtmlWidget::toVirtual(const QPoint &p) const
|
||||
return {int(p.x() / d->zoomFactor), int(p.y() / d->zoomFactor)};
|
||||
}
|
||||
|
||||
QPoint QLiteHtmlWidget::fromVirtual(const QPoint &p) const
|
||||
{
|
||||
return {int(p.x() * d->zoomFactor), int(p.y() * d->zoomFactor)};
|
||||
}
|
||||
|
||||
QSize QLiteHtmlWidget::toVirtual(const QSize &s) const
|
||||
{
|
||||
return {int(s.width() / d->zoomFactor), int(s.height() / d->zoomFactor)};
|
||||
}
|
||||
|
||||
QSize QLiteHtmlWidget::fromVirtual(const QSize &s) const
|
||||
{
|
||||
return {int(s.width() * d->zoomFactor + 0.5), int(s.height() * d->zoomFactor + 0.5)};
|
||||
}
|
||||
|
||||
QRect QLiteHtmlWidget::toVirtual(const QRect &r) const
|
||||
{
|
||||
return {toVirtual(r.topLeft()), toVirtual(r.size())};
|
||||
@@ -686,5 +676,9 @@ QRect QLiteHtmlWidget::toVirtual(const QRect &r) const
|
||||
|
||||
QRect QLiteHtmlWidget::fromVirtual(const QRect &r) const
|
||||
{
|
||||
return {fromVirtual(r.topLeft()), fromVirtual(r.size())};
|
||||
const QPoint tl{int(r.x() * d->zoomFactor), int(r.y() * d->zoomFactor)};
|
||||
// round size up, and add one since the topleft point was rounded down
|
||||
const QSize s{int(r.width() * d->zoomFactor + 0.5) + 1,
|
||||
int(r.height() * d->zoomFactor + 0.5) + 1};
|
||||
return {tl, s};
|
||||
}
|
||||
|
@@ -82,9 +82,7 @@ private:
|
||||
QPoint scrollPosition() const;
|
||||
void htmlPos(const QPoint &pos, QPoint *viewportPos, QPoint *htmlPos) const;
|
||||
QPoint toVirtual(const QPoint &p) const;
|
||||
QPoint fromVirtual(const QPoint &p) const;
|
||||
QSize toVirtual(const QSize &s) const;
|
||||
QSize fromVirtual(const QSize &s) const;
|
||||
QRect toVirtual(const QRect &r) const;
|
||||
QRect fromVirtual(const QRect &r) const;
|
||||
|
||||
|
Reference in New Issue
Block a user