diff --git a/core_lib/src/interface/scribblearea.cpp b/core_lib/src/interface/scribblearea.cpp index 0a6931988..446bd9d0c 100644 --- a/core_lib/src/interface/scribblearea.cpp +++ b/core_lib/src/interface/scribblearea.cpp @@ -517,7 +517,7 @@ void ScribbleArea::pointerPressEvent(PointerEvent* event) if (isPressed && mQuickSizing) { //qDebug() << "Start Adjusting" << event->buttons(); - if (isDoingAssistedToolAdjustment(event->modifiers())) + if (currentTool()->startAdjusting(event->modifiers(), 1)) { return; } @@ -686,23 +686,6 @@ void ScribbleArea::resizeEvent(QResizeEvent* event) updateAllFrames(); } -bool ScribbleArea::isDoingAssistedToolAdjustment(Qt::KeyboardModifiers keyMod) -{ - if ((keyMod == Qt::ShiftModifier) && (currentTool()->properties.width > -1)) - { - //adjust width if not locked - currentTool()->startAdjusting(WIDTH, 1); - return true; - } - if ((keyMod == Qt::ControlModifier) && (currentTool()->properties.feather > -1)) - { - //adjust feather if not locked - currentTool()->startAdjusting(FEATHER, 1); - return true; - } - return false; -} - void ScribbleArea::showLayerNotVisibleWarning() { QMessageBox::warning(this, tr("Warning"), diff --git a/core_lib/src/interface/scribblearea.h b/core_lib/src/interface/scribblearea.h index 81121475e..9f0d3d0d3 100644 --- a/core_lib/src/interface/scribblearea.h +++ b/core_lib/src/interface/scribblearea.h @@ -131,8 +131,6 @@ public slots: void updateToolCursor(); void paletteColorChanged(QColor); - bool isDoingAssistedToolAdjustment(Qt::KeyboardModifiers keyMod); - void showLayerNotVisibleWarning(); diff --git a/core_lib/src/tool/basetool.cpp b/core_lib/src/tool/basetool.cpp index be87d8c91..713357e89 100644 --- a/core_lib/src/tool/basetool.cpp +++ b/core_lib/src/tool/basetool.cpp @@ -287,19 +287,32 @@ QPixmap BaseTool::quickSizeCursor(qreal scalingFac) return cursorPixmap; } -void BaseTool::startAdjusting(ToolPropertyType propertyType, qreal step) +bool BaseTool::startAdjusting(Qt::KeyboardModifiers modifiers, qreal step) { - msIsAdjusting = true; - mAdjustmentStep = step; - if (propertyType == WIDTH) + if (mQuickSizingProperties.contains(modifiers)) { - msOriginalPropertyValue = properties.width; - } - else if (propertyType == FEATHER) - { - msOriginalPropertyValue = properties.feather; + switch (mQuickSizingProperties.value(modifiers)) { + case WIDTH: + msOriginalPropertyValue = properties.width; + break; + case FEATHER: + msOriginalPropertyValue = properties.feather; + break; + case TOLERANCE: + msOriginalPropertyValue = properties.tolerance; + break; + default: + qDebug() << "Unhandled quick sizing property for tool" << typeName(); + Q_ASSERT(false); + return false; + } + + msIsAdjusting = true; + mAdjustmentStep = step; + mScribbleArea->updateCanvasCursor(); + return true; } - mScribbleArea->updateCanvasCursor(); + return false; } void BaseTool::stopAdjusting() @@ -310,15 +323,11 @@ void BaseTool::stopAdjusting() mEditor->getScribbleArea()->updateCanvasCursor(); } -void BaseTool::adjustCursor(Qt::KeyboardModifiers keyMod) +void BaseTool::adjustCursor(Qt::KeyboardModifiers modifiers) { - ToolPropertyType propertyType; - propertyType = (keyMod & Qt::ControlModifier) ? FEATHER : WIDTH; - + if (mQuickSizingProperties.contains(modifiers)); qreal inc = qPow(msOriginalPropertyValue * 100, 0.5); qreal newValue = inc + getCurrentPoint().x(); - int max = (propertyType == FEATHER) ? 200 : 200; - int min = (propertyType == FEATHER) ? 2 : 1; if (newValue < 0) { @@ -331,27 +340,21 @@ void BaseTool::adjustCursor(Qt::KeyboardModifiers keyMod) int tempValue = (int)(newValue / mAdjustmentStep); // + 0.5 ? newValue = tempValue * mAdjustmentStep; } - if (newValue < min) // can be optimized for size: min(200,max(0.2,newValueX)) - { - newValue = min; - } - else if (newValue > max) - { - newValue = max; - } - switch (propertyType) + switch (mQuickSizingProperties.value(modifiers)) { + case WIDTH: + mEditor->tools()->setWidth(qBound(1., newValue, 200.)); + break; case FEATHER: - if ((type() == BRUSH) || (type() == ERASER) || (this->type() == SMUDGE)) - { - mEditor->tools()->setFeather(newValue); - } + mEditor->tools()->setFeather(qBound(2., newValue, 200.)); break; - case WIDTH: - mEditor->tools()->setWidth(newValue); + case TOLERANCE: + mEditor->tools()->setTolerance(qBound(0., newValue, 100.)); break; default: + qDebug() << "Unhandled quick sizing property for tool" << typeName(); + Q_ASSERT(false); break; }; } diff --git a/core_lib/src/tool/basetool.h b/core_lib/src/tool/basetool.h index 709ab894f..b407664e5 100644 --- a/core_lib/src/tool/basetool.h +++ b/core_lib/src/tool/basetool.h @@ -83,9 +83,9 @@ class BaseTool : public QObject virtual bool keyReleaseEvent(QKeyEvent*) { return false; } // dynamic cursor adjustment - virtual void startAdjusting(ToolPropertyType argSettingType, qreal argStep); + virtual bool startAdjusting(Qt::KeyboardModifiers modifiers, qreal argStep); virtual void stopAdjusting(); - virtual void adjustCursor(Qt::KeyboardModifiers keyMod); + virtual void adjustCursor(Qt::KeyboardModifiers modifiers); virtual void clearToolData() {} virtual void resetToDefault() {} @@ -143,6 +143,8 @@ class BaseTool : public QObject Editor* mEditor = nullptr; ScribbleArea* mScribbleArea = nullptr; + QMap mQuickSizingProperties; + private: StrokeManager* mStrokeManager = nullptr; qreal mAdjustmentStep = 0.0f; diff --git a/core_lib/src/tool/brushtool.cpp b/core_lib/src/tool/brushtool.cpp index e3c3aa0d2..e8bb80d1e 100644 --- a/core_lib/src/tool/brushtool.cpp +++ b/core_lib/src/tool/brushtool.cpp @@ -66,6 +66,9 @@ void BrushTool::loadSettings() if (properties.width <= 0) { setWidth(15); } if (std::isnan(properties.feather)) { setFeather(15); } + + mQuickSizingProperties.insert(Qt::ShiftModifier, WIDTH); + mQuickSizingProperties.insert(Qt::ControlModifier, FEATHER); } void BrushTool::resetToDefault() diff --git a/core_lib/src/tool/buckettool.cpp b/core_lib/src/tool/buckettool.cpp index bde79460a..717e873c4 100644 --- a/core_lib/src/tool/buckettool.cpp +++ b/core_lib/src/tool/buckettool.cpp @@ -147,6 +147,20 @@ void BucketTool::pointerReleaseEvent(PointerEvent* event) endStroke(); } +bool BucketTool::startAdjusting(Qt::KeyboardModifiers modifiers, qreal argStep) +{ + mQuickSizingProperties.clear(); + if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR) + { + mQuickSizingProperties.insert(Qt::ShiftModifier, WIDTH); + } + else + { + mQuickSizingProperties.insert(Qt::ControlModifier, TOLERANCE); + } + return BaseTool::startAdjusting(modifiers, argStep); +} + void BucketTool::paintBitmap(Layer* layer) { Layer* targetLayer = layer; // by default diff --git a/core_lib/src/tool/buckettool.h b/core_lib/src/tool/buckettool.h index 96b2f5bc3..59aa3bcd4 100644 --- a/core_lib/src/tool/buckettool.h +++ b/core_lib/src/tool/buckettool.h @@ -37,6 +37,8 @@ class BucketTool : public StrokeTool void pointerMoveEvent(PointerEvent*) override; void pointerReleaseEvent(PointerEvent*) override; + bool startAdjusting(Qt::KeyboardModifiers modifiers, qreal argStep) override; + void setTolerance(const int tolerance) override; void setWidth(const qreal width) override; diff --git a/core_lib/src/tool/erasertool.cpp b/core_lib/src/tool/erasertool.cpp index 62040e0a9..fe84ed9c3 100644 --- a/core_lib/src/tool/erasertool.cpp +++ b/core_lib/src/tool/erasertool.cpp @@ -62,6 +62,9 @@ void EraserTool::loadSettings() properties.useAA = settings.value("eraserAA", 1).toInt(); if (properties.useFeather) { properties.useAA = -1; } + + mQuickSizingProperties.insert(Qt::ShiftModifier, WIDTH); + mQuickSizingProperties.insert(Qt::ControlModifier, FEATHER); } void EraserTool::resetToDefault() diff --git a/core_lib/src/tool/penciltool.cpp b/core_lib/src/tool/penciltool.cpp index d7871a534..dd373f995 100644 --- a/core_lib/src/tool/penciltool.cpp +++ b/core_lib/src/tool/penciltool.cpp @@ -56,6 +56,8 @@ void PencilTool::loadSettings() properties.useFillContour = false; // properties.invisibility = 1; // properties.preserveAlpha = 0; + + mQuickSizingProperties.insert(Qt::ShiftModifier, WIDTH); } void PencilTool::resetToDefault() diff --git a/core_lib/src/tool/pentool.cpp b/core_lib/src/tool/pentool.cpp index fd861cb07..b9967519d 100644 --- a/core_lib/src/tool/pentool.cpp +++ b/core_lib/src/tool/pentool.cpp @@ -51,6 +51,8 @@ void PenTool::loadSettings() properties.preserveAlpha = OFF; properties.useAA = settings.value("penAA", true).toBool(); properties.stabilizerLevel = settings.value("penLineStabilization", StabilizationLevel::STRONG).toInt(); + + mQuickSizingProperties.insert(Qt::ShiftModifier, WIDTH); } void PenTool::resetToDefault() diff --git a/core_lib/src/tool/smudgetool.cpp b/core_lib/src/tool/smudgetool.cpp index 1b8a911ee..072161459 100644 --- a/core_lib/src/tool/smudgetool.cpp +++ b/core_lib/src/tool/smudgetool.cpp @@ -51,6 +51,9 @@ void SmudgeTool::loadSettings() properties.feather = settings.value("smudgeFeather", 48.0).toDouble(); properties.pressure = false; properties.stabilizerLevel = -1; + + mQuickSizingProperties.insert(Qt::ShiftModifier, WIDTH); + mQuickSizingProperties.insert(Qt::ControlModifier, FEATHER); } void SmudgeTool::resetToDefault()