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 resizing of the canvas when migrating screens
Dmitry Kazakov68aa11e7853c
diff --git a/libs/ui/canvas/KoCanvasControllerWidget.cpp b/libs/ui/canvas/KoCanvasControllerWidget.cppindex 48276cdf06..888768572c 100644--- a/libs/ui/canvas/KoCanvasControllerWidget.cpp+++ b/libs/ui/canvas/KoCanvasControllerWidget.cpp@@ -125,7 +125,16 @@ void KoCanvasControllerWidget::resizeEvent(QResizeEvent *event){const KisCanvasState oldCanvasState = canvasState();- updateCanvasWidgetSizeInternal(event->size());+ /**+ * When the window is moved from one screen to another,+ * the screen scaling factor may also change and we should+ * notify the converter about that.+ *+ * The actual signal from KisScreenMigrationTracker will come+ * much later, when the resize process has already been completed+ * and it is too late.+ */+ updateCanvasWidgetSizeInternal(event->size(), this->devicePixelRatioF());const KisCanvasState newCanvasState = canvasState();diff --git a/libs/ui/canvas/KoCanvasControllerWidget.h b/libs/ui/canvas/KoCanvasControllerWidget.hindex 962ee6e01e..8339a41d69 100644--- a/libs/ui/canvas/KoCanvasControllerWidget.h+++ b/libs/ui/canvas/KoCanvasControllerWidget.h@@ -129,7 +129,7 @@ protected:bool viewportEvent(QEvent *event) override;virtual void updateCanvasOffsetInternal(const QPointF &newOffset) = 0;- virtual void updateCanvasWidgetSizeInternal(const QSize &newSize) = 0;+ virtual void updateCanvasWidgetSizeInternal(const QSize &newSize, qreal devicePixelRatio) = 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;diff --git a/libs/ui/canvas/kis_canvas_controller.cpp b/libs/ui/canvas/kis_canvas_controller.cppindex 66b03a2c6f..6e340456a6 100644--- a/libs/ui/canvas/kis_canvas_controller.cpp+++ b/libs/ui/canvas/kis_canvas_controller.cpp@@ -513,8 +513,9 @@ void KisCanvasController::updateCanvasOffsetInternal(const QPointF &newOffset)m_d->coordinatesConverter->setDocumentOffset(newOffset);}-void KisCanvasController::updateCanvasWidgetSizeInternal(const QSize &newSize)+void KisCanvasController::updateCanvasWidgetSizeInternal(const QSize &newSize, qreal devicePixelRatio){+ m_d->coordinatesConverter->setDevicePixelRatio(devicePixelRatio);m_d->coordinatesConverter->setCanvasWidgetSizeKeepZoom(newSize);}diff --git a/libs/ui/canvas/kis_canvas_controller.h b/libs/ui/canvas/kis_canvas_controller.hindex 44fd753ceb..3f47db9409 100644--- a/libs/ui/canvas/kis_canvas_controller.h+++ b/libs/ui/canvas/kis_canvas_controller.h@@ -95,7 +95,7 @@ public Q_SLOTS:protected:void updateCanvasOffsetInternal(const QPointF &newOffset) override;- void updateCanvasWidgetSizeInternal(const QSize &newSize) override;+ void updateCanvasWidgetSizeInternal(const QSize &newSize, qreal devicePixelRatio) override;void updateCanvasZoomInternal(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional<KoViewTransformStillPoint> &docStillPoint) override;void zoomToInternal(const QRect &viewRect) override;diff --git a/libs/ui/opengl/KisOpenGLCanvasRenderer.cpp b/libs/ui/opengl/KisOpenGLCanvasRenderer.cppindex baa2e35ff2..58ba854341 100644--- a/libs/ui/opengl/KisOpenGLCanvasRenderer.cpp+++ b/libs/ui/opengl/KisOpenGLCanvasRenderer.cpp@@ -350,8 +350,9 @@ void KisOpenGLCanvasRenderer::resizeGL(int width, int height)int viewportWidth = static_cast<int>(width * devicePixelRatioF());int viewportHeight = static_cast<int>(height * devicePixelRatioF());- // we expect the size to be adjusted in the converter at the higher- // level of hierarchy+ // We expect the size to be adjusted in the converter at the higher+ // level of hierarchy. It happens in KisCanvasControllerWidget, which+ // then explicitly resizes the canvas widget.KIS_SAFE_ASSERT_RECOVER_NOOP(QSize(viewportWidth, viewportHeight) == coordinatesConverter()->viewportDevicePixelSize());}