From 6be3dcb417bb016bf9f65cf38616534d8666ad71 Mon Sep 17 00:00:00 2001 From: khoidauminh Date: Fri, 28 Jun 2024 12:45:42 +0700 Subject: [PATCH 1/2] Temporarily modify width and feather during Quick Sizing --- core_lib/src/managers/toolmanager.cpp | 25 +++++++++++++++++++++++++ core_lib/src/managers/toolmanager.h | 4 ++++ core_lib/src/tool/basetool.cpp | 11 +++++++++++ core_lib/src/tool/basetool.h | 4 ++++ core_lib/src/tool/stroketool.cpp | 8 ++++++-- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/core_lib/src/managers/toolmanager.cpp b/core_lib/src/managers/toolmanager.cpp index c80e5b6a75..d12fe7e965 100644 --- a/core_lib/src/managers/toolmanager.cpp +++ b/core_lib/src/managers/toolmanager.cpp @@ -169,6 +169,31 @@ void ToolManager::setFeather(float newFeather) emit toolPropertyChanged(currentTool()->type(), FEATHER); } +// Temporarily sets the width and feather of tool during Quick Sizing. +void ToolManager::setTmpWidth(float newWidth) +{ + if (std::isnan(newWidth) || newWidth < 0) + { + newWidth = 1.f; + } + + currentTool()->setTmpWidth(static_cast(newWidth)); + emit penWidthValueChanged(newWidth); + emit toolPropertyChanged(currentTool()->type(), WIDTH); +} + +void ToolManager::setTmpFeather(float newFeather) +{ + if (std::isnan(newFeather) || newFeather < 0) + { + newFeather = 0.f; + } + + currentTool()->setTmpFeather(static_cast(newFeather)); + emit penFeatherValueChanged(newFeather); + emit toolPropertyChanged(currentTool()->type(), FEATHER); +} + void ToolManager::setUseFeather(bool usingFeather) { int usingAA = currentTool()->properties.useAA; diff --git a/core_lib/src/managers/toolmanager.h b/core_lib/src/managers/toolmanager.h index 6ba1cd3321..dc72238252 100644 --- a/core_lib/src/managers/toolmanager.h +++ b/core_lib/src/managers/toolmanager.h @@ -65,6 +65,10 @@ public slots: void setWidth(float); void setFeather(float); + + void setTmpWidth(float); + void setTmpFeather(float); + void setUseFeather(bool); void setInvisibility(bool); void setPreserveAlpha(bool); diff --git a/core_lib/src/tool/basetool.cpp b/core_lib/src/tool/basetool.cpp index 7ae8cb0626..dc1ad8b1f5 100644 --- a/core_lib/src/tool/basetool.cpp +++ b/core_lib/src/tool/basetool.cpp @@ -133,6 +133,17 @@ void BaseTool::setFeather(const qreal feather) properties.feather = feather; } +// Temporarily set the Width and Feather of the tool during Quick Sizing. +void BaseTool::setTmpWidth(const qreal width) +{ + properties.width = width; +} + +void BaseTool::setTmpFeather(const qreal feather) +{ + properties.feather = feather; +} + void BaseTool::setUseFeather(const bool usingFeather) { properties.useFeather = usingFeather; diff --git a/core_lib/src/tool/basetool.h b/core_lib/src/tool/basetool.h index 2724354796..bfd56a650e 100644 --- a/core_lib/src/tool/basetool.h +++ b/core_lib/src/tool/basetool.h @@ -107,6 +107,10 @@ class BaseTool : public QObject virtual void setWidth(const qreal width); virtual void setFeather(const qreal feather); + + void setTmpWidth(const qreal width); + void setTmpFeather(const qreal feather); + virtual void setInvisibility(const bool invisibility); virtual void setBezier(const bool bezier_state); virtual void setPressure(const bool pressure); diff --git a/core_lib/src/tool/stroketool.cpp b/core_lib/src/tool/stroketool.cpp index b3cfa6894c..5317ffc8b6 100644 --- a/core_lib/src/tool/stroketool.cpp +++ b/core_lib/src/tool/stroketool.cpp @@ -331,6 +331,10 @@ void StrokeTool::stopAdjusting() { msIsAdjusting = false; mAdjustPosition = QPointF(); + + mEditor->tools()->setWidth(properties.width); + mEditor->tools()->setFeather(properties.feather); + updateCanvasCursor(); } @@ -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)); + mEditor->tools()->setTmpWidth(qBound(WIDTH_MIN, newValue, WIDTH_MAX)); break; } case FEATHER: { @@ -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)); + mEditor->tools()->setTmpFeather(qBound(FEATHER_MIN, mappedValue, FEATHER_MAX)); break; } default: From 0cb6fc7ac7bb89a0dc5101de2ea5f9f65e373566 Mon Sep 17 00:00:00 2001 From: MrStevns Date: Sat, 27 Jul 2024 12:38:58 +0200 Subject: [PATCH 2/2] 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. --- core_lib/src/managers/toolmanager.cpp | 28 --------------------------- core_lib/src/managers/toolmanager.h | 7 ------- core_lib/src/tool/basetool.cpp | 11 ----------- core_lib/src/tool/basetool.h | 3 --- core_lib/src/tool/stroketool.cpp | 26 +++++++++++++++++++++++-- core_lib/src/tool/stroketool.h | 6 ++++++ 6 files changed, 30 insertions(+), 51 deletions(-) diff --git a/core_lib/src/managers/toolmanager.cpp b/core_lib/src/managers/toolmanager.cpp index d12fe7e965..a228ff78b1 100644 --- a/core_lib/src/managers/toolmanager.cpp +++ b/core_lib/src/managers/toolmanager.cpp @@ -153,7 +153,6 @@ void ToolManager::setWidth(float newWidth) } currentTool()->setWidth(static_cast(newWidth)); - emit penWidthValueChanged(newWidth); emit toolPropertyChanged(currentTool()->type(), WIDTH); } @@ -165,32 +164,6 @@ void ToolManager::setFeather(float newFeather) } currentTool()->setFeather(static_cast(newFeather)); - emit penFeatherValueChanged(newFeather); - emit toolPropertyChanged(currentTool()->type(), FEATHER); -} - -// Temporarily sets the width and feather of tool during Quick Sizing. -void ToolManager::setTmpWidth(float newWidth) -{ - if (std::isnan(newWidth) || newWidth < 0) - { - newWidth = 1.f; - } - - currentTool()->setTmpWidth(static_cast(newWidth)); - emit penWidthValueChanged(newWidth); - emit toolPropertyChanged(currentTool()->type(), WIDTH); -} - -void ToolManager::setTmpFeather(float newFeather) -{ - if (std::isnan(newFeather) || newFeather < 0) - { - newFeather = 0.f; - } - - currentTool()->setTmpFeather(static_cast(newFeather)); - emit penFeatherValueChanged(newFeather); emit toolPropertyChanged(currentTool()->type(), FEATHER); } @@ -258,7 +231,6 @@ void ToolManager::setTolerance(int newTolerance) newTolerance = qMax(0, newTolerance); currentTool()->setTolerance(newTolerance); - emit toleranceValueChanged(newTolerance); emit toolPropertyChanged(currentTool()->type(), TOLERANCE); } diff --git a/core_lib/src/managers/toolmanager.h b/core_lib/src/managers/toolmanager.h index dc72238252..b01be3177b 100644 --- a/core_lib/src/managers/toolmanager.h +++ b/core_lib/src/managers/toolmanager.h @@ -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); @@ -66,9 +62,6 @@ public slots: void setWidth(float); void setFeather(float); - void setTmpWidth(float); - void setTmpFeather(float); - void setUseFeather(bool); void setInvisibility(bool); void setPreserveAlpha(bool); diff --git a/core_lib/src/tool/basetool.cpp b/core_lib/src/tool/basetool.cpp index dc1ad8b1f5..7ae8cb0626 100644 --- a/core_lib/src/tool/basetool.cpp +++ b/core_lib/src/tool/basetool.cpp @@ -133,17 +133,6 @@ void BaseTool::setFeather(const qreal feather) properties.feather = feather; } -// Temporarily set the Width and Feather of the tool during Quick Sizing. -void BaseTool::setTmpWidth(const qreal width) -{ - properties.width = width; -} - -void BaseTool::setTmpFeather(const qreal feather) -{ - properties.feather = feather; -} - void BaseTool::setUseFeather(const bool usingFeather) { properties.useFeather = usingFeather; diff --git a/core_lib/src/tool/basetool.h b/core_lib/src/tool/basetool.h index bfd56a650e..d3ef527218 100644 --- a/core_lib/src/tool/basetool.h +++ b/core_lib/src/tool/basetool.h @@ -108,9 +108,6 @@ class BaseTool : public QObject virtual void setWidth(const qreal width); virtual void setFeather(const qreal feather); - void setTmpWidth(const qreal width); - void setTmpFeather(const qreal feather); - virtual void setInvisibility(const bool invisibility); virtual void setBezier(const bool bezier_state); virtual void setPressure(const bool pressure); diff --git a/core_lib/src/tool/stroketool.cpp b/core_lib/src/tool/stroketool.cpp index 5317ffc8b6..4ff0c29e43 100644 --- a/core_lib/src/tool/stroketool.cpp +++ b/core_lib/src/tool/stroketool.cpp @@ -347,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()->setTmpWidth(qBound(WIDTH_MIN, newValue, WIDTH_MAX)); + setTemporaryWidth(qBound(WIDTH_MIN, newValue, WIDTH_MAX)); break; } case FEATHER: { @@ -361,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()->setTmpFeather(qBound(FEATHER_MIN, mappedValue, FEATHER_MAX)); + setTemporaryFeather(qBound(FEATHER_MIN, mappedValue, FEATHER_MAX)); break; } default: @@ -375,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); +} diff --git a/core_lib/src/tool/stroketool.h b/core_lib/src/tool/stroketool.h index 63ad63f0a2..8d21fa7090 100644 --- a/core_lib/src/tool/stroketool.h +++ b/core_lib/src/tool/stroketool.h @@ -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