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

Allow drawing lines by holding shift while painting #3970

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 30 additions & 10 deletions src/tiled/stampbrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
if (brushItem()->isVisible()) {
if (event->button() == Qt::LeftButton) {
switch (mBrushState) {
case BrushState::PaintStartSet: // shouldn't occur
case BrushState::StartSet:
doPaint();
mStampReference = tilePosition();
Expand All @@ -134,19 +135,26 @@ void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
case BrushBehavior::Line:
case BrushBehavior::Circle:
mStampReference = tilePosition();
mBrushState = BrushState::StartSet;
if (mBrushState == BrushState::Paint)
mBrushState = BrushState::PaintStartSet;
else
mBrushState = BrushState::StartSet;
break;
}
break;
case BrushState::Capture:
break;
}
return;
} else if (event->button() == Qt::RightButton &&
!(event->modifiers() & Qt::ControlModifier))
{
beginCapture();
return;
} else if (event->button() == Qt::RightButton) {
if (mBrushState == BrushState::StartSet || mBrushState == BrushState::PaintStartSet) {
mBrushState = BrushState::Free;
updatePreview();
return;
} else if (!(event->modifiers() & Qt::ControlModifier)) {
beginCapture();
return;
}
}
}

Expand All @@ -156,11 +164,14 @@ void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
void StampBrush::mouseReleased(QGraphicsSceneMouseEvent *event)
{
switch (mBrushState) {
case BrushState::PaintStartSet:
case BrushState::StartSet:
if (event->button() == Qt::LeftButton) {
if (mStampReference != tilePosition()) {
doPaint();
mBrushState = BrushState::Free;
} else {
mBrushState = BrushState::StartSet;
}
}
break;
Expand All @@ -178,8 +189,7 @@ void StampBrush::mouseReleased(QGraphicsSceneMouseEvent *event)
updatePreview();
}
break;
default:
// do nothing?
case BrushState::Free:
break;
}
}
Expand All @@ -196,14 +206,23 @@ void StampBrush::updateBrushBehavior()
BrushState brushState = mBrushState;

if (mModifiers & Qt::ShiftModifier) {
if (mModifiers & Qt::ControlModifier)
if (mModifiers & Qt::ControlModifier) {
brushBehavior = BrushBehavior::Circle;
else
} else {
brushBehavior = BrushBehavior::Line;
}
if (brushState == BrushState::Paint) {
mStampReference = tilePosition();
brushState = BrushState::PaintStartSet;
}
} else {
brushBehavior = BrushBehavior::Neutral;
if (brushState == BrushState::StartSet)
brushState = BrushState::Free;
else if (brushState == BrushState::PaintStartSet) {
doPaint();
brushState = BrushState::Paint;
}
}

if (brushBehavior != mBrushBehavior || brushState != mBrushState) {
Expand Down Expand Up @@ -602,6 +621,7 @@ void StampBrush::updatePreview(QPoint tilePos)
} else {
switch (mBrushState) {
case BrushState::StartSet:
case BrushState::PaintStartSet:
if (mBrushBehavior == BrushBehavior::Circle) {
drawPreviewLayer(pointsOnEllipse(mStampReference,
qAbs(mStampReference.x() - tilePos.x()),
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/stampbrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ public slots:
// preview of the selection
Capture, // right mouse pressed: capture a rectangle
Paint, // left mouse pressed: free painting
StartSet // when you have defined a starting point,
StartSet, // when you have defined a starting point,
// cancel with right click
PaintStartSet // starting point set while painting
};

/**
Expand Down
Loading