libs/flake

KoCanvasController Class Reference

This widget is a wrapper around your canvas providing scrollbars. More...

#include <KoCanvasController.h>

Inheritance diagram for KoCanvasController:

List of all members.

Public Types

enum  CanvasMode { AlignTop, Centered, Infinite, Presentation }

Public Slots

void addGuideLine (Qt::Orientation orientation, int viewPosition)
void setDocumentSize (const QSize &newSize, bool recalculateCenter=true)

Signals

void canvasMousePositionChanged (const QPoint &pos)
void canvasOffsetXChanged (int offset)
void canvasOffsetYChanged (int offset)
void canvasRemoved (KoCanvasController *cv)
void canvasSet (KoCanvasController *cv)
void documentMousePositionChanged (const QPointF &pos)
void moveDocumentOffset (const QPoint &point)
void sizeChanged (const QSize &size)
void toolOptionWidgetsChanged (const QMap< QString, QWidget * > &)
void toolOptionWidgetsChanged (const QMap< QString, QWidget * > &, QWidget *)
void zoomBy (const qreal factor)

Public Member Functions

 KoCanvasController (QWidget *parent=0)
virtual ~KoCanvasController ()
KoCanvasBasecanvas () const
CanvasMode canvasMode () const
int canvasOffsetX () const
int canvasOffsetY () const
void changeCanvasWidget (QWidget *widget)
void ensureVisible (KoShape *shape)
void ensureVisible (const QRectF &rect, bool smooth=false)
virtual bool eventFilter (QObject *watched, QEvent *event)
bool isCanvasOpenGL () const
int margin () const
void pan (const QPoint &distance)
QPoint preferredCenter () const
void recenterPreferred ()
QPoint scrollBarValue () const
void scrollContentsBy (int dx, int dy)
void setCanvas (KoCanvasBase *canvas)
void setCanvasMode (CanvasMode mode)
void setDrawShadow (bool drawShadow)
void setMargin (int margin)
void setPreferredCenter (const QPoint &viewPoint)
void setScrollBarValue (const QPoint &value)
void setToolOptionWidgets (const QMap< QString, QWidget * > &)
int visibleHeight () const
int visibleWidth () const
void zoomBy (const QPoint &center, qreal zoom)
void zoomIn (const QPoint &center)
void zoomOut (const QPoint &center)
void zoomTo (const QRect &rect)

Protected Slots

void updateCanvasOffsetX ()
void updateCanvasOffsetY ()

Protected Member Functions

virtual void dragEnterEvent (QDragEnterEvent *event)
virtual void dragLeaveEvent (QDragLeaveEvent *event)
virtual void dragMoveEvent (QDragMoveEvent *event)
virtual void dropEvent (QDropEvent *event)
virtual bool focusNextPrevChild (bool next)
virtual void keyPressEvent (QKeyEvent *event)
virtual void paintEvent (QPaintEvent *event)
virtual void resizeEvent (QResizeEvent *resizeEvent)
virtual void wheelEvent (QWheelEvent *event)

Detailed Description

This widget is a wrapper around your canvas providing scrollbars.

Flake does not provide a canvas, the application will have to extend a QWidget and implement that themselves; but Flake does make it a lot easier to do so. One of those things is this widget that acts as a decorator around the canvas widget and provides scrollbars and allows the canvas to be centered in the viewArea

The using application can intantiate this class and add its canvas using the setCanvas() call. Which is designed so it can be called multiple times for those that wish to exchange one canvas widget for another.

Effectively, there is _one_ KoCanvasController per KoView in your application.

The canvas widget is at most as big as the viewport of the scroll area, and when the view on the document is near its edges, smaller. In your canvas widget code, you can find the right place in your document in pixel coordinates by adding the documentOffset

Definition at line 55 of file KoCanvasController.h.


Member Enumeration Documentation

An enum to alter the positioning and size of the canvas insize the canvas controller.

Enumerator:
AlignTop 

canvas is top aligned if smaller than the viewport

Centered 

canvas is centered if smaller than the viewport

Infinite 

canvas is never smaller than the viewport

Presentation 

canvas is not handled by KoCanvasController, canvas is full screen

Definition at line 60 of file KoCanvasController.h.


Constructor & Destructor Documentation

KoCanvasController::KoCanvasController ( QWidget parent = 0  )  [explicit]

Constructor.

Parameters:
parent the parent this widget will belong to

Definition at line 77 of file KoCanvasController.cpp.

KoCanvasController::~KoCanvasController (  )  [virtual]

Definition at line 101 of file KoCanvasController.cpp.


Member Function Documentation

void KoCanvasController::addGuideLine ( Qt::Orientation  orientation,
int  viewPosition 
) [slot]

Starts adding a new guide line.

The guides tool is activated which then handles placing the new guide line according to the mouse movement.

Definition at line 689 of file KoCanvasController.cpp.

KoCanvasBase * KoCanvasController::canvas (  )  const

Return the curently set canvas.

Returns:
the curently set canvas

Definition at line 147 of file KoCanvasController.cpp.

KoCanvasController::CanvasMode KoCanvasController::canvasMode (  )  const

Returns the current canvas mode.

Definition at line 212 of file KoCanvasController.cpp.

void KoCanvasController::canvasMousePositionChanged ( const QPoint pos  )  [signal]

Emitted when the cursor is moved over the canvas widget.

Parameters:
pos the position in widget pixels.
int KoCanvasController::canvasOffsetX (  )  const

return the amount of pixels that are not visible on the left side of the canvas.

The leftmost pixel that is shown is returned.

Definition at line 217 of file KoCanvasController.cpp.

void KoCanvasController::canvasOffsetXChanged ( int  offset  )  [signal]

Emitted when canvasOffsetX() changes.

Parameters:
offset the new canvas offset
int KoCanvasController::canvasOffsetY (  )  const

return the amount of pixels that are not visible on the top side of the canvas.

The topmost pixel that is shown is returned.

Definition at line 232 of file KoCanvasController.cpp.

void KoCanvasController::canvasOffsetYChanged ( int  offset  )  [signal]

Emitted when canvasOffsetY() changes.

Parameters:
offset the new canvas offset
void KoCanvasController::canvasRemoved ( KoCanvasController cv  )  [signal]

Emitted when a previously added canvas is about to be removed.

Parameters:
cv this object
void KoCanvasController::canvasSet ( KoCanvasController cv  )  [signal]

Emitted when a canvas is set on this widget.

Parameters:
cv this object
void KoCanvasController::changeCanvasWidget ( QWidget widget  ) 

Change the actual canvas widget used by the current canvas.

This allows the canvas widget to be changed while keeping the current KoCanvasBase canvas and its associated resources as they are. This might be used, for example, to switch from a QWidget to a QGLWidget canvas.

Parameters:
widget the new canvas widget.

Definition at line 152 of file KoCanvasController.cpp.

void KoCanvasController::documentMousePositionChanged ( const QPointF pos  )  [signal]

Emitted when the cursor is moved over the canvas widget.

Parameters:
pos the position in document coordinates.
void KoCanvasController::dragEnterEvent ( QDragEnterEvent event  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 572 of file KoCanvasController.cpp.

void KoCanvasController::dragLeaveEvent ( QDragLeaveEvent event  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 587 of file KoCanvasController.cpp.

void KoCanvasController::dragMoveEvent ( QDragMoveEvent event  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 582 of file KoCanvasController.cpp.

void KoCanvasController::dropEvent ( QDropEvent event  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 577 of file KoCanvasController.cpp.

void KoCanvasController::ensureVisible ( KoShape shape  ) 

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

This is just a wrapper function of the above function.

Parameters:
shape the shape to make visible

Definition at line 307 of file KoCanvasController.cpp.

void KoCanvasController::ensureVisible ( const QRectF rect,
bool  smooth = false 
)

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

The rect is to be specified in document coordinates. The scrollbar positions are changed so that the centerpoint of the rectangle is centered if possible.

Parameters:
rect the rectangle to make visible
smooth if true the viewport translation will make be just enough to ensure visibility, no more.

Definition at line 313 of file KoCanvasController.cpp.

bool KoCanvasController::eventFilter ( QObject watched,
QEvent event 
) [virtual]

Reimplemented from QObject.

Definition at line 271 of file KoCanvasController.cpp.

bool KoCanvasController::focusNextPrevChild ( bool  next  )  [protected, virtual]

reimplemented from QWidget

Definition at line 626 of file KoCanvasController.cpp.

bool KoCanvasController::isCanvasOpenGL (  )  const

Returns true if canvas uses QGLWidget (OpenGL can be used for painting on canvas).

Definition at line 486 of file KoCanvasController.cpp.

void KoCanvasController::keyPressEvent ( QKeyEvent event  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 592 of file KoCanvasController.cpp.

int KoCanvasController::margin (  )  const

Returns the current margin that is used to pad the canvas with.

This value is read from the KConfig property "canvasmargin"

Definition at line 666 of file KoCanvasController.cpp.

void KoCanvasController::moveDocumentOffset ( const QPoint point  )  [signal]

Emitted whenever the document is scrolled.

Parameters:
point the new top-left point from which the document should be drawn.
void KoCanvasController::paintEvent ( QPaintEvent event  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 566 of file KoCanvasController.cpp.

void KoCanvasController::pan ( const QPoint distance  ) 

Move the canvas over the x and y distance of the parameter distance.

Parameters:
distance the distance in pixels. A positive distance means moving the canvas up/left.

Definition at line 541 of file KoCanvasController.cpp.

QPoint KoCanvasController::preferredCenter (  )  const

Returns the currently set preferred center point in pixels.

Definition at line 558 of file KoCanvasController.cpp.

void KoCanvasController::recenterPreferred (  ) 

repositions the scrollbars so previous center is once again center

The previous center is cached from when the user uses the scrollbars or zoomTo are called. zoomTo is mostly used when a zoom tool of sorts have marked an area to zoom in on

The success of this method is limited by the size of thing. But we try our best.

Definition at line 350 of file KoCanvasController.cpp.

void KoCanvasController::resizeEvent ( QResizeEvent resizeEvent  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 118 of file KoCanvasController.cpp.

QPoint KoCanvasController::scrollBarValue (  )  const

Get the position of the scrollbar.

Definition at line 639 of file KoCanvasController.cpp.

void KoCanvasController::scrollContentsBy ( int  dx,
int  dy 
)

Reimplemented from QAbstractScrollArea.

Reimplemented from QAbstractScrollArea.

Definition at line 106 of file KoCanvasController.cpp.

void KoCanvasController::setCanvas ( KoCanvasBase canvas  ) 

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

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

Definition at line 128 of file KoCanvasController.cpp.

void KoCanvasController::setCanvasMode ( CanvasMode  mode  ) 

Sets the how the canvas behaves if the zoomed document becomes smaller than the viewport.

Parameters:
mode the new canvas mode, CanvasMode::Centered is the default value

Definition at line 192 of file KoCanvasController.cpp.

void KoCanvasController::setDocumentSize ( const QSize newSize,
bool  recalculateCenter = true 
) [slot]

Call this slot whenever the size of your document in pixels changes, for instance when zooming.

Parameters:
newSize the new size, in pixels, of the document.
recalculateCenter if true the offset in the document we center on after calling recenterPreferred() will be recalculated for the new document size so the visual offset stays the same.

Definition at line 438 of file KoCanvasController.cpp.

void KoCanvasController::setDrawShadow ( bool  drawShadow  ) 

Set the shadow option -- by default the canvas controller draws a black shadow around the canvas widget, which you may or may not want.

Parameters:
drawShadow if true, the shadow is drawn, if false, not

Definition at line 113 of file KoCanvasController.cpp.

void KoCanvasController::setMargin ( int  margin  ) 

Set the new margin to pad the canvas with.

Definition at line 632 of file KoCanvasController.cpp.

void KoCanvasController::setPreferredCenter ( const QPoint viewPoint  ) 

Sets the preferred center point in pixels.

Parameters:
viewPoint the new preferred center

Definition at line 551 of file KoCanvasController.cpp.

void KoCanvasController::setScrollBarValue ( const QPoint value  ) 

Set the position of the scrollbar.

Parameters:
the new values of the sroll bars

Definition at line 654 of file KoCanvasController.cpp.

void KoCanvasController::setToolOptionWidgets ( const QMap< QString, QWidget * > &  widgetMap  ) 

will cause the toolOptionWidgetsChanged to be emitted and all listeners to be updated to the new widget.

FIXME: This doesn't belong her and it does an inherits("KoView") so it too much tied to komain

Parameters:
widget the widget

Definition at line 424 of file KoCanvasController.cpp.

void KoCanvasController::sizeChanged ( const QSize size  )  [signal]

Emitted when the entire controller size changes.

Parameters:
size the size in widget pixels.
void KoCanvasController::toolOptionWidgetsChanged ( const QMap< QString, QWidget * > &   )  [signal]

Emit the new tool option widgets to be used with this canvas.

void KoCanvasController::toolOptionWidgetsChanged ( const QMap< QString, QWidget * > &  ,
QWidget  
) [signal]

Emit the new tool option widgets to be used with this canvas.

void KoCanvasController::updateCanvasOffsetX (  )  [protected, slot]

Called by the horizontal scrollbar when its value changes.

Definition at line 247 of file KoCanvasController.cpp.

void KoCanvasController::updateCanvasOffsetY (  )  [protected, slot]

Called by the vertical scrollbar when its value changes.

Definition at line 259 of file KoCanvasController.cpp.

int KoCanvasController::visibleHeight (  )  const

return the amount of pixels vertically visible of the child canvas.

Returns:
the amount of pixels vertically visible of the child canvas.

Definition at line 162 of file KoCanvasController.cpp.

int KoCanvasController::visibleWidth (  )  const

return the amount of pixels horizontally visible of the child canvas.

Returns:
the amount of pixels horizontally visible of the child canvas.

Definition at line 177 of file KoCanvasController.cpp.

void KoCanvasController::wheelEvent ( QWheelEvent event  )  [protected, virtual]

reimplemented from QWidget

Reimplemented from QAbstractScrollArea.

Definition at line 597 of file KoCanvasController.cpp.

void KoCanvasController::zoomBy ( const qreal  factor  )  [signal]

Emitted when zoomTo have calculated a factor by which the zoom should change, or if someone calls requestZoomBy Someone needs to connect to this and take action.

Parameters:
factor by how much the zoom needs to change.
void KoCanvasController::zoomBy ( const QPoint center,
qreal  zoom 
)

zooms around the center.

The center must be specified in pixel coordinates. The scrollbar positions are changed so that the center becomes center if possible.

Parameters:
center the position to zoom around
zoom the zoom to apply

Definition at line 391 of file KoCanvasController.cpp.

void KoCanvasController::zoomIn ( const QPoint center  ) 

zooms in around the center.

The center must be specified in document coordinates. The scrollbar positions are changed so that the center becomes center if possible.

Parameters:
center the position to zoom in on

Definition at line 381 of file KoCanvasController.cpp.

void KoCanvasController::zoomOut ( const QPoint center  ) 

zooms out around the center.

The center must be specified in pixel coordinates. The scrollbar positions are changed so that the center becomes center if possible.

Parameters:
center the position to zoom out around

Definition at line 386 of file KoCanvasController.cpp.

void KoCanvasController::zoomTo ( const QRect rect  ) 

zoom so that rect is exactly visible (as close as possible)

The rect must be specified in pixel coordinates. The scrollbar positions are changed so that the center of the rect becomes center if possible.

Parameters:
rect the rect in pixel coords that should fit the view afterwards

Definition at line 404 of file KoCanvasController.cpp.


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