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.
This commit is contained in:
Nikola Nikolic 2022-09-09 18:03:34 +02:00
parent 04059bae4b
commit 69a2cc144f

View File

@ -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<double>(annotBoundingRect.left, annotBoundingRect.left + delta.x);
double right = qMax<double>(annotBoundingRect.right, annotBoundingRect.right + delta.x);
double top = qMin<double>(annotBoundingRect.top, annotBoundingRect.top + delta.y);
double bottom = qMax<double>(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<Page *> &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<double>(annotBoundingRect.left, annotBoundingRect.left + delta1.x);
const double right = qMax<double>(annotBoundingRect.right, annotBoundingRect.right + delta2.x);
const double top = qMin<double>(annotBoundingRect.top, annotBoundingRect.top + delta1.y);
const double bottom = qMax<double>(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<Page *> &newPagesVector)