Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix drifiting of the canvas when zooming and rotating
Dmitry Kazakovdae0d6e1b294
diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txtindex 45b691d775..ce8cb1d61f 100644--- a/libs/flake/CMakeLists.txt+++ b/libs/flake/CMakeLists.txt@@ -106,6 +106,7 @@ set(kritaflake_SRCSKoSharedLoadingData.cppKoSharedSavingData.cppKoViewConverter.cpp+ KoViewTransformStillPoint.cppKoFilterEffect.cppKoFilterEffectStack.cppKoFilterEffectFactoryBase.cppdiff --git a/libs/flake/KoCanvasController.h b/libs/flake/KoCanvasController.hindex bc620d622f..cc8a3b3e8d 100644--- a/libs/flake/KoCanvasController.h+++ b/libs/flake/KoCanvasController.h@@ -29,6 +29,7 @@ class QRectF;class KoShape;class KoCanvasBase;class KoCanvasControllerProxyObject;+class KoViewTransformStillPoint;/*** KoCanvasController is the base class for wrappers around your canvas@@ -99,25 +100,15 @@ public:virtual void ensureVisibleDoc(const QRectF &docRect, bool smooth) = 0;/**- * @brief zooms in around the center.- *- * The center must be specified in **widget** coordinates. The scrollbar positions- * are changed so that the center becomes center if possible.- *- * @param center the position to zoom in on+ * @brief zooms in keeping @p stillPoint not moved.*/- virtual void zoomIn(const QPoint ¢er) = 0;+ virtual void zoomIn(const KoViewTransformStillPoint &stillPoint) = 0;virtual void zoomIn() = 0;/**- * @brief zooms out around the center.- *- * The center must be specified in **widget** coordinates. The scrollbar positions- * are changed so that the center becomes center if possible.- *- * @param center the position to zoom out around+ * @brief zooms out keeping @p stillPoint not moved.*/- virtual void zoomOut(const QPoint ¢er) = 0;+ virtual void zoomOut(const KoViewTransformStillPoint &stillPoint) = 0;virtual void zoomOut() = 0;/**diff --git a/libs/flake/KoViewTransformStillPoint.cpp b/libs/flake/KoViewTransformStillPoint.cppnew file mode 100644index 0000000000..2c78124f12--- /dev/null+++ b/libs/flake/KoViewTransformStillPoint.cpp@@ -0,0 +1,32 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include <QDebug>+#include "KoViewTransformStillPoint.h"++KoViewTransformStillPoint::KoViewTransformStillPoint(const QPointF &docPoint, const QPointF &viewPoint)+ : std::pair<QPointF, QPointF>(docPoint, viewPoint)+{+}++KoViewTransformStillPoint::KoViewTransformStillPoint(const std::pair<QPointF, QPointF> &rhs)+ : std::pair<QPointF, QPointF>(rhs)+{+}++QPointF KoViewTransformStillPoint::docPoint() const {+ return first;+}++QPointF KoViewTransformStillPoint::viewPoint() const {+ return second;+}++QDebug operator<<(QDebug dbg, const KoViewTransformStillPoint &point)+{+ dbg.nospace() << "KoViewTransformStillPoint(docPoint: " << point.docPoint() << ", viewPoint: " << point.viewPoint() << ")";+ return dbg.space();+}\ No newline at end of filediff --git a/libs/flake/KoViewTransformStillPoint.h b/libs/flake/KoViewTransformStillPoint.hnew file mode 100644index 0000000000..98ac0189a4--- /dev/null+++ b/libs/flake/KoViewTransformStillPoint.h@@ -0,0 +1,51 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#ifndef KOVIEWTRANSFORMSTILLPOINT_H+#define KOVIEWTRANSFORMSTILLPOINT_H++#include <kritaflake_export.h>+#include <QPointF>+#include <utility>++class KisCoordinatesConverter;++/**+ * A special class the defines a "still point" for the transformations+ * applied to the canvas. "Still point" is defined as a point that does+ * not move on screen when a transformation happens. For example, when+ * rotating the canvas, the center of rotation does not move, hence+ * it is considered as a "still point".+ *+ * A lot of canvas operations in Krita cannot guarantee that the+ * point will precisely "stand still" during transformation. It may+ * happen that the canvas will be slightly moved to the side to ensure+ * that it is aligned to the hardware pixels.+ *+ * In such cases we should remember what was our original intention in+ * positioning the image on the canvas. We should remember both, the+ * image point and the widget point. Otherwise slight and unpleasant+ * drifts will happen when the user zooms or rotates the image.+ */+class KRITAFLAKE_EXPORT KoViewTransformStillPoint : public std::pair<QPointF, QPointF>+{+public:+ KoViewTransformStillPoint() = default;+ KoViewTransformStillPoint(const QPointF &docPoint, const QPointF &viewPoint);+ KoViewTransformStillPoint(const std::pair<QPointF, QPointF> &rhs);++ KoViewTransformStillPoint(const KoViewTransformStillPoint &rhs) = default;+ KoViewTransformStillPoint(KoViewTransformStillPoint &&rhs) = default;+ KoViewTransformStillPoint& operator=(const KoViewTransformStillPoint &rhs) = default;+ KoViewTransformStillPoint& operator=(KoViewTransformStillPoint &&rhs) = default;++ QPointF docPoint() const;+ QPointF viewPoint() const;+};++KRITAFLAKE_EXPORT QDebug operator<<(QDebug dbg, const KoViewTransformStillPoint &point);++#endif // KOVIEWTRANSFORMSTILLPOINT_H\ No newline at end of filediff --git a/libs/flake/tools/KoZoomStrategy.cpp b/libs/flake/tools/KoZoomStrategy.cppindex 884b969661..aa4660f414 100644--- a/libs/flake/tools/KoZoomStrategy.cpp+++ b/libs/flake/tools/KoZoomStrategy.cpp@@ -11,6 +11,7 @@#include "KoCanvasBase.h"#include "KoCanvasController.h"#include "KoViewConverter.h"+#include "KoViewTransformStillPoint.h"#include <FlakeDebug.h>@@ -37,12 +38,18 @@ void KoZoomStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)if (modifiers & Qt::ControlModifier) {m_zoomOut = !m_zoomOut;}++ auto makeStillPoint = [&] () -> KoViewTransformStillPoint {+ const QPointF center = pixelRect.center();+ return { m_controller->canvas()->viewConverter()->viewToDocument(center), center };+ };+if (m_zoomOut) {- m_controller->zoomOut(pixelRect.center());+ m_controller->zoomOut(makeStillPoint());} else if (pixelRect.width() > 5 && pixelRect.height() > 5) {m_controller->zoomTo(pixelRect);} else {- m_controller->zoomIn(pixelRect.center());+ m_controller->zoomIn(makeStillPoint());}}diff --git a/libs/ui/canvas/KoCanvasControllerWidget.cpp b/libs/ui/canvas/KoCanvasControllerWidget.cppindex fc569cb264..ed31038b91 100644--- a/libs/ui/canvas/KoCanvasControllerWidget.cpp+++ b/libs/ui/canvas/KoCanvasControllerWidget.cpp@@ -31,6 +31,7 @@#include <QOpenGLWidget>#include <KisCanvasState.h>+#include <KoViewTransformStillPoint.h>#include <math.h>#include <kis_debug.h>@@ -287,20 +288,15 @@ void KoCanvasControllerWidget::dragLeaveEvent(QDragLeaveEvent *event)d->viewportWidget->handleDragLeaveEvent(event);}-void KoCanvasControllerWidget::zoomRelativeToPoint(const QPointF &widgetPoint, qreal zoomCoeff)-{- const qreal newZoom = d->canvas->viewConverter()->zoom() * zoomCoeff;- setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, widgetPoint);-}-void KoCanvasControllerWidget::setZoom(KoZoomMode::Mode mode, qreal zoom){- setZoom(mode, zoom, QRectF(QPointF(), canvasState().canvasSize).center());+ KoZoomHandler *zoomHandler = dynamic_cast<KoZoomHandler*>(d->canvas->viewConverter());+ KIS_SAFE_ASSERT_RECOVER_RETURN(zoomHandler);+ setZoom(mode, zoom, zoomHandler->resolutionX(), zoomHandler->resolutionY(), std::nullopt);}-void KoCanvasControllerWidget::setZoom(KoZoomMode::Mode mode, qreal zoom, const QPointF &stillPoint)+void KoCanvasControllerWidget::setZoom(KoZoomMode::Mode mode, qreal zoom, const KoViewTransformStillPoint &stillPoint){-KoZoomHandler *zoomHandler = dynamic_cast<KoZoomHandler*>(d->canvas->viewConverter());KIS_SAFE_ASSERT_RECOVER_RETURN(zoomHandler);setZoom(mode, zoom, zoomHandler->resolutionX(), zoomHandler->resolutionY(), stillPoint);@@ -308,15 +304,13 @@ void KoCanvasControllerWidget::setZoom(KoZoomMode::Mode mode, qreal zoom, constvoid KoCanvasControllerWidget::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY){- setZoom(mode, zoom, resolutionX, resolutionY, QRectF(QPointF(), canvasState().canvasSize).center());+ setZoom(mode, zoom, resolutionX, resolutionY, std::nullopt);}-void KoCanvasControllerWidget::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint)+void KoCanvasControllerWidget::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &stillPoint){const KisCanvasState oldCanvasState = canvasState();-updateCanvasZoomInternal(mode, zoom, resolutionX, resolutionY, stillPoint);-const KisCanvasState newCanvasState = canvasState();emitSignals(oldCanvasState, newCanvasState);diff --git a/libs/ui/canvas/KoCanvasControllerWidget.h b/libs/ui/canvas/KoCanvasControllerWidget.hindex 69d63e2de1..639f9abf34 100644--- a/libs/ui/canvas/KoCanvasControllerWidget.h+++ b/libs/ui/canvas/KoCanvasControllerWidget.h@@ -22,6 +22,7 @@ class KoShape;class KoCanvasBase;class KoCanvasSupervisor;class KisCanvasState;+class KoViewTransformStillPoint;/*** KoCanvasController implementation for QWidget based canvases@@ -76,18 +77,11 @@ public:void zoomTo(const QRect &rect) override;- /**- * Zoom document keeping point \p widgetPoint unchanged- * \param widgetPoint sticky point in widget pixels- * \param zoomCoeff the coefficient to which zoom will be changed- */- Q_DECL_DEPRECATED_X("use setZoom() with absolute zoom value instead")- void zoomRelativeToPoint(const QPointF &widgetPoint, qreal zoomCoeff);-void setZoom(KoZoomMode::Mode mode, qreal zoom) override;- void setZoom(KoZoomMode::Mode mode, qreal zoom, const QPointF &stillPoint);void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY);- void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint);++ void setZoom(KoZoomMode::Mode mode, qreal zoom, const KoViewTransformStillPoint &stillPoint);+ void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &docStillPoint);void pan(const QPoint &distance) override;@@ -135,7 +129,7 @@ protected:virtual void updateCanvasOffsetInternal(const QPointF &newOffset) = 0;virtual void updateCanvasWidgetSizeInternal(const QSize &newSize) = 0;- virtual void updateCanvasZoomInternal(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint) = 0;+ virtual void updateCanvasZoomInternal(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &docStillPoint) = 0;virtual void zoomToInternal(const QRect &viewRect) = 0;void emitSignals(const KisCanvasState &oldState, const KisCanvasState &newState);diff --git a/libs/ui/canvas/kis_canvas_controller.cpp b/libs/ui/canvas/kis_canvas_controller.cppindex 85e23b482a..682e7d25ce 100644--- a/libs/ui/canvas/kis_canvas_controller.cpp+++ b/libs/ui/canvas/kis_canvas_controller.cpp@@ -25,6 +25,7 @@#include "kis_signal_compressor_with_param.h"#include "kis_config_notifier.h"#include <KoUnit.h>+#include <KoViewTransformStillPoint.h>#include "KisCanvasState.h"@@ -223,10 +224,10 @@ void KisCanvasController::Private::showMirrorStateOnCanvas()QIcon(), 500, KisFloatingMessage::Low);}-void KisCanvasController::mirrorCanvasImpl(const QPointF &widgetPoint, bool enable)+void KisCanvasController::mirrorCanvasImpl(const std::optional<KoViewTransformStillPoint> &stillPoint, bool enable){const KisCanvasState oldCanvasState = canvasState();- m_d->coordinatesConverter->mirror(widgetPoint, enable, false);+ m_d->coordinatesConverter->mirror(stillPoint, enable, false);const KisCanvasState newCanvasState = canvasState();emitSignals(oldCanvasState, newCanvasState);@@ -235,7 +236,7 @@ void KisCanvasController::mirrorCanvasImpl(const QPointF &widgetPoint, bool enabvoid KisCanvasController::mirrorCanvas(bool enable){- mirrorCanvasImpl(m_d->coordinatesConverter->widgetCenterPoint(), enable);+ mirrorCanvasImpl(std::nullopt, enable);}void KisCanvasController::mirrorCanvasAroundCursor(bool enable)@@ -246,19 +247,23 @@ void KisCanvasController::mirrorCanvasAroundCursor(bool enable): QCursor::pos();KoCanvasBase* canvas = m_d->view->canvasBase();QWidget *canvasWidget = canvas->canvasWidget();- QPointF cursorPosWidget = canvasWidget->mapFromGlobal(pos);-- if (!canvasWidget->rect().contains(cursorPosWidget.toPoint())) {- cursorPosWidget = m_d->coordinatesConverter->widgetCenterPoint();+ const QPointF cursorPosWidget = canvasWidget->mapFromGlobal(pos);++ std::optional<KoViewTransformStillPoint> stillPoint;++ if (canvasWidget->rect().contains(cursorPosWidget.toPoint())) {+ stillPoint = m_d->coordinatesConverter->makeViewStillPoint(cursorPosWidget);}-- mirrorCanvasImpl(cursorPosWidget, enable);++ mirrorCanvasImpl(stillPoint, enable);}void KisCanvasController::mirrorCanvasAroundCanvas(bool enable){- const QPointF center = m_d->coordinatesConverter->imageCenterInWidgetPixel();- mirrorCanvasImpl(center, enable);+ auto stillPoint =+ m_d->coordinatesConverter->makeDocStillPoint(+ m_d->coordinatesConverter->imageRectInDocumentPixels().center());+ mirrorCanvasImpl(stillPoint, enable);}void KisCanvasController::Private::showRotationValueOnCanvas()@@ -281,13 +286,13 @@ void KisCanvasController::endCanvasRotation()m_d->coordinatesConverter->endRotation();}-void KisCanvasController::rotateCanvas(qreal angle, const QPointF ¢er, bool isNativeGesture)+void KisCanvasController::rotateCanvas(qreal angle, const std::optional<KoViewTransformStillPoint> &stillPoint, bool isNativeGesture){if(isNativeGesture) {m_d->coordinatesConverter->enableNatureGestureFlag();}const KisCanvasState oldCanvasState = canvasState();- m_d->coordinatesConverter->rotate(center, angle);+ m_d->coordinatesConverter->rotate(stillPoint, angle);const KisCanvasState newCanvasState = canvasState();emitSignals(oldCanvasState, newCanvasState);@@ -296,7 +301,7 @@ void KisCanvasController::rotateCanvas(qreal angle, const QPointF ¢er, boolvoid KisCanvasController::rotateCanvas(qreal angle){- rotateCanvas(angle, m_d->coordinatesConverter->widgetCenterPoint());+ rotateCanvas(angle, std::nullopt);}void KisCanvasController::rotateCanvasRight15()@@ -317,7 +322,7 @@ qreal KisCanvasController::rotation() constvoid KisCanvasController::resetCanvasRotation(){const KisCanvasState oldCanvasState = canvasState();- m_d->coordinatesConverter->resetRotation(m_d->coordinatesConverter->widgetCenterPoint());+ m_d->coordinatesConverter->resetRotation(std::nullopt);const KisCanvasState newCanvasState = canvasState();emitSignals(oldCanvasState, newCanvasState);@@ -478,10 +483,11 @@ void KisCanvasController::syncOnImageResolutionChange()if (!m_d->usePrintResolutionMode) {m_d->coordinatesConverter->setZoom(m_d->coordinatesConverter->zoomMode(),- m_d->coordinatesConverter->zoom(),- effectiveCanvasResolutionX(),- effectiveCanvasResolutionY(),- m_d->coordinatesConverter->imageCenterInWidgetPixel());+ m_d->coordinatesConverter->zoom(),+ effectiveCanvasResolutionX(),+ effectiveCanvasResolutionY(),+ m_d->coordinatesConverter->makeViewStillPoint(+ m_d->coordinatesConverter->imageCenterInWidgetPixel()));}const KisCanvasState newCanvasState = canvasState();@@ -512,9 +518,9 @@ void KisCanvasController::updateCanvasWidgetSizeInternal(const QSize &newSize)m_d->coordinatesConverter->setCanvasWidgetSizeKeepZoom(newSize);}-void KisCanvasController::updateCanvasZoomInternal(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint)+void KisCanvasController::updateCanvasZoomInternal(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &docStillPoint){- m_d->coordinatesConverter->setZoom(mode, zoom, resolutionX, resolutionY, stillPoint);+ m_d->coordinatesConverter->setZoom(mode, zoom, resolutionX, resolutionY, docStillPoint);}KisCanvasState KisCanvasController::canvasState() const@@ -545,27 +551,45 @@ void KisCanvasController::setPreferredCenter(const QPointF &viewPoint)void KisCanvasController::zoomIn(){- zoomIn(m_d->coordinatesConverter->widgetCenterPoint().toPoint());+ zoomInImpl(std::nullopt);}void KisCanvasController::zoomOut(){- zoomOut(m_d->coordinatesConverter->widgetCenterPoint().toPoint());+ zoomOutImpl(std::nullopt);+}++void KisCanvasController::zoomIn(const KoViewTransformStillPoint &stillPoint)+{+ zoomInImpl(stillPoint);}-void KisCanvasController::zoomIn(const QPoint ¢er)+void KisCanvasController::zoomOut(const KoViewTransformStillPoint &stillPoint)+{+ zoomOutImpl(stillPoint);+}++void KisCanvasController::zoomInImpl(const std::optional<KoViewTransformStillPoint> &stillPoint){const qreal newZoom = KisCoordinatesConverter::findNextZoom(m_d->coordinatesConverter->zoom(), m_d->coordinatesConverter->standardZoomLevels());if (!qFuzzyCompare(newZoom, m_d->coordinatesConverter->zoom())) {- setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, center);+ if (stillPoint) {+ setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, *stillPoint);+ } else {+ setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom);+ }}}-void KisCanvasController::zoomOut(const QPoint ¢er)+void KisCanvasController::zoomOutImpl(const std::optional<KoViewTransformStillPoint> &stillPoint){const qreal newZoom = KisCoordinatesConverter::findPrevZoom(m_d->coordinatesConverter->zoom(), m_d->coordinatesConverter->standardZoomLevels());if (!qFuzzyCompare(newZoom, m_d->coordinatesConverter->zoom())) {- setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, center);+ if (stillPoint) {+ setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, *stillPoint);+ } else {+ setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom);+ }}}diff --git a/libs/ui/canvas/kis_canvas_controller.h b/libs/ui/canvas/kis_canvas_controller.hindex 6ae8b524d8..44fd753ceb 100644--- a/libs/ui/canvas/kis_canvas_controller.h+++ b/libs/ui/canvas/kis_canvas_controller.h@@ -19,6 +19,7 @@ class KConfigGroup;class KisView;class KisCanvasState;+class KRITAUI_EXPORT KisCanvasController : public KoCanvasControllerWidget{Q_OBJECT@@ -43,14 +44,16 @@ public:void setPreferredCenter(const QPointF &viewPoint) override;void zoomIn() override;- void zoomIn(const QPoint ¢er) override;+ void zoomIn(const KoViewTransformStillPoint &widgetStillPoint) override;void zoomOut() override;- void zoomOut(const QPoint ¢er) override;+ void zoomOut(const KoViewTransformStillPoint &widgetStillPoint) override;void syncOnReferencesChange(const QRectF &referencesRect);void syncOnImageResolutionChange();void syncOnImageSizeChange(const QPointF &oldStillPoint, const QPointF &newStillPoint);+ void rotateCanvas(qreal angle, const std::optional<KoViewTransformStillPoint> &stillPoint, bool isNativeGesture = false);+public:bool wrapAroundMode() const;WrapAroundAxis wrapAroundModeAxis() const;@@ -76,7 +79,6 @@ public Q_SLOTS:void beginCanvasRotation();void endCanvasRotation();- void rotateCanvas(qreal angle, const QPointF ¢er, bool isNativeGesture = false);void rotateCanvas(qreal angle);void rotateCanvasRight15();void rotateCanvasLeft15();@@ -94,11 +96,13 @@ public Q_SLOTS:protected:void updateCanvasOffsetInternal(const QPointF &newOffset) override;void updateCanvasWidgetSizeInternal(const QSize &newSize) override;- void updateCanvasZoomInternal(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint) override;+ void updateCanvasZoomInternal(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &docStillPoint) override;void zoomToInternal(const QRect &viewRect) override;private:- void mirrorCanvasImpl(const QPointF &widgetPoint, bool enable);+ void zoomInImpl(const std::optional<KoViewTransformStillPoint> &stillPoint);+ void zoomOutImpl(const std::optional<KoViewTransformStillPoint> &stillPoint);+ void mirrorCanvasImpl(const std::optional<KoViewTransformStillPoint> &stillPoint, bool enable);Q_SIGNALS:void documentSizeChanged();diff --git a/libs/ui/canvas/kis_coordinates_converter.cpp b/libs/ui/canvas/kis_coordinates_converter.cppindex 6357b319bc..8182e23393 100644--- a/libs/ui/canvas/kis_coordinates_converter.cpp+++ b/libs/ui/canvas/kis_coordinates_converter.cpp@@ -8,6 +8,7 @@#include <cmath>#include "kis_coordinates_converter.h"+#include "KoViewTransformStillPoint.h"#include <QtMath>#include <QTransform>@@ -31,6 +32,7 @@ struct KisCoordinatesConverter::Private {isNativeGesture(false),rotationAngle(0.0),rotationBaseAngle(0.0),+ rotationIsOrthogonal(true),devicePixelRatio(1.0),standardZoomLevels(this){@@ -47,9 +49,11 @@ struct KisCoordinatesConverter::Private {bool isNativeGesture;qreal rotationAngle;qreal rotationBaseAngle;+ bool rotationIsOrthogonal;QSizeF canvasWidgetSize;qreal devicePixelRatio;QPointF documentOffset;+ QPointF preferredTransformationCenterImage;QPoint minimumOffset;QPoint maximumOffset;@@ -69,6 +73,10 @@ struct KisCoordinatesConverter::Private {QTransform imageToDocument;QTransform documentToFlake;QTransform widgetToViewport;++ QPointF preferredTransformationCenterInDocumentPixels() const {+ return imageToDocument.map(preferredTransformationCenterImage);+ }};/**@@ -176,6 +184,11 @@ void KisCoordinatesConverter::correctTransformationToOffset()m_d->flakeToWidget *= QTransform::fromTranslate(diff.x(), diff.y());}+void KisCoordinatesConverter::resetPreferredTransformationCenter()+{+ m_d->preferredTransformationCenterImage = widgetToImage(this->widgetCenterPoint());+}+void KisCoordinatesConverter::recalculateTransformations(){m_d->imageToDocument = QTransform::fromScale(1 / m_d->imageXRes,@@ -217,6 +230,10 @@ void KisCoordinatesConverter::setCanvasWidgetSize(QSizeF size){m_d->canvasWidgetSize = snapWidgetSizeToDevicePixel(size);recalculateTransformations();++ // the widget center has changed, hence the preferred+ // center changes as well+ resetPreferredTransformationCenter();}void KisCoordinatesConverter::setDevicePixelRatio(qreal value)@@ -242,9 +259,10 @@ void KisCoordinatesConverter::setImage(KisImageWSP image)// proposed mode and postpone the actual recentering of the image// (this case is supposed to happen in unittests only)KoZoomHandler::setZoomMode(KoZoomMode::ZOOM_PAGE);+ m_d->preferredTransformationCenterImage = m_d->imageBounds.center();} else {// the default mode after initialization is "Zoom Page"- setZoom(KoZoomMode::ZOOM_PAGE, 777.7, resolutionX(), resolutionY(), QPointF(8888.8, 9999.9));+ setZoom(KoZoomMode::ZOOM_PAGE, 777.7, resolutionX(), resolutionY(), std::nullopt);}}@@ -275,6 +293,8 @@ void KisCoordinatesConverter::setImageBounds(const QRect &rect, const QPointF olconst QPointF newWidgetStillPoint = imageToWidget(newImageStillPoint);m_d->documentOffset = snapToDevicePixel(m_d->documentOffset + newWidgetStillPoint - oldWidgetStillPoint);recalculateTransformations();++ resetPreferredTransformationCenter();}void KisCoordinatesConverter::setImageResolution(qreal xRes, qreal yRes)@@ -302,6 +322,8 @@ void KisCoordinatesConverter::setImageResolution(qreal xRes, qreal yRes)const QPointF newImageCenter = imageCenterInWidgetPixel();m_d->documentOffset = snapToDevicePixel(m_d->documentOffset + newImageCenter - oldImageCenter);recalculateTransformations();++ resetPreferredTransformationCenter();}void KisCoordinatesConverter::setDocumentOffset(const QPointF& offset)@@ -323,6 +345,8 @@ void KisCoordinatesConverter::setDocumentOffset(const QPointF& offset)m_d->documentOffset = snapToDevicePixel(offset);recalculateTransformations();++ resetPreferredTransformationCenter();}qreal KisCoordinatesConverter::devicePixelRatio() const@@ -340,6 +364,11 @@ QPointF KisCoordinatesConverter::documentOffsetF() constreturn m_d->documentOffset;}+QPointF KisCoordinatesConverter::preferredTransformationCenter() const+{+ return m_d->preferredTransformationCenterImage;+}+qreal KisCoordinatesConverter::rotationAngle() const{return m_d->rotationAngle;@@ -353,6 +382,7 @@ void KisCoordinatesConverter::setZoom(qreal zoom)KoZoomHandler::setZoom(zoom);recalculateTransformations();+ resetPreferredTransformationCenter();}void KisCoordinatesConverter::setCanvasWidgetSizeKeepZoom(const QSizeF &size)@@ -370,7 +400,7 @@ void KisCoordinatesConverter::setCanvasWidgetSizeKeepZoom(const QSizeF &size)* canvas before transformation to calculate the position of the still point,* hence we cannot change the state separately.*/- setZoom(zoomMode(), 777.0, resolutionX(), resolutionY(), QPointF(8888.8, 9999.9));+ setZoom(zoomMode(), 777.0, resolutionX(), resolutionY(), std::nullopt);}}@@ -400,7 +430,7 @@ QSize KisCoordinatesConverter::viewportDevicePixelSize() const(m_d->canvasWidgetSize * m_d->devicePixelRatio).toSize();}-void KisCoordinatesConverter::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint)+void KisCoordinatesConverter::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &stillPoint){const int cfgMargin = zoomMarginSize();@@ -418,18 +448,24 @@ void KisCoordinatesConverter::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal r/// fit-modes are allowed to zoom as much as neededzoom = clampZoom(zoom);- const QPointF oldStillPointInImagePixels =- widgetToImage(stillPoint);+ KoViewTransformStillPoint effectiveStillPoint =+ stillPoint ? *stillPoint :+ KoViewTransformStillPoint(m_d->preferredTransformationCenterInDocumentPixels(), widgetCenterPoint());updateDisplayResolution();KoZoomHandler::setZoom(zoom);KoZoomHandler::setZoomMode(mode);recalculateTransformations();- const QPointF newStillPoint = imageToWidget(oldStillPointInImagePixels);- const QPointF offset = newStillPoint - stillPoint;+ const QPointF newStillPoint = documentToWidget(effectiveStillPoint.docPoint());+ const QPointF offset = newStillPoint - effectiveStillPoint.viewPoint();m_d->documentOffset = snapToDevicePixel(m_d->documentOffset + offset);recalculateTransformations();++ if (stillPoint) {+ resetPreferredTransformationCenter();+ }+} else if (mode == KoZoomMode::ZOOM_PAGE || mode == KoZoomMode::ZOOM_WIDTH || mode == KoZoomMode::ZOOM_HEIGHT) {updateDisplayResolution();recalculateTransformations();@@ -469,6 +505,8 @@ void KisCoordinatesConverter::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal rm_d->documentOffset = snapToDevicePixel(newDocumentOffset);recalculateTransformations();++ resetPreferredTransformationCenter();}}@@ -492,6 +530,8 @@ void KisCoordinatesConverter::zoomTo(const QRectF &zoomRectWidget)m_d->documentOffset = snapToDevicePixel(newDocumentOffset);recalculateTransformations();++ resetPreferredTransformationCenter();}qreal KisCoordinatesConverter::effectiveZoom() const@@ -543,10 +583,14 @@ void KisCoordinatesConverter::endRotation()m_d->isRotating = false;}-void KisCoordinatesConverter::rotate(QPointF center, qreal angle)+void KisCoordinatesConverter::rotate(const std::optional<KoViewTransformStillPoint> &stillPoint, qreal angle){setZoomMode(KoZoomMode::ZOOM_CONSTANT);+ KoViewTransformStillPoint effectiveStillPoint =+ stillPoint ? *stillPoint :+ KoViewTransformStillPoint(m_d->preferredTransformationCenterInDocumentPixels(), widgetCenterPoint());+QTransform rot;rot.rotate(angle);@@ -562,19 +606,35 @@ void KisCoordinatesConverter::rotate(QPointF center, qreal angle)m_d->rotationAngle = std::fmod(m_d->rotationAngle + angle, 360.0);}- m_d->flakeToWidget *= QTransform::fromTranslate(-center.x(),-center.y());- m_d->flakeToWidget *= rot;- m_d->flakeToWidget *= QTransform::fromTranslate(center.x(), center.y());+ {+ const qreal numQuadrants = m_d->rotationAngle / 90.0;+ m_d->rotationIsOrthogonal = std::floor(numQuadrants) == numQuadrants;+ }+ m_d->flakeToWidget *= rot;correctOffsetToTransformationAndSnap();recalculateTransformations();++ const QPointF newStillPoint = documentToWidget(effectiveStillPoint.docPoint());+ const QPointF offset = newStillPoint - effectiveStillPoint.viewPoint();+ m_d->documentOffset = snapToDevicePixel(m_d->documentOffset + offset);+ recalculateTransformations();++ if (stillPoint) {+ resetPreferredTransformationCenter();+ }}-void KisCoordinatesConverter::mirror(QPointF center, bool mirrorXAxis, bool mirrorYAxis)+void KisCoordinatesConverter::mirror(const std::optional<KoViewTransformStillPoint> &stillPoint, bool mirrorXAxis, bool mirrorYAxis){bool keepOrientation = false; // XXX: Keep here for now, maybe some day we can restore the parameter again.- if (kisSquareDistance(center, widgetCenterPoint()) > 2.0) {+ KoViewTransformStillPoint effectiveStillPoint =+ stillPoint ? *stillPoint :+ KoViewTransformStillPoint(m_d->preferredTransformationCenterInDocumentPixels(), widgetCenterPoint());+++ if (kisSquareDistance(effectiveStillPoint.viewPoint(), widgetCenterPoint()) > 2.0) {// when mirroring not against the center, reset the zoom modesetZoomMode(KoZoomMode::ZOOM_CONSTANT);}@@ -590,7 +650,7 @@ void KisCoordinatesConverter::mirror(QPointF center, bool mirrorXAxis, bool mirrQTransform rot;rot.rotate(m_d->rotationAngle);- m_d->flakeToWidget *= QTransform::fromTranslate(-center.x(),-center.y());+ m_d->flakeToWidget *= QTransform::fromTranslate(-effectiveStillPoint.viewPoint().x(),-effectiveStillPoint.viewPoint().y());if (keepOrientation) {m_d->flakeToWidget *= rot.inverted();@@ -602,7 +662,7 @@ void KisCoordinatesConverter::mirror(QPointF center, bool mirrorXAxis, bool mirrm_d->flakeToWidget *= rot;}- m_d->flakeToWidget *= QTransform::fromTranslate(center.x(),center.y());+ m_d->flakeToWidget *= QTransform::fromTranslate(effectiveStillPoint.viewPoint().x(),effectiveStillPoint.viewPoint().y());if (!keepOrientation && (doXMirroring ^ doYMirroring)) {@@ -617,9 +677,18 @@ void KisCoordinatesConverter::mirror(QPointF center, bool mirrorXAxis, bool mirrif (zoomMode() != KoZoomMode::ZOOM_CONSTANT) {// we were "centered", so let's try to keep the offset as beforem_d->documentOffset = oldDocumentOffset;+ } else {+ recalculateTransformations();+ const QPointF newStillPoint = documentToWidget(effectiveStillPoint.docPoint());+ const QPointF offset = newStillPoint - effectiveStillPoint.viewPoint();+ m_d->documentOffset = snapToDevicePixel(m_d->documentOffset + offset);}recalculateTransformations();++ if (stillPoint) {+ resetPreferredTransformationCenter();+ }}bool KisCoordinatesConverter::xAxisMirrored() const@@ -632,18 +701,30 @@ bool KisCoordinatesConverter::yAxisMirrored() constreturn m_d->isYAxisMirrored;}-void KisCoordinatesConverter::resetRotation(QPointF center)+void KisCoordinatesConverter::resetRotation(const std::optional<KoViewTransformStillPoint> &stillPoint){+ KoViewTransformStillPoint effectiveStillPoint =+ stillPoint ? *stillPoint :+ KoViewTransformStillPoint(m_d->preferredTransformationCenterInDocumentPixels(), widgetCenterPoint());+QTransform rot;rot.rotate(-m_d->rotationAngle);- m_d->flakeToWidget *= QTransform::fromTranslate(-center.x(), -center.y());m_d->flakeToWidget *= rot;- m_d->flakeToWidget *= QTransform::fromTranslate(center.x(), center.y());m_d->rotationAngle = 0.0;+ m_d->rotationIsOrthogonal = true;correctOffsetToTransformationAndSnap();recalculateTransformations();++ const QPointF newStillPoint = documentToWidget(effectiveStillPoint.docPoint());+ const QPointF offset = newStillPoint - effectiveStillPoint.viewPoint();+ m_d->documentOffset = snapToDevicePixel(m_d->documentOffset + offset);+ recalculateTransformations();++ if (stillPoint) {+ resetPreferredTransformationCenter();+ }}QTransform KisCoordinatesConverter::imageToWidgetTransform() const {@@ -815,6 +896,10 @@ void KisCoordinatesConverter::imagePhysicalScale(qreal *scaleX, qreal *scaleY) cQPointF KisCoordinatesConverter::snapToDevicePixel(const QPointF &point) const{+ if (!m_d->rotationIsOrthogonal) {+ return point;+ }+QPoint devicePixel = (point * m_d->devicePixelRatio).toPoint();// These adjusted coords will be in logical pixel but is aligned in device// pixel space for pixel-perfect rendering.@@ -877,4 +962,14 @@ qreal KisCoordinatesConverter::findNextZoom(qreal currentZoom, const QVector<qreqreal KisCoordinatesConverter::findPrevZoom(qreal currentZoom, const QVector<qreal> &zoomLevels){return KoZoomMode::findPrevZoom(currentZoom, zoomLevels);+}++KoViewTransformStillPoint KisCoordinatesConverter::makeViewStillPoint(const QPointF &viewPoint) const+{+ return {widgetToDocument(viewPoint), viewPoint};+}++KoViewTransformStillPoint KisCoordinatesConverter::makeDocStillPoint(const QPointF &docPoint) const+{+ return {docPoint, documentToWidget(docPoint)};}\ No newline at end of filediff --git a/libs/ui/canvas/kis_coordinates_converter.h b/libs/ui/canvas/kis_coordinates_converter.hindex faf337d185..01ebc0f93a 100644--- a/libs/ui/canvas/kis_coordinates_converter.h+++ b/libs/ui/canvas/kis_coordinates_converter.h@@ -14,6 +14,8 @@#include "kritaui_export.h"#include "kis_types.h"+class KoViewTransformStillPoint;+#define EPSILON 1e-6#define SCALE_LESS_THAN(scX, scY, value) \@@ -63,6 +65,27 @@ public:QPointF documentOffsetF() const;qreal rotationAngle() const;++ /**+ * \brief returns the point in image coordinates which is supposed to be+ * the default still point for the transformations of the canvas.+ * It returns the point of the image that is "roughly" mapped to+ * to the center of the canvas widget.+ *+ * Some of the methods of the converter accept std::optional<KoViewTransformStillPoint>+ * for a still point, over which the transformation should happen. When this argument is+ * std::nullotp, then preferredTransformationCenter() is used.+ *+ * One important property of preferredTransformationCenter() is that it is **not**+ * changed when the canvas is transformed over it, even when pixel alignment happens.+ * It means that preferredTransformationCenter() may **not** exactly map to the center+ * of the widget, due to hardware-pixel-alignment.+ *+ * Keeping this value unchanged allows us to avoid drifts of the offset when zooming+ * and rotating the canvas.+ */+ QPointF preferredTransformationCenter() const;+// Use the begin/end interface to rotate the canvas in one transformation.// This method is more accurate and doesn't amplify numerical errors from very small angles.void beginRotation();@@ -70,16 +93,56 @@ public:void enableNatureGestureFlag();- void rotate(QPointF center, qreal angle);- void mirror(QPointF center, bool mirrorXAxis, bool mirrorYAxis);+ /**+ * \brief rotates the canvas+ *+ * For the meaning of \p stillPoint \see setZoom()+ */+ void rotate(const std::optional<KoViewTransformStillPoint> &stillPoint, qreal angle);++ /**+ * \brief mirrors the canvas+ *+ * For the meaning of \p stillPoint \see setZoom()+ */+ void mirror(const std::optional<KoViewTransformStillPoint> &stillPoint, bool mirrorXAxis, bool mirrorYAxis);+bool xAxisMirrored() const;bool yAxisMirrored() const;- void resetRotation(QPointF center);++ /**+ * \brief resets canvas rotation+ *+ * For the meaning of \p stillPoint \see setZoom()+ */+ void resetRotation(const std::optional<KoViewTransformStillPoint> &stillPoint);void setZoom(qreal zoom) override;void zoomTo(const QRectF &widgetRect);- void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint);++ /**+ * \brief changes the zoom mode of the canvas+ *+ * When \p mode is KoZoomMode::ZOOM_CONSTANT, \p stillPoint instructs the converter+ * to keep the passed point "still", i.e. to make sure that stillPoint.docPoint()+ * maps to stillPoint.widgetPoint() on screen.+ *+ * Please make sure that there is **no guarantee** that the still point will map+ * to the passed points exactly! The still point may be offset by at most+ * (0.5 * sqrt(2) / devicePixelRatio()) due to hardware pixel alignment.+ *+ * This alignement is the reason why we pass both document and view points+ * as a still point, because both values should be kept constant during iterative+ * zoom operations. Otherwise the canvas will drift to the side because of the+ * pixel alignmentl.+ *+ * If \p stillPoint is std::nullopt, then the zooming happens over+ * preferredTransformationCenter(), which is basically the center of+ * canvas widget, but with some guards against the drifting.+ */+ void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &stillPoint);+void setCanvasWidgetSizeKeepZoom(const QSizeF &size);/**@@ -172,6 +235,25 @@ public:static qreal findNextZoom(qreal currentZoom, const QVector<qreal> &zoomLevels);static qreal findPrevZoom(qreal currentZoom, const QVector<qreal> &zoomLevels);+ /**+ * \brief Creates a still point that links the \p viewPoint of the widget+ * to the corresponding point of the image.+ *+ * The link is "baked" in KoViewTransformStillPoint object, hence+ * intermediate transformations will not affect it.+ */+ KoViewTransformStillPoint makeViewStillPoint(const QPointF &viewPoint) const;++ /**+ * \brief Creates a still point that links the \p docPoint of the image+ * (in document pixels!) to the curresponding point on the screen+ * (in the canvas widget).+ *+ * The link is "baked" in KoViewTransformStillPoint object, hence+ * intermediate transformations will not affect it.+ */+ KoViewTransformStillPoint makeDocStillPoint(const QPointF &docPoint) const;+public:// overrides from KoViewConverterQTransform viewToWidget() const override;@@ -184,6 +266,7 @@ private:QPointF centeringCorrection() const;void correctOffsetToTransformationAndSnap();void correctTransformationToOffset();+ void resetPreferredTransformationCenter();void recalculateTransformations();void recalculateZoomLevelLimits();void recalculateOffsetBoundsAndCrop();diff --git a/libs/ui/input/kis_rotate_canvas_action.cpp b/libs/ui/input/kis_rotate_canvas_action.cppindex 00c59a1a7b..ef391d5a11 100644--- a/libs/ui/input/kis_rotate_canvas_action.cpp+++ b/libs/ui/input/kis_rotate_canvas_action.cpp@@ -14,11 +14,26 @@#include "kis_canvas_controller.h"#include <kis_canvas2.h>#include "kis_input_manager.h"+#include <KoViewTransformStillPoint.h>#include <math.h>constexpr qreal DISCRETE_ANGLE_STEP = 15.0; // discrete rotation snapping angle+inline QPoint pointFromEvent(QEvent *event) {+ if (!event) {+ return QPoint();+ } else if (QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event)) {+ return mouseEvent->pos();+ } else if (QTabletEvent *tabletEvent = dynamic_cast<QTabletEvent*>(event)) {+ return tabletEvent->pos();+ } else if (QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent*>(event)) {+ return wheelEvent->position().toPoint();+ }++ return QPoint();+}+class KisRotateCanvasAction::Private{public:@@ -31,6 +46,7 @@ public:qreal snapRotation {0.0};qreal touchRotation {0.0};bool allowRotation {false};+ KoViewTransformStillPoint actionStillPoint;};@@ -98,6 +114,7 @@ void KisRotateCanvasAction::begin(int shortcut, QEvent *event)const qreal startRotation = inputManager()->canvas()->rotationAngle();d->snapRotation = startRotation - std::trunc(startRotation / DISCRETE_ANGLE_STEP) * DISCRETE_ANGLE_STEP;canvasController->beginCanvasRotation();+ d->actionStillPoint = inputManager()->canvas()->coordinatesConverter()->makeViewStillPoint(pointFromEvent(event));break;}case RotateLeftShortcut:@@ -172,7 +189,11 @@ void KisRotateCanvasAction::inputEvent(QEvent* event)const float angle = gevent->value();QPoint widgetPos = canvas->canvasWidget()->mapFromGlobal(gevent->globalPos());- controller->rotateCanvas(angle, widgetPos, true);++ KoViewTransformStillPoint adjustedStillPoint = d->actionStillPoint;+ adjustedStillPoint.second = widgetPos;++ controller->rotateCanvas(angle, adjustedStillPoint, true);return;}case QEvent::TouchUpdate: {diff --git a/libs/ui/input/kis_zoom_action.cpp b/libs/ui/input/kis_zoom_action.cppindex b2718ffafa..8f74edcea2 100644--- a/libs/ui/input/kis_zoom_action.cpp+++ b/libs/ui/input/kis_zoom_action.cpp@@ -15,6 +15,7 @@#include <kis_canvas2.h>#include <kis_canvas_controller.h>+#include <KoViewTransformStillPoint.h>#include "kis_cursor.h"#include "KisViewManager.h"#include "kis_input_manager.h"@@ -50,6 +51,8 @@ public:QPointF lastPosition;float lastDistance {0.0};+ KoViewTransformStillPoint actionStillPoint;+qreal startZoom {1.0};qreal lastDiscreteZoomDistance {0.0};};@@ -134,6 +137,7 @@ void KisZoomAction::begin(int shortcut, QEvent *event)d->startZoom = inputManager()->canvas()->coordinatesConverter()->zoom();d->mode = (Shortcuts)shortcut;d->lastPosition = QPoint();+ d->actionStillPoint = inputManager()->canvas()->coordinatesConverter()->makeViewStillPoint(pointFromEvent(event));break;}case DiscreteZoomModeShortcut:@@ -141,6 +145,7 @@ void KisZoomAction::begin(int shortcut, QEvent *event)d->startZoom = inputManager()->canvas()->coordinatesConverter()->zoom();d->lastDiscreteZoomDistance = 0;d->mode = (Shortcuts)shortcut;+ d->actionStillPoint = inputManager()->canvas()->coordinatesConverter()->makeViewStillPoint(pointFromEvent(event));break;case ZoomInShortcut:case ZoomOutShortcut:@@ -150,26 +155,33 @@ void KisZoomAction::begin(int shortcut, QEvent *event)dynamic_cast<KoCanvasControllerWidget *>(inputManager()->canvas()->canvasController());KIS_SAFE_ASSERT_RECOVER_RETURN(controller);- QPoint pt = pointFromEvent(event);- if (pt.isNull()) {- if (shortcut == ZoomInToCursorShortcut || shortcut == ZoomOutFromCursorShortcut) {+ QPoint pt;+ if (shortcut == ZoomInToCursorShortcut || shortcut == ZoomOutFromCursorShortcut) {+ pt = pointFromEvent(event);+ if (pt.isNull()) {pt = controller->mapFromGlobal(QCursor::pos());- } else {- pt = inputManager()->canvas()->coordinatesConverter()->widgetCenterPoint().toPoint();}}if (shortcut == ZoomInToCursorShortcut || shortcut == ZoomInShortcut) {- controller->zoomIn(pt);+ if (pt.isNull()) {+ controller->zoomIn();+ } else {+ controller->zoomIn(inputManager()->canvas()->coordinatesConverter()->makeViewStillPoint(pt));+ }} else {- controller->zoomOut(pt);+ if (pt.isNull()) {+ controller->zoomOut();+ } else {+ controller->zoomOut(inputManager()->canvas()->coordinatesConverter()->makeViewStillPoint(pt));+ }}break;}case Zoom100PctShortcut: {KoCanvasControllerWidget *controller =dynamic_cast<KoCanvasControllerWidget *>(inputManager()->canvas()->canvasController());- controller->setZoom(KoZoomMode::ZOOM_CONSTANT, 1.0, inputManager()->canvas()->coordinatesConverter()->widgetCenterPoint());+ controller->setZoom(KoZoomMode::ZOOM_CONSTANT, 1.0);break;}case FitToViewShortcut: {@@ -259,11 +271,11 @@ void KisZoomAction::inputEvent( QEvent* event )}KisCanvasController *controller = static_cast<KisCanvasController *>(inputManager()->canvas()->canvasController());- controller->zoomRelativeToPoint(p0.toPoint(), delta);+ const qreal newZoom = controller->canvas()->viewConverter()->zoom() * delta;+ KoViewTransformStillPoint adjustedStillPoint = d->actionStillPoint;+ adjustedStillPoint.second = p0;+ controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, adjustedStillPoint);d->lastDistance = dist;-- QPointF moveDelta = (p0 - d->lastPosition) * delta;- controller->pan(-moveDelta.toPoint());d->lastPosition = p0;return; // Don't try to update the cursor during a pinch-zoom}@@ -272,8 +284,9 @@ void KisZoomAction::inputEvent( QEvent* event )if (gevent->gestureType() == Qt::ZoomNativeGesture) {KisCanvas2 *canvas = inputManager()->canvas();KisCanvasController *controller = static_cast<KisCanvasController*>(canvas->canvasController());- const float delta = 1.0f + gevent->value();- controller->zoomRelativeToPoint(canvas->canvasWidget()->mapFromGlobal(gevent->globalPos()), delta);+ const qreal delta = 1.0f + gevent->value();+ const qreal newZoom = controller->canvas()->viewConverter()->zoom() * delta;+ controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, d->actionStillPoint);} else if (gevent->gestureType() == Qt::SmartZoomNativeGesture) {KisCanvas2 *canvas = inputManager()->canvas();KoCanvasController *controller = canvas->canvasController();@@ -320,7 +333,7 @@ void KisZoomAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &if (d->mode == ZoomModeShortcut) {controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom);} else {- controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, startPos.toPoint());+ controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, d->actionStillPoint);}} else if (d->mode == DiscreteZoomModeShortcut ||@@ -332,18 +345,23 @@ void KisZoomAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &KisConfig cfg(true);- QPoint stillPoint = d->mode == RelativeDiscreteZoomModeShortcut ?- startPos.toPoint() : inputManager()->canvas()->coordinatesConverter()->widgetCenterPoint().toPoint();-qreal axisDiff = qreal(cfg.zoomHorizontal() ? -diff.x() : diff.y());qreal currentDiff = axisDiff / stepDisc - d->lastDiscreteZoomDistance;const bool zoomIn = currentDiff > 0;while (qAbs(currentDiff) > 1.0) {if (zoomIn) {- controller->zoomIn(stillPoint);+ if (d->mode == RelativeDiscreteZoomModeShortcut) {+ controller->zoomIn(d->actionStillPoint);+ } else {+ controller->zoomIn();+ }} else {- controller->zoomOut(stillPoint);+ if (d->mode == RelativeDiscreteZoomModeShortcut) {+ controller->zoomOut(d->actionStillPoint);+ } else {+ controller->zoomOut();+ }}d->lastDiscreteZoomDistance += zoomIn ? 1.0 : -1.0;currentDiff = axisDiff / stepDisc - d->lastDiscreteZoomDistance;diff --git a/libs/ui/input/kis_zoom_and_rotate_action.cpp b/libs/ui/input/kis_zoom_and_rotate_action.cppindex c2b67ff6c3..4d6e70c2e1 100644--- a/libs/ui/input/kis_zoom_and_rotate_action.cpp+++ b/libs/ui/input/kis_zoom_and_rotate_action.cpp@@ -16,6 +16,7 @@#include "kis_zoom_and_rotate_action.h"#include "kis_input_manager.h"+#include <KoViewTransformStillPoint.h>class KisZoomAndRotateAction::Private {public:@@ -27,6 +28,8 @@ public:qreal previousAngle {0.0};qreal initialReferenceAngle {0.0};qreal accumRotationAngle {0.0};++ KoViewTransformStillPoint actionStillPoint;};KisZoomAndRotateAction::KisZoomAndRotateAction()@@ -70,6 +73,7 @@ void KisZoomAndRotateAction::begin(int shortcut, QEvent *event)d->previousAngle = 0;d->initialReferenceAngle = 0;d->accumRotationAngle = 0;+ d->actionStillPoint = inputManager()->canvas()->coordinatesConverter()->makeViewStillPoint(d->lastPosition);}}@@ -100,15 +104,13 @@ void KisZoomAndRotateAction::inputEvent(QEvent *event)const float dist = QLineF(p0, p1).length();const float scaleDelta = qFuzzyCompare(1.0f, 1.0f + d->lastDistance) ? 1.f : dist / d->lastDistance;- QTransform transform;- transform.rotate(rotationAngle);- const QPointF stationaryPointOffset = (p0 - d->lastPosition) * transform * scaleDelta;-KisCanvas2 *canvas = inputManager()->canvas();KisCanvasController *controller = static_cast<KisCanvasController *>(canvas->canvasController());- controller->zoomRelativeToPoint(p0.toPoint(), scaleDelta);- controller->rotateCanvas(rotationAngle, p0);- controller->pan(-stationaryPointOffset.toPoint());+ const qreal newZoom = canvas->viewConverter()->zoom() * scaleDelta;+ KoViewTransformStillPoint adjustedStillPoint = d->actionStillPoint;+ adjustedStillPoint.second = p0;+ controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, adjustedStillPoint);+ controller->rotateCanvas(rotationAngle, adjustedStillPoint);d->lastPosition = p0;d->lastDistance = dist;diff --git a/libs/ui/tests/kis_coordinates_converter_test.cpp b/libs/ui/tests/kis_coordinates_converter_test.cppindex fcb74cec34..c3ced32574 100644--- a/libs/ui/tests/kis_coordinates_converter_test.cpp+++ b/libs/ui/tests/kis_coordinates_converter_test.cpp@@ -18,6 +18,7 @@#include "kis_coordinates_converter.h"#include "kis_filter_strategy.h"#include <kis_algebra_2d.h>+#include <KoViewTransformStillPoint.h>#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)Q_DECLARE_METATYPE(KoZoomMode::Mode)@@ -174,7 +175,7 @@ void KisCoordinatesConverterTest::testRotation()converter.setDocumentOffset(QPoint(0,0));converter.setCanvasWidgetSize(widgetSize);- converter.rotate(converter.widgetCenterPoint(), 30);+ converter.rotate(std::nullopt, 30);QTransform viewportToWidget = converter.viewportToWidgetTransform();@@ -213,7 +214,7 @@ void KisCoordinatesConverterTest::testMirroring()// QTransform flakeToWidget;// QTransform viewportToWidget;- converter.mirror(converter.imageCenterInWidgetPixel(), true, false);+ converter.mirror(converter.makeViewStillPoint(converter.imageCenterInWidgetPixel()), true, false);// image pixels == flake pixels@@ -247,7 +248,7 @@ void KisCoordinatesConverterTest::testMirroringCanvasBiggerThanImage()// QTransform flakeToWidget;// QTransform viewportToWidget;- converter.mirror(converter.imageCenterInWidgetPixel(), true, false);+ converter.mirror(converter.makeViewStillPoint(converter.imageCenterInWidgetPixel()), true, false);// image pixels == flake pixels@@ -283,13 +284,13 @@ void KisCoordinatesConverterTest::testCanvasOffset()qDebug() << " " << ppVar(converter.imageToWidget(QPointF(0, 0)));qDebug() << " " << ppVar(converter.imageToWidget(QPointF(1000, 0)));- converter.mirror(converter.widgetCenterPoint(), true, false);+ converter.mirror(std::nullopt, true, false);qDebug() << "after mirror" << ppVar(converter.documentOffset());qDebug() << " " << ppVar(converter.imageToWidget(QPointF(0, 0)));qDebug() << " " << ppVar(converter.imageToWidget(QPointF(1000, 0)));- converter.mirror(converter.widgetCenterPoint(), false, false);+ converter.mirror(std::nullopt, false, false);}{@@ -300,13 +301,13 @@ void KisCoordinatesConverterTest::testCanvasOffset()qDebug() << " " << ppVar(converter.imageToWidget(QPointF(0, 0)));qDebug() << " " << ppVar(converter.imageToWidget(QPointF(1000, 0)));- converter.mirror(converter.widgetCenterPoint(), true, false);+ converter.mirror(std::nullopt, true, false);qDebug() << "after mirror" << ppVar(converter.documentOffset());qDebug() << " " << ppVar(converter.imageToWidget(QPointF(0, 0)));qDebug() << " " << ppVar(converter.imageToWidget(QPointF(1000, 0)));- converter.mirror(converter.widgetCenterPoint(), false, false);+ converter.mirror(std::nullopt, false, false);}{@@ -317,7 +318,7 @@ void KisCoordinatesConverterTest::testCanvasOffset()qDebug() << " " << ppVar(converter.imageToWidget(QPointF(0, 0)));qDebug() << " " << ppVar(converter.imageToWidget(QPointF(1000, 0)));- converter.rotate(converter.widgetCenterPoint(), 30);+ converter.rotate(std::nullopt, 30);qDebug() << "after rotate" << ppVar(converter.documentOffset());qDebug() << " " << ppVar(converter.imageToWidget(QPointF(0, 0)));@@ -325,7 +326,7 @@ void KisCoordinatesConverterTest::testCanvasOffset()qDebug() << " " << ppVar(converter.imageToWidget(QPointF(1000, 1000)));qDebug() << " " << ppVar(converter.imageToWidget(QPointF(0, 1000)));- converter.mirror(converter.widgetCenterPoint(), false, false);+ converter.mirror(std::nullopt, false, false);}}@@ -463,7 +464,7 @@ void KisCoordinatesConverterTest::testOffsetLimitsCropping()// This mirror operation cause clipping of the offset, since// the left edge of the document shoudl appear at position// 480, which is higer than the limit of 450.- converter.mirror(QPointF(490, 0), true, false);+ converter.mirror(converter.makeViewStillPoint(QPointF(490, 0)), true, false);QCOMPARE(converter.documentOffset(), QPoint(-450,0));QCOMPARE(converter.imageToWidget(QPointF(0,0)), QPointF(950,0));@@ -477,7 +478,7 @@ void KisCoordinatesConverterTest::testOffsetLimitsCropping()// Now mirror on the left side. The offset should be corrected// to the right- converter.mirror(QPointF(10, 0), false, false);+ converter.mirror(converter.makeViewStillPoint(QPointF(10, 0)), false, false);QCOMPARE(converter.documentOffset(), QPoint(450,0));QCOMPARE(converter.imageToWidget(QPointF(0,0)), QPointF(-450,0));@@ -896,7 +897,8 @@ void KisCoordinatesConverterTest::testZoomMode()}}- converter.setZoom(newZoomMode, newConstantZoom, newScreenResolution.x(), newScreenResolution.y(), widgetStillPoint);+ const KoViewTransformStillPoint stillPoint = converter.makeViewStillPoint(widgetStillPoint);+ converter.setZoom(newZoomMode, newConstantZoom, newScreenResolution.x(), newScreenResolution.y(), stillPoint);QCOMPARE(converter.zoom(), expectedZoom);QCOMPARE(converter.zoomMode(), newZoomMode);@@ -1034,7 +1036,7 @@ void KisCoordinatesConverterTest::testChangeCanvasSize()converter.setImage(image);converter.setCanvasWidgetSize(originalWidgetSize);- converter.setZoom(zoomMode, originalZoom, image->xRes(), image->yRes(), QRectF(QPointF(), originalWidgetSize).center());+ converter.setZoom(zoomMode, originalZoom, image->xRes(), image->yRes(), std::nullopt);if (zoomMode == KoZoomMode::ZOOM_CONSTANT) {converter.setDocumentOffset(originalOffset);}@@ -1142,7 +1144,7 @@ void KisCoordinatesConverterTest::testChangeImageResolution()converter.setImage(image);converter.setCanvasWidgetSize(widgetSize);- converter.setZoom(zoomMode, originalZoom, image->xRes(), image->yRes(), QRectF(QPointF(), widgetSize).center());+ converter.setZoom(zoomMode, originalZoom, image->xRes(), image->yRes(), std::nullopt);if (zoomMode == KoZoomMode::ZOOM_CONSTANT) {converter.setDocumentOffset(originalOffset);}@@ -1258,7 +1260,7 @@ void KisCoordinatesConverterTest::testChangeImageSize()converter.setImage(image);converter.setCanvasWidgetSize(widgetSize);- converter.setZoom(zoomMode, originalZoom, image->xRes(), image->yRes(), QRectF(QPointF(), widgetSize).center());+ converter.setZoom(zoomMode, originalZoom, image->xRes(), image->yRes(), std::nullopt);if (zoomMode == KoZoomMode::ZOOM_CONSTANT) {converter.setDocumentOffset(originalOffset);}@@ -1378,7 +1380,12 @@ void KisCoordinatesConverterTest::testResolutionModes()}}- converter.setZoom(KoZoomMode::ZOOM_CONSTANT, originalZoom, newScreenResolution, newScreenResolution, -originalOffset);+ const KoViewTransformStillPoint stillPoint = converter.makeViewStillPoint(-originalOffset);++ // that should be exactly the topleft of the document+ QCOMPARE(stillPoint.docPoint(), QPointF());++ converter.setZoom(KoZoomMode::ZOOM_CONSTANT, originalZoom, newScreenResolution, newScreenResolution, stillPoint);QCOMPARE(converter.zoom(), expectedZoom);QCOMPARE(converter.effectiveZoom(), expectedEffectiveZoom);@@ -1759,7 +1766,7 @@ void KisCoordinatesConverterTest::testZoomLimits()converter.zoom(),finalScreenResolution.x(),finalScreenResolution.y(),- converter.widgetCenterPoint());+ std::nullopt);converter.setDocumentOffset(QPointF());}@@ -1856,7 +1863,7 @@ void KisCoordinatesConverterTest::testZoomLimitsEnforcement()converter.setZoom(requestedZoomMode, requestedZoom,converter.resolutionX(), converter.resolutionY(),- converter.imageCenterInWidgetPixel());+ converter.makeViewStillPoint(converter.imageCenterInWidgetPixel()));QCOMPARE(converter.zoomMode(), expectedFinalZoomMode);QCOMPARE(converter.zoom(), expectedFinalZoom);@@ -2007,7 +2014,8 @@ enum TestHiDPIModeImageResolution,ImageBounds,ZoomTo,- Rotate+ Rotate,+ RotateOrthogonal};Q_DECLARE_METATYPE(TestHiDPIMode)@@ -2015,21 +2023,27 @@ Q_DECLARE_METATYPE(TestHiDPIMode)void KisCoordinatesConverterTest::testHiDPIOffsetSnapping_data(){QTest::addColumn<TestHiDPIMode>("testingMode");-- QTest::addRow("page-to-const7") << ZoomPageTo7;- QTest::addRow("page-to-width") << ZoomPageToWidth;- QTest::addRow("scroll-to-fraction") << ScrollToFraction;- QTest::addRow("scroll-away") << ScrollAway;- QTest::addRow("image-resolution") << ImageResolution;- QTest::addRow("image-bounds") << ImageBounds;- QTest::addRow("zoom-to") << ZoomTo;- QTest::addRow("rotate") << Rotate;-+ QTest::addColumn<bool>("expectsPixelAlignment");++ QTest::addRow("page-to-const7") << ZoomPageTo7 << true;+ QTest::addRow("page-to-width") << ZoomPageToWidth << true;+ QTest::addRow("scroll-to-fraction") << ScrollToFraction << true;+ QTest::addRow("scroll-away") << ScrollAway << true;+ QTest::addRow("image-resolution") << ImageResolution << true;+ QTest::addRow("image-bounds") << ImageBounds << true;+ QTest::addRow("zoom-to") << ZoomTo << true;+ QTest::addRow("rotate-orthogonal") << RotateOrthogonal << true;+ /**+ * In non-orthogonal rotation mode we disable pixel alignment+ * to make rotations smoother.+ */+ QTest::addRow("rotate") << Rotate << false;}void KisCoordinatesConverterTest::testHiDPIOffsetSnapping(){QFETCH(TestHiDPIMode, testingMode);+ QFETCH(bool, expectsPixelAlignment);KisImageSP image;KisCoordinatesConverter converter;@@ -2059,11 +2073,11 @@ void KisCoordinatesConverterTest::testHiDPIOffsetSnapping()switch (testingMode) {case ZoomPageTo7:converter.setZoom(KoZoomMode::ZOOM_CONSTANT, 0.17,- converter.resolutionX(), converter.resolutionY(), converter.imageCenterInWidgetPixel());+ converter.resolutionX(), converter.resolutionY(), converter.makeViewStillPoint(converter.imageCenterInWidgetPixel()));break;case ZoomPageToWidth:converter.setZoom(KoZoomMode::ZOOM_WIDTH, 1.0,- converter.resolutionX(), converter.resolutionY(), converter.imageCenterInWidgetPixel());+ converter.resolutionX(), converter.resolutionY(), converter.makeViewStillPoint(converter.imageCenterInWidgetPixel()));break;case ScrollToFraction:converter.setDocumentOffset(QPointF(-100.33, -200.77));@@ -2082,14 +2096,153 @@ void KisCoordinatesConverterTest::testHiDPIOffsetSnapping()converter.zoomTo(QRectF(13.33, 17.77, 333.17, 234.13));break;case Rotate:- converter.rotate(converter.imageCenterInWidgetPixel(), 17.3);+ converter.rotate(converter.makeViewStillPoint(converter.imageCenterInWidgetPixel()), 17.3);+ break;+ case RotateOrthogonal:+ converter.rotate(converter.makeViewStillPoint(converter.imageCenterInWidgetPixel()), 90.0);break;}{const QPointF imageTopLeftInDevicePixelsHW = converter.imageRectInWidgetPixels().topLeft() * converter.devicePixelRatio();- QCOMPARE(roundTo5thDigit(imageTopLeftInDevicePixelsHW.x()), qRound(imageTopLeftInDevicePixelsHW.x()));- QCOMPARE(roundTo5thDigit(imageTopLeftInDevicePixelsHW.y()), qRound(imageTopLeftInDevicePixelsHW.y()));+ if (expectsPixelAlignment) {+ QCOMPARE(roundTo5thDigit(imageTopLeftInDevicePixelsHW.x()), qRound(imageTopLeftInDevicePixelsHW.x()));+ QCOMPARE(roundTo5thDigit(imageTopLeftInDevicePixelsHW.y()), qRound(imageTopLeftInDevicePixelsHW.y()));+ } else {+ QCOMPARE_NE(roundTo5thDigit(imageTopLeftInDevicePixelsHW.x()), qRound(imageTopLeftInDevicePixelsHW.x()));+ QCOMPARE_NE(roundTo5thDigit(imageTopLeftInDevicePixelsHW.y()), qRound(imageTopLeftInDevicePixelsHW.y()));+ }+ }+}++void KisCoordinatesConverterTest::testPreferredCenterTransformations_data()+{+ QTest::addColumn<QString>("testingMode");+ QTest::addColumn<bool>("useCustomStillPoint");++ QTest::addRow("iterative-zoom") << "zoom" << false;+ QTest::addRow("iterative-zoom-still-point") << "zoom" << true;+ QTest::addRow("iterative-rotate") << "rotate" << false;+ QTest::addRow("iterative-rotate-still-point") << "rotate" << true;+ QTest::addRow("reset-rotation") << "reset-rotation" << false;+ QTest::addRow("reset-rotation-still-point") << "reset-rotation" << true;+ QTest::addRow("mirror") << "mirror" << false;+ QTest::addRow("mirror-still-point") << "mirror" << true;++ QTest::addRow("zoom-width") << "zoom-width" << false;+ QTest::addRow("pan") << "pan" << false;+ QTest::addRow("change-widget-size-page") << "change-widget-size-page" << false;+ QTest::addRow("change-widget-size-const") << "change-widget-size-const" << false;+ QTest::addRow("change-image-size") << "change-image-size" << false;+ QTest::addRow("change-image-resolution") << "change-image-resolution" << false;+}++void KisCoordinatesConverterTest::testPreferredCenterTransformations()+{+ QFETCH(QString, testingMode);+ QFETCH(bool, useCustomStillPoint);++ KisImageSP image;+ KisCoordinatesConverter converter;+ initImage(&image, &converter);++ converter.setImage(image);+ converter.setCanvasWidgetSizeKeepZoom(QSize(700, 500));++ KoViewTransformStillPoint expectedStillPoint;+ std::optional<KoViewTransformStillPoint> realStillPoint;++ if (!useCustomStillPoint) {+ expectedStillPoint = {converter.imageRectInDocumentPixels().center(), converter.imageCenterInWidgetPixel()};+ realStillPoint = std::nullopt;+ } else {+ expectedStillPoint = converter.makeViewStillPoint({100.0,100.0});+ realStillPoint = expectedStillPoint;+ }++ bool ignoreStillPointComparison = false;++ if (testingMode == "zoom") {+ for (int i = 0; i < 100; i++) {+ const qreal zoom = 0.033 + 0.0073 * i;+ converter.setZoom(KoZoomMode::ZOOM_CONSTANT,+ zoom,+ converter.resolutionX(),+ converter.resolutionY(),+ realStillPoint);+ }+ } else if (testingMode == "rotate") {+ for (int i = 0; i < 100; i++) {+ converter.rotate(realStillPoint, M_PI / 113.0);+ }+ } else if (testingMode == "reset-rotation") {+ converter.rotate(realStillPoint, M_PI / 6);+ converter.resetRotation(realStillPoint);+ } else if (testingMode == "mirror") {+ converter.mirror(realStillPoint, true, false);+ } else if (testingMode == "zoom-width") {+ converter.setZoom(KoZoomMode::ZOOM_WIDTH, 1.0,+ converter.resolutionX(), converter.resolutionY(),+ std::nullopt);+ } else if (testingMode == "pan") {+ converter.setDocumentOffset(converter.documentOffsetF() + QPointF(100.0, 0.0));++ /// the actual still point is checked in a different test,+ /// here we only need to test the preferred center+ ignoreStillPointComparison = true;+ } else if (testingMode == "change-widget-size-page") {+ const qreal oldZoom = converter.zoom();+ const QPointF oldOffset = converter.documentOffsetF();+ converter.setCanvasWidgetSizeKeepZoom(QSize(1100,400));+ QCOMPARE_NE(converter.zoom(), oldZoom);+ QCOMPARE_NE(converter.documentOffsetF(), oldOffset);++ // update the expected still point to the ceter of the "new" widget+ expectedStillPoint.second = converter.widgetCenterPoint();++ } else if (testingMode == "change-widget-size-const") {+ converter.setZoom(KoZoomMode::ZOOM_CONSTANT,+ converter.zoom(),+ converter.resolutionX(),+ converter.resolutionY(),+ std::nullopt);++ const qreal oldZoom = converter.zoom();+ const QPointF oldOffset = converter.documentOffsetF();+ converter.setCanvasWidgetSizeKeepZoom(QSize(1100,400));+ QCOMPARE(converter.zoom(), oldZoom);+ QCOMPARE(converter.documentOffsetF(), oldOffset);+ } else if (testingMode == "change-image-size") {+ converter.setImageBounds(QRect(0,0,113, 117), QPointF(77,17), QPointF(111, 110));++ /// the actual still point is checked in a different test,+ /// here we only need to test the preferred center+ ignoreStillPointComparison = true;+ } else if (testingMode == "change-image-resolution") {+ converter.setDocumentOffset(converter.documentOffsetF() + QPointF(100.0, 0.0));+ converter.setImageResolution(7.77, 3.13);++ /// the actual still point is checked in a different test,+ /// here we only need to test the preferred center+ ignoreStillPointComparison = true;+ } else {+ qFatal("Unknown tesing mode");+ }++ if (!ignoreStillPointComparison &&+ kisDistance(converter.documentToWidget(expectedStillPoint.docPoint()), expectedStillPoint.viewPoint()) > 1.0) {+ qDebug() << "Failed to compare the final image center:";+ qDebug() << " " << ppVar(expectedStillPoint);+ qDebug() << " " << ppVar(converter.documentToWidget(expectedStillPoint.docPoint()));+ QFAIL("The image center is not preserved");+ }++ if (kisDistance(converter.imageToWidget(converter.preferredTransformationCenter()), converter.widgetCenterPoint()) > 1.0) {+ qDebug() << "Failed to compare the preferred center position";+ qDebug() << " " << ppVar(converter.preferredTransformationCenter());+ qDebug() << " " << ppVar(converter.imageToWidget(converter.preferredTransformationCenter()));+ qDebug() << " " << ppVar(converter.widgetCenterPoint());+ QFAIL("The preferred center position does not point to the center of the widget");}}diff --git a/libs/ui/tests/kis_coordinates_converter_test.h b/libs/ui/tests/kis_coordinates_converter_test.hindex 4ddf1a197a..4316fda936 100644--- a/libs/ui/tests/kis_coordinates_converter_test.h+++ b/libs/ui/tests/kis_coordinates_converter_test.h@@ -59,6 +59,9 @@ private Q_SLOTS:void testHiDPIOffsetSnapping_data();void testHiDPIOffsetSnapping();++ void testPreferredCenterTransformations_data();+ void testPreferredCenterTransformations();};#endif /* KIS_COORDINATES_CONVERTER_TEST_H */