From 69a2cc144fc64dcb2052a7d5a6930e652164292a Mon Sep 17 00:00:00 2001 From: Nikola Nikolic Date: Fri, 9 Sep 2022 18:03:34 +0200 Subject: [PATCH] Fix viewport transition when translating/resizing annotations Viewport isn't centered on annotations when translating/resizing. This is best seen if the page is zoomed in and annotation is translated so that several viewport transitions had happened. Using undo after translation will expose error. Function moveViewportIfBoundingRectNotFullyVisible centers viewport based on translated/resized annotation's bounding rectangle. For that reason functions translateBoundingRectangle/adjustBoundingRectangle need to return the same bounding rectangle as annotation's translate/adjust functions. --- core/documentcommands.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/documentcommands.cpp b/core/documentcommands.cpp index ead5eb22b..47c2e5730 100644 --- a/core/documentcommands.cpp +++ b/core/documentcommands.cpp @@ -233,12 +233,12 @@ Okular::NormalizedPoint TranslateAnnotationCommand::minusDelta() Okular::NormalizedRect TranslateAnnotationCommand::translateBoundingRectangle(const Okular::NormalizedPoint &delta) { Okular::NormalizedRect annotBoundingRect = m_annotation->boundingRectangle(); - double left = qMin(annotBoundingRect.left, annotBoundingRect.left + delta.x); - double right = qMax(annotBoundingRect.right, annotBoundingRect.right + delta.x); - double top = qMin(annotBoundingRect.top, annotBoundingRect.top + delta.y); - double bottom = qMax(annotBoundingRect.bottom, annotBoundingRect.bottom + delta.y); - Okular::NormalizedRect boundingRect(left, top, right, bottom); - return boundingRect; + annotBoundingRect.left = annotBoundingRect.left + delta.x; + annotBoundingRect.right = annotBoundingRect.right + delta.x; + annotBoundingRect.top = annotBoundingRect.top + delta.y; + annotBoundingRect.bottom = annotBoundingRect.bottom + delta.y; + + return annotBoundingRect; } bool TranslateAnnotationCommand::refreshInternalPageReferences(const QVector &newPagesVector) @@ -303,12 +303,13 @@ bool AdjustAnnotationCommand::mergeWith(const QUndoCommand *uc) Okular::NormalizedRect AdjustAnnotationCommand::adjustBoundingRectangle(const Okular::NormalizedPoint &delta1, const Okular::NormalizedPoint &delta2) { - const Okular::NormalizedRect annotBoundingRect = m_annotation->boundingRectangle(); - const double left = qMin(annotBoundingRect.left, annotBoundingRect.left + delta1.x); - const double right = qMax(annotBoundingRect.right, annotBoundingRect.right + delta2.x); - const double top = qMin(annotBoundingRect.top, annotBoundingRect.top + delta1.y); - const double bottom = qMax(annotBoundingRect.bottom, annotBoundingRect.bottom + delta2.y); - return Okular::NormalizedRect(left, top, right, bottom); + Okular::NormalizedRect annotBoundingRect = m_annotation->boundingRectangle(); + annotBoundingRect.left = annotBoundingRect.left + delta1.x; + annotBoundingRect.right = annotBoundingRect.right + delta2.x; + annotBoundingRect.top = annotBoundingRect.top + delta1.y; + annotBoundingRect.bottom = annotBoundingRect.bottom + delta2.y; + + return annotBoundingRect; } bool AdjustAnnotationCommand::refreshInternalPageReferences(const QVector &newPagesVector)