Commit 605fc2e9 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Merge branch 'tool-manager-switching-devices-kazakov'

parents aaf7fe65 cf2d7731
......@@ -157,7 +157,7 @@ public:
KoToolManager::Private::Private(KoToolManager *qq)
: q(qq),
canvasData(0),
layerEnabled(true)
layerExplicitlyDisabled(false)
{
}
......@@ -186,15 +186,6 @@ CanvasData *KoToolManager::Private::createCanvasData(KoCanvasController *control
return cd;
}
bool KoToolManager::Private::toolCanBeUsed(const QString &activationShapeId)
{
if (layerEnabled)
return true;
if (activationShapeId.endsWith(QLatin1String("/always")))
return true;
return false;
}
void KoToolManager::Private::setup()
{
if (tools.size() > 0)
......@@ -292,8 +283,6 @@ void KoToolManager::Private::switchTool(const QString &id, bool temporary)
foreach(ToolHelper *th, tools) {
if (th->id() == id) {
if (!toolCanBeUsed(th->activationShapeId()))
return;
canvasData->activationShapeId = th->activationShapeId();
break;
}
......@@ -343,12 +332,10 @@ void KoToolManager::Private::postSwitchTool(bool temporary)
}
if (canvasData->canvas->canvas()) {
KoCanvasBase *canvas = canvasData->canvas->canvas();
// Caller of postSwitchTool expect this to be called to update the selected tool
KoToolProxy *tp = proxies.value(canvas);
if (tp)
tp->setActiveTool(canvasData->activeTool);
updateToolForProxy();
canvasData->activeTool->activate(toolActivation, shapesToOperateOn);
KoCanvasBase *canvas = canvasData->canvas->canvas();
canvas->updateInputMethodInfo();
} else {
canvasData->activeTool->activate(toolActivation, shapesToOperateOn);
......@@ -394,8 +381,6 @@ void KoToolManager::Private::postSwitchTool(bool temporary)
void KoToolManager::Private::toolActivated(ToolHelper *tool)
{
Q_ASSERT(tool);
if (!toolCanBeUsed(tool->activationShapeId()))
return;
Q_ASSERT(canvasData);
if (!canvasData) return;
......@@ -632,19 +617,20 @@ void KoToolManager::Private::selectionChanged(QList<KoShape*> shapes)
void KoToolManager::Private::currentLayerChanged(const KoShapeLayer *layer)
{
kDebug(30006) << "layer changed to" << layer;
emit q->currentLayerChanged(canvasData->canvas, layer);
layerEnabled = layer == 0 || (layer->isEditable() && layer->isVisible());
layerExplicitlyDisabled = layer && !layer->isEditable();
updateToolForProxy();
kDebug(30006) << "and the layer enabled is" << (layerEnabled ? "true" : "false");
kDebug(30006) << "Layer changed to" << layer << "explicitly disabled:" << layerExplicitlyDisabled;
}
void KoToolManager::Private::updateToolForProxy()
{
KoToolProxy *proxy = proxies.value(canvasData->canvas->canvas());
kDebug(30006) << " and the proxy is" << proxy;
if (proxy) {
kDebug(30006) << " set" << canvasData->activeTool << (layerEnabled ? "enabled" : "disabled");
proxy->setActiveTool(toolCanBeUsed(canvasData->activationShapeId) ? canvasData->activeTool : 0);
}
if(!proxy) return;
bool canUseTool = !layerExplicitlyDisabled || canvasData->activationShapeId.endsWith(QLatin1String("/always"));
proxy->setActiveTool(canUseTool ? canvasData->activeTool : 0);
}
void KoToolManager::Private::switchInputDevice(const KoInputDevice &device)
......
......@@ -64,9 +64,9 @@ public:
void switchBackRequested();
void selectionChanged(QList<KoShape*> shapes);
void currentLayerChanged(const KoShapeLayer *layer);
void updateToolForProxy();
void switchToolTemporaryRequested(const QString &id);
CanvasData *createCanvasData(KoCanvasController *controller, KoInputDevice device);
bool toolCanBeUsed( const QString &activationShapeId);
/**
* Request a switch from to the param input device.
......@@ -98,7 +98,7 @@ public:
KoInputDevice inputDevice;
bool layerEnabled;
bool layerExplicitlyDisabled;
};
/// \internal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment