libs/flake
KoToolManager Class Reference
This class manages the activation and deactivation of tools for each input device. More...
#include <KoToolManager.h>

Detailed Description
This class manages the activation and deactivation of tools for each input device.
Managing the active tool and switching tool based on various variables.
The state of the toolbox will be the same for all views in the process so practically you can say we have one toolbox per application instance (process). Implementation does not allow one widget to be in more then one view, so we just make sure the toolbox is hidden in not-in-focus views.
The ToolManager is a singleton and will manage all views in all applications that are loaded in this process. This means you will have to register and unregister your view. When creating your new view you should use a KoCanvasController() and register that with the ToolManager like this:
MyGuiWidget::MyGuiWidget() {
m_canvasController = new KoCanvasController(this);
m_canvasController->setCanvas(m_canvas);
KoToolManager::instance()->addControllers(m_canvasController));
}
MyGuiWidget::~MyGuiWidget() {
KoToolManager::instance()->removeCanvasController(m_canvasController);
}
For a new view that extends KoView all you need to do is implement KoView::createToolBox()
KoToolManager also keeps track of the current tool based on a complex set of conditions and heuristics:
- there is one active tool per KoCanvasController (and there is one KoCanvasController per view, because this is a class with scrollbars and a zoomlevel and so on)
- for every pointing device (determined by the unique id of tablet, or 0 for mice -- you may have more than one mouse attached, but Qt cannot distinquish between them, there is an associated tool.
- depending on things like tablet leave/enter proximity, incoming mouse or tablet events and a little timer (that gets stopped when we know what is what), the active pointing device is determined, and the active tool is set accordingly.
Nota bene: if you use KoToolManager and register your canvases with it you no longer have to manually implement methods to route mouse, tablet, key or wheel events to the active tool. In fact, it's no longer interesting to you which tool is active; you can safely route the paint event through KoToolProxy::paint().
(The reason the input events are handled completely by the toolmanager and the paint events not is that, generally speaking, it's okay if the tools get the input events first, but you want to paint your shapes or other canvas stuff first and only then paint the tool stuff.)
Definition at line 98 of file KoToolManager.h.
Constructor & Destructor Documentation
| KoToolManager::~KoToolManager | ( | ) |
Definition at line 176 of file KoToolManager.cpp.
Member Function Documentation
| KoCanvasController * KoToolManager::activeCanvasController | ( | ) | const |
- Returns:
- the active canvas controller
Definition at line 702 of file KoToolManager.cpp.
| QString KoToolManager::activeToolId | ( | ) | const |
Returns the toolId of the currently active tool.
Definition at line 863 of file KoToolManager.cpp.
| void KoToolManager::addController | ( | KoCanvasController * | controller | ) |
Register a new canvas controller.
- Parameters:
-
controller the view controller that this toolmanager will manage the tools for
Definition at line 267 of file KoToolManager.cpp.
| void KoToolManager::changedCanvas | ( | const KoCanvasBase * | canvas | ) | [signal] |
Emitted whenever the active canvas changed.
- Parameters:
-
canvas the new activated canvas (might be 0)
| void KoToolManager::changedStatusText | ( | const QString & | statusText | ) | [signal] |
Emitted whenever the active tool changes the status text.
- Parameters:
-
statusText the new status text
| void KoToolManager::changedTool | ( | KoCanvasController * | canvas, | |
| int | uniqueToolId | |||
| ) | [signal] |
Emitted when a new tool was selected or became active.
- Parameters:
-
canvas the currently active canvas. uniqueToolId a random but unique code for the new tool.
| QList< KoToolManager::Button > KoToolManager::createToolList | ( | KoCanvasBase * | canvas | ) | const |
Create a list of buttons to represent all the tools.
- Returns:
- a list of Buttons. This is a factory method for buttons and meta information on the button to better display the button.
Definition at line 207 of file KoToolManager.cpp.
| KoInputDevice KoToolManager::currentInputDevice | ( | ) | const |
- Returns:
- the currently active pointing device
Definition at line 241 of file KoToolManager.cpp.
| void KoToolManager::currentLayerChanged | ( | const KoCanvasController * | canvas, | |
| const KoShapeLayer * | layer | |||
| ) | [signal] |
Emitted after the current layer changed either its properties or to a new layer.
- Parameters:
-
canvas the currently active canvas. layer the layer that is selected.
| KoGuidesTool * KoToolManager::guidesTool | ( | KoCanvasBase * | canvas | ) | const |
Returns the tool that is able to add/edit guides for this param canvas.
- Parameters:
-
canvas the canvas that is a child of a previously registered controller who's tool you want.
- See also:
- addController()
Definition at line 647 of file KoToolManager.cpp.
| void KoToolManager::injectDeviceEvent | ( | KoDeviceEvent * | event | ) |
Injects an input event from a plugin based input device.
Definition at line 845 of file KoToolManager.cpp.
| void KoToolManager::inputDeviceChanged | ( | const KoInputDevice & | device | ) | [signal] |
Every time a new input device gets used by a tool, this event is emitted.
- Parameters:
-
device the new input device that the user picked up.
| KoToolManager * KoToolManager::instance | ( | ) | [static] |
Return the toolmanager singleton.
Definition at line 857 of file KoToolManager.cpp.
For the list of shapes find out which tool is the highest priorty tool that can handle it.
- Returns:
- the toolId for the shapes.
- Parameters:
-
shapes a list of shapes, a selection for example, that is used to look for the tool.
Definition at line 724 of file KoToolManager.cpp.
| void KoToolManager::registerToolProxy | ( | KoToolProxy * | proxy, | |
| KoCanvasBase * | canvas | |||
| ) | [protected] |
Whenever a new tool proxy class is instantiated, it will use this method to register itself so the toolManager can update it to the latest active tool.
- Parameters:
-
proxy the proxy to register. canvas which canvas the proxy is associated with; whenever a new tool is selected for that canvas, the proxy gets an update.
Definition at line 834 of file KoToolManager.cpp.
| void KoToolManager::registerTools | ( | KActionCollection * | ac, | |
| KoCanvasController * | controller = 0 | |||
| ) |
Register actions for switching to tools at the actionCollection parameter.
The actions will have the text / shortcut as stated by the toolFactory. If the application calls this in their KoView extending class they will have all the benefits from allowing this in the menus and to allow the use to configure the shortcuts used.
- Parameters:
-
ac the actionCollection that will be the parent of the actions. controller tools registered with this controller will have all their actions added as well.
Definition at line 246 of file KoToolManager.cpp.
| void KoToolManager::removeCanvasController | ( | KoCanvasController * | controller | ) |
Remove a set of controllers When the controller is no longer used it should be removed so all tools can be deleted and stop eating memory.
- Parameters:
-
controller the controller that is removed
Definition at line 278 of file KoToolManager.cpp.
| void KoToolManager::requestToolActivation | ( | KoCanvasController * | controller | ) |
Request tool activation for the given canvas controller.
Definition at line 228 of file KoToolManager.cpp.
| KoCreateShapesTool * KoToolManager::shapeCreatorTool | ( | KoCanvasBase * | canvas | ) | const |
Return the tool that is able to create shapes for this param canvas.
This is typically used by the KoShapeSelector to set which shape to create next.
- Parameters:
-
canvas the canvas that is a child of a previously registered controller who's tool you want.
- See also:
- addController()
Definition at line 632 of file KoToolManager.cpp.
| void KoToolManager::switchInputDevice | ( | const KoInputDevice & | device | ) | [protected] |
Request a switch from to the param input device.
This will cause the tool for that device to be selected.
Definition at line 748 of file KoToolManager.cpp.
| void KoToolManager::switchToolByShortcut | ( | QKeyEvent * | event | ) | [protected] |
Definition at line 708 of file KoToolManager.cpp.
| void KoToolManager::switchToolRequested | ( | const QString & | id | ) | [slot] |
Request switching tool.
- Parameters:
-
id the id of the tool
Definition at line 604 of file KoToolManager.cpp.
| void KoToolManager::switchToolTemporaryRequested | ( | const QString & | id | ) | [protected, slot] |
Definition at line 614 of file KoToolManager.cpp.
| void KoToolManager::toolCodesSelected | ( | const KoCanvasController * | canvas, | |
| QList< QString > | types | |||
| ) | [signal] |
Emitted after the selection changed to state which unique shape-types are now in the selection.
- Parameters:
-
canvas the currently active canvas. types a list of string that are the shape types of the selected objects.
The documentation for this class was generated from the following files:
