Skip to content

Commit

Permalink
Temporarily modify width and feather during Quick Sizing (#1853)
Browse files Browse the repository at this point in the history
* Temporarily modify width and feather during Quick Sizing

* Make sure only stroke tool is aware of the new temporary call

We don't need to expose quick sizing behaviour to the ToolManager, since the value itself is not important, we just need to notify the UI, so the slider updates.

---------

Co-authored-by: MrStevns <[email protected]>
  • Loading branch information
khoidauminh and MrStevns authored Jul 31, 2024
1 parent cfeeed8 commit 7d1847e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
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 @@ -239,7 +237,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 @@ -108,6 +108,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 setClosedPath(const bool closed);
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

0 comments on commit 7d1847e

Please sign in to comment.