File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 2828
2929#include < QActionGroup>
3030#include < QApplication>
31+ #include < QKeyEvent>
3132#include < QToolBar>
3233#include < QUndoStack>
3334
34- #include < memory>
35-
3635using namespace Tiled ;
3736
3837ShapeFillTool::ShapeFillTool (QObject *parent)
@@ -86,9 +85,7 @@ void ShapeFillTool::mousePressed(QGraphicsSceneMouseEvent *event)
8685{
8786 // Right-click cancels drawing a shape
8887 if (mToolBehavior == MakingShape && event->button () == Qt::RightButton) {
89- mToolBehavior = Free;
90- clearOverlay ();
91- updateStatusInfo ();
88+ cancelMakingShape ();
9289 return ;
9390 }
9491
@@ -139,6 +136,18 @@ void ShapeFillTool::modifiersChanged(Qt::KeyboardModifiers modifiers)
139136 updateFillOverlay ();
140137}
141138
139+ void ShapeFillTool::keyPressed (QKeyEvent *event)
140+ {
141+ if (event->key () == Qt::Key_Escape) {
142+ if (mToolBehavior == MakingShape) {
143+ cancelMakingShape ();
144+ return ;
145+ }
146+ }
147+
148+ AbstractTileFillTool::keyPressed (event);
149+ }
150+
142151void ShapeFillTool::languageChanged ()
143152{
144153 setName (tr (" Shape Fill Tool" ));
@@ -153,7 +162,7 @@ void ShapeFillTool::populateToolBar(QToolBar *toolBar)
153162{
154163 AbstractTileFillTool::populateToolBar (toolBar);
155164
156- QActionGroup *actionGroup = new QActionGroup (toolBar);
165+ auto *actionGroup = new QActionGroup (toolBar);
157166 actionGroup->addAction (mRectFill );
158167 actionGroup->addAction (mCircleFill );
159168
@@ -194,6 +203,13 @@ void ShapeFillTool::setCurrentShape(Shape shape)
194203 mCurrentShape = shape;
195204}
196205
206+ void ShapeFillTool::cancelMakingShape ()
207+ {
208+ mToolBehavior = Free;
209+ clearOverlay ();
210+ updateStatusInfo ();
211+ }
212+
197213void ShapeFillTool::updateFillOverlay ()
198214{
199215 int dx = tilePosition ().x () - mStartCorner .x ();
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ class ShapeFillTool : public AbstractTileFillTool
4141
4242 void modifiersChanged (Qt::KeyboardModifiers) override ;
4343
44+ void keyPressed (QKeyEvent *event) override ;
45+
4446 void languageChanged () override ;
4547
4648 void populateToolBar (QToolBar *toolBar) override ;
@@ -73,6 +75,7 @@ class ShapeFillTool : public AbstractTileFillTool
7375 void setActionsEnabled (bool enabled);
7476
7577 void setCurrentShape (Shape shape);
78+ void cancelMakingShape ();
7679 void updateFillOverlay ();
7780};
7881
You can’t perform that action at this time.
0 commit comments