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

Second draft of python binding of Canvas:setPreferredCenter()

Dov Grobgeldaafab15c2c6f
diff --git a/libs/libkis/Canvas.cpp b/libs/libkis/Canvas.cpp
index 41e7011660..b548e04c6e 100644
--- a/libs/libkis/Canvas.cpp
+++ b/libs/libkis/Canvas.cpp
@@ -54,6 +54,36 @@ void Canvas::setZoomLevel(qreal value)
d->canvas->imageView()->zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, value);
}
+void Canvas::setPreferredCenter(const QPointF& imagePos)
+{
+ if (!d->canvas) return;
+
+ const KisCoordinatesConverter *coordConv = d->canvas->coordinatesConverter();
+
+ QPointF documentPos = coordConv->imageToDocument(imagePos);
+ QPointF flakePos = coordConv->documentToFlake(documentPos);
+
+ d->canvas->imageView()->canvasController()->setPreferredCenter(flakePos);
+}
+
+QPointF Canvas::preferredCenter() const
+{
+ if (!d->canvas) return QPointF();
+
+ QPointF flakePos = d->canvas->imageView()->canvasController()->preferredCenter();
+
+ const KisCoordinatesConverter *coordConv = d->canvas->coordinatesConverter();
+ QPointF docPos = coordConv->flakeToDocument(flakePos);
+ QPointF imagePos = coordConv->documentToImage(docPos);
+
+ return imagePos;
+}
+
+void Canvas::pan(const QPoint& offset)
+{
+ d->canvas->imageView()->canvasController()->pan(offset);
+}
+
void Canvas::resetZoom()
{
if (!d->canvas) return;
diff --git a/libs/libkis/Canvas.h b/libs/libkis/Canvas.h
index fb83cbaebd..f822d80883 100644
--- a/libs/libkis/Canvas.h
+++ b/libs/libkis/Canvas.h
@@ -42,6 +42,21 @@ public Q_SLOTS:
*/
void setZoomLevel(qreal value);
+ /**
+ * @brief setPan Centers the image pixel at \p imagePos in the current view
+ */
+ void setPreferredCenter(const QPointF& imagePos);
+
+ /**
+ * @brief \return the position of the image pixel that is placed in the center of the current view
+ */
+ QPointF preferredCenter() const;
+
+ /**
+ * @brief pan the current view in pixels.
+ */
+ void pan(const QPoint& offset);
+
/**
* @brief resetZoom set the zoomlevel to 100%
*/
diff --git a/plugins/extensions/pykrita/sip/krita/Canvas.sip b/plugins/extensions/pykrita/sip/krita/Canvas.sip
index a479819102..36068fb01b 100644
--- a/plugins/extensions/pykrita/sip/krita/Canvas.sip
+++ b/plugins/extensions/pykrita/sip/krita/Canvas.sip
@@ -22,6 +22,9 @@ public:
public Q_SLOTS:
qreal zoomLevel() const;
void setZoomLevel(qreal value);
+ QPointF preferredCenter() const;
+ void setPreferredCenter(const QPointF& imagePos);
+ void pan(const QPoint& offset);
void resetZoom();
void resetRotation();
qreal rotation() const;