Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Remove now unused parts of the zooming/panning framework

Dmitry Kazakovb89e641c9f3b
diff --git a/libs/flake/KoCanvasBase.cpp b/libs/flake/KoCanvasBase.cpp
index 0c6aa02bae..ec2b72139f 100644
--- a/libs/flake/KoCanvasBase.cpp
+++ b/libs/flake/KoCanvasBase.cpp
@@ -91,13 +91,6 @@ KoCanvasResourceProvider *KoCanvasBase::resourceManager() const
return d->resourceManager;
}
-void KoCanvasBase::ensureVisible(const QRectF &rect)
-{
- if (d->controller && d->controller->canvas())
- d->controller->ensureVisible(
- d->controller->canvas()->viewConverter()->documentToView(rect));
-}
-
void KoCanvasBase::setCanvasController(KoCanvasController *controller)
{
d->controller = controller;
diff --git a/libs/flake/KoCanvasBase.h b/libs/flake/KoCanvasBase.h
index ae58682b42..79f82840e7 100644
--- a/libs/flake/KoCanvasBase.h
+++ b/libs/flake/KoCanvasBase.h
@@ -209,15 +209,6 @@ public:
*/
KoCanvasController *canvasController() const;
- /**
- * @brief Scrolls the content of the canvas so that the given rect is visible.
- *
- * The rect is to be specified in document coordinates.
- *
- * @param rect the rectangle to make visible
- */
- virtual void ensureVisible(const QRectF &rect);
-
/**
* Returns the snap guide of the canvas
*/
diff --git a/libs/flake/KoCanvasController.cpp b/libs/flake/KoCanvasController.cpp
index 92680f49aa..bd6353335e 100644
--- a/libs/flake/KoCanvasController.cpp
+++ b/libs/flake/KoCanvasController.cpp
@@ -15,14 +15,12 @@ class Q_DECL_HIDDEN KoCanvasController::Private
{
public:
Private()
- : margin(0)
- , preferredCenterFractionX(0.5)
+ : preferredCenterFractionX(0.5)
, preferredCenterFractionY(0.5)
, actionCollection(0)
{
}
- int margin;
QSizeF documentSize;
QPoint documentOffset;
qreal preferredCenterFractionX;
@@ -44,16 +42,6 @@ KoCanvasController::~KoCanvasController()
delete proxyObject;
}
-void KoCanvasController::setMargin(int margin)
-{
- d->margin = margin;
-}
-
-int KoCanvasController::margin() const
-{
- return d->margin;
-}
-
KoCanvasBase* KoCanvasController::canvas() const
{
return 0;
diff --git a/libs/flake/KoCanvasController.h b/libs/flake/KoCanvasController.h
index 65156c347a..a5cc8b7a4c 100644
--- a/libs/flake/KoCanvasController.h
+++ b/libs/flake/KoCanvasController.h
@@ -69,22 +69,6 @@ public:
virtual ~KoCanvasController();
public:
- /**
- * Returns the current margin that is used to pad the canvas with.
- * This value is read from the KConfig property "canvasmargin"
- */
- virtual int margin() const;
-
- /**
- * Set the new margin to pad the canvas with.
- */
- virtual void setMargin(int margin);
-
- /**
- * compatibility with QAbstractScrollArea
- */
- virtual void scrollContentsBy(int dx, int dy) = 0;
-
/**
* @return the size of the viewport
*/
@@ -105,50 +89,16 @@ public:
*/
virtual KoCanvasBase *canvas() const;
- /**
- * return the amount of pixels vertically visible of the child canvas.
- * @return the amount of pixels vertically visible of the child canvas.
- */
- virtual int visibleHeight() const = 0;
-
- /**
- * return the amount of pixels horizontally visible of the child canvas.
- * @return the amount of pixels horizontally visible of the child canvas.
- */
- virtual int visibleWidth() const = 0;
-
- /**
- * return the amount of pixels that are not visible on the left side of the canvas.
- * The leftmost pixel that is shown is returned.
- */
- virtual int canvasOffsetX() const = 0;
-
- /**
- * return the amount of pixels that are not visible on the top side of the canvas.
- * The topmost pixel that is shown is returned.
- */
- virtual int canvasOffsetY() const = 0;
-
/**
* @brief Scrolls the content of the canvas so that the given rect is visible.
*
- * The rect is to be specified in view coordinates (pixels). The scrollbar positions
+ * The rect is to be specified in document coordinates (points). The scrollbar positions
* are changed so that the centerpoint of the rectangle is centered if possible.
*
* @param rect the rectangle to make visible
* @param smooth if true the viewport translation will make be just enough to ensure visibility, no more.
- * @see KoViewConverter::documentToView()
- */
- virtual void ensureVisible(const QRectF &rect, bool smooth = false) = 0;
-
- /**
- * @brief Scrolls the content of the canvas so that the given shape is visible.
- *
- * This is just a wrapper function of the above function.
- *
- * @param shape the shape to make visible
*/
- virtual void ensureVisible(KoShape *shape) = 0;
+ virtual void ensureVisibleDoc(const QRectF &docRect, bool smooth) = 0;
/**
* @brief zooms in around the center.
@@ -262,12 +212,6 @@ public:
*/
virtual void updateDocumentSize(const QSizeF &sz, bool recalculateCenter) = 0;
- /**
- * Set mouse wheel to zoom behaviour
- * @param zoom if true wheel will zoom instead of scroll, control modifier will scroll
- */
- virtual void setZoomWithWheel(bool zoom) = 0;
-
/**
* Set scroll area to be bigger than actual document.
* It allows the user to move the corner of the document
@@ -331,8 +275,7 @@ public:
void emitCanvasRemoved(KoCanvasController *canvasController) { Q_EMIT canvasRemoved(canvasController); }
void emitCanvasSet(KoCanvasController *canvasController) { Q_EMIT canvasSet(canvasController); }
- void emitCanvasOffsetXChanged(int offset) { Q_EMIT canvasOffsetXChanged(offset); }
- void emitCanvasOffsetYChanged(int offset) { Q_EMIT canvasOffsetYChanged(offset); }
+ void emitCanvasOffsetChanged() { Q_EMIT canvasOffsetChanged(); }
void emitCanvasMousePositionChanged(const QPoint &position) { Q_EMIT canvasMousePositionChanged(position); }
void emitDocumentMousePositionChanged(const QPointF &position) { Q_EMIT documentMousePositionChanged(position); }
void emitSizeChanged(const QSize &size) { Q_EMIT sizeChanged(size); }
@@ -356,16 +299,9 @@ Q_SIGNALS:
void canvasSet(KoCanvasController *canvasController);
/**
- * Emitted when canvasOffsetX() changes
- * @param offset the new canvas offset
- */
- void canvasOffsetXChanged(int offset);
-
- /**
- * Emitted when canvasOffsetY() changes
- * @param offset the new canvas offset
+ * Emitted when canvasOffset() changes
*/
- void canvasOffsetYChanged(int offset);
+ void canvasOffsetChanged();
/**
* Emitted when the cursor is moved over the canvas widget.
@@ -435,16 +371,10 @@ public:
{}
- void scrollContentsBy(int /*dx*/, int /*dy*/) override {}
QSizeF viewportSize() const override { return QSizeF(); }
void setCanvas(KoCanvasBase *canvas) override {Q_UNUSED(canvas)}
KoCanvasBase *canvas() const override {return 0;}
- int visibleHeight() const override {return 0;}
- int visibleWidth() const override {return 0;}
- int canvasOffsetX() const override {return 0;}
- int canvasOffsetY() const override {return 0;}
- void ensureVisible(const QRectF &/*rect*/, bool /*smooth */ = false) override {}
- void ensureVisible(KoShape *shape) override {Q_UNUSED(shape)}
+ void ensureVisibleDoc(const QRectF &, bool ) override {}
void zoomIn(const QPoint &/*center*/) override {}
void zoomOut(const QPoint &/*center*/) override {}
void zoomBy(const QPoint &/*center*/, qreal /*zoom*/) override {}
@@ -461,7 +391,6 @@ public:
void setScrollBarValue(const QPoint &/*value*/) override {}
void resetScrollBars() override {}
void updateDocumentSize(const QSizeF &/*sz*/, bool /*recalculateCenter*/) override {}
- void setZoomWithWheel(bool /*zoom*/) override {}
void setVastScrolling(qreal /*factor*/) override {}
QPointF currentCursorPosition() const override { return QPointF(); }
};
diff --git a/libs/flake/KoCanvasControllerWidget.cpp b/libs/flake/KoCanvasControllerWidget.cpp
index b4bbc6f4d6..09f12a2e81 100644
--- a/libs/flake/KoCanvasControllerWidget.cpp
+++ b/libs/flake/KoCanvasControllerWidget.cpp
@@ -57,40 +57,6 @@ void KoCanvasControllerWidget::Private::setDocumentOffset()
q->setDocumentOffset(pt);
}
-void KoCanvasControllerWidget::Private::resetScrollBars()
-{
- // The scrollbar value always points at the top-left corner of the
- // bit of image we paint.
-
- int docH = (int)q->documentSize().height() + q->margin();
- int docW = (int)q->documentSize().width() + q->margin();
- int drawH = viewportWidget->height();
- int drawW = viewportWidget->width();
-
- QScrollBar *hScroll = q->horizontalScrollBar();
- QScrollBar *vScroll = q->verticalScrollBar();
-
- int horizontalReserve = vastScrollingFactor * drawW;
- int verticalReserve = vastScrollingFactor * drawH;
-
- int xMin = -horizontalReserve;
- int yMin = -verticalReserve;
-
- int xMax = docW - drawW + horizontalReserve;
- int yMax = docH - drawH + verticalReserve;
-
- hScroll->setRange(xMin, xMax);
- vScroll->setRange(yMin, yMax);
-
- int fontheight = QFontMetrics(q->font()).height();
-
- vScroll->setPageStep(drawH);
- vScroll->setSingleStep(fontheight);
- hScroll->setPageStep(drawW);
- hScroll->setSingleStep(fontheight);
-
-}
-
void KoCanvasControllerWidget::Private::emitPointerPositionChangedSignals(QEvent *event)
{
if (!canvas) return;
@@ -257,61 +223,9 @@ void KoCanvasControllerWidget::changeCanvasWidget(QWidget *widget)
setFocusProxy(d->canvas->canvasWidget());
}
-int KoCanvasControllerWidget::visibleHeight() const
-{
- if (d->canvas == 0)
- return 0;
- QWidget *canvasWidget = canvas()->canvasWidget();
-
- int height1;
- if (canvasWidget == 0)
- height1 = viewport()->height();
- else
- height1 = qMin(viewport()->height(), canvasWidget->height());
- int height2 = height();
- return qMin(height1, height2);
-}
-
-int KoCanvasControllerWidget::visibleWidth() const
-{
- if (d->canvas == 0)
- return 0;
- QWidget *canvasWidget = canvas()->canvasWidget();
-
- int width1;
- if (canvasWidget == 0)
- width1 = viewport()->width();
- else
- width1 = qMin(viewport()->width(), canvasWidget->width());
- int width2 = width();
- return qMin(width1, width2);
-}
-
-int KoCanvasControllerWidget::canvasOffsetX() const
-{
- int offset = -horizontalScrollBar()->value();
-
- if (d->canvas) {
- offset += d->canvas->canvasWidget()->x() + frameWidth();
- }
-
- return offset;
-}
-
-int KoCanvasControllerWidget::canvasOffsetY() const
-{
- int offset = -verticalScrollBar()->value();
-
- if (d->canvas) {
- offset += d->canvas->canvasWidget()->y() + frameWidth();
- }
-
- return offset;
-}
-
void KoCanvasControllerWidget::updateCanvasOffsetX()
{
- proxyObject->emitCanvasOffsetXChanged(canvasOffsetX());
+ proxyObject->emitCanvasOffsetChanged();
if (d->ignoreScrollSignals)
return;
@@ -321,7 +235,7 @@ void KoCanvasControllerWidget::updateCanvasOffsetX()
void KoCanvasControllerWidget::updateCanvasOffsetY()
{
- proxyObject->emitCanvasOffsetYChanged(canvasOffsetY());
+ proxyObject->emitCanvasOffsetChanged();
if (d->ignoreScrollSignals)
return;
@@ -329,48 +243,6 @@ void KoCanvasControllerWidget::updateCanvasOffsetY()
+ verticalScrollBar()->pageStep() / 2.0) / documentSize().height());
}
-void KoCanvasControllerWidget::ensureVisible(KoShape *shape)
-{
- Q_ASSERT(shape);
- ensureVisible(d->canvas->viewConverter()->documentToView(shape->boundingRect()));
-}
-
-void KoCanvasControllerWidget::ensureVisible(const QRectF &rect, bool smooth)
-{
- QRect currentVisible(-canvasOffsetX(), -canvasOffsetY(), visibleWidth(), visibleHeight());
-
- QRect viewRect = rect.toRect();
- viewRect.translate(d->canvas->documentOrigin());
- if (!viewRect.isValid() || currentVisible.contains(viewRect))
- return; // its visible. Nothing to do.
-
- // if we move, we move a little more so the amount of times we have to move is less.
- int jumpWidth = smooth ? 0 : currentVisible.width() / 5;
- int jumpHeight = smooth ? 0 : currentVisible.height() / 5;
- if (!smooth && viewRect.width() + jumpWidth > currentVisible.width())
- jumpWidth = 0;
- if (!smooth && viewRect.height() + jumpHeight > currentVisible.height())
- jumpHeight = 0;
-
- int horizontalMove = 0;
- if (currentVisible.width() <= viewRect.width()) // center view
- horizontalMove = viewRect.center().x() - currentVisible.center().x();
- else if (currentVisible.x() > viewRect.x()) // move left
- horizontalMove = viewRect.x() - currentVisible.x() - jumpWidth;
- else if (currentVisible.right() < viewRect.right()) // move right
- horizontalMove = viewRect.right() - qMax(0, currentVisible.right() - jumpWidth);
-
- int verticalMove = 0;
- if (currentVisible.height() <= viewRect.height()) // center view
- verticalMove = viewRect.center().y() - currentVisible.center().y();
- if (currentVisible.y() > viewRect.y()) // move up
- verticalMove = viewRect.y() - currentVisible.y() - jumpHeight;
- else if (currentVisible.bottom() < viewRect.bottom()) // move down
- verticalMove = viewRect.bottom() - qMax(0, currentVisible.bottom() - jumpHeight);
-
- pan(QPoint(horizontalMove, verticalMove));
-}
-
void KoCanvasControllerWidget::recenterPreferred()
{
const bool oldIgnoreScrollSignals = d->ignoreScrollSignals;
@@ -446,11 +318,6 @@ void KoCanvasControllerWidget::updateDocumentSize(const QSizeF &sz, bool recalcu
d->ignoreScrollSignals = oldIgnoreScrollSignals;
}
-void KoCanvasControllerWidget::setZoomWithWheel(bool zoom)
-{
- d->zoomWithWheel = zoom;
-}
-
void KoCanvasControllerWidget::setVastScrolling(qreal factor)
{
d->vastScrollingFactor = factor;
@@ -530,17 +397,6 @@ void KoCanvasControllerWidget::dragLeaveEvent(QDragLeaveEvent *event)
d->viewportWidget->handleDragLeaveEvent(event);
}
-void KoCanvasControllerWidget::wheelEvent(QWheelEvent *event)
-{
- if (d->zoomWithWheel != ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier)) {
- const qreal zoomCoeff = event->angleDelta().y() > 0 ? sqrt(2.0) : sqrt(0.5);
- zoomRelativeToPoint(event->position().toPoint(), zoomCoeff);
-
- event->accept();
- } else
- QAbstractScrollArea::wheelEvent(event);
-}
-
void KoCanvasControllerWidget::zoomRelativeToPoint(const QPoint &widgetPoint, qreal zoomCoeff)
{
const QPoint offset = scrollBarValue();
@@ -569,13 +425,6 @@ bool KoCanvasControllerWidget::viewportEvent(QEvent *event) {
return QAbstractScrollArea::viewportEvent(event);
}
-void KoCanvasControllerWidget::setMargin(int margin)
-{
- KoCanvasController::setMargin(margin);
- Q_ASSERT(d->viewportWidget);
- d->viewportWidget->setMargin(margin);
-}
-
QPoint KoCanvasControllerWidget::scrollBarValue() const
{
QScrollBar * hBar = horizontalScrollBar();
@@ -593,11 +442,6 @@ void KoCanvasControllerWidget::setScrollBarValue(const QPoint &value)
vBar->setValue(value.y());
}
-void KoCanvasControllerWidget::resetScrollBars()
-{
- d->resetScrollBars();
-}
-
qreal KoCanvasControllerWidget::vastScrollingFactor() const
{
return d->vastScrollingFactor;
diff --git a/libs/flake/KoCanvasControllerWidget.h b/libs/flake/KoCanvasControllerWidget.h
index 91605e0aa2..f6b5c12b70 100644
--- a/libs/flake/KoCanvasControllerWidget.h
+++ b/libs/flake/KoCanvasControllerWidget.h
@@ -62,15 +62,6 @@ public:
*/
virtual void changeCanvasWidget(QWidget *widget);
- int visibleHeight() const override;
- int visibleWidth() const override;
- int canvasOffsetX() const override;
- int canvasOffsetY() const override;
-
- void ensureVisible(const QRectF &rect, bool smooth = false) override;
-
- void ensureVisible(KoShape *shape) override;
-
/**
* will cause the toolOptionWidgetsChanged to be emitted and all
* listeners to be updated to the new widget.
@@ -111,8 +102,6 @@ public:
virtual void panLeft() override;
virtual void panRight() override;
- void setMargin(int margin) override;
-
QPoint scrollBarValue() const override;
/**
@@ -123,18 +112,10 @@ public:
void updateDocumentSize(const QSizeF &sz, bool recalculateCenter = true) override;
- /**
- * Set mouse wheel to zoom behaviour
- * @param zoom if true wheel will zoom instead of scroll, control modifier will scroll
- */
- void setZoomWithWheel(bool zoom) override;
-
void setVastScrolling(qreal factor) override;
QPointF currentCursorPosition() const override;
- void resetScrollBars() override;
-
/**
* \internal
*/
@@ -167,8 +148,6 @@ protected:
/// reimplemented from QWidget
void dragLeaveEvent(QDragLeaveEvent *event) override;
/// reimplemented from QWidget
- void wheelEvent(QWheelEvent *event) override;
- /// reimplemented from QWidget
bool focusNextPrevChild(bool next) override;
/// reimplemented from QAbstractScrollArea
bool viewportEvent(QEvent *event) override;
diff --git a/libs/flake/KoCanvasControllerWidgetViewport_p.cpp b/libs/flake/KoCanvasControllerWidgetViewport_p.cpp
index 6d053763f0..ec4e204868 100644
--- a/libs/flake/KoCanvasControllerWidgetViewport_p.cpp
+++ b/libs/flake/KoCanvasControllerWidgetViewport_p.cpp
@@ -40,7 +40,6 @@ Viewport::Viewport(KoCanvasControllerWidget *parent)
, m_draggedShape(0)
, m_canvas(0)
, m_documentOffset(QPoint(0, 0))
- , m_margin(0)
{
setAutoFillBackground(true);
setAcceptDrops(true);
diff --git a/libs/flake/KoCanvasControllerWidgetViewport_p.h b/libs/flake/KoCanvasControllerWidgetViewport_p.h
index 8a058d6a8b..96414b65fa 100644
--- a/libs/flake/KoCanvasControllerWidgetViewport_p.h
+++ b/libs/flake/KoCanvasControllerWidgetViewport_p.h
@@ -43,7 +43,6 @@ public:
void handleDragMoveEvent(QDragMoveEvent *event);
void handleDragLeaveEvent(QDragLeaveEvent *event);
void handlePaintEvent(QPainter &gc, QPaintEvent *event);
- void setMargin(int margin) { m_margin = margin; resetLayout(); }
private:
@@ -66,7 +65,6 @@ private:
QWidget *m_canvas;
QSizeF m_documentSize; // Size in pixels of the document
QPoint m_documentOffset; // Place where the canvas widget should
- int m_margin; // The viewport margin around the document
};
#endif
diff --git a/libs/flake/KoCanvasControllerWidget_p.h b/libs/flake/KoCanvasControllerWidget_p.h
index b56dc60e1b..01961747aa 100644
--- a/libs/flake/KoCanvasControllerWidget_p.h
+++ b/libs/flake/KoCanvasControllerWidget_p.h
@@ -31,7 +31,6 @@ public:
, canvas(0)
, viewportWidget(0)
, ignoreScrollSignals(false)
- , zoomWithWheel(false)
, vastScrollingFactor(0)
{
}
@@ -52,7 +51,6 @@ public:
QPointer<KoCanvasBase> canvas;
Viewport *viewportWidget;
bool ignoreScrollSignals;
- bool zoomWithWheel;
qreal vastScrollingFactor;
};
diff --git a/libs/flake/KoToolProxy.cpp b/libs/flake/KoToolProxy.cpp
index edce399b20..8d81083cbb 100644
--- a/libs/flake/KoToolProxy.cpp
+++ b/libs/flake/KoToolProxy.cpp
@@ -48,26 +48,17 @@ void KoToolProxyPrivate::timeout() // Auto scroll the canvas
{
Q_ASSERT(controller);
- QPoint offset = QPoint(controller->canvasOffsetX(), controller->canvasOffsetY());
- QPoint origin = controller->canvas()->documentOrigin();
- QPoint viewPoint = widgetScrollPoint - origin - offset;
+ const QPoint originalWidgetPoint = parent->documentToWidget(widgetScrollPointDoc).toPoint();
- QRectF mouseArea(viewPoint, QSizeF(10, 10));
+ QRectF mouseArea(widgetScrollPointDoc, QSizeF(10, 10));
mouseArea.setTopLeft(mouseArea.center());
- controller->ensureVisible(mouseArea, true);
+ controller->ensureVisibleDoc(mouseArea, true);
- QPoint newOffset = QPoint(controller->canvasOffsetX(), controller->canvasOffsetY());
+ widgetScrollPointDoc = parent->widgetToDocument(originalWidgetPoint);
- QPoint moved = offset - newOffset;
- if (moved.isNull())
- return;
-
- widgetScrollPoint += moved;
-
- QPointF documentPoint = parent->widgetToDocument(widgetScrollPoint);
- QMouseEvent event(QEvent::MouseMove, widgetScrollPoint, Qt::LeftButton, Qt::LeftButton, QFlags<Qt::KeyboardModifier>());
- KoPointerEvent ev(&event, documentPoint);
+ QMouseEvent event(QEvent::MouseMove, originalWidgetPoint, Qt::LeftButton, Qt::LeftButton, QFlags<Qt::KeyboardModifier>());
+ KoPointerEvent ev(&event, widgetScrollPointDoc);
activeTool->mouseMoveEvent(&ev);
}
@@ -81,7 +72,7 @@ void KoToolProxyPrivate::checkAutoScroll(const KoPointerEvent &event)
if (event.buttons() != Qt::LeftButton) return;
- widgetScrollPoint = event.pos();
+ widgetScrollPointDoc = event.point;
if (! scrollTimer.isActive())
scrollTimer.start();
@@ -131,16 +122,6 @@ void KoToolProxy::repaintDecorations()
if (d->activeTool) d->activeTool->repaintDecorations();
}
-
-QPointF KoToolProxy::widgetToDocument(const QPointF &widgetPoint) const
-{
- QPoint offset = QPoint(d->controller->canvasOffsetX(), d->controller->canvasOffsetY());
- QPoint origin = d->controller->canvas()->documentOrigin();
- QPointF viewPoint = widgetPoint.toPoint() - QPointF(origin - offset);
-
- return d->controller->canvas()->viewConverter()->viewToDocument(viewPoint);
-}
-
KoCanvasBase* KoToolProxy::canvas() const
{
return d->controller->canvas();
diff --git a/libs/flake/KoToolProxy.h b/libs/flake/KoToolProxy.h
index f5736676d5..9ec77d0604 100644
--- a/libs/flake/KoToolProxy.h
+++ b/libs/flake/KoToolProxy.h
@@ -182,7 +182,8 @@ Q_SIGNALS:
void toolChanged(const QString &toolId);
protected:
- virtual QPointF widgetToDocument(const QPointF &widgetPoint) const;
+ virtual QPointF widgetToDocument(const QPointF &widgetPoint) const = 0;
+ virtual QPointF documentToWidget(const QPointF &documentPoint) const = 0;
KoCanvasBase* canvas() const;
diff --git a/libs/flake/KoToolProxy_p.h b/libs/flake/KoToolProxy_p.h
index f6896d26fb..1c77bcc598 100644
--- a/libs/flake/KoToolProxy_p.h
+++ b/libs/flake/KoToolProxy_p.h
@@ -38,7 +38,7 @@ public:
KoToolBase *activeTool {0};
bool hasSelection {false};
QTimer scrollTimer;
- QPoint widgetScrollPoint;
+ QPointF widgetScrollPointDoc;
KoCanvasController *controller {0};
KoToolProxy *parent {0};
diff --git a/libs/ui/KisView.cpp b/libs/ui/KisView.cpp
index 1b75e6cb10..08e5fc2fbe 100644
--- a/libs/ui/KisView.cpp
+++ b/libs/ui/KisView.cpp
@@ -346,10 +346,6 @@ void KisView::setViewManager(KisViewManager *view)
KisShapeController* shapeController = dynamic_cast<KisShapeController*>(d->document->shapeController());
shapeController->setInitialShapeForCanvas(&d->canvas);
- if (resourceProvider()) {
- resourceProvider()->slotImageSizeChanged();
- }
-
if (d->viewManager && d->viewManager->nodeManager()) {
d->viewManager->nodeManager()->nodesUpdated();
}
@@ -357,7 +353,6 @@ void KisView::setViewManager(KisViewManager *view)
connect(image(), SIGNAL(sigSizeChanged(QPointF,QPointF)), this, SLOT(slotImageSizeChanged(QPointF,QPointF)));
connect(image(), SIGNAL(sigResolutionChanged(double,double)), this, SLOT(slotImageResolutionChanged()));
-
d->addNodeConnection.connectSync(image(), &KisImage::sigNodeAddedAsync,
this, &KisView::slotContinueAddNode);
@@ -1505,12 +1500,6 @@ void KisView::slotImageResolutionChanged()
resetImageSizeAndScroll(false);
zoomManager()->updateImageBoundsSnapping();
zoomManager()->updateGuiAfterDocumentSize();
-
- // update KoUnit value for the document
- if (resourceProvider()) {
- resourceProvider()->resourceManager()->
- setResource(KoCanvasResource::Unit, d->canvas.unit());
- }
}
void KisView::slotImageSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint)
diff --git a/libs/ui/canvas/kis_canvas_controller.cpp b/libs/ui/canvas/kis_canvas_controller.cpp
index 174eb7e657..ec32319721 100644
--- a/libs/ui/canvas/kis_canvas_controller.cpp
+++ b/libs/ui/canvas/kis_canvas_controller.cpp
@@ -154,6 +154,41 @@ bool KisCanvasController::eventFilter(QObject *watched, QEvent *event)
return false;
}
+void KisCanvasController::ensureVisibleDoc(const QRectF &docRect, bool smooth)
+{
+ const QRect currentVisible = viewport()->rect();
+ const QRect viewRect = m_d->coordinatesConverter->documentToWidget(docRect).toAlignedRect();
+
+ if (!viewRect.isValid() || currentVisible.contains(viewRect))
+ return; // its visible. Nothing to do.
+
+ // if we move, we move a little more so the amount of times we have to move is less.
+ int jumpWidth = smooth ? 0 : currentVisible.width() / 5;
+ int jumpHeight = smooth ? 0 : currentVisible.height() / 5;
+ if (!smooth && viewRect.width() + jumpWidth > currentVisible.width())
+ jumpWidth = 0;
+ if (!smooth && viewRect.height() + jumpHeight > currentVisible.height())
+ jumpHeight = 0;
+
+ int horizontalMove = 0;
+ if (currentVisible.width() <= viewRect.width()) // center view
+ horizontalMove = viewRect.center().x() - currentVisible.center().x();
+ else if (currentVisible.x() > viewRect.x()) // move left
+ horizontalMove = viewRect.x() - currentVisible.x() - jumpWidth;
+ else if (currentVisible.right() < viewRect.right()) // move right
+ horizontalMove = viewRect.right() - qMax(0, currentVisible.right() - jumpWidth);
+
+ int verticalMove = 0;
+ if (currentVisible.height() <= viewRect.height()) // center view
+ verticalMove = viewRect.center().y() - currentVisible.center().y();
+ if (currentVisible.y() > viewRect.y()) // move up
+ verticalMove = viewRect.y() - currentVisible.y() - jumpHeight;
+ else if (currentVisible.bottom() < viewRect.bottom()) // move down
+ verticalMove = viewRect.bottom() - qMax(0, currentVisible.bottom() - jumpHeight);
+
+ pan(QPoint(horizontalMove, verticalMove));
+}
+
void KisCanvasController::updateDocumentSize(const QSizeF &sz, bool recalculateCenter)
{
KoCanvasControllerWidget::updateDocumentSize(sz, recalculateCenter);
@@ -206,19 +241,9 @@ void KisCanvasController::mirrorCanvasAroundCursor(bool enable)
void KisCanvasController::mirrorCanvasAroundCanvas(bool enable)
{
- int docWidth = KoCanvasControllerWidget::documentSize().width();
- int docOffsetX = KoCanvasControllerWidget::canvasOffsetX();
-
- QPoint center = QPoint(docOffsetX + (docWidth / 2), 0);
+ const QPointF center = m_d->coordinatesConverter->imageCenterInWidgetPixel();
QPoint newOffset = m_d->coordinatesConverter->mirror(center, enable, false);
-
setScrollBarValue(newOffset);
-
- // When the width is odd one side will be 1 pixel bigger, mirroring will
- // make the canvas move left by 1 pixel hence we pan it back to place.
- if (docWidth % 2 == 1)
- KoCanvasControllerWidget::pan(QPoint(-1, 0));
-
m_d->updateDocumentSizeAfterTransform();
m_d->showMirrorStateOnCanvas();
diff --git a/libs/ui/canvas/kis_canvas_controller.h b/libs/ui/canvas/kis_canvas_controller.h
index 9f9163515b..4c0de91a14 100644
--- a/libs/ui/canvas/kis_canvas_controller.h
+++ b/libs/ui/canvas/kis_canvas_controller.h
@@ -25,6 +25,7 @@ public:
KisCanvasController(QPointer<KisView>parent, KoCanvasSupervisor *observerProvider, KisKActionCollection * actionCollection);
~KisCanvasController() override;
+ void ensureVisibleDoc(const QRectF &docRect, bool smooth) override;
void setCanvas(KoCanvasBase *canvas) override;
void keyPressEvent(QKeyEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
diff --git a/libs/ui/canvas/kis_tool_proxy.cpp b/libs/ui/canvas/kis_tool_proxy.cpp
index c41513ac04..737ca6ebe2 100644
--- a/libs/ui/canvas/kis_tool_proxy.cpp
+++ b/libs/ui/canvas/kis_tool_proxy.cpp
@@ -40,6 +40,14 @@ QPointF KisToolProxy::widgetToDocument(const QPointF &widgetPoint) const
return kritaCanvas->coordinatesConverter()->widgetToDocument(widgetPoint);
}
+QPointF KisToolProxy::documentToWidget(const QPointF &documentPoint) const
+{
+ KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
+ Q_ASSERT(kritaCanvas);
+
+ return kritaCanvas->coordinatesConverter()->documentToWidget(documentPoint);
+}
+
KoPointerEvent KisToolProxy::convertEventToPointerEvent(QEvent *event, const QPointF &docPoint, bool *result)
{
switch (event->type()) {
diff --git a/libs/ui/canvas/kis_tool_proxy.h b/libs/ui/canvas/kis_tool_proxy.h
index e2c98bb31e..f6675408ef 100644
--- a/libs/ui/canvas/kis_tool_proxy.h
+++ b/libs/ui/canvas/kis_tool_proxy.h
@@ -57,6 +57,7 @@ private:
protected:
QPointF widgetToDocument(const QPointF &widgetPoint) const override;
+ QPointF documentToWidget(const QPointF &documentPoint) const override;
private:
bool m_isActionActivated;
diff --git a/libs/ui/kis_canvas_resource_provider.cpp b/libs/ui/kis_canvas_resource_provider.cpp
index 1901593e8d..dfc99e0f0e 100644
--- a/libs/ui/kis_canvas_resource_provider.cpp
+++ b/libs/ui/kis_canvas_resource_provider.cpp
@@ -31,6 +31,7 @@
#include "kis_config.h"
#include "KisViewManager.h"
#include "canvas/kis_canvas2.h"
+#include <KoUnit.h>
KisCanvasResourceProvider::KisCanvasResourceProvider(KisViewManager * view)
@@ -299,6 +300,10 @@ void KisCanvasResourceProvider::slotOnScreenResolutionChanged()
if(!image || !canvas) return;
+ // update KoUnit value for the document
+ m_resourceManager->
+ setResource(KoCanvasResource::Unit, canvas->unit());
+
qreal zoomX, zoomY;
canvas->coordinatesConverter()->zoom(&zoomX, &zoomY);
diff --git a/libs/ui/kis_zoom_manager.cc b/libs/ui/kis_zoom_manager.cc
index 073cf41b38..8e4598c3bb 100644
--- a/libs/ui/kis_zoom_manager.cc
+++ b/libs/ui/kis_zoom_manager.cc
@@ -163,10 +163,7 @@ void KisZoomManager::setup(KisKActionCollection * actionCollection)
layout->addWidget(m_verticalRuler, 1, 0);
layout->addWidget(static_cast<KoCanvasControllerWidget*>(m_canvasController), 1, 1);
- connect(m_canvasController->proxyObject, SIGNAL(canvasOffsetXChanged(int)),
- this, SLOT(pageOffsetChanged()));
-
- connect(m_canvasController->proxyObject, SIGNAL(canvasOffsetYChanged(int)),
+ connect(m_canvasController->proxyObject, SIGNAL(canvasOffsetChanged()),
this, SLOT(pageOffsetChanged()));
connect(m_zoomController, SIGNAL(zoomChanged(KoZoomMode::Mode,qreal)),
diff --git a/libs/widgets/KoZoomController.cpp b/libs/widgets/KoZoomController.cpp
index 6e162b357e..f43f17ecb8 100644
--- a/libs/widgets/KoZoomController.cpp
+++ b/libs/widgets/KoZoomController.cpp
@@ -25,7 +25,7 @@ void KoZoomController::Private::init(KoCanvasController *co,
KisKActionCollection *actionCollection)
{
canvasController = co;
- fitMargin = co->margin();
+ fitMargin = 0; // TODO: remove
zoomHandler = zh;
connect(action, SIGNAL(zoomChanged(KoZoomMode::Mode,qreal)),
parent, SLOT(setZoom(KoZoomMode::Mode,qreal)));
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index 0bda29fc3f..8106a71def 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -1240,7 +1240,7 @@ void SvgTextCursor::updateCursor(bool firstUpdate)
}
if (d->shape && !firstUpdate) {
QRectF rect = d->shape->shapeToDocument(d->cursorShape.boundingRect());
- d->canvas->canvasController()->ensureVisible(d->canvas->viewConverter()->documentToView(rect).adjusted(-1, -1, 1, 1));
+ d->canvas->canvasController()->ensureVisibleDoc(rect, false);
}
if (d->canvas->canvasWidget()->hasFocus()) {
d->cursorFlash.start();