From 0de0f20e304bbed4d8c52e4cc09586bb12d34c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 20 Mar 2018 12:24:21 +0100 Subject: [PATCH] Re-enabled Space for toggling layer visibility Also added Ctrl+Space as shortcut for toggling whether the current layer is locked. These shortcuts only work while the layer list is focused. --- src/tiled/layerdock.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/tiled/layerdock.cpp b/src/tiled/layerdock.cpp index d097b76a64..9891054ef6 100644 --- a/src/tiled/layerdock.cpp +++ b/src/tiled/layerdock.cpp @@ -23,6 +23,7 @@ #include "layerdock.h" +#include "changelayer.h" #include "layer.h" #include "layermodel.h" #include "map.h" @@ -350,14 +351,24 @@ void LayerView::contextMenuEvent(QContextMenuEvent *event) void LayerView::keyPressEvent(QKeyEvent *event) { + Layer *layer = mMapDocument ? mMapDocument->currentLayer() : nullptr; + switch (event->key()) { case Qt::Key_Delete: case Qt::Key_Backspace: - if (mMapDocument) { - const LayerModel *layerModel = mMapDocument->layerModel(); - const QModelIndex index = mProxyModel->mapToSource(currentIndex()); - if (auto layer = layerModel->toLayer(index)) - mMapDocument->removeLayer(layer); + if (layer) { + mMapDocument->removeLayer(layer); + return; + } + break; + case Qt::Key_Space: + if (layer) { + QUndoCommand *command = nullptr; + if (event->modifiers() & Qt::ControlModifier) + command = new SetLayerLocked(mMapDocument, layer, !layer->isLocked()); + else + command = new SetLayerVisible(mMapDocument, layer, !layer->isVisible()); + mMapDocument->undoStack()->push(command); return; } break;