Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Holding shift with the eraser erases from all layers #2897

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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