Skip to content
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Added button to toggle Terrain Brush to full tile mode (by Finlay Pearson, #3407)
* Added square selection and expand-from-center to Rectangular Select tool (#4201)
* Added status info for various Stamp Brush, Terrain Brush and Eraser modes (#3092, #4201)
* Added Escape to clear tile selection when any tile related tool is selected (#4243)
* Added Escape to cancel tile selection and shape drawing operations
* Added export plugin for Remixed Dungeon (by Mikhael Danilov, #4158)
* Added "World > World Properties" menu action (with dogboydog, #4190)
* Added Delete shortcut to Remove Tiles action by default and avoid ambiguity (#4201)
Expand Down
15 changes: 15 additions & 0 deletions src/tiled/abstracttiletool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "abstracttiletool.h"

#include "brushitem.h"
#include "changeselectedarea.h"
#include "map.h"
#include "mapdocument.h"
#include "maprenderer.h"
Expand Down Expand Up @@ -152,6 +153,20 @@ void AbstractTileTool::mousePressed(QGraphicsSceneMouseEvent *event)
event->ignore();
}

void AbstractTileTool::keyPressed(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape) {
MapDocument *document = mapDocument();
if (document && !document->selectedArea().isEmpty()) {
QUndoCommand *cmd = new ChangeSelectedArea(document, QRegion());
document->undoStack()->push(cmd);
return;
}
}

AbstractTool::keyPressed(event);
}

void AbstractTileTool::mapDocumentChanged(MapDocument *oldDocument,
MapDocument *newDocument)
{
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/abstracttiletool.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class AbstractTileTool : public AbstractTool
void mouseMoved(const QPointF &pos, Qt::KeyboardModifiers modifiers) override;
void mousePressed(QGraphicsSceneMouseEvent *event) override;

void keyPressed(QKeyEvent *event) override;

protected:
void mapDocumentChanged(MapDocument *oldDocument,
MapDocument *newDocument) override;
Expand Down
28 changes: 22 additions & 6 deletions src/tiled/shapefilltool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@

#include <QActionGroup>
#include <QApplication>
#include <QKeyEvent>
#include <QToolBar>
#include <QUndoStack>

#include <memory>

using namespace Tiled;

ShapeFillTool::ShapeFillTool(QObject *parent)
Expand Down Expand Up @@ -86,9 +85,7 @@ void ShapeFillTool::mousePressed(QGraphicsSceneMouseEvent *event)
{
// Right-click cancels drawing a shape
if (mToolBehavior == MakingShape && event->button() == Qt::RightButton) {
mToolBehavior = Free;
clearOverlay();
updateStatusInfo();
cancelMakingShape();
return;
}

Expand Down Expand Up @@ -139,6 +136,18 @@ void ShapeFillTool::modifiersChanged(Qt::KeyboardModifiers modifiers)
updateFillOverlay();
}

void ShapeFillTool::keyPressed(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape) {
if (mToolBehavior == MakingShape) {
cancelMakingShape();
return;
}
}

AbstractTileFillTool::keyPressed(event);
}

void ShapeFillTool::languageChanged()
{
setName(tr("Shape Fill Tool"));
Expand All @@ -153,7 +162,7 @@ void ShapeFillTool::populateToolBar(QToolBar *toolBar)
{
AbstractTileFillTool::populateToolBar(toolBar);

QActionGroup *actionGroup = new QActionGroup(toolBar);
auto *actionGroup = new QActionGroup(toolBar);
actionGroup->addAction(mRectFill);
actionGroup->addAction(mCircleFill);

Expand Down Expand Up @@ -194,6 +203,13 @@ void ShapeFillTool::setCurrentShape(Shape shape)
mCurrentShape = shape;
}

void ShapeFillTool::cancelMakingShape()
{
mToolBehavior = Free;
clearOverlay();
updateStatusInfo();
}

void ShapeFillTool::updateFillOverlay()
{
int dx = tilePosition().x() - mStartCorner.x();
Expand Down
3 changes: 3 additions & 0 deletions src/tiled/shapefilltool.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class ShapeFillTool : public AbstractTileFillTool

void modifiersChanged(Qt::KeyboardModifiers) override;

void keyPressed(QKeyEvent *event) override;

void languageChanged() override;

void populateToolBar(QToolBar *toolBar) override;
Expand Down Expand Up @@ -73,6 +75,7 @@ class ShapeFillTool : public AbstractTileFillTool
void setActionsEnabled(bool enabled);

void setCurrentShape(Shape shape);
void cancelMakingShape();
void updateFillOverlay();
};

Expand Down
17 changes: 17 additions & 0 deletions src/tiled/tileselectiontool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "mapscene.h"

#include <QApplication>
#include <QKeyEvent>

using namespace Tiled;

Expand Down Expand Up @@ -174,6 +175,22 @@ void TileSelectionTool::modifiersChanged(Qt::KeyboardModifiers modifiers)
mLastModifiers = modifiers;
}

void TileSelectionTool::keyPressed(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape) {
if (mSelecting) {
// Cancel the ongoing selection
mSelecting = false;
mMouseDown = false;
brushItem()->setTileRegion(QRegion());
updateStatusInfo();
return;
}
}

AbstractTileSelectionTool::keyPressed(event);
}

void TileSelectionTool::languageChanged()
{
setName(tr("Rectangular Select"));
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/tileselectiontool.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class TileSelectionTool : public AbstractTileSelectionTool

void modifiersChanged(Qt::KeyboardModifiers modifiers) override;

void keyPressed(QKeyEvent *event) override;

void languageChanged() override;

protected:
Expand Down
Loading