[calligra/calligra/2.9] krita: [FEATURE] Implement 'Scalable smoothness' feature for Stabilizer smoother

Dmitry Kazakov dimula73 at gmail.com
Thu Aug 20 07:59:41 UTC 2015


Git commit b6011fb1c50c86dce5e4c5e2a06769025d24595e by Dmitry Kazakov.
Committed on 20/08/2015 at 07:58.
Pushed by dkazakov into branch 'calligra/2.9'.

[FEATURE] Implement 'Scalable smoothness' feature for Stabilizer smoother

Now 'Scalable smoothness' is also available for the Stabilizer

Fixes T497
CC:kimageshop at kde.org

M  +6    -1    krita/plugins/tools/defaulttools/kis_tool_brush.cc
M  +16   -10   krita/ui/tool/kis_tool_freehand_helper.cpp

http://commits.kde.org/calligra/b6011fb1c50c86dce5e4c5e2a06769025d24595e

diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.cc b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
index b0435d5..85ff008 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_brush.cc
+++ b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
@@ -161,7 +161,7 @@ void KisToolBrush::slotSetSmoothingType(int index)
         showControl(m_sliderSmoothnessDistance, true);
         showControl(m_sliderTailAggressiveness, false);
         showControl(m_chkSmoothPressure, false);
-        showControl(m_chkUseScalableDistance, false);
+        showControl(m_chkUseScalableDistance, true);
         showControl(m_sliderDelayDistance, true);
         showControl(m_chkFinishStabilizedCurve, true);
         showControl(m_chkStabilizeSensors, true);
@@ -400,6 +400,11 @@ QWidget * KisToolBrush::createOptionWidget()
     m_chkUseScalableDistance->setChecked(smoothingOptions()->useScalableDistance());
     m_chkUseScalableDistance->setMinimumHeight(qMax(m_sliderSmoothnessDistance->sizeHint().height()-3,
                                                     m_chkUseScalableDistance->sizeHint().height()));
+    m_chkUseScalableDistance->setToolTip(i18nc("@info:tooltip",
+                                               "Scalable distance takes zoom level "
+                                               "into account and makes the distance "
+                                               "be visually constant whatever zoom "
+                                               "level is chosen"));
     connect(m_chkUseScalableDistance, SIGNAL(toggled(bool)), this, SLOT(setUseScalableDistance(bool)));
     addOptionWidgetOption(m_chkUseScalableDistance, new QLabel(QString("%1:").arg(i18n("Scalable Distance"))));
 
diff --git a/krita/ui/tool/kis_tool_freehand_helper.cpp b/krita/ui/tool/kis_tool_freehand_helper.cpp
index fa73232..ee450bd 100644
--- a/krita/ui/tool/kis_tool_freehand_helper.cpp
+++ b/krita/ui/tool/kis_tool_freehand_helper.cpp
@@ -78,13 +78,15 @@ struct KisToolFreehandHelper::Private
     QQueue<KisPaintInformation> stabilizerDeque;
     KisPaintInformation stabilizerLastPaintInfo;
     QTimer stabilizerPollTimer;
-    
+
     int canvasRotation;
     bool canvasMirroredH;
 
     KisPaintInformation
     getStabilizedPaintInfo(const QQueue<KisPaintInformation> &queue,
                            const KisPaintInformation &lastPaintInfo);
+
+    qreal effectiveSmoothnessDistance() const;
 };
 
 
@@ -332,6 +334,16 @@ void KisToolFreehandHelper::paintBezierSegment(KisPaintInformation pi1, KisPaint
                      pi2);
 }
 
+qreal KisToolFreehandHelper::Private::effectiveSmoothnessDistance() const
+{
+    const qreal effectiveSmoothnessDistance =
+        !smoothingOptions->useScalableDistance() ?
+        smoothingOptions->smoothnessDistance() :
+        smoothingOptions->smoothnessDistance() / resources->effectiveZoom();
+
+    return effectiveSmoothnessDistance;
+}
+
 void KisToolFreehandHelper::paint(KoPointerEvent *event)
 {
     KisPaintInformation info =
@@ -384,13 +396,7 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event)
         qreal y = 0.0;
 
         if (m_d->history.size() > 3) {
-            const qreal effectiveSmoothnessDistance =
-                !m_d->smoothingOptions->useScalableDistance() ?
-                m_d->smoothingOptions->smoothnessDistance() :
-                m_d->smoothingOptions->smoothnessDistance() /
-                m_d->resources->effectiveZoom();
-
-            const qreal sigma = effectiveSmoothnessDistance / 3.0; // '3.0' for (3 * sigma) range
+            const qreal sigma = m_d->effectiveSmoothnessDistance() / 3.0; // '3.0' for (3 * sigma) range
 
             qreal gaussianWeight = 1 / (sqrt(2 * M_PI) * sigma);
             qreal gaussianWeight2 = sigma * sigma;
@@ -562,8 +568,8 @@ int KisToolFreehandHelper::elapsedStrokeTime() const
 void KisToolFreehandHelper::stabilizerStart(KisPaintInformation firstPaintInfo)
 {
     // FIXME: Ugly hack, this is no a "distance" in any way
-    int sampleSize = m_d->smoothingOptions->smoothnessDistance();
-    assert(sampleSize > 0);
+    int sampleSize = qRound(m_d->effectiveSmoothnessDistance());
+    sampleSize = qMax(3, sampleSize);
 
     // Fill the deque with the current value repeated until filling the sample
     m_d->stabilizerDeque.clear();


More information about the kimageshop mailing list