mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-03-12 09:20:14 +01:00
Issue #207: Zoom to Cursor (Zoom Anchoring)
This commit is contained in:
parent
2a93ca5a1f
commit
b97e36ce0d
@ -1231,21 +1231,41 @@ 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)
|
||||||
{
|
{
|
||||||
const PDFReal oldHorizontalOffsetMM = m_horizontalOffset * m_pixelToDeviceSpaceUnit;
|
if (widgetPosition.has_value())
|
||||||
const PDFReal oldVerticalOffsetMM = m_verticalOffset * m_pixelToDeviceSpaceUnit;
|
{
|
||||||
|
QPointF point = widgetPosition.value();
|
||||||
|
|
||||||
m_zoom = clampedZoom;
|
const PDFReal posX = (m_horizontalOffset - point.x()) * m_pixelToDeviceSpaceUnit;
|
||||||
|
const PDFReal posY = (m_verticalOffset - point.y()) * m_pixelToDeviceSpaceUnit;
|
||||||
|
|
||||||
update();
|
m_zoom = clampedZoom;
|
||||||
|
|
||||||
// Try to restore offsets, so we are in the same place
|
update();
|
||||||
setHorizontalOffset(oldHorizontalOffsetMM * m_deviceSpaceUnitToPixel);
|
|
||||||
setVerticalOffset(oldVerticalOffsetMM * m_deviceSpaceUnitToPixel);
|
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 oldVerticalOffsetMM = m_verticalOffset * m_pixelToDeviceSpaceUnit;
|
||||||
|
|
||||||
|
m_zoom = clampedZoom;
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
// Try to restore offsets, so we are in the same place
|
||||||
|
setHorizontalOffset(oldHorizontalOffsetMM * m_deviceSpaceUnitToPixel);
|
||||||
|
setVerticalOffset(oldVerticalOffsetMM * m_deviceSpaceUnitToPixel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user