[calligra/calligra/2.7] krita: [FEATURE] Add an option to smooth the pressure in Weighted Smoothing mode

Dmitry Kazakov dimula73 at gmail.com
Fri Jul 12 08:25:24 UTC 2013


Git commit 00ae21b9658d9d8a89ce8e8f7037ad11f3173f41 by Dmitry Kazakov.
Committed on 24/06/2013 at 13:38.
Pushed by dkazakov into branch 'calligra/2.7'.

[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 at kde.org

Rename smooth parameter

Renamed "Tail Aggressiveness" option "Stroke Ending"

Other nice variants we considered:

-"Tail Aggressiveness"
-"Tail Chasing"
-"Goofiness"

:)

Renamed "Smooth Distance" to "Distance"

M  +16   -2    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/00ae21b9658d9d8a89ce8e8f7037ad11f3173f41

diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.cc b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
index 56ff0d2..a652bea 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);
@@ -96,14 +105,19 @@ QWidget * KisToolBrush::createOptionWidget()
     m_sliderSmoothnessDistance->setEnabled(true);
     connect(m_sliderSmoothnessDistance, SIGNAL(valueChanged(qreal)), SLOT(slotSetSmoothnessDistance(qreal)));
     m_sliderSmoothnessDistance->setValue(m_smoothingOptions.smoothnessDistance);
-    addOptionWidgetOption(m_sliderSmoothnessDistance, new QLabel(i18n("Weight:")));
+    addOptionWidgetOption(m_sliderSmoothnessDistance, new QLabel(i18n("Distance:")));
 
     m_sliderTailAggressiveness = new KisDoubleSliderSpinBox(optionWidget);
     m_sliderTailAggressiveness->setRange(0.0, 1.0, 2);
     m_sliderTailAggressiveness->setEnabled(true);
     connect(m_sliderTailAggressiveness, SIGNAL(valueChanged(qreal)), SLOT(slotSetTailAgressiveness(qreal)));
     m_sliderTailAggressiveness->setValue(m_smoothingOptions.tailAggressiveness);
-    addOptionWidgetOption(m_sliderTailAggressiveness, new QLabel(i18n("Tail Aggressiveness:")));
+    addOptionWidgetOption(m_sliderTailAggressiveness, new QLabel(i18n("Stroke Ending:")));
+
+    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);
 
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 ae4230d..812f6aa 100644
--- a/krita/ui/tool/kis_tool_freehand_helper.cpp
+++ b/krita/ui/tool/kis_tool_freehand_helper.cpp
@@ -260,6 +260,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());
@@ -308,16 +309,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;
             }
         }


More information about the kimageshop mailing list