Commit cf2d7731 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fixed a tool activation when the current layer is not enabled

Way to reproduce:
1) Open new document
2) Disable a layer with a mouse
3) Enable a layer with a tablet
You will not be able to paint with the tablet.

What actually happened was that a new CanvasData was created, but
the previous tool could not be activated in the new data, because of
an explicit check in switchTool. So that we ended up in a state with
no tool at all.

This patch brings a bit more consistency there. Now you can always
switch the tool in the KoToolManager, even when active layer is
disabled, but the KoToolProxy will get information about the new tool
only when the layer gets enabled back. This is what the code in
currentLayerChanged() and toolCanBeUsed() has been doing before. There was
inconsistency in postSwitchTool(), because it didn't check for the
availability of the active layer, now it is gone.

BUG:277047
parent 6ae88957
......@@ -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