Code

LPE: implement 'edit next LPE parameter'. Accessible through key '7'.
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 28 Oct 2007 16:03:07 +0000 (16:03 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 28 Oct 2007 16:03:07 +0000 (16:03 +0000)
13 files changed:
share/keys/default.xml
share/keys/inkscape.xml
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/parameter/parameter.cpp
src/live_effects/parameter/parameter.h
src/live_effects/parameter/path.cpp
src/live_effects/parameter/path.h
src/selection-chemistry.cpp
src/selection-chemistry.h
src/sp-shape.cpp
src/sp-shape.h
src/verbs.cpp

index d77cdaa25509b310f3b6f590f369461564675fa3..cb8044a0a753268ef155668b17d957fe8c33e142 100644 (file)
@@ -320,7 +320,9 @@ override) the bindings in the main default.xml.
 
   <bind key="Escape" action="EditDeselect" /> 
 
-<!-- Objects/selection -->
+  <bind key="7" action="EditNextPathEffectParameter" display="true"/>
+
+  <!-- Objects/selection -->
 
   <bind key="h" action="ObjectFlipHorizontally" display="true"/>
   <bind key="H" action="ObjectFlipHorizontally" />
index d77cdaa25509b310f3b6f590f369461564675fa3..d478010a3dcede6a8079ff992338c620a7158135 100644 (file)
@@ -320,6 +320,8 @@ override) the bindings in the main default.xml.
 
   <bind key="Escape" action="EditDeselect" /> 
 
+  <bind key="7" action="EditNextPathEffectParameter" display="true"/>
+
 <!-- Objects/selection -->
 
   <bind key="h" action="ObjectFlipHorizontally" display="true"/>
index cfabc88b429df8b48febb5a8e4a6368e0fcbf30a..3802066ec7549efec3d71b40eb25b52ec6083661 100644 (file)
@@ -90,6 +90,7 @@ Effect::Effect(LivePathEffectObject *lpeobject)
     vbox = NULL;
     tooltips = NULL;
     lpeobj = lpeobject;
+    oncanvasedit_it = param_map.begin();
 }
 
 Effect::~Effect()
@@ -261,6 +262,46 @@ Effect::getSPDoc()
     return SP_OBJECT_DOCUMENT(lpeobj);
 }
 
+Parameter *
+Effect::getNextOncanvasEditableParam()
+{
+    oncanvasedit_it++;
+    if (oncanvasedit_it == param_map.end()) {
+        oncanvasedit_it = param_map.begin();
+    }
+    param_map_type::iterator old_it = oncanvasedit_it;
+
+    do {
+        Parameter * param = oncanvasedit_it->second;
+        if(param->oncanvas_editable) {
+            return param;
+        } else {
+            oncanvasedit_it++;
+            if (oncanvasedit_it == param_map.end()) {  // loop round the map
+                oncanvasedit_it = param_map.begin();
+            }
+        }
+    } while (oncanvasedit_it != old_it); // iterate until complete loop through map has been made
+
+    return NULL;
+}
+
+void
+Effect::editNextParamOncanvas(SPItem * item, SPDesktop * desktop)
+{
+    if (!desktop) return;
+
+    Parameter * param = getNextOncanvasEditableParam();
+    if (param) {
+        param->param_editOncanvas(item, desktop);
+        gchar *message = g_strdup_printf(_("Editing parameter <b>%s</b>."), param->param_label.c_str());
+        desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, message);
+        g_free(message);
+    } else {
+        desktop->messageStack()->flash( Inkscape::WARNING_MESSAGE,
+                                        _("None of the applied path effect's parameters can be edited on-canvas.") );
+    }
+}
 
 } /* namespace LivePathEffect */
 
index 8c647e5994840c942e46d16b9ff585402d5bef5b..844a158b59ca9e59ccf1f2aa1b62b2c7386d9e69 100644 (file)
@@ -21,8 +21,9 @@
 
 //#define LPE_ENABLE_TEST_EFFECTS
 
-struct SPShape;
 struct SPDocument;
+struct SPDesktop;
+struct SPItem;
 class NArtBpath;
 struct LivePathEffectObject;
 
@@ -75,6 +76,8 @@ public:
     void readallParameters(Inkscape::XML::Node * repr);
     void setParameter(const gchar * key, const gchar * new_value);
 
+    void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
+
 protected:
     Effect(LivePathEffectObject *lpeobject);
 
@@ -91,6 +94,7 @@ protected:
             doEffect (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in);
 
     void registerParameter(Parameter * param);
+    Parameter * getNextOncanvasEditableParam();
 
     typedef std::map<Glib::ustring, Parameter *> param_map_type;
     param_map_type param_map;
@@ -101,6 +105,8 @@ protected:
 
     LivePathEffectObject *lpeobj;
 
+    param_map_type::iterator oncanvasedit_it;
+
 private:
     Effect(const Effect&);
     Effect& operator=(const Effect&);
index efca9908d257feeb46e71880b9e9ac2795ab7c34..9ee7faae433d67200b32681dfc232d82707658a7 100644 (file)
@@ -28,6 +28,7 @@ namespace LivePathEffect {
 Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip,
                       const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
                       Effect* effect )
+    : oncanvas_editable(false)
 {
     param_label = label;
     param_tooltip = tip;
index a6b05bf362ad8185393ba4650b5ac42f7ecbc5ba..a41d5f7c6907d337023fdb27c6577ab799fd889c 100644 (file)
@@ -16,6 +16,9 @@
 #include "ui/widget/registry.h"
 #include "ui/widget/registered-widget.h"
 
+struct SPDesktop;
+struct SPItem;
+
 namespace Gtk {
     class Widget;
 }
@@ -45,10 +48,14 @@ public:
     virtual Gtk::Widget * param_getWidget() = 0;
     virtual Glib::ustring * param_getTooltip() { return &param_tooltip; };
 
+    virtual void param_editOncanvas(SPItem * item, SPDesktop * dt) { return; };
+
     Glib::ustring param_key;
     Inkscape::UI::Widget::Registry * param_wr;
     Glib::ustring param_label;
 
+    bool oncanvas_editable;
+
 protected:
     Glib::ustring param_tooltip;
 
index db1064511dccf966254cad639ec82c1d56d7cfc1..2b558d2dda59a93858a5e62211aa15687df1d393 100644 (file)
@@ -46,6 +46,7 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip,
     edit_button = NULL;
     defvalue = g_strdup(default_value);
     param_readSVGValue(defvalue);
+    oncanvas_editable = true;
 }
 
 PathParam::~PathParam()
@@ -128,17 +129,34 @@ PathParam::param_getWidget()
 }
 
 void
-PathParam::on_edit_button_click()
+PathParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
 {
-    // Switch to node edit tool:
-    tools_switch_current(TOOLS_NODES);
+    // If not already in nodecontext, goto it!
+    if (!tools_isactive(dt, TOOLS_NODES)) {
+        tools_switch_current(TOOLS_NODES);
+    }
 
-    // set this parameter to edit:
-    ShapeEditor * shape_editor = SP_NODE_CONTEXT( SP_ACTIVE_DESKTOP->event_context )->shape_editor;
-    SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem();
+    ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
     shape_editor->set_item_livepatheffect_parameter(item, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str());
 }
 
+void
+PathParam::param_write_to_repr(const char * svgd)
+{
+    param_effect->getRepr()->setAttribute(param_key.c_str(), svgd);
+}
+
+
+/* CALLBACK FUNCTIONS FOR THE BUTTONS */
+void
+PathParam::on_edit_button_click()
+{
+    SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem();
+    if (item != NULL) {
+        param_editOncanvas(item, SP_ACTIVE_DESKTOP);
+    }
+}
+
 void
 PathParam::on_paste_button_click()
 {
@@ -170,12 +188,6 @@ PathParam::on_paste_button_click()
     }
 }
 
-void
-PathParam::param_write_to_repr(const char * svgd)
-{
-    param_effect->getRepr()->setAttribute(param_key.c_str(), svgd);
-}
-
 
 } /* namespace LivePathEffect */
 
index 14387f4194c7aad942c3febfe840c0bf3fec164f..6ba6e7e4b77417326f4e11aa13ca4317ec00b270 100644 (file)
@@ -44,6 +44,8 @@ public:
 
     void param_set_default();
 
+    void param_editOncanvas(SPItem * item, SPDesktop * dt);
+
     sigc::signal <void> signal_path_pasted;
     sigc::signal <void> signal_path_changed;
 
index 8d0aa4e79eb1c0aed1ee6218bcab239979f850f2..d97bcfc080a5dd8d0f6e9c271143b6d54a6f429e 100644 (file)
@@ -2005,6 +2005,24 @@ sp_selection_item_prev(void)
     }
 }
 
+void sp_selection_next_patheffect_param(SPDesktop * dt)
+{
+    if (!dt) return;
+
+    Inkscape::Selection *selection = sp_desktop_selection(dt);
+    if ( selection && !selection->isEmpty() ) {
+        SPItem *item = selection->singleItem();
+        if ( item && SP_IS_SHAPE(item)) {
+            SPShape *shape = SP_SHAPE(item);
+            if (sp_shape_has_path_effect(shape)) {
+                sp_shape_edit_next_param_oncanvas(shape, dt);
+            } else {
+                dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied path effect."));
+            }
+        }
+    }
+}
+
 namespace {
 
 template <typename D>
index 66aab7d77d2cc31639011e1ab0207279529192b9..09f95733203d0176bc1a09b0829e8c8c9875afbc 100644 (file)
@@ -88,6 +88,8 @@ void sp_selection_move_screen (gdouble dx, gdouble dy);
 void sp_selection_item_next (void);
 void sp_selection_item_prev (void);
 
+void sp_selection_next_patheffect_param(SPDesktop * dt);
+
 void scroll_to_show_item(SPDesktop *desktop, SPItem *item);
 
 void sp_undo (SPDesktop *desktop, SPDocument *doc);
index 511081b4c2062b4e85e80167debe3437f73972ab..ddec7aecc1dda7bbc196e9909dcfd8c0f68896e0 100644 (file)
@@ -1214,6 +1214,14 @@ bool sp_shape_has_path_effect(SPShape *shape)
     return (shape->path_effect_href != NULL);
 }
 
+void sp_shape_edit_next_param_oncanvas(SPShape *shape, SPDesktop *dt)
+{
+    LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(shape);
+    if (lpeobj && lpeobj->lpe) {
+        lpeobj->lpe->editNextParamOncanvas(SP_ITEM(shape), dt);
+    }
+}
+
 /*
   Local Variables:
   mode:c++
index 7563e2c7d760e29cda4fe0bdf494fda5bb623935..eb7d01245604277276f41c9142715dc9642f8be0 100644 (file)
@@ -27,6 +27,7 @@
 
 #define SP_SHAPE_WRITE_PATH (1 << 2)
 
+struct SPDesktop;
 struct LivePathEffectObject;
 namespace Inkscape{ 
 namespace LivePathEffect{
@@ -84,4 +85,6 @@ void sp_shape_set_path_effect(SPShape *shape, gchar *value);
 void sp_shape_remove_path_effect(SPShape *shape);
 bool sp_shape_has_path_effect(SPShape *shape);
 
+void sp_shape_edit_next_param_oncanvas(SPShape *shape, SPDesktop *dt);
+
 #endif
index 32e0c46af55b323c914796271207e7a797cf537c..cc3adb8e2f6cbf46796bd7092d9671687b4e33d1 100644 (file)
@@ -1001,16 +1001,7 @@ EditVerb::perform(SPAction *action, void *data, void *pdata)
             break;
 
         case SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER:
-          //FACTOR OUT THIS CODE TO SOMEWHERE ELSE!
-            // if(selection has LPE) {
-                // If not already in nodecontext, goto it!
-          //      if (!tools_isactive(dt, TOOLS_NODES)) {
-           //         tools_switch_current(TOOLS_NODES);
-            //    }
-                // add goto next code here:
-            //} else {
-            // statusbar message: selection has no path effect applied.
-            //}
+            sp_selection_next_patheffect_param(dt);
             break;
         default:
             break;