libs/flake

KoInteractionTool Class Reference

The interaction tool adds to the normal KoTool class the concept of strategies as a means to get one tool to have different actions the user can perform using the mouse. More...

#include <KoInteractionTool.h>

Inheritance diagram for KoInteractionTool:

List of all members.

Public Member Functions

 KoInteractionTool (KoCanvasBase *canvas)
virtual ~KoInteractionTool ()
virtual void keyPressEvent (QKeyEvent *event)
virtual void keyReleaseEvent (QKeyEvent *event)
virtual void mouseMoveEvent (KoPointerEvent *event)
virtual void mousePressEvent (KoPointerEvent *event)
virtual void mouseReleaseEvent (KoPointerEvent *event)
virtual void paint (QPainter &painter, const KoViewConverter &converter)

Protected Member Functions

virtual KoInteractionStrategycreateStrategy (KoPointerEvent *event)=0

Protected Attributes

KoInteractionStrategym_currentStrategy

Detailed Description

The interaction tool adds to the normal KoTool class the concept of strategies as a means to get one tool to have different actions the user can perform using the mouse.

Each time the user presses the mouse until she releases the mouse a strategy object will be created, used and disgarded. If the usage of a tool fits this pattern you need to inherit from this class instead of the plain KoTool and reimplement your createStrategy() method which returns a tool-specific strategy where all the real interaction code is placed. A tool can then become as simple as this;

    class MyTool : public KoInteractionTool
    {
    public:
        MyTool::MyTool(KoCanvasBase *canvas) : KoInteractionTool( canvas ) { }

        KoInteractionStrategy *MyTool::createStrategy(KoPointerEvent *event) {
            return new MyStrategy(this, m_canvas, event->point);
        }
    };

Whereas your strategy (MyStrategy in the example) will contain the interaction code.

Definition at line 54 of file KoInteractionTool.h.


Constructor & Destructor Documentation

KoInteractionTool::KoInteractionTool ( KoCanvasBase canvas  )  [explicit]

Constructor for basic interaction tool where user actions are translated and handled by interaction strategies of type KoInteractionStrategy.

Parameters:
canvas the canvas this tool will be working for.

Definition at line 35 of file KoInteractionTool.cpp.

KoInteractionTool::~KoInteractionTool (  )  [virtual]

Definition at line 42 of file KoInteractionTool.cpp.


Member Function Documentation

virtual KoInteractionStrategy* KoInteractionTool::createStrategy ( KoPointerEvent event  )  [protected, pure virtual]

Reimplement this factory method to create your strategy to be used for mouse interaction.

Returns:
a new strategy, or 0 when there is nothing to do.

Implemented in KoCreateShapesTool.

void KoInteractionTool::keyPressEvent ( QKeyEvent event  )  [virtual]

Called when a key is pressed.

Implementors should call event->ignore() if they do not actually use the event. Default implementation ignores this event.

Parameters:
event state and reason of this key press

Reimplemented from KoTool.

Reimplemented in KoZoomTool.

Definition at line 91 of file KoInteractionTool.cpp.

void KoInteractionTool::keyReleaseEvent ( QKeyEvent event  )  [virtual]

Called when a key is released Implementors should call event->ignore() if they do not actually use the event.

Default implementation ignores this event.

Parameters:
event state and reason of this key release

Reimplemented from KoTool.

Reimplemented in KoZoomTool.

Definition at line 103 of file KoInteractionTool.cpp.

void KoInteractionTool::mouseMoveEvent ( KoPointerEvent event  )  [virtual]

Called when the mouse or stylus moved over the canvas.

Implementors should call event->ignore() if they do not actually use the event.

Parameters:
event state and reason of this mouse or stylus move

Implements KoTool.

Reimplemented in KoZoomTool.

Definition at line 68 of file KoInteractionTool.cpp.

void KoInteractionTool::mousePressEvent ( KoPointerEvent event  )  [virtual]

Called when (one of) the mouse or stylus buttons is pressed.

Implementors should call event->ignore() if they do not actually use the event.

Parameters:
event state and reason of this mouse or stylus press

Implements KoTool.

Definition at line 55 of file KoInteractionTool.cpp.

void KoInteractionTool::mouseReleaseEvent ( KoPointerEvent event  )  [virtual]

Called when (one of) the mouse or stylus buttons is released.

Implementors should call event->ignore() if they do not actually use the event.

Parameters:
event state and reason of this mouse or stylus release

Implements KoTool.

Reimplemented in KoCreateShapesTool, and KoZoomTool.

Definition at line 77 of file KoInteractionTool.cpp.

void KoInteractionTool::paint ( QPainter painter,
const KoViewConverter converter 
) [virtual]

Called by the canvas to paint any decorations that the tool deems needed.

The painter has the top left of the canvas as its origin.

Parameters:
painter used for painting the shape
converter to convert between internal and view coordinates.

Implements KoTool.

Reimplemented in KoCreateShapesTool.

Definition at line 49 of file KoInteractionTool.cpp.


Member Data Documentation

the strategy that is 'in progress'

Definition at line 77 of file KoInteractionTool.h.


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