Skip to content

Commit

Permalink
Eraser: Added Shift to erase on all layers (#2897)
Browse files Browse the repository at this point in the history
Co-authored-by: Thorbjørn Lindeijer <[email protected]>
  • Loading branch information
aganm and bjorn authored Sep 29, 2020
1 parent 10c943f commit a75e8b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/manual/editing-tile-layers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------

Expand Down
29 changes: 19 additions & 10 deletions src/tiled/eraser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Eraser::Eraser(QObject *parent)
QKeySequence(Qt::Key_E),
nullptr,
parent)
, mMode(Nothing)
{
}

Expand All @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -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<TileLayer*>(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);
Expand All @@ -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<TileLayer*>(layer));
} else {
for (Layer *layer : mapDocument()->selectedLayers())
if (TileLayer *tileLayer = layer->asTileLayer())
eraseOnLayer(tileLayer);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/tiled/eraser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -52,7 +54,8 @@ class Eraser : public AbstractTileTool
RectangleErase
};

Mode mMode;
Mode mMode = Nothing;
bool mAllLayers = false;
QPoint mLastTilePos;
QPoint mStart;
};
Expand Down

0 comments on commit a75e8b9

Please sign in to comment.