18#include "kopalettemanager.h"
20#include "kis_part_layer.h"
21#include "kis_tool_manager.h"
22#include "kis_tool_registry.h"
23#include "kis_tool_dummy.h"
24#include "kis_canvas_subject.h"
25#include "kis_tool_controller.h"
27#include "kis_canvas.h"
28#include "kis_cursor.h"
32#include "kis_input_device.h"
37 m_controller(controller)
43 m_actionCollection = 0;
44 m_tools_disabled =
false;
48KisToolManager::~KisToolManager()
53void KisToolManager::setUp(KoToolBox * toolbox, KoPaletteManager * paletteManager, TDEActionCollection * actionCollection)
56 resetToolBox( toolbox );
61 m_paletteManager = paletteManager;
62 m_actionCollection = actionCollection;
66 m_dummyTool = KisToolDummyFactory().createTool(actionCollection);
68 TQValueVector<KisInputDevice> inputDevices = KisInputDevice::inputDevices();
70 for (TQ_UINT32 inputDevice = 0; inputDevice < inputDevices.count(); inputDevice++) {
71 m_inputDeviceToolSetMap[inputDevices[inputDevice]] = KisToolRegistry::instance()->createTools(actionCollection, m_subject);
74 m_tools = m_inputDeviceToolSetMap[KisInputDevice::mouse()];
75 for (vKisTool_it it = m_tools.begin(); it != m_tools.end(); ++it) {
78 toolbox->registerTool( t->action(), t->toolType(), t->priority() );
81 toolbox->setupTools();
83 KisTool * t = findTool(
"tool_brush");
94void KisToolManager::youAintGotNoToolBox()
97 m_oldTool = currentTool();
100void KisToolManager::resetToolBox(KoToolBox * toolbox)
104 m_tools = m_inputDeviceToolSetMap[KisInputDevice::mouse()];
105 for (vKisTool_it it = m_tools.begin(); it != m_tools.end(); ++it) {
108 m_toolBox->registerTool( t->action(), t->toolType(), t->priority() );
111 toolbox->setupTools();
114 setCurrentTool(findTool(
"tool_brush"));
118 setCurrentTool(m_oldTool);
125void KisToolManager::updateGUI()
128 if (m_subject == 0) {
133 if (!m_toolBox)
return;
135 KisImageSP img = m_subject->currentImg();
141 KisPartLayer * partLayer =
dynamic_cast<KisPartLayer*
>(l.data());
144 l = img->activeLayer();
145 enable = l && !l->locked() && l->visible() && (partLayer == 0);
148 m_toolBox->enableTools( enable );
150 KisTool * current = currentTool();
153 if (!enable && current != m_dummyTool) {
155 m_oldTool = currentTool();
158 m_dummyTool = KisToolDummyFactory().createTool(m_actionCollection);
160 setCurrentTool(m_dummyTool);
161 m_tools_disabled =
true;
163 else if (enable && m_tools_disabled) {
164 m_tools_disabled =
false;
167 setCurrentTool(m_oldTool);
172 KisTool * t = findTool(
"tool_brush");
178void KisToolManager::setCurrentTool(KisTool *tool)
180 KisTool *oldTool = currentTool();
181 KisCanvas * canvas = (KisCanvas*)m_controller->kiscanvas();
186 oldTool->deactivate();
187 oldTool->action()->setChecked(
false );
189 m_paletteManager->removeWidget(chalk::TOOL_OPTION_WIDGET);
194 if (!tool->optionWidget()) {
195 tool->createOptionWidget(0);
197 TQWidget * w = tool->optionWidget();
200 m_paletteManager->addWidget(w, chalk::TOOL_OPTION_WIDGET, chalk::CONTROL_PALETTE );
202 m_inputDeviceToolMap[m_controller->currentInputDevice()] = tool;
203 m_controller->setCanvasCursor(tool->cursor());
205 canvas->enableMoveEventCompressionHint(
dynamic_cast<KisToolNonPaint *
>(tool) != NULL);
207 m_subject->notifyObservers();
209 tool->action()->setChecked(
true );
210 tool->action()->activate();
211 m_toolBox->slotSetTool(tool->name());
213 m_inputDeviceToolMap[m_controller->currentInputDevice()] = 0;
214 m_controller->setCanvasCursor(KisCursor::arrowCursor());
219void KisToolManager::setCurrentTool(
const TQString & toolName )
221 setCurrentTool(findTool(toolName));
224KisTool * KisToolManager::currentTool()
const
226 InputDeviceToolMap::const_iterator it = m_inputDeviceToolMap.find(m_controller->currentInputDevice());
228 if (it != m_inputDeviceToolMap.end()) {
236void KisToolManager::setToolForInputDevice(KisInputDevice oldDevice, KisInputDevice newDevice)
238 InputDeviceToolSetMap::iterator vit = m_inputDeviceToolSetMap.find(oldDevice);
240 if (vit != m_inputDeviceToolSetMap.end()) {
241 vKisTool& oldTools = (*vit).second;
242 for (vKisTool::iterator it = oldTools.begin(); it != oldTools.end(); ++it) {
244 TDEAction *toolAction = tool->action();
245 toolAction->disconnect(TQ_SIGNAL(activated()), tool, TQ_SLOT(activate()));
248 KisTool *oldTool = currentTool();
251 m_paletteManager->removeWidget(chalk::TOOL_OPTION_WIDGET);
252 oldTool->deactivate();
256 vit = m_inputDeviceToolSetMap.find(newDevice);
258 Q_ASSERT(vit != m_inputDeviceToolSetMap.end());
260 vKisTool& tools = (*vit).second;
262 for (vKisTool::iterator it = tools.begin(); it != tools.end(); ++it) {
264 TDEAction *toolAction = tool->action();
265 connect(toolAction, TQ_SIGNAL(activated()), tool, TQ_SLOT(activate()));
269void KisToolManager::activateCurrentTool()
271 KisTool * t = currentTool();
272 if (t && t->action()) {
273 t->action()->activate();
277KisTool * KisToolManager::findTool(
const TQString &toolName, KisInputDevice inputDevice)
const
279 if (inputDevice == KisInputDevice::unknown()) {
280 inputDevice = m_controller->currentInputDevice();
285 InputDeviceToolSetMap::const_iterator vit = m_inputDeviceToolSetMap.find(inputDevice);
287 Q_ASSERT(vit != m_inputDeviceToolSetMap.end());
289 const vKisTool& tools = (*vit).second;
291 for (vKisTool::const_iterator it = tools.begin(); it != tools.end(); ++it) {
293 if (t->name() == toolName) {
303#include "kis_tool_manager.moc"
Interface for classes that implement a canvas; i.e., a widget where KisImages are painted onto.
KisCanvasSubject is part of the Observer pattern.