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

Temporarily modify width and feather during Quick Sizing #1853

Merged
merged 2 commits into from
Jul 31, 2024
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
3 changes: 0 additions & 3 deletions core_lib/src/managers/toolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ void ToolManager::setWidth(float newWidth)
}

currentTool()->setWidth(static_cast<qreal>(newWidth));
emit penWidthValueChanged(newWidth);
emit toolPropertyChanged(currentTool()->type(), WIDTH);
}

Expand All @@ -165,7 +164,6 @@ void ToolManager::setFeather(float newFeather)
}

currentTool()->setFeather(static_cast<qreal>(newFeather));
emit penFeatherValueChanged(newFeather);
emit toolPropertyChanged(currentTool()->type(), FEATHER);
}

Expand Down Expand Up @@ -233,7 +231,6 @@ void ToolManager::setTolerance(int newTolerance)
newTolerance = qMax(0, newTolerance);

currentTool()->setTolerance(newTolerance);
emit toleranceValueChanged(newTolerance);
emit toolPropertyChanged(currentTool()->type(), TOLERANCE);
}

Expand Down
5 changes: 1 addition & 4 deletions core_lib/src/managers/toolmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ class ToolManager : public BaseManager
int propertySwitch(bool condition, int property);

signals:
void penWidthValueChanged(float);
void penFeatherValueChanged(float);
void toleranceValueChanged(qreal);

void toolChanged(ToolType);
void toolPropertyChanged(ToolType, ToolPropertyType);

Expand All @@ -65,6 +61,7 @@ public slots:

void setWidth(float);
void setFeather(float);

void setUseFeather(bool);
void setInvisibility(bool);
void setPreserveAlpha(bool);
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/tool/basetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class BaseTool : public QObject

virtual void setWidth(const qreal width);
virtual void setFeather(const qreal feather);

virtual void setInvisibility(const bool invisibility);
virtual void setBezier(const bool bezier_state);
virtual void setPressure(const bool pressure);
Expand Down
30 changes: 28 additions & 2 deletions core_lib/src/tool/stroketool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ void StrokeTool::stopAdjusting()
{
msIsAdjusting = false;
mAdjustPosition = QPointF();

mEditor->tools()->setWidth(properties.width);
mEditor->tools()->setFeather(properties.feather);

updateCanvasCursor();
}

Expand All @@ -343,7 +347,7 @@ void StrokeTool::adjustCursor(Qt::KeyboardModifiers modifiers)
// map it back to its original value, we can multiply by the factor we divided with
const qreal newValue = QLineF(mAdjustPosition, getCurrentPoint()).length() * 2.0;

mEditor->tools()->setWidth(qBound(WIDTH_MIN, newValue, WIDTH_MAX));
setTemporaryWidth(qBound(WIDTH_MIN, newValue, WIDTH_MAX));
break;
}
case FEATHER: {
Expand All @@ -357,7 +361,7 @@ void StrokeTool::adjustCursor(Qt::KeyboardModifiers modifiers)
// We flip min and max here in order to get the inverted value for the UI
const qreal mappedValue = MathUtils::map(distance, inputMin, inputMax, outputMax, outputMin);

mEditor->tools()->setFeather(qBound(FEATHER_MIN, mappedValue, FEATHER_MAX));
setTemporaryFeather(qBound(FEATHER_MIN, mappedValue, FEATHER_MAX));
break;
}
default:
Expand All @@ -371,3 +375,25 @@ void StrokeTool::paint(QPainter& painter, const QRect& blitRect)
{
mCanvasCursorPainter.paint(painter, blitRect);
}

void StrokeTool::setTemporaryWidth(qreal width)
{
if (std::isnan(width) || width < 0)
{
width = 1.f;
}

properties.width = width;
emit mEditor->tools()->toolPropertyChanged(this->type(), WIDTH);
}

void StrokeTool::setTemporaryFeather(qreal feather)
{
if (std::isnan(feather) || feather < 0)
{
feather = 0.f;
}

properties.feather = feather;
emit mEditor->tools()->toolPropertyChanged(this->type(), FEATHER);
}
6 changes: 6 additions & 0 deletions core_lib/src/tool/stroketool.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public slots:
CanvasCursorPainter mCanvasCursorPainter;

StrokeInterpolator mInterpolator;

private:
/// Sets the width value without calling settings to store the state
void setTemporaryWidth(qreal width);
/// Sets the feather value, without calling settings to store the state
void setTemporaryFeather(qreal feather);
};

#endif // STROKETOOL_H
Loading