[calligra] krita/plugins/tools/defaulttools: [FEATURE] Add actions for choosing the smoothing type with a key shortcut

Dmitry Kazakov dimula73 at gmail.com
Sun Jul 27 07:20:46 UTC 2014


Git commit e596183da6f7696e593c632b9e03c91739679bdb by Dmitry Kazakov.
Committed on 27/07/2014 at 07:20.
Pushed by dkazakov into branch 'master'.

[FEATURE] Add actions for choosing the smoothing type with a key shortcut

Now you can go to Settings->Configure Shortcuts and set desired shortcuts
for any of "Brush Smoothing: ..." group of actions

CCMAIL:kimageshop at kde.org

M  +50   -0    krita/plugins/tools/defaulttools/kis_tool_brush.cc
M  +9    -0    krita/plugins/tools/defaulttools/kis_tool_brush.h

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

diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.cc b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
index f6d7f2e..91b1a8d 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_brush.cc
+++ b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
@@ -24,6 +24,11 @@
 #include <QComboBox>
 
 #include <klocale.h>
+#include <kaction.h>
+#include <kactioncollection.h>
+
+#include <KoCanvasBase.h>
+#include <KoCanvasController.h>
 
 #include "kis_cursor.h"
 #include "kis_config.h"
@@ -33,6 +38,24 @@
 #define MAXIMUM_MAGNETISM 1000
 
 
+void KisToolBrush::addSmoothingAction(int enumId, const QString &id, const QString &name, KActionCollection *globalCollection)
+{
+    /**
+     * KisToolBrush is the base of several tools, but the actions
+     * should be unique, so let's be careful with them
+     */
+    if (!globalCollection->action(id)) {
+        KAction *action = new KAction(name, globalCollection);
+        globalCollection->addAction(id, action);
+    }
+
+    KAction *action = dynamic_cast<KAction*>(globalCollection->action(id));
+    addAction(id, action);
+
+    connect(action, SIGNAL(triggered()), &m_signalMapper, SLOT(map()));
+    m_signalMapper.setMapping(action, enumId);
+}
+
 KisToolBrush::KisToolBrush(KoCanvasBase * canvas)
     : KisToolFreehand(canvas,
                       KisCursor::load("tool_freehand_cursor.png", 5, 5),
@@ -40,12 +63,31 @@ KisToolBrush::KisToolBrush(KoCanvasBase * canvas)
 {
     setObjectName("tool_brush");
     connect(this, SIGNAL(smoothingTypeChanged()), this, SLOT(resetCursorStyle()));
+
+    KActionCollection *collection = this->canvas()->canvasController()->actionCollection();
+
+    addSmoothingAction(KisSmoothingOptions::NO_SMOOTHING, "set_no_brush_smoothing", i18nc("@action", "Brush Smoothing: Disabled"), collection);
+    addSmoothingAction(KisSmoothingOptions::SIMPLE_SMOOTHING, "set_simple_brush_smoothing", i18nc("@action", "Brush Smoothing: Basic"), collection);
+    addSmoothingAction(KisSmoothingOptions::WEIGHTED_SMOOTHING, "set_weighted_brush_smoothing", i18nc("@action", "Brush Smoothing: Weighted"), collection);
+    addSmoothingAction(KisSmoothingOptions::STABILIZER, "set_stabilizer_brush_smoothing", i18nc("@action", "Brush Smoothing: Stabilizer"), collection);
 }
 
 KisToolBrush::~KisToolBrush()
 {
 }
 
+void KisToolBrush::activate(ToolActivation activation, const QSet<KoShape*> &shapes)
+{
+    KisToolFreehand::activate(activation, shapes);
+    connect(&m_signalMapper, SIGNAL(mapped(int)), SLOT(slotSetSmoothingType(int)), Qt::UniqueConnection);
+}
+
+void KisToolBrush::deactivate()
+{
+    disconnect(&m_signalMapper, 0, this, 0);
+    KisToolFreehand::deactivate();
+}
+
 int KisToolBrush::smoothingType() const
 {
     return smoothingOptions()->smoothingType();
@@ -68,6 +110,14 @@ qreal KisToolBrush::smoothnessFactor() const
 
 void KisToolBrush::slotSetSmoothingType(int index)
 {
+    /**
+     * The slot can also be called from smoothing-type-switching
+     * action that would mean the combo box will not be synchronized
+     */
+    if (m_cmbSmoothingType->currentIndex() != index) {
+        m_cmbSmoothingType->setCurrentIndex(index);
+    }
+
     switch (index) {
     case 0:
         smoothingOptions()->setSmoothingType(KisSmoothingOptions::NO_SMOOTHING);
diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.h b/krita/plugins/tools/defaulttools/kis_tool_brush.h
index ac0a2b6..885870c 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_brush.h
+++ b/krita/plugins/tools/defaulttools/kis_tool_brush.h
@@ -21,6 +21,8 @@
 
 #include "kis_tool_freehand.h"
 
+#include <QSignalMapper>
+
 #include "KoToolFactoryBase.h"
 
 #include <flake/kis_node_shape.h>
@@ -56,6 +58,9 @@ public:
 
     QWidget * createOptionWidget();
 
+    void activate(ToolActivation activation, const QSet<KoShape*> &shapes);
+    void deactivate();
+
     int smoothnessQuality() const;
     qreal smoothnessFactor() const;
     bool smoothPressure() const;
@@ -101,6 +106,9 @@ Q_SIGNALS:
     void stabilizeSensorsChanged();
 
 private:
+    void addSmoothingAction(int enumId, const QString &id, const QString &name, KActionCollection *globalCollection);
+
+private:
     QComboBox *m_cmbSmoothingType;
 
     QCheckBox *m_chkAssistant;
@@ -115,6 +123,7 @@ private:
     KisDoubleSliderSpinBox *m_sliderDelayDistance;
 
     QCheckBox *m_chkFinishStabilizedCurve;
+    QSignalMapper m_signalMapper;
 };
 
 


More information about the kimageshop mailing list