Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
CanvasView Class Reference

Custom QGraphicsView for a canvas application. More...

#include <canvas_view.h>

Inheritance diagram for CanvasView:

Public Member Functions

 CanvasView (QWidget *parent=nullptr)
 Constructs a new CanvasView object.
QPointF getCenter () const
 Gets the current center point of the view.
qreal getScale () const
 Gets the current scale factor of the view.
void setScale (qreal scale)
 Sets the scale factor of the view.
void zoom (float scaleFactor)
 Zooms in by a given scale factor.
void centerOn (const QPointF &pos)
 Centers the view on a specific position.
void centerOn (const QGraphicsItem *item)
 Centers the view on a specific QGraphicsItem.
void onSettingsChanged (const AppearanceSettings &settings)
 Handles settings changes, specifically for appearance settings.

Protected Member Functions

void keyPressEvent (QKeyEvent *) override
 Overrides the key press event to handle zoom and pan controls.
void keyReleaseEvent (QKeyEvent *) override
 Overrides the key release event to handle zoom and pan controls.
void mouseMoveEvent (QMouseEvent *) override
 Overrides the mouse move event to handle panning.
void mousePressEvent (QMouseEvent *) override
 Overrides the mouse press event to start panning or zooming.
void mouseReleaseEvent (QMouseEvent *) override
 Overrides the mouse release event to stop panning.
void wheelEvent (QWheelEvent *) override
 Overrides the wheel event to handle zooming.
void drawBackground (QPainter *painter, const QRectF &rect) override
 Draws the background of the view, including a grid if enabled.

Private Member Functions

void zoomIn ()
 Zooms in by applying a zoom factor of 1 + mZoomDelta.
void zoomOut ()
 Zooms out by applying a zoom factor of 1 - mZoomDelta.
void resetZoom ()
 Resets the view to its default scale.
qreal quantisedScale (qreal proposedScale) const
 Quantises the proposed scale to ensure it is within valid limits and aligned with grid size.
void setMaxSize ()
 Sets the maximum size of the view's scene rectangle.

Private Attributes

bool mDoMousePanning
 Flags to determine if zooming or panning should be done.
bool mDoKeyZoom
 Flag to determine if key-based zooming is active.
bool mShowGrid
 Flag to show the grid on the canvas.
QPoint mLastMousePos
 Last mouse position for panning.
qreal mZoomDelta
 Delta value for zooming.
qreal mZoomKey
 Key used for zooming.
qreal mMinZoom
 Minimum allowed zoom level.
qreal mMaxZoom
 Maximum allowed zoom level.
Qt::MouseButton mPanButton
 Mouse button used for panning.

Detailed Description

Custom QGraphicsView for a canvas application.

Constructor & Destructor Documentation

◆ CanvasView()

CanvasView::CanvasView ( QWidget * parent = nullptr)

Constructs a new CanvasView object.

Parameters
parentPointer to the parent widget.

Member Function Documentation

◆ centerOn() [1/2]

void CanvasView::centerOn ( const QGraphicsItem * item)

Centers the view on a specific QGraphicsItem.

Parameters
itemThe QGraphicsItem to center on.

◆ centerOn() [2/2]

void CanvasView::centerOn ( const QPointF & pos)

Centers the view on a specific position.

Parameters
posThe position to center on.

◆ drawBackground()

void CanvasView::drawBackground ( QPainter * painter,
const QRectF & rect )
overrideprotected

Draws the background of the view, including a grid if enabled.

Parameters
painterPointer to the QPainter object.
rectThe rectangle to draw the background in.

◆ getCenter()

QPointF CanvasView::getCenter ( ) const

Gets the current center point of the view.

Returns
QPointF The center point.

◆ getScale()

qreal CanvasView::getScale ( ) const

Gets the current scale factor of the view.

Returns
qreal The scale factor.

◆ keyPressEvent()

void CanvasView::keyPressEvent ( QKeyEvent * event)
overrideprotected

Overrides the key press event to handle zoom and pan controls.

Parameters
eventPointer to the QKeyEvent object.

◆ keyReleaseEvent()

void CanvasView::keyReleaseEvent ( QKeyEvent * event)
overrideprotected

Overrides the key release event to handle zoom and pan controls.

Parameters
eventPointer to the QKeyEvent object.

◆ mouseMoveEvent()

void CanvasView::mouseMoveEvent ( QMouseEvent * event)
overrideprotected

Overrides the mouse move event to handle panning.

Parameters
eventPointer to the QMouseEvent object.

◆ mousePressEvent()

void CanvasView::mousePressEvent ( QMouseEvent * event)
overrideprotected

Overrides the mouse press event to start panning or zooming.

Parameters
eventPointer to the QMouseEvent object.

◆ mouseReleaseEvent()

void CanvasView::mouseReleaseEvent ( QMouseEvent * event)
overrideprotected

Overrides the mouse release event to stop panning.

Parameters
eventPointer to the QMouseEvent object.

◆ onSettingsChanged()

void CanvasView::onSettingsChanged ( const AppearanceSettings & settings)

Handles settings changes, specifically for appearance settings.

Parameters
settingsThe new appearance settings.

◆ quantisedScale()

qreal CanvasView::quantisedScale ( qreal proposedScale) const
private

Quantises the proposed scale to ensure it is within valid limits and aligned with grid size.

Parameters
proposedScaleThe proposed scale factor.
Returns
qreal The quantised scale factor.

◆ setScale()

void CanvasView::setScale ( qreal scale)

Sets the scale factor of the view.

Parameters
scaleThe new scale factor.

◆ wheelEvent()

void CanvasView::wheelEvent ( QWheelEvent * event)
overrideprotected

Overrides the wheel event to handle zooming.

Parameters
eventPointer to the QWheelEvent object.

◆ zoom()

void CanvasView::zoom ( float scaleFactor)

Zooms in by a given scale factor.

Parameters
scaleFactorThe zoom scale factor.

The documentation for this class was generated from the following files:
  • /__w/maki/maki/app/system/canvas_view.h
  • /__w/maki/maki/app/system/canvas_view.cpp