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);
|
Q_ASSERT(scale != 0);
|
||||||
d->zoomFactor = scale;
|
d->zoomFactor = scale;
|
||||||
render();
|
withFixedTextPosition([this] { render(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QLiteHtmlWidget::zoomFactor() const
|
qreal QLiteHtmlWidget::zoomFactor() const
|
||||||
@@ -559,17 +559,10 @@ static litehtml::element::ptr elementForY(int y, const litehtml::document::ptr &
|
|||||||
|
|
||||||
void QLiteHtmlWidget::resizeEvent(QResizeEvent *event)
|
void QLiteHtmlWidget::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
// remember element to which to scroll after re-rendering
|
withFixedTextPosition([this, event] {
|
||||||
QPoint viewportPos;
|
QAbstractScrollArea::resizeEvent(event);
|
||||||
QPoint pos;
|
render();
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QLiteHtmlWidget::mouseMoveEvent(QMouseEvent *event)
|
void QLiteHtmlWidget::mouseMoveEvent(QMouseEvent *event)
|
||||||
@@ -625,6 +618,20 @@ void QLiteHtmlWidget::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
emit contextMenuRequested(event->pos(), d->documentContainer.linkAt(pos, viewportPos));
|
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()
|
void QLiteHtmlWidget::render()
|
||||||
{
|
{
|
||||||
if (!d->documentContainer.document())
|
if (!d->documentContainer.document())
|
||||||
|
@@ -77,6 +77,7 @@ protected:
|
|||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void withFixedTextPosition(const std::function<void()> &action);
|
||||||
void render();
|
void render();
|
||||||
QPoint scrollPosition() const;
|
QPoint scrollPosition() const;
|
||||||
void htmlPos(const QPoint &pos, QPoint *viewportPos, QPoint *htmlPos) const;
|
void htmlPos(const QPoint &pos, QPoint *viewportPos, QPoint *htmlPos) const;
|
||||||
|
Reference in New Issue
Block a user