forked from qt-creator/qt-creator
Help/litehtml: Keep top position also when zooming
Change-Id: I65e12d4fca33719bc1a3ae08f7871d08d8d9c449 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -439,7 +439,7 @@ void QLiteHtmlWidget::setZoomFactor(qreal scale)
|
||||
{
|
||||
Q_ASSERT(scale != 0);
|
||||
d->zoomFactor = scale;
|
||||
render();
|
||||
withFixedTextPosition([this] { render(); });
|
||||
}
|
||||
|
||||
qreal QLiteHtmlWidget::zoomFactor() const
|
||||
@@ -559,17 +559,10 @@ static litehtml::element::ptr elementForY(int y, const litehtml::document::ptr &
|
||||
|
||||
void QLiteHtmlWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
// remember element to which to scroll after re-rendering
|
||||
QPoint viewportPos;
|
||||
QPoint pos;
|
||||
htmlPos({}, &viewportPos, &pos); // top-left
|
||||
const litehtml::element::ptr element = elementForY(pos.y(), d->documentContainer.document());
|
||||
QAbstractScrollArea::resizeEvent(event);
|
||||
render();
|
||||
if (element) {
|
||||
verticalScrollBar()->setValue(
|
||||
std::min(element->get_placement().y, verticalScrollBar()->maximum()));
|
||||
}
|
||||
withFixedTextPosition([this, event] {
|
||||
QAbstractScrollArea::resizeEvent(event);
|
||||
render();
|
||||
});
|
||||
}
|
||||
|
||||
void QLiteHtmlWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
@@ -625,6 +618,20 @@ void QLiteHtmlWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||
emit contextMenuRequested(event->pos(), d->documentContainer.linkAt(pos, viewportPos));
|
||||
}
|
||||
|
||||
void QLiteHtmlWidget::withFixedTextPosition(const std::function<void()> &action)
|
||||
{
|
||||
// remember element to which to scroll after re-rendering
|
||||
QPoint viewportPos;
|
||||
QPoint pos;
|
||||
htmlPos({}, &viewportPos, &pos); // top-left
|
||||
const litehtml::element::ptr element = elementForY(pos.y(), d->documentContainer.document());
|
||||
action();
|
||||
if (element) {
|
||||
verticalScrollBar()->setValue(
|
||||
std::min(element->get_placement().y, verticalScrollBar()->maximum()));
|
||||
}
|
||||
}
|
||||
|
||||
void QLiteHtmlWidget::render()
|
||||
{
|
||||
if (!d->documentContainer.document())
|
||||
|
@@ -77,6 +77,7 @@ protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
|
||||
private:
|
||||
void withFixedTextPosition(const std::function<void()> &action);
|
||||
void render();
|
||||
QPoint scrollPosition() const;
|
||||
void htmlPos(const QPoint &pos, QPoint *viewportPos, QPoint *htmlPos) const;
|
||||
|
Reference in New Issue
Block a user