From a75e8b91c293b06a701b9fe37920b960938eb93e Mon Sep 17 00:00:00 2001 From: Michael Aganier Date: Tue, 29 Sep 2020 06:46:36 -0400 Subject: [PATCH] Eraser: Added Shift to erase on all layers (#2897) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Thorbjørn Lindeijer --- docs/manual/editing-tile-layers.rst | 2 ++ src/tiled/eraser.cpp | 29 +++++++++++++++++++---------- src/tiled/eraser.h | 5 ++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/manual/editing-tile-layers.rst b/docs/manual/editing-tile-layers.rst index cc0c3e9e98..7ca269e3cf 100644 --- a/docs/manual/editing-tile-layers.rst +++ b/docs/manual/editing-tile-layers.rst @@ -147,6 +147,8 @@ Shortcut: ``E`` A simple eraser tool. Left click erases single tiles and right click can be used to quickly erase rectangular areas. +- Holding ``Shift`` erases on all layers. + Selection Tools --------------- diff --git a/src/tiled/eraser.cpp b/src/tiled/eraser.cpp index b0cc05d031..3f2ca6b18c 100644 --- a/src/tiled/eraser.cpp +++ b/src/tiled/eraser.cpp @@ -38,7 +38,6 @@ Eraser::Eraser(QObject *parent) QKeySequence(Qt::Key_E), nullptr, parent) - , mMode(Nothing) { } @@ -59,7 +58,7 @@ void Eraser::mousePressed(QGraphicsSceneMouseEvent *event) mMode = Erase; doErase(false); return; - } else if (event->button() == Qt::RightButton && event->modifiers() == Qt::NoModifier) { + } else if (event->button() == Qt::RightButton) { mStart = tilePosition(); mMode = RectangleErase; return; @@ -88,6 +87,11 @@ void Eraser::mouseReleased(QGraphicsSceneMouseEvent *event) } } +void Eraser::modifiersChanged(Qt::KeyboardModifiers modifiers) +{ + mAllLayers = modifiers & Qt::ShiftModifier; +} + void Eraser::languageChanged() { setName(tr("Eraser")); @@ -105,17 +109,13 @@ void Eraser::doErase(bool continuation) } mLastTilePos = tilePos; - for (Layer *layer : mapDocument()->selectedLayers()) { - if (!layer->isTileLayer()) - continue; - if (!layer->isUnlocked()) - continue; - - auto tileLayer = static_cast(layer); + auto eraseOnLayer = [&] (TileLayer *tileLayer) { + if (!tileLayer->isUnlocked()) + return; QRegion eraseRegion = globalEraseRegion.intersected(tileLayer->bounds()); if (eraseRegion.isEmpty()) - continue; + return; EraseTiles *erase = new EraseTiles(mapDocument(), tileLayer, eraseRegion); erase->setMergeable(continuation); @@ -124,6 +124,15 @@ void Eraser::doErase(bool continuation) emit mapDocument()->regionEdited(eraseRegion, tileLayer); continuation = true; // further erases are always continuations + }; + + if (mAllLayers) { + for (Layer *layer : mapDocument()->map()->tileLayers()) + eraseOnLayer(static_cast(layer)); + } else { + for (Layer *layer : mapDocument()->selectedLayers()) + if (TileLayer *tileLayer = layer->asTileLayer()) + eraseOnLayer(tileLayer); } } diff --git a/src/tiled/eraser.h b/src/tiled/eraser.h index b7bb7a338b..9dee905fb7 100644 --- a/src/tiled/eraser.h +++ b/src/tiled/eraser.h @@ -37,6 +37,8 @@ class Eraser : public AbstractTileTool void mousePressed(QGraphicsSceneMouseEvent *event) override; void mouseReleased(QGraphicsSceneMouseEvent *event) override; + void modifiersChanged(Qt::KeyboardModifiers) override; + void languageChanged() override; protected: @@ -52,7 +54,8 @@ class Eraser : public AbstractTileTool RectangleErase }; - Mode mMode; + Mode mMode = Nothing; + bool mAllLayers = false; QPoint mLastTilePos; QPoint mStart; };