Issue #207: Zoom to Cursor (Zoom Anchoring)

This commit is contained in:
Jakub Melka 2024-08-31 19:25:08 +02:00
parent 2a93ca5a1f
commit b97e36ce0d
4 changed files with 32 additions and 10 deletions

View File

@ -1231,10 +1231,29 @@ QPoint PDFDrawWidgetProxy::scrollByPixels(QPoint offset)
return QPoint(m_horizontalOffset - oldHorizontalOffset, m_verticalOffset - oldVerticalOffset); return QPoint(m_horizontalOffset - oldHorizontalOffset, m_verticalOffset - oldVerticalOffset);
} }
void PDFDrawWidgetProxy::zoom(PDFReal zoom) void PDFDrawWidgetProxy::zoom(PDFReal zoom, std::optional<QPointF> widgetPosition)
{ {
const PDFReal clampedZoom = qBound(MIN_ZOOM, zoom, MAX_ZOOM); const PDFReal clampedZoom = qBound(MIN_ZOOM, zoom, MAX_ZOOM);
if (m_zoom != clampedZoom) if (m_zoom != clampedZoom)
{
if (widgetPosition.has_value())
{
QPointF point = widgetPosition.value();
const PDFReal posX = (m_horizontalOffset - point.x()) * m_pixelToDeviceSpaceUnit;
const PDFReal posY = (m_verticalOffset - point.y()) * m_pixelToDeviceSpaceUnit;
m_zoom = clampedZoom;
update();
const PDFReal hp = posX / m_pixelToDeviceSpaceUnit + point.x();
const PDFReal vp = posY / m_pixelToDeviceSpaceUnit + point.y();
setHorizontalOffset(hp);
setVerticalOffset(vp);
}
else
{ {
const PDFReal oldHorizontalOffsetMM = m_horizontalOffset * m_pixelToDeviceSpaceUnit; const PDFReal oldHorizontalOffsetMM = m_horizontalOffset * m_pixelToDeviceSpaceUnit;
const PDFReal oldVerticalOffsetMM = m_verticalOffset * m_pixelToDeviceSpaceUnit; const PDFReal oldVerticalOffsetMM = m_verticalOffset * m_pixelToDeviceSpaceUnit;
@ -1248,6 +1267,7 @@ void PDFDrawWidgetProxy::zoom(PDFReal zoom)
setVerticalOffset(oldVerticalOffsetMM * m_deviceSpaceUnitToPixel); setVerticalOffset(oldVerticalOffsetMM * m_deviceSpaceUnitToPixel);
} }
} }
}
PDFReal PDFDrawWidgetProxy::getZoomHint(ZoomHint hint) const PDFReal PDFDrawWidgetProxy::getZoomHint(ZoomHint hint) const
{ {

View File

@ -254,7 +254,8 @@ public:
/// Sets the zoom. Tries to preserve current offsets (so the current visible /// Sets the zoom. Tries to preserve current offsets (so the current visible
/// area will be visible after the zoom). /// area will be visible after the zoom).
/// \param zoom New zoom /// \param zoom New zoom
void zoom(PDFReal zoom); /// \param widgetPosition Position of the mouse during zooming
void zoom(PDFReal zoom, std::optional<QPointF> widgetPosition = std::nullopt);
enum class ZoomHint enum class ZoomHint
{ {

View File

@ -551,7 +551,7 @@ void PDFDrawWidget::wheelEvent(QWheelEvent* event)
const PDFReal zoom = m_widget->getDrawWidgetProxy()->getZoom(); const PDFReal zoom = m_widget->getDrawWidgetProxy()->getZoom();
const PDFReal zoomStep = std::pow(PDFDrawWidgetProxy::ZOOM_STEP, static_cast<PDFReal>(angleDeltaY) / static_cast<PDFReal>(QWheelEvent::DefaultDeltasPerStep)); const PDFReal zoomStep = std::pow(PDFDrawWidgetProxy::ZOOM_STEP, static_cast<PDFReal>(angleDeltaY) / static_cast<PDFReal>(QWheelEvent::DefaultDeltasPerStep));
const PDFReal newZoom = zoom * zoomStep; const PDFReal newZoom = zoom * zoomStep;
proxy->zoom(newZoom); proxy->zoom(newZoom, event->position());
} }
else else
{ {

View File

@ -1,4 +1,5 @@
CURRENT: CURRENT:
- Issue #207: Zoom to Cursor (Zoom Anchoring)
- Issue #185: Latest git fails to build in linux - Issue #185: Latest git fails to build in linux
V: 1.4.0.0 4.7.2024 V: 1.4.0.0 4.7.2024