[calligra] krita: [FEATURE] Added a Scalable Distance option to Weighted Smoothing

Dmitry Kazakov dimula73 at gmail.com
Fri Jun 6 12:17:52 UTC 2014


Git commit 5111f3feb003b5e052201b0115a424d5237a8423 by Dmitry Kazakov.
Committed on 06/06/2014 at 12:16.
Pushed by dkazakov into branch 'master'.

[FEATURE] Added a Scalable Distance option to Weighted Smoothing

Now if you activate "Scalable Distance" option for a brush tool,
the distance will be corrected to your current zoom level. It means
that your stylus will be "stabilized" the same way at any zoom level
you choose.

BUG:335834
CCMAIL:kimageshop at kde.org

M  +19   -0    krita/plugins/tools/defaulttools/kis_tool_brush.cc
M  +5    -0    krita/plugins/tools/defaulttools/kis_tool_brush.h
M  +6    -0    krita/ui/canvas/kis_coordinates_converter.cpp
M  +1    -0    krita/ui/kis_canvas_resource_provider.cpp
M  +2    -1    krita/ui/kis_canvas_resource_provider.h
M  +10   -0    krita/ui/kis_config.cc
M  +3    -0    krita/ui/kis_config.h
M  +6    -0    krita/ui/kis_zoom_manager.cc
M  +6    -0    krita/ui/tool/kis_resources_snapshot.cpp
M  +2    -0    krita/ui/tool/kis_resources_snapshot.h
M  +12   -0    krita/ui/tool/kis_smoothing_options.cpp
M  +3    -0    krita/ui/tool/kis_smoothing_options.h
M  +7    -1    krita/ui/tool/kis_tool_freehand_helper.cpp

http://commits.kde.org/calligra/5111f3feb003b5e052201b0115a424d5237a8423

diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.cc b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
index ceab3d8..84fede3 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_brush.cc
+++ b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
@@ -74,12 +74,14 @@ void KisToolBrush::slotSetSmoothingType(int index)
         m_sliderSmoothnessDistance->setEnabled(false);
         m_sliderTailAggressiveness->setEnabled(false);
         m_chkSmoothPressure->setEnabled(false);
+        m_chkUseScalableDistance->setEnabled(false);
         break;
     case 1:
         m_smoothingOptions.setSmoothingType(KisSmoothingOptions::SIMPLE_SMOOTHING);
         m_sliderSmoothnessDistance->setEnabled(false);
         m_sliderTailAggressiveness->setEnabled(false);
         m_chkSmoothPressure->setEnabled(false);
+        m_chkUseScalableDistance->setEnabled(false);
         break;
     case 2:
     default:
@@ -87,6 +89,7 @@ void KisToolBrush::slotSetSmoothingType(int index)
         m_sliderSmoothnessDistance->setEnabled(true);
         m_sliderTailAggressiveness->setEnabled(true);
         m_chkSmoothPressure->setEnabled(true);
+        m_chkUseScalableDistance->setEnabled(true);
     }
     emit smoothingTypeChanged();
 }
@@ -113,6 +116,17 @@ void KisToolBrush::slotSetMagnetism(int magnetism)
     m_magnetism = expf(magnetism / (double)MAXIMUM_MAGNETISM) / expf(1.0);
 }
 
+bool KisToolBrush::useScalableDistance() const
+{
+    return m_smoothingOptions.useScalableDistance();
+}
+
+void KisToolBrush::setUseScalableDistance(bool value)
+{
+    m_smoothingOptions.setUseScalableDistance(value);
+    emit useScalableDistanceChanged();
+}
+
 QWidget * KisToolBrush::createOptionWidget()
 {
     QWidget *optionsWidget = KisToolFreehand::createOptionWidget();
@@ -177,6 +191,11 @@ QWidget * KisToolBrush::createOptionWidget()
     connect(m_chkSmoothPressure, SIGNAL(toggled(bool)), this, SLOT(setSmoothPressure(bool)));
     addOptionWidgetOption(m_chkSmoothPressure, new QLabel(i18n("Smooth Pressure")));
 
+    m_chkUseScalableDistance = new QCheckBox("", optionsWidget);
+    m_chkUseScalableDistance->setChecked(m_smoothingOptions.useScalableDistance());
+    connect(m_chkUseScalableDistance, SIGNAL(toggled(bool)), this, SLOT(setUseScalableDistance(bool)));
+    addOptionWidgetOption(m_chkUseScalableDistance, new QLabel(i18n("Scalable Distance")));
+
     m_buttonGroup->button((int)m_smoothingOptions.smoothingType())->setChecked(true);
     slotSetSmoothingType((int)m_smoothingOptions.smoothingType());
 
diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.h b/krita/plugins/tools/defaulttools/kis_tool_brush.h
index 25e47da..ed2d389 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_brush.h
+++ b/krita/plugins/tools/defaulttools/kis_tool_brush.h
@@ -41,6 +41,7 @@ class KisToolBrush : public KisToolFreehand
     Q_PROPERTY(qreal smoothnessFactor READ smoothnessFactor WRITE slotSetTailAgressiveness NOTIFY smoothnessFactorChanged)
     Q_PROPERTY(bool smoothPressure READ smoothPressure WRITE setSmoothPressure NOTIFY smoothPressureChanged)
     Q_PROPERTY(int smoothingType READ smoothingType WRITE slotSetSmoothingType NOTIFY smoothingTypeChanged)
+    Q_PROPERTY(bool useScalableDistance READ useScalableDistance WRITE setUseScalableDistance NOTIFY useScalableDistanceChanged)
 
 public:
     KisToolBrush(KoCanvasBase * canvas);
@@ -52,6 +53,7 @@ public:
     qreal smoothnessFactor() const;
     bool smoothPressure() const;
     int smoothingType() const;
+    bool useScalableDistance() const;
 
 public slots:
     void slotSetSmoothnessDistance(qreal distance);
@@ -59,12 +61,14 @@ public slots:
     void slotSetSmoothingType(int index);
     void slotSetTailAgressiveness(qreal argh_rhhrr);
     void setSmoothPressure(bool value);
+    void setUseScalableDistance(bool value);
 
 Q_SIGNALS:
     void smoothnessQualityChanged();
     void smoothnessFactorChanged();
     void smoothPressureChanged();
     void smoothingTypeChanged();
+    void useScalableDistanceChanged();
 
 private:
     QGridLayout *m_optionLayout;
@@ -74,6 +78,7 @@ private:
     KisDoubleSliderSpinBox *m_sliderSmoothnessDistance;
     KisDoubleSliderSpinBox *m_sliderTailAggressiveness;
     QCheckBox *m_chkSmoothPressure;
+    QCheckBox *m_chkUseScalableDistance;
     QButtonGroup * m_buttonGroup;
 };
 
diff --git a/krita/ui/canvas/kis_coordinates_converter.cpp b/krita/ui/canvas/kis_coordinates_converter.cpp
index e098240..6a4f106 100644
--- a/krita/ui/canvas/kis_coordinates_converter.cpp
+++ b/krita/ui/canvas/kis_coordinates_converter.cpp
@@ -415,6 +415,12 @@ QPointF KisCoordinatesConverter::widgetCenterPoint() const
 
 void KisCoordinatesConverter::imageScale(qreal *scaleX, qreal *scaleY) const
 {
+    if(!m_d->image) {
+        *scaleX = 1.0;
+        *scaleY = 1.0;
+        return;
+    }
+
     // get the x and y zoom level of the canvas
     qreal zoomX, zoomY;
     KoZoomHandler::zoom(&zoomX, &zoomY);
diff --git a/krita/ui/kis_canvas_resource_provider.cpp b/krita/ui/kis_canvas_resource_provider.cpp
index c2762b8..30652e2 100644
--- a/krita/ui/kis_canvas_resource_provider.cpp
+++ b/krita/ui/kis_canvas_resource_provider.cpp
@@ -79,6 +79,7 @@ void KisCanvasResourceProvider::setResourceManager(KoCanvasResourceManager *reso
 
     m_resourceManager->setResource(HdrExposure, 0.0);
     m_resourceManager->setResource(HdrGamma, 1.0);
+    m_resourceManager->setResource(EffectiveZoom, 1.0);
 
     connect(m_resourceManager, SIGNAL(canvasResourceChanged(int,QVariant)),
             this, SLOT(slotCanvasResourceChanged(int,QVariant)));
diff --git a/krita/ui/kis_canvas_resource_provider.h b/krita/ui/kis_canvas_resource_provider.h
index eb0cf06..b72de92 100644
--- a/krita/ui/kis_canvas_resource_provider.h
+++ b/krita/ui/kis_canvas_resource_provider.h
@@ -66,7 +66,8 @@ public:
         Opacity,
         HdrGamma,
         GlobalAlphaLock,
-        PreviousPaintOpPreset
+        PreviousPaintOpPreset,
+        EffectiveZoom ///<-Used only by painting tools for non-displaying purposes
     };
 
 
diff --git a/krita/ui/kis_config.cc b/krita/ui/kis_config.cc
index 4ea3ae2..e167c74 100644
--- a/krita/ui/kis_config.cc
+++ b/krita/ui/kis_config.cc
@@ -1125,6 +1125,16 @@ void KisConfig::setLineSmoothingSmoothPressure(bool value)
     m_cfg.writeEntry("LineSmoothingSmoothPressure", value);
 }
 
+bool KisConfig::lineSmoothingScalableDistance() const
+{
+    return m_cfg.readEntry("LineSmoothingScalableDistance", true);
+}
+
+void KisConfig::setLineSmoothingScalableDistance(bool value)
+{
+    m_cfg.writeEntry("LineSmoothingScalableDistance", value);
+}
+
 int KisConfig::paletteDockerPaletteViewSectionSize() const
 {
     return m_cfg.readEntry("paletteDockerPaletteViewSectionSize", 12);
diff --git a/krita/ui/kis_config.h b/krita/ui/kis_config.h
index 5ca4386..aa99f64 100644
--- a/krita/ui/kis_config.h
+++ b/krita/ui/kis_config.h
@@ -342,6 +342,9 @@ public:
     bool lineSmoothingSmoothPressure() const;
     void setLineSmoothingSmoothPressure(bool value);
 
+    bool lineSmoothingScalableDistance() const;
+    void setLineSmoothingScalableDistance(bool value);
+
     int paletteDockerPaletteViewSectionSize() const;
     void setPaletteDockerPaletteViewSectionSize(int value) const;
 
diff --git a/krita/ui/kis_zoom_manager.cc b/krita/ui/kis_zoom_manager.cc
index 81a9713..ee8161a 100644
--- a/krita/ui/kis_zoom_manager.cc
+++ b/krita/ui/kis_zoom_manager.cc
@@ -49,6 +49,8 @@
 #include "kis_statusbar.h"
 #include "kis_config.h"
 #include "krita_utils.h"
+#include "kis_canvas_resource_provider.h"
+
 
 class KisZoomController : public KoZoomController
 {
@@ -230,6 +232,10 @@ void KisZoomManager::slotZoomChanged(KoZoomMode::Mode mode, qreal zoom)
                   KritaUtils::prettyFormatReal(humanZoom)),
             QIcon(), 500, KisFloatingMessage::Low);
 
+    qreal scaleX, scaleY;
+    m_view->canvasBase()->coordinatesConverter()->imageScale(&scaleX, &scaleY);
+    KIS_ASSERT_RECOVER_NOOP(scaleX == scaleY && "Zoom is not isotropic!");
+    m_view->canvasBase()->resourceManager()->setResource(KisCanvasResourceProvider::EffectiveZoom, scaleX);
 }
 
 void KisZoomManager::slotScrollAreaSizeChanged()
diff --git a/krita/ui/tool/kis_resources_snapshot.cpp b/krita/ui/tool/kis_resources_snapshot.cpp
index 76b5698..a50cf94 100644
--- a/krita/ui/tool/kis_resources_snapshot.cpp
+++ b/krita/ui/tool/kis_resources_snapshot.cpp
@@ -67,6 +67,7 @@ struct KisResourcesSnapshot::Private {
     KisPainter::FillStyle fillStyle;
 
     bool globalAlphaLock;
+    qreal effectiveZoom;
 };
 
 KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager, KisDefaultBoundsBaseSP bounds)
@@ -118,6 +119,7 @@ KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUn
     m_d->fillStyle = KisPainter::FillStyleNone;
 
     m_d->globalAlphaLock = resourceManager->resource(KisCanvasResourceProvider::GlobalAlphaLock).toBool();
+    m_d->effectiveZoom = resourceManager->resource(KisCanvasResourceProvider::EffectiveZoom).toDouble();
 }
 
 KisResourcesSnapshot::~KisResourcesSnapshot()
@@ -282,3 +284,7 @@ QBitArray KisResourcesSnapshot::channelLockFlags() const
     return channelFlags;
 }
 
+qreal KisResourcesSnapshot::effectiveZoom() const
+{
+    return m_d->effectiveZoom;
+}
diff --git a/krita/ui/tool/kis_resources_snapshot.h b/krita/ui/tool/kis_resources_snapshot.h
index a68883e..ea08f6d 100644
--- a/krita/ui/tool/kis_resources_snapshot.h
+++ b/krita/ui/tool/kis_resources_snapshot.h
@@ -69,6 +69,8 @@ public:
     /// @return the channel lock flags of the current node with the global override applied
     QBitArray channelLockFlags() const;
 
+    qreal effectiveZoom() const;
+
 private:
     struct Private;
     Private * const m_d;
diff --git a/krita/ui/tool/kis_smoothing_options.cpp b/krita/ui/tool/kis_smoothing_options.cpp
index 7e0a73c..ecc8909 100644
--- a/krita/ui/tool/kis_smoothing_options.cpp
+++ b/krita/ui/tool/kis_smoothing_options.cpp
@@ -24,12 +24,14 @@ KisSmoothingOptions::KisSmoothingOptions()
     , m_smoothnessDistance(55.0)
     , m_tailAggressiveness(0.15)
     , m_smoothPressure(false)
+    , m_useScalableDistance(true)
 {
     KisConfig cfg;
     m_smoothingType = (SmoothingType)cfg.lineSmoothingType();
     m_smoothnessDistance = cfg.lineSmoothingDistance();
     m_tailAggressiveness = cfg.lineSmoothingTailAggressiveness();
     m_smoothPressure = cfg.lineSmoothingSmoothPressure();
+    m_useScalableDistance = cfg.lineSmoothingScalableDistance();
 }
 
 KisSmoothingOptions::SmoothingType KisSmoothingOptions::smoothingType() const
@@ -80,4 +82,14 @@ void KisSmoothingOptions::setSmoothPressure(bool value)
     m_smoothPressure = value;
 }
 
+bool KisSmoothingOptions::useScalableDistance() const
+{
+    return m_useScalableDistance;
+}
 
+void KisSmoothingOptions::setUseScalableDistance(bool value)
+{
+    KisConfig cfg;
+    cfg.setLineSmoothingScalableDistance(value);
+    m_useScalableDistance = value;
+}
diff --git a/krita/ui/tool/kis_smoothing_options.h b/krita/ui/tool/kis_smoothing_options.h
index f2d5388..14905eb 100644
--- a/krita/ui/tool/kis_smoothing_options.h
+++ b/krita/ui/tool/kis_smoothing_options.h
@@ -46,12 +46,15 @@ public:
     bool smoothPressure() const;
     void setSmoothPressure(bool value);
 
+    bool useScalableDistance() const;
+    void setUseScalableDistance(bool value);
 
 private:
     SmoothingType m_smoothingType;
     qreal m_smoothnessDistance;
     qreal m_tailAggressiveness;
     bool m_smoothPressure;
+    bool m_useScalableDistance;
 };
 
 #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 aae08f1..a1f8eac 100644
--- a/krita/ui/tool/kis_tool_freehand_helper.cpp
+++ b/krita/ui/tool/kis_tool_freehand_helper.cpp
@@ -350,7 +350,13 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event)
         qreal y = 0.0;
 
         if (m_d->history.size() > 3) {
-            const qreal sigma = m_d->smoothingOptions.smoothnessDistance() / 3.0; // '3.0' for (3 * sigma) range
+            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
 
             qreal gaussianWeight = 1 / (sqrt(2 * M_PI) * sigma);
             qreal gaussianWeight2 = sigma * sigma;


More information about the kimageshop mailing list