From kde-kimageshop Mon Jun 24 13:39:27 2013 From: Dmitry Kazakov Date: Mon, 24 Jun 2013 13:39:27 +0000 To: kde-kimageshop Subject: [calligra] krita: [FEATURE] Add an option to smooth the pressure in Weighted Smoothing mode Message-Id: X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=137208118708478 Git commit 9d1910790a1425358bf62cda509c10e8dfa8a893 by Dmitry Kazakov. Committed on 24/06/2013 at 13:38. Pushed by dkazakov into branch 'master'. [FEATURE] Add an option to smooth the pressure in Weighted Smoothing mode This feature makes the shape of the line be more stable, but still there is one drawback: When the option is active you almost cannot control the shape of the beginning of the line, it is always very thin. CCMAIL:kimageshop@kde.org M +14 -0 krita/plugins/tools/defaulttools/kis_tool_brush.cc M +2 -0 krita/plugins/tools/defaulttools/kis_tool_brush.h M +1 -0 krita/ui/tool/kis_smoothing_options.cpp M +1 -0 krita/ui/tool/kis_smoothing_options.h M +12 -0 krita/ui/tool/kis_tool_freehand_helper.cpp http://commits.kde.org/calligra/9d1910790a1425358bf62cda509c10e8dfa8a893 diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.cc b/krita/plugins/tools/defaulttools/kis_tool_brush.cc index 56ff0d2..3347d45 100644 --- a/krita/plugins/tools/defaulttools/kis_tool_brush.cc +++ b/krita/plugins/tools/defaulttools/kis_tool_brush.cc @@ -51,17 +51,20 @@ void KisToolBrush::slotSetSmoothingType(int index) m_smoothingOptions.smoothingType = KisSmoothingOptions::NO_SMOOTHING; m_sliderSmoothnessDistance->setEnabled(false); m_sliderTailAggressiveness->setEnabled(false); + m_chkSmoothPressure->setEnabled(false); break; case 1: m_smoothingOptions.smoothingType = KisSmoothingOptions::SIMPLE_SMOOTHING; m_sliderSmoothnessDistance->setEnabled(false); m_sliderTailAggressiveness->setEnabled(false); + m_chkSmoothPressure->setEnabled(false); break; case 2: default: m_smoothingOptions.smoothingType = KisSmoothingOptions::WEIGHTED_SMOOTHING; m_sliderSmoothnessDistance->setEnabled(true); m_sliderTailAggressiveness->setEnabled(true); + m_chkSmoothPressure->setEnabled(true); } } @@ -74,6 +77,12 @@ void KisToolBrush::slotSetTailAgressiveness(qreal argh_rhhrr) { m_smoothingOptions.tailAggressiveness = argh_rhhrr; } + +void KisToolBrush::setSmoothPressure(bool value) +{ + m_smoothingOptions.smoothPressure = value; +} + void KisToolBrush::slotSetMagnetism(int magnetism) { m_magnetism = expf(magnetism / (double)MAXIMUM_MAGNETISM) / expf(1.0); @@ -105,6 +114,11 @@ QWidget * KisToolBrush::createOptionWidget() m_sliderTailAggressiveness->setValue(m_smoothingOptions.tailAggressiveness); addOptionWidgetOption(m_sliderTailAggressiveness, new QLabel(i18n("Tail Aggressiveness:"))); + m_chkSmoothPressure = new QCheckBox("", optionWidget); + m_chkSmoothPressure->setChecked(m_smoothingOptions.smoothPressure); + connect(m_chkSmoothPressure, SIGNAL(toggled(bool)), this, SLOT(setSmoothPressure(bool))); + addOptionWidgetOption(m_chkSmoothPressure, new QLabel(i18n("Smooth Pressure"))); + slotSetSmoothingType(1); // Drawing assistant configuration diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.h b/krita/plugins/tools/defaulttools/kis_tool_brush.h index f38cbb7..d40ba4a 100644 --- a/krita/plugins/tools/defaulttools/kis_tool_brush.h +++ b/krita/plugins/tools/defaulttools/kis_tool_brush.h @@ -49,6 +49,7 @@ private slots: void slotSetMagnetism(int magnetism); void slotSetSmoothingType(int index); void slotSetTailAgressiveness(qreal argh_rhhrr); + void setSmoothPressure(bool value); private: QGridLayout *m_optionLayout; @@ -58,6 +59,7 @@ private: KisSliderSpinBox *m_sliderMagnetism; KisDoubleSliderSpinBox *m_sliderSmoothnessDistance; KisDoubleSliderSpinBox *m_sliderTailAggressiveness; + QCheckBox *m_chkSmoothPressure; }; diff --git a/krita/ui/tool/kis_smoothing_options.cpp b/krita/ui/tool/kis_smoothing_options.cpp index d8b41ee..85dc511 100644 --- a/krita/ui/tool/kis_smoothing_options.cpp +++ b/krita/ui/tool/kis_smoothing_options.cpp @@ -21,5 +21,6 @@ KisSmoothingOptions::KisSmoothingOptions() : smoothingType(WEIGHTED_SMOOTHING) , smoothnessDistance(50.0) , tailAggressiveness(0.15) + , smoothPressure(false) { } diff --git a/krita/ui/tool/kis_smoothing_options.h b/krita/ui/tool/kis_smoothing_options.h index c74ba01..dda58ad 100644 --- a/krita/ui/tool/kis_smoothing_options.h +++ b/krita/ui/tool/kis_smoothing_options.h @@ -34,6 +34,7 @@ struct KisSmoothingOptions SmoothingType smoothingType; qreal smoothnessDistance; qreal tailAggressiveness; + bool smoothPressure; }; #endif // KIS_SMOOTHING_OPTIONS_H diff --git a/krita/ui/tool/kis_tool_freehand_helper.cpp b/krita/ui/tool/kis_tool_freehand_helper.cpp index 98c56e9..333c7d5 100644 --- a/krita/ui/tool/kis_tool_freehand_helper.cpp +++ b/krita/ui/tool/kis_tool_freehand_helper.cpp @@ -261,6 +261,7 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event) qreal gaussianWeight2 = sigma * sigma; qreal velocitySum = 0.0; qreal scaleSum = 0.0; + qreal pressure = 0.0; qreal baseRate = 0.0; Q_ASSERT(m_d->history.size() == m_d->velocityHistory.size()); @@ -309,16 +310,27 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event) scaleSum += rate; x += rate * nextInfo.pos().x(); y += rate * nextInfo.pos().y(); + + if (m_d->smoothingOptions.smoothPressure) { + pressure += rate * nextInfo.pressure(); + } } if (scaleSum != 0.0) { x /= scaleSum; y /= scaleSum; + + if (m_d->smoothingOptions.smoothPressure) { + pressure /= scaleSum; + } } if ((x != 0.0 && y != 0.0) || (x == info.pos().x() && y == info.pos().y())) { info.setMovement(toKisVector2D(info.pos() - QPointF(x, y))); info.setPos(QPointF(x, y)); + if (m_d->smoothingOptions.smoothPressure) { + info.setPressure(pressure); + } m_d->history.last() = info; } } _______________________________________________ Krita mailing list kimageshop@kde.org https://mail.kde.org/mailman/listinfo/kimageshop