Skip to content

Commit

Permalink
Fixed handling of Shift modifiers in Bucket and Shape Fill tools
Browse files Browse the repository at this point in the history
While handling the key press event, QApplication::keyboardModifiers()
does not appear to be updated yet.

It may be related to catching the key event in an event filter, but the
behavior appears to have changed in some Qt version since I'm sure this
has worked before.

Closes #2883
  • Loading branch information
bjorn committed Jan 13, 2021
1 parent 8693dce commit bfa6cd1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/tiled/bucketfilltool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void BucketFillTool::tilePositionChanged(QPoint tilePos)
if (!tileLayer)
return;

bool shiftPressed = QApplication::keyboardModifiers() & Qt::ShiftModifier;
bool shiftPressed = mModifiers & Qt::ShiftModifier;
bool fillRegionChanged = false;

TilePainter regionComputer(mapDocument(), tileLayer);
Expand Down Expand Up @@ -165,8 +165,10 @@ void BucketFillTool::mousePressed(QGraphicsSceneMouseEvent *event)
mapDocument()->undoStack()->endMacro();
}

void BucketFillTool::modifiersChanged(Qt::KeyboardModifiers)
void BucketFillTool::modifiersChanged(Qt::KeyboardModifiers modifiers)
{
mModifiers = modifiers;

// Don't need to recalculate fill region if there was no fill region
if (!mPreviewMap)
return;
Expand Down
1 change: 1 addition & 0 deletions src/tiled/bucketfilltool.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class BucketFillTool : public AbstractTileFillTool
private:
void clearOverlay();

Qt::KeyboardModifiers mModifiers;
bool mLastShiftStatus;

/**
Expand Down
6 changes: 4 additions & 2 deletions src/tiled/shapefilltool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ void ShapeFillTool::mouseReleased(QGraphicsSceneMouseEvent *event)
}
}

void ShapeFillTool::modifiersChanged(Qt::KeyboardModifiers)
void ShapeFillTool::modifiersChanged(Qt::KeyboardModifiers modifiers)
{
mModifiers = modifiers;

if (mToolBehavior == MakingShape)
updateFillOverlay();
}
Expand Down Expand Up @@ -179,7 +181,7 @@ void ShapeFillTool::updateFillOverlay()
int dx = tilePosition().x() - mStartCorner.x();
int dy = tilePosition().y() - mStartCorner.y();

if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
if (mModifiers & Qt::ShiftModifier) {
const int min = std::min(std::abs(dx), std::abs(dy));
dx = ((dx > 0) - (dx < 0)) * min;
dy = ((dy > 0) - (dy < 0)) * min;
Expand Down
1 change: 1 addition & 0 deletions src/tiled/shapefilltool.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ShapeFillTool : public AbstractTileFillTool
Circle // making a circle
};

Qt::KeyboardModifiers mModifiers;
ToolBehavior mToolBehavior;
Shape mCurrentShape;
QPoint mStartCorner;
Expand Down

0 comments on commit bfa6cd1

Please sign in to comment.