Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCanvasController Class Reference

#include <kis_canvas_controller.h>

+ Inheritance diagram for KisCanvasController:

Classes

struct  Private
 

Public Slots

void beginCanvasRotation ()
 
void endCanvasRotation ()
 
void mirrorCanvas (bool enable)
 
void mirrorCanvasAroundCanvas (bool enable)
 
void mirrorCanvasAroundCursor (bool enable)
 
void resetCanvasRotation ()
 
void rotateCanvas (qreal angle)
 
void rotateCanvasLeft15 ()
 
void rotateCanvasRight15 ()
 
qreal rotation () const
 
void setUsePrintResolutionMode (bool value)
 
void slotSetWrapAroundModeAxis (WrapAroundAxis axis)
 
void slotSetWrapAroundModeAxisH ()
 
void slotSetWrapAroundModeAxisHV ()
 
void slotSetWrapAroundModeAxisV ()
 
void slotToggleLevelOfDetailMode (bool value)
 
void slotTogglePixelGrid (bool value)
 
void slotToggleWrapAroundMode (bool value)
 

Signals

void documentSizeChanged ()
 
void sigUsePrintResolutionModeChanged (bool value)
 

Public Member Functions

void activate () override
 Reimplemented from KoCanvasController.
 
KisCanvasState canvasState () const override
 
QPointF currentCursorPosition () const override
 
qreal effectiveCanvasResolutionX () const
 
qreal effectiveCanvasResolutionY () const
 
void ensureVisibleDoc (const QRectF &docRect, bool smooth) override
 Scrolls the content of the canvas so that the given rect is visible.
 
bool eventFilter (QObject *watched, QEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
 KisCanvasController (QPointer< KisView >parent, KoCanvasSupervisor *observerProvider, KisKActionCollection *actionCollection)
 
bool levelOfDetailMode () const
 
QPointF preferredCenter () const override
 Returns the currently set preferred center point in view coordinates (pixels)
 
void resetScrollBars () override
 
void restoreCanvasState (const KisPropertiesConfiguration &config)
 
void rotateCanvas (qreal angle, const std::optional< KoViewTransformStillPoint > &stillPoint, bool isNativeGesture=false)
 
void saveCanvasState (KisPropertiesConfiguration &config) const
 
void setCanvas (KoCanvasBase *canvas) override
 
void setPreferredCenter (const QPointF &viewPoint) override
 
void syncOnImageResolutionChange ()
 
void syncOnImageSizeChange (const QPointF &oldStillPoint, const QPointF &newStillPoint)
 
void syncOnReferencesChange (const QRectF &referencesRect)
 
void updateScreenResolution (QWidget *parentWidget)
 
bool usePrintResolutionMode ()
 
void wheelEvent (QWheelEvent *event) override
 
bool wrapAroundMode () const
 
WrapAroundAxis wrapAroundModeAxis () const
 
void zoomIn () override
 
void zoomIn (const KoViewTransformStillPoint &widgetStillPoint) override
 zooms in keeping stillPoint not moved.
 
void zoomOut () override
 
void zoomOut (const KoViewTransformStillPoint &widgetStillPoint) override
 zooms out keeping stillPoint not moved.
 
KoZoomState zoomState () const override
 
 ~KisCanvasController () override
 
- Public Member Functions inherited from KoCanvasControllerWidget
void activate ()
 
KoCanvasBasecanvas () const override
 
virtual void changeCanvasWidget (QWidget *widget)
 
 KoCanvasControllerWidget (KisKActionCollection *actionCollection, KoCanvasSupervisor *observerProvider, QWidget *parent=0)
 
void pan (const QPoint &distance) override
 
virtual void panDown () override
 
virtual void panLeft () override
 
virtual void panRight () override
 
virtual void panUp () override
 
KoCanvasControllerWidget::Privatepriv ()
 
 Private (KoCanvasControllerWidget *qq, KoCanvasSupervisor *observerProvider)
 
QPoint scrollBarValue () const override
 
void scrollContentsBy (int dx, int dy) override
 
void setCanvas (KoCanvasBase *canvas) override
 
void setScrollBarValue (const QPoint &value) override
 
void setToolOptionWidgets (const QList< QPointer< QWidget > > &widgets)
 
void setZoom (KoZoomMode::Mode mode, qreal zoom) override
 
void setZoom (KoZoomMode::Mode mode, qreal zoom, const KoViewTransformStillPoint &stillPoint)
 
void setZoom (KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY)
 
void setZoom (KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional< KoViewTransformStillPoint > &docStillPoint)
 
void unsetCanvas ()
 
void zoomTo (const QRect &rect) override
 zoom so that rect is exactly visible (as close as possible)
 
 ~KoCanvasControllerWidget () override
 
- Public Member Functions inherited from KoCanvasController
KisKActionCollectionactionCollection () const
 
 KoCanvasController (KisKActionCollection *actionCollection)
 
 Private ()
 
virtual ~KoCanvasController ()
 

Protected Member Functions

void updateCanvasOffsetInternal (const QPointF &newOffset) override
 
void updateCanvasWidgetSizeInternal (const QSize &newSize) override
 
void updateCanvasZoomInternal (KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const std::optional< KoViewTransformStillPoint > &docStillPoint) override
 
void zoomToInternal (const QRect &viewRect) override
 
- Protected Member Functions inherited from KoCanvasControllerWidget
void dragEnterEvent (QDragEnterEvent *event) override
 reimplemented from QWidget
 
void dragLeaveEvent (QDragLeaveEvent *event) override
 reimplemented from QWidget
 
void dragMoveEvent (QDragMoveEvent *event) override
 reimplemented from QWidget
 
void dropEvent (QDropEvent *event) override
 reimplemented from QWidget
 
void emitSignals (const KisCanvasState &oldState, const KisCanvasState &newState)
 
bool focusNextPrevChild (bool next) override
 reimplemented from QWidget
 
void paintEvent (QPaintEvent *event) override
 reimplemented from QWidget
 
void resizeEvent (QResizeEvent *resizeEvent) override
 reimplemented from QWidget
 
bool viewportEvent (QEvent *event) override
 reimplemented from QAbstractScrollArea
 
- Protected Member Functions inherited from KoCanvasController
void setDocumentOffset (const QPoint &offset)
 

Private Member Functions

void mirrorCanvasImpl (const std::optional< KoViewTransformStillPoint > &stillPoint, bool enable)
 
void zoomInImpl (const std::optional< KoViewTransformStillPoint > &stillPoint)
 
void zoomOutImpl (const std::optional< KoViewTransformStillPoint > &stillPoint)
 

Private Attributes

Private *const m_d
 

Additional Inherited Members

- Public Attributes inherited from KoCanvasControllerWidget
QPointer< KoCanvasBasecanvas
 
bool ignoreScrollSignals
 
KoCanvasSupervisorobserverProvider
 
KoCanvasControllerWidgetq
 
ViewportviewportWidget
 
- Public Attributes inherited from KoCanvasController
KisKActionCollectionactionCollection
 
QPoint documentOffset
 
QSizeF documentSize
 
qreal preferredCenterFractionX
 
qreal preferredCenterFractionY
 
QPointer< KoCanvasControllerProxyObjectproxyObject
 

Detailed Description

Definition at line 23 of file kis_canvas_controller.h.

Constructor & Destructor Documentation

◆ KisCanvasController()

KisCanvasController::KisCanvasController ( QPointer< KisView > parent,
KoCanvasSupervisor * observerProvider,
KisKActionCollection * actionCollection )

Definition at line 74 of file kis_canvas_controller.cpp.

76 m_d(new Private(this))
77{
78 m_d->view = parent;
79}
KoCanvasControllerWidget(KisKActionCollection *actionCollection, KoCanvasSupervisor *observerProvider, QWidget *parent=0)
KisKActionCollection * actionCollection
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References m_d, and KisCanvasController::Private::view.

◆ ~KisCanvasController()

KisCanvasController::~KisCanvasController ( )
override

Definition at line 81 of file kis_canvas_controller.cpp.

82{
83 delete m_d;
84}

References m_d.

Member Function Documentation

◆ activate()

void KisCanvasController::activate ( )
overridevirtual

Reimplemented from KoCanvasController.

Activate this canvascontroller

Reimplemented from KoCanvasControllerWidget.

Definition at line 129 of file kis_canvas_controller.cpp.

130{
132}
virtual void activate()
Reimplemented from KoCanvasController.

References KoCanvasControllerWidget::activate().

◆ beginCanvasRotation

void KisCanvasController::beginCanvasRotation ( )
slot

◆ canvasState()

KisCanvasState KisCanvasController::canvasState ( ) const
overridevirtual

Implements KoCanvasControllerWidget.

Definition at line 526 of file kis_canvas_controller.cpp.

527{
529}
static KisCanvasState fromConverter(const KisCoordinatesConverter &converter)

References KisCanvasController::Private::coordinatesConverter, KisCanvasState::fromConverter(), and m_d.

◆ currentCursorPosition()

QPointF KisCanvasController::currentCursorPosition ( ) const
overridevirtual
Returns
the current position of the cursor fetched from QCursor::pos() and converted into document coordinates

Implements KoCanvasController.

Definition at line 134 of file kis_canvas_controller.cpp.

135{
136 KoCanvasBase *canvas = m_d->view->canvasBase();
137 QWidget *canvasWidget = canvas->canvasWidget();
138 const QPointF cursorPosWidget = canvasWidget->mapFromGlobal(QCursor::pos());
139
140 return m_d->coordinatesConverter->widgetToDocument(cursorPosWidget);
141}
_Private::Traits< T >::Result widgetToDocument(const T &obj) const
QPointer< KoCanvasBase > canvas

References KoCanvasControllerWidget::canvas, KisCanvasController::Private::coordinatesConverter, m_d, KisCanvasController::Private::view, and KisCoordinatesConverter::widgetToDocument().

◆ documentSizeChanged

void KisCanvasController::documentSizeChanged ( )
signal

◆ effectiveCanvasResolutionX()

qreal KisCanvasController::effectiveCanvasResolutionX ( ) const

◆ effectiveCanvasResolutionY()

◆ endCanvasRotation

void KisCanvasController::endCanvasRotation ( )
slot

◆ ensureVisibleDoc()

void KisCanvasController::ensureVisibleDoc ( const QRectF & docRect,
bool smooth )
overridevirtual

Scrolls the content of the canvas so that the given rect is visible.

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.

Parameters
rectthe rectangle to make visible
smoothif true the viewport translation will make be just enough to ensure visibility, no more.

Implements KoCanvasController.

Definition at line 181 of file kis_canvas_controller.cpp.

182{
183 const QRect currentVisible = viewport()->rect();
184 const QRect viewRect = m_d->coordinatesConverter->documentToWidget(docRect).toAlignedRect();
185
186 if (!viewRect.isValid() || currentVisible.contains(viewRect))
187 return; // its visible. Nothing to do.
188
189 // if we move, we move a little more so the amount of times we have to move is less.
190 int jumpWidth = smooth ? 0 : currentVisible.width() / 5;
191 int jumpHeight = smooth ? 0 : currentVisible.height() / 5;
192 if (!smooth && viewRect.width() + jumpWidth > currentVisible.width())
193 jumpWidth = 0;
194 if (!smooth && viewRect.height() + jumpHeight > currentVisible.height())
195 jumpHeight = 0;
196
197 int horizontalMove = 0;
198 if (currentVisible.width() <= viewRect.width()) // center view
199 horizontalMove = viewRect.center().x() - currentVisible.center().x();
200 else if (currentVisible.x() > viewRect.x()) // move left
201 horizontalMove = viewRect.x() - currentVisible.x() - jumpWidth;
202 else if (currentVisible.right() < viewRect.right()) // move right
203 horizontalMove = viewRect.right() - qMax(0, currentVisible.right() - jumpWidth);
204
205 int verticalMove = 0;
206 if (currentVisible.height() <= viewRect.height()) // center view
207 verticalMove = viewRect.center().y() - currentVisible.center().y();
208 if (currentVisible.y() > viewRect.y()) // move up
209 verticalMove = viewRect.y() - currentVisible.y() - jumpHeight;
210 else if (currentVisible.bottom() < viewRect.bottom()) // move down
211 verticalMove = viewRect.bottom() - qMax(0, currentVisible.bottom() - jumpHeight);
212
213 pan(QPoint(horizontalMove, verticalMove));
214}
_Private::Traits< T >::Result documentToWidget(const T &obj) const
void pan(const QPoint &distance) override

References KisCanvasController::Private::coordinatesConverter, KisCoordinatesConverter::documentToWidget(), m_d, and KoCanvasControllerWidget::pan().

◆ eventFilter()

bool KisCanvasController::eventFilter ( QObject * watched,
QEvent * event )
override

Definition at line 163 of file kis_canvas_controller.cpp.

164{
165 KoCanvasBase *canvas = this->canvas();
166 if (!canvas || !canvas->canvasWidget() || canvas->canvasWidget() != watched) return false;
167
168 if (event->type() == QEvent::MouseMove) {
169 QMouseEvent *mevent = static_cast<QMouseEvent*>(event);
170 m_d->mousePositionCompressor->start(mevent->pos());
171 } else if (event->type() == QEvent::TabletMove) {
172 QTabletEvent *tevent = static_cast<QTabletEvent*>(event);
173 m_d->mousePositionCompressor->start(tevent->pos());
174 } else if (event->type() == QEvent::FocusIn) {
175 m_d->view->syncLastActiveNodeToDocument();
176 }
177
178 return false;
179}
QScopedPointer< KisSignalCompressorWithParam< QPoint > > mousePositionCompressor

References KoCanvasControllerWidget::canvas, m_d, KisCanvasController::Private::mousePositionCompressor, and KisCanvasController::Private::view.

◆ keyPressEvent()

void KisCanvasController::keyPressEvent ( QKeyEvent * event)
override

Dirty Hack Alert: Do not call the KoCanvasControllerWidget::keyPressEvent() to avoid activation of Pan and Default tool activation shortcuts

Definition at line 143 of file kis_canvas_controller.cpp.

144{
150 Q_UNUSED(event);
151}

◆ levelOfDetailMode()

bool KisCanvasController::levelOfDetailMode ( ) const

Definition at line 429 of file kis_canvas_controller.cpp.

430{
431 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
432 Q_ASSERT(kritaCanvas);
433
434 return kritaCanvas->lodPreferredInCanvas();
435}
bool lodPreferredInCanvas() const

References KoCanvasControllerWidget::canvas, and KisCanvas2::lodPreferredInCanvas().

◆ mirrorCanvas

void KisCanvasController::mirrorCanvas ( bool enable)
slot

Definition at line 237 of file kis_canvas_controller.cpp.

238{
239 mirrorCanvasImpl(std::nullopt, enable);
240}
void mirrorCanvasImpl(const std::optional< KoViewTransformStillPoint > &stillPoint, bool enable)

References mirrorCanvasImpl().

◆ mirrorCanvasAroundCanvas

void KisCanvasController::mirrorCanvasAroundCanvas ( bool enable)
slot

Definition at line 261 of file kis_canvas_controller.cpp.

262{
263 auto stillPoint =
266 mirrorCanvasImpl(stillPoint, enable);
267}
KoViewTransformStillPoint makeDocStillPoint(const QPointF &docPoint) const override
Creates a still point that links the docPoint of the image (in document pixels!) to the corresponding...

References KisCanvasController::Private::coordinatesConverter, KisCoordinatesConverter::imageRectInDocumentPixels(), m_d, KisCoordinatesConverter::makeDocStillPoint(), and mirrorCanvasImpl().

◆ mirrorCanvasAroundCursor

void KisCanvasController::mirrorCanvasAroundCursor ( bool enable)
slot

Definition at line 242 of file kis_canvas_controller.cpp.

243{
244 QVariant customPos = sender()->property("customPosition");
245 QPoint pos = customPos.isValid()
246 ? customPos.value<QPoint>()
247 : QCursor::pos();
248 KoCanvasBase* canvas = m_d->view->canvasBase();
249 QWidget *canvasWidget = canvas->canvasWidget();
250 const QPointF cursorPosWidget = canvasWidget->mapFromGlobal(pos);
251
252 std::optional<KoViewTransformStillPoint> stillPoint;
253
254 if (canvasWidget->rect().contains(cursorPosWidget.toPoint())) {
255 stillPoint = m_d->coordinatesConverter->makeWidgetStillPoint(cursorPosWidget);
256 }
257
258 mirrorCanvasImpl(stillPoint, enable);
259}
KoViewTransformStillPoint makeWidgetStillPoint(const QPointF &viewPoint) const override
Creates a still point that links the viewPoint of the widget to the corresponding point of the image.

References KoCanvasControllerWidget::canvas, KisCanvasController::Private::coordinatesConverter, m_d, KisCoordinatesConverter::makeWidgetStillPoint(), mirrorCanvasImpl(), and KisCanvasController::Private::view.

◆ mirrorCanvasImpl()

void KisCanvasController::mirrorCanvasImpl ( const std::optional< KoViewTransformStillPoint > & stillPoint,
bool enable )
private

Definition at line 227 of file kis_canvas_controller.cpp.

228{
229 const KisCanvasState oldCanvasState = canvasState();
230 m_d->coordinatesConverter->mirror(stillPoint, enable, false);
231 const KisCanvasState newCanvasState = canvasState();
232 emitSignals(oldCanvasState, newCanvasState);
233
235}
KisCanvasState canvasState() const override
void mirror(const std::optional< KoViewTransformStillPoint > &stillPoint, bool mirrorXAxis, bool mirrorYAxis)
mirrors the canvas
void emitSignals(const KisCanvasState &oldState, const KisCanvasState &newState)

References canvasState(), KisCanvasController::Private::coordinatesConverter, KoCanvasControllerWidget::emitSignals(), m_d, KisCoordinatesConverter::mirror(), and KisCanvasController::Private::showMirrorStateOnCanvas().

◆ preferredCenter()

QPointF KisCanvasController::preferredCenter ( ) const
overridevirtual

Returns the currently set preferred center point in view coordinates (pixels)

Implements KoCanvasController.

Definition at line 536 of file kis_canvas_controller.cpp.

537{
538 const QPointF transformedImageBoundsTopleft = m_d->coordinatesConverter->imageRectInWidgetPixels().topLeft();
539 return m_d->coordinatesConverter->widgetCenterPoint() - transformedImageBoundsTopleft;
540}

References KisCanvasController::Private::coordinatesConverter, KisCoordinatesConverter::imageRectInWidgetPixels(), m_d, and KisCoordinatesConverter::widgetCenterPoint().

◆ resetCanvasRotation

void KisCanvasController::resetCanvasRotation ( )
slot

Definition at line 322 of file kis_canvas_controller.cpp.

323{
324 const KisCanvasState oldCanvasState = canvasState();
325 m_d->coordinatesConverter->resetRotation(std::nullopt);
326 const KisCanvasState newCanvasState = canvasState();
327 emitSignals(oldCanvasState, newCanvasState);
328
330}
void resetRotation(const std::optional< KoViewTransformStillPoint > &stillPoint)
resets canvas rotation

References canvasState(), KisCanvasController::Private::coordinatesConverter, KoCanvasControllerWidget::emitSignals(), m_d, KisCoordinatesConverter::resetRotation(), and KisCanvasController::Private::showRotationValueOnCanvas().

◆ resetScrollBars()

void KisCanvasController::resetScrollBars ( )
overridevirtual

Update the range of scroll bars

Implements KoCanvasController.

Definition at line 601 of file kis_canvas_controller.cpp.

602{
603 // The scrollbar value always points at the top-left corner of the
604 // bit of image we paint.
605
606 const QPoint minOffset = m_d->coordinatesConverter->minimumOffset();
607 const QPoint maxOffset = m_d->coordinatesConverter->maximumOffset();
608 const QPoint offset = m_d->coordinatesConverter->documentOffset();
609
610 QScrollBar *hScroll = horizontalScrollBar();
611 QScrollBar *vScroll = verticalScrollBar();
612
613 QSignalBlocker b1(hScroll);
614 QSignalBlocker b2(vScroll);
615
616 hScroll->setRange(minOffset.x(), maxOffset.x());
617 hScroll->setValue(offset.x());
618 vScroll->setRange(minOffset.y(), maxOffset.y());
619 vScroll->setValue(offset.y());
620
621 const int drawH = viewport()->height() / 4;
622 const int drawW = viewport()->width() / 4;
623 const int fontHeight = QFontMetrics(font()).height();
624
625 vScroll->setPageStep(drawH);
626 vScroll->setSingleStep(fontHeight);
627 hScroll->setPageStep(drawW);
628 hScroll->setSingleStep(fontHeight);
629}

References KisCanvasController::Private::coordinatesConverter, KisCoordinatesConverter::documentOffset(), m_d, KisCoordinatesConverter::maximumOffset(), and KisCoordinatesConverter::minimumOffset().

◆ restoreCanvasState()

void KisCanvasController::restoreCanvasState ( const KisPropertiesConfiguration & config)

Definition at line 450 of file kis_canvas_controller.cpp.

451{
452 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
453 Q_ASSERT(kritaCanvas);
454
455 mirrorCanvas(config.getBool("mirror", false));
456 rotateCanvas(config.getFloat("rotation", 0.0f));
457
458 const QPointF &center = preferredCenter();
459 float panX = config.getFloat("panX", center.x());
460 float panY = config.getFloat("panY", center.y());
461 setPreferredCenter(QPointF(panX, panY));
462
463 slotToggleWrapAroundMode(config.getBool("wrapAround", false));
464 slotSetWrapAroundModeAxis((WrapAroundAxis)config.getInt("wrapAroundAxis", 0));
465 kritaCanvas->setLodPreferredInCanvas(config.getBool("enableInstantPreview", false));
466}
WrapAroundAxis
void setLodPreferredInCanvas(bool value)
void setPreferredCenter(const QPointF &viewPoint) override
void slotToggleWrapAroundMode(bool value)
void rotateCanvas(qreal angle, const std::optional< KoViewTransformStillPoint > &stillPoint, bool isNativeGesture=false)
void slotSetWrapAroundModeAxis(WrapAroundAxis axis)
QPointF preferredCenter() const override
Returns the currently set preferred center point in view coordinates (pixels)
bool getBool(const QString &name, bool def=false) const
int getInt(const QString &name, int def=0) const
float getFloat(const QString &name, float def=0.0) const

References KoCanvasControllerWidget::canvas, KisPropertiesConfiguration::getBool(), KisPropertiesConfiguration::getFloat(), KisPropertiesConfiguration::getInt(), mirrorCanvas(), preferredCenter(), rotateCanvas(), KisCanvas2::setLodPreferredInCanvas(), setPreferredCenter(), slotSetWrapAroundModeAxis(), and slotToggleWrapAroundMode().

◆ rotateCanvas [1/2]

void KisCanvasController::rotateCanvas ( qreal angle)
slot

Definition at line 302 of file kis_canvas_controller.cpp.

303{
304 rotateCanvas(angle, std::nullopt);
305}

References rotateCanvas().

◆ rotateCanvas() [2/2]

void KisCanvasController::rotateCanvas ( qreal angle,
const std::optional< KoViewTransformStillPoint > & stillPoint,
bool isNativeGesture = false )

Definition at line 289 of file kis_canvas_controller.cpp.

290{
291 if(isNativeGesture) {
293 }
294 const KisCanvasState oldCanvasState = canvasState();
295 m_d->coordinatesConverter->rotate(stillPoint, angle);
296 const KisCanvasState newCanvasState = canvasState();
297 emitSignals(oldCanvasState, newCanvasState);
298
300}
void rotate(const std::optional< KoViewTransformStillPoint > &stillPoint, qreal angle)
rotates the canvas

References canvasState(), KisCanvasController::Private::coordinatesConverter, KoCanvasControllerWidget::emitSignals(), KisCoordinatesConverter::enableNatureGestureFlag(), m_d, KisCoordinatesConverter::rotate(), and KisCanvasController::Private::showRotationValueOnCanvas().

◆ rotateCanvasLeft15

void KisCanvasController::rotateCanvasLeft15 ( )
slot

Definition at line 312 of file kis_canvas_controller.cpp.

313{
314 rotateCanvas(-15.0);
315}

References rotateCanvas().

◆ rotateCanvasRight15

void KisCanvasController::rotateCanvasRight15 ( )
slot

Definition at line 307 of file kis_canvas_controller.cpp.

308{
309 rotateCanvas(15.0);
310}

References rotateCanvas().

◆ rotation

qreal KisCanvasController::rotation ( ) const
slot

◆ saveCanvasState()

void KisCanvasController::saveCanvasState ( KisPropertiesConfiguration & config) const

Definition at line 437 of file kis_canvas_controller.cpp.

438{
439 const QPointF &center = preferredCenter();
440 config.setProperty("panX", center.x());
441 config.setProperty("panY", center.y());
442
443 config.setProperty("rotation", rotation());
445 config.setProperty("wrapAround", wrapAroundMode());
446 config.setProperty("wrapAroundAxis", wrapAroundModeAxis());
447 config.setProperty("enableInstantPreview", levelOfDetailMode());
448}
WrapAroundAxis wrapAroundModeAxis() const
virtual void setProperty(const QString &name, const QVariant &value)

References KisCanvasController::Private::coordinatesConverter, levelOfDetailMode(), m_d, preferredCenter(), rotation(), KisPropertiesConfiguration::setProperty(), wrapAroundMode(), wrapAroundModeAxis(), and KisCoordinatesConverter::xAxisMirrored().

◆ setCanvas()

void KisCanvasController::setCanvas ( KoCanvasBase * canvas)
overridevirtual

Set the new canvas to be shown as a child Calling this will Q_EMIT canvasRemoved() if there was a canvas before, and will emit canvasSet() with the new canvas.

Parameters
canvasthe new canvas. The KoCanvasBase::canvas() will be called to retrieve the actual widget which will then be added as child of this one.

Implements KoCanvasController.

Definition at line 86 of file kis_canvas_controller.cpp.

87{
88 if (canvas) {
89 KisCanvas2 *kritaCanvas = qobject_cast<KisCanvas2*>(canvas);
91 const_cast<KisCoordinatesConverter*>(kritaCanvas->coordinatesConverter());
92 } else {
94 }
95
97}
KisCoordinatesConverter * coordinatesConverter
void setCanvas(KoCanvasBase *canvas) override

References KoCanvasControllerWidget::canvas, KisCanvas2::coordinatesConverter, KisCanvasController::Private::coordinatesConverter, m_d, and KoCanvasControllerWidget::setCanvas().

◆ setPreferredCenter()

void KisCanvasController::setPreferredCenter ( const QPointF & viewPoint)
overridevirtual

Sets the preferred center point in view coordinates (pixels).

Parameters
viewPointthe new preferred center

Implements KoCanvasController.

Definition at line 542 of file kis_canvas_controller.cpp.

543{
544 const KisCanvasState oldState = canvasState();
545
546 const QPointF expectedTransformedImageBoundsTopleft = m_d->coordinatesConverter->widgetCenterPoint() - viewPoint;
547 updateCanvasOffsetInternal(-expectedTransformedImageBoundsTopleft);
548
549 emitSignals(oldState, canvasState());
550}
void updateCanvasOffsetInternal(const QPointF &newOffset) override

References canvasState(), KisCanvasController::Private::coordinatesConverter, KoCanvasControllerWidget::emitSignals(), m_d, updateCanvasOffsetInternal(), and KisCoordinatesConverter::widgetCenterPoint().

◆ setUsePrintResolutionMode

void KisCanvasController::setUsePrintResolutionMode ( bool value)
slot

Definition at line 636 of file kis_canvas_controller.cpp.

637{
638 const bool changed = value != m_d->usePrintResolutionMode;
639
640 KisImageSP image = m_d->view->image();
641
642 // changeCanvasMappingMode is called with the same canvasMappingMode when the window is
643 // moved across screens. Preserve the old zoomMode if this is the case.
644 const KoZoomMode::Mode newMode =
646 const qreal newZoom = m_d->coordinatesConverter->zoom();
647
649
651
652 if (changed) {
654 }
655}
float value(const T *src, size_t ch)
qreal effectiveCanvasResolutionY() const
void sigUsePrintResolutionModeChanged(bool value)
qreal effectiveCanvasResolutionX() const
void setZoom(KoZoomMode::Mode mode, qreal zoom) override
KoZoomMode::Mode zoomMode() const
void zoom(qreal *zoomX, qreal *zoomY) const override
@ ZOOM_CONSTANT
zoom x %
Definition KoZoomMode.h:24

References KisCanvasController::Private::coordinatesConverter, effectiveCanvasResolutionX(), effectiveCanvasResolutionY(), m_d, KoCanvasControllerWidget::setZoom(), sigUsePrintResolutionModeChanged(), KisCanvasController::Private::usePrintResolutionMode, value(), KisCanvasController::Private::view, KoZoomHandler::zoom(), KoZoomMode::ZOOM_CONSTANT, and KoZoomHandler::zoomMode().

◆ sigUsePrintResolutionModeChanged

void KisCanvasController::sigUsePrintResolutionModeChanged ( bool value)
signal

◆ slotSetWrapAroundModeAxis

void KisCanvasController::slotSetWrapAroundModeAxis ( WrapAroundAxis axis)
slot

Definition at line 353 of file kis_canvas_controller.cpp.

354{
355 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
356 Q_ASSERT(kritaCanvas);
357
359 kritaCanvas->image()->setWrapAroundModeAxis(value);
360}
KisImageWSP image() const
void setWrapAroundViewingModeAxis(WrapAroundAxis value)
void setWrapAroundModeAxis(WrapAroundAxis value)

References KoCanvasControllerWidget::canvas, KisCanvas2::image(), KisImage::setWrapAroundModeAxis(), KisCanvas2::setWrapAroundViewingModeAxis(), and value().

◆ slotSetWrapAroundModeAxisH

void KisCanvasController::slotSetWrapAroundModeAxisH ( )
slot

◆ slotSetWrapAroundModeAxisHV

void KisCanvasController::slotSetWrapAroundModeAxisHV ( )
slot

◆ slotSetWrapAroundModeAxisV

void KisCanvasController::slotSetWrapAroundModeAxisV ( )
slot

◆ slotToggleLevelOfDetailMode

void KisCanvasController::slotToggleLevelOfDetailMode ( bool value)
slot

Definition at line 393 of file kis_canvas_controller.cpp.

394{
395 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
396 Q_ASSERT(kritaCanvas);
397
398 kritaCanvas->setLodPreferredInCanvas(value);
399
400 bool result = levelOfDetailMode();
401
402 if (!value || result) {
403 m_d->view->viewManager()->showFloatingMessage(
404 i18n("Instant Preview Mode: %1", result ?
405 i18n("ON") : i18n("OFF")),
406 QIcon(), 500, KisFloatingMessage::Low);
407 } else {
408 QString reason;
409
410 if (!kritaCanvas->canvasIsOpenGL()) {
411 reason = i18n("Instant Preview is only supported with OpenGL activated");
412 }
413 else if (kritaCanvas->openGLFilterMode() == KisOpenGL::BilinearFilterMode ||
415 QString filteringMode =
417 i18n("Bilinear") : i18n("Nearest Neighbour");
418 reason = i18n("Instant Preview is supported\n in Trilinear or High Quality filtering modes.\nCurrent mode is %1", filteringMode);
419 }
420
421 m_d->view->viewManager()->showFloatingMessage(
422 i18n("Failed activating Instant Preview mode!\n\n%1", reason),
423 QIcon(), 5000, KisFloatingMessage::Low);
424 }
425
426
427}
bool canvasIsOpenGL() const override
The KisFloatingMessage class shows the given message in a semi-transparent bubble that doesn't take f...
@ NearestFilterMode
Definition kis_opengl.h:34
@ BilinearFilterMode
Definition kis_opengl.h:35

References KisOpenGL::BilinearFilterMode, KoCanvasControllerWidget::canvas, KisCanvas2::canvasIsOpenGL(), levelOfDetailMode(), KisFloatingMessage::Low, m_d, KisOpenGL::NearestFilterMode, KisCanvas2::openGLFilterMode, KisCanvas2::setLodPreferredInCanvas(), value(), and KisCanvasController::Private::view.

◆ slotTogglePixelGrid

void KisCanvasController::slotTogglePixelGrid ( bool value)
slot

◆ slotToggleWrapAroundMode

void KisCanvasController::slotToggleWrapAroundMode ( bool value)
slot

Definition at line 332 of file kis_canvas_controller.cpp.

333{
334 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
335 Q_ASSERT(kritaCanvas);
336
337 if (!canvas()->canvasIsOpenGL() && value) {
338 m_d->view->viewManager()->showFloatingMessage(i18n("You are activating wrap-around mode, but have not enabled OpenGL.\n"
339 "To visualize wrap-around mode, enable OpenGL."), QIcon());
340 }
341 kritaCanvas->setWrapAroundViewingMode(value);
342 kritaCanvas->image()->setWrapAroundModePermitted(value);
343}
void setWrapAroundViewingMode(bool value)
void setWrapAroundModePermitted(bool value)

References KoCanvasControllerWidget::canvas, KisCanvas2::image(), m_d, KisImage::setWrapAroundModePermitted(), KisCanvas2::setWrapAroundViewingMode(), value(), and KisCanvasController::Private::view.

◆ syncOnImageResolutionChange()

void KisCanvasController::syncOnImageResolutionChange ( )

Definition at line 477 of file kis_canvas_controller.cpp.

478{
479 const KisCanvasState oldCanvasState = canvasState();
480
481 KisImageSP image = m_d->view->image();
483
491 }
492
493 const KisCanvasState newCanvasState = canvasState();
494
495 emitSignals(oldCanvasState, newCanvasState);
496}
void setZoom(qreal zoom) override
void setImageResolution(qreal xRes, qreal yRes)
double xRes() const
double yRes() const

References canvasState(), KisCanvasController::Private::coordinatesConverter, effectiveCanvasResolutionX(), effectiveCanvasResolutionY(), KoCanvasControllerWidget::emitSignals(), KisCoordinatesConverter::imageCenterInWidgetPixel(), m_d, KisCoordinatesConverter::makeWidgetStillPoint(), KisCoordinatesConverter::setImageResolution(), KisCoordinatesConverter::setZoom(), KisCanvasController::Private::usePrintResolutionMode, KisCanvasController::Private::view, KisImage::xRes(), KisImage::yRes(), KoZoomHandler::zoom(), and KoZoomHandler::zoomMode().

◆ syncOnImageSizeChange()

void KisCanvasController::syncOnImageSizeChange ( const QPointF & oldStillPoint,
const QPointF & newStillPoint )

Definition at line 498 of file kis_canvas_controller.cpp.

499{
500 const KisCanvasState oldCanvasState = canvasState();
501
502 KisImageSP image = m_d->view->image();
503 m_d->coordinatesConverter->setImageBounds(image->bounds(), oldStillPoint, newStillPoint);
504
505 const KisCanvasState newCanvasState = canvasState();
506
507 emitSignals(oldCanvasState, newCanvasState);
508}
void setImageBounds(const QRect &rect, const QPointF oldImageStillPoint, const QPointF newImageStillPoint)
QRect bounds() const override

References KisImage::bounds(), canvasState(), KisCanvasController::Private::coordinatesConverter, KoCanvasControllerWidget::emitSignals(), m_d, KisCoordinatesConverter::setImageBounds(), and KisCanvasController::Private::view.

◆ syncOnReferencesChange()

void KisCanvasController::syncOnReferencesChange ( const QRectF & referencesRect)

Definition at line 468 of file kis_canvas_controller.cpp.

469{
470 const KisCanvasState oldCanvasState = canvasState();
471 m_d->coordinatesConverter->setExtraReferencesBounds(referencesRect.toAlignedRect());
472 const KisCanvasState newCanvasState = canvasState();
473
474 emitSignals(oldCanvasState, newCanvasState);
475}
void setExtraReferencesBounds(const QRect &imageRect)

References canvasState(), KisCanvasController::Private::coordinatesConverter, KoCanvasControllerWidget::emitSignals(), m_d, and KisCoordinatesConverter::setExtraReferencesBounds().

◆ updateCanvasOffsetInternal()

void KisCanvasController::updateCanvasOffsetInternal ( const QPointF & newOffset)
overrideprotectedvirtual

Implements KoCanvasControllerWidget.

Definition at line 510 of file kis_canvas_controller.cpp.

511{
512 // not need to snap to device pixels, it is done by the converter automatically
514}
void setDocumentOffset(const QPointF &offset)

References KisCanvasController::Private::coordinatesConverter, m_d, and KisCoordinatesConverter::setDocumentOffset().

◆ updateCanvasWidgetSizeInternal()

void KisCanvasController::updateCanvasWidgetSizeInternal ( const QSize & newSize)
overrideprotectedvirtual

◆ updateCanvasZoomInternal()

void KisCanvasController::updateCanvasZoomInternal ( KoZoomMode::Mode mode,
qreal zoom,
qreal resolutionX,
qreal resolutionY,
const std::optional< KoViewTransformStillPoint > & docStillPoint )
overrideprotectedvirtual

Implements KoCanvasControllerWidget.

Definition at line 521 of file kis_canvas_controller.cpp.

522{
523 m_d->coordinatesConverter->setZoom(mode, zoom, resolutionX, resolutionY, docStillPoint);
524}

References KisCanvasController::Private::coordinatesConverter, m_d, and KisCoordinatesConverter::setZoom().

◆ updateScreenResolution()

void KisCanvasController::updateScreenResolution ( QWidget * parentWidget)

Definition at line 99 of file kis_canvas_controller.cpp.

100{
101 if (qFuzzyCompare(parentWidget->physicalDpiX(), m_d->physicalDpiX) &&
102 qFuzzyCompare(parentWidget->physicalDpiY(), m_d->physicalDpiY) &&
103 qFuzzyCompare(parentWidget->devicePixelRatioF(), m_d->devicePixelRatio)) {
104
105 return;
106 }
107
108 m_d->physicalDpiX = parentWidget->physicalDpiX();
109 m_d->physicalDpiY = parentWidget->physicalDpiY();
110 m_d->devicePixelRatio = parentWidget->devicePixelRatioF();
111
113
115}
void setUsePrintResolutionMode(bool value)
static bool qFuzzyCompare(half p1, half p2)

References KisCanvasController::Private::coordinatesConverter, KisCanvasController::Private::devicePixelRatio, m_d, KisCanvasController::Private::physicalDpiX, KisCanvasController::Private::physicalDpiY, qFuzzyCompare(), KisCoordinatesConverter::setDevicePixelRatio(), setUsePrintResolutionMode(), and KisCanvasController::Private::usePrintResolutionMode.

◆ usePrintResolutionMode()

bool KisCanvasController::usePrintResolutionMode ( )

Definition at line 631 of file kis_canvas_controller.cpp.

632{
634}

References m_d, and KisCanvasController::Private::usePrintResolutionMode.

◆ wheelEvent()

void KisCanvasController::wheelEvent ( QWheelEvent * event)
override

Dirty Hack Alert: Do not call the KoCanvasControllerWidget::wheelEvent() to disable the default behavior of KoCanvasControllerWidget and QAbstractScrollArea

Definition at line 153 of file kis_canvas_controller.cpp.

154{
160 Q_UNUSED(event);
161}

◆ wrapAroundMode()

bool KisCanvasController::wrapAroundMode ( ) const

Definition at line 345 of file kis_canvas_controller.cpp.

346{
347 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
348 Q_ASSERT(kritaCanvas);
349
350 return kritaCanvas->wrapAroundViewingMode();
351}
bool wrapAroundViewingMode() const

References KoCanvasControllerWidget::canvas, and KisCanvas2::wrapAroundViewingMode().

◆ wrapAroundModeAxis()

WrapAroundAxis KisCanvasController::wrapAroundModeAxis ( ) const

Definition at line 377 of file kis_canvas_controller.cpp.

378{
379 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
380 Q_ASSERT(kritaCanvas);
381
382 return kritaCanvas->wrapAroundViewingModeAxis();
383}
WrapAroundAxis wrapAroundViewingModeAxis() const

References KoCanvasControllerWidget::canvas, and KisCanvas2::wrapAroundViewingModeAxis().

◆ zoomIn() [1/2]

void KisCanvasController::zoomIn ( )
overridevirtual

Implements KoCanvasController.

Definition at line 552 of file kis_canvas_controller.cpp.

553{
554 zoomInImpl(std::nullopt);
555}
void zoomInImpl(const std::optional< KoViewTransformStillPoint > &stillPoint)

References zoomInImpl().

◆ zoomIn() [2/2]

void KisCanvasController::zoomIn ( const KoViewTransformStillPoint & stillPoint)
overridevirtual

zooms in keeping stillPoint not moved.

Implements KoCanvasController.

Definition at line 562 of file kis_canvas_controller.cpp.

563{
564 zoomInImpl(stillPoint);
565}

References zoomInImpl().

◆ zoomInImpl()

void KisCanvasController::zoomInImpl ( const std::optional< KoViewTransformStillPoint > & stillPoint)
private

◆ zoomOut() [1/2]

void KisCanvasController::zoomOut ( )
overridevirtual

Implements KoCanvasController.

Definition at line 557 of file kis_canvas_controller.cpp.

558{
559 zoomOutImpl(std::nullopt);
560}
void zoomOutImpl(const std::optional< KoViewTransformStillPoint > &stillPoint)

References zoomOutImpl().

◆ zoomOut() [2/2]

void KisCanvasController::zoomOut ( const KoViewTransformStillPoint & stillPoint)
overridevirtual

zooms out keeping stillPoint not moved.

Implements KoCanvasController.

Definition at line 567 of file kis_canvas_controller.cpp.

568{
569 zoomOutImpl(stillPoint);
570}

References zoomOutImpl().

◆ zoomOutImpl()

void KisCanvasController::zoomOutImpl ( const std::optional< KoViewTransformStillPoint > & stillPoint)
private

◆ zoomState()

KoZoomState KisCanvasController::zoomState ( ) const
overridevirtual

Implements KoCanvasController.

Definition at line 531 of file kis_canvas_controller.cpp.

532{
533 return canvasState().zoomState();
534}
KoZoomState zoomState() const

References canvasState(), and KisCanvasState::zoomState().

◆ zoomToInternal()

void KisCanvasController::zoomToInternal ( const QRect & viewRect)
overrideprotectedvirtual

Member Data Documentation

◆ m_d

Private* const KisCanvasController::m_d
private

Definition at line 116 of file kis_canvas_controller.h.


The documentation for this class was generated from the following files: