Code

Fix bug [ 1818794 ] Showing grid on opening svg
authorjohanengelen <johanengelen@users.sourceforge.net>
Wed, 24 Oct 2007 23:19:48 +0000 (23:19 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Wed, 24 Oct 2007 23:19:48 +0000 (23:19 +0000)
+ some bits of code to do on-canvas path parameter editing LPE.

src/attributes-test.h
src/attributes.cpp
src/attributes.h
src/desktop.cpp
src/desktop.h
src/display/canvas-grid.cpp
src/live_effects/parameter/path.cpp
src/sp-namedview.cpp
src/sp-namedview.h
src/verbs.cpp
src/verbs.h

index 1030f9e46755ca94599b8ed2418ff862d54674de..57eb03eb5ae77a78e109e89867c28d3a5a84e3fb 100644 (file)
@@ -404,12 +404,12 @@ struct {char const *attr; bool supported;} const all_attrs[] = {
     /* SPNamedView */
     {"viewonly", true},
     {"showgrid", true},
-    {"gridtype", true},
+//    {"gridtype", true},
     {"showguides", true},
     {"gridtolerance", true},
     {"guidetolerance", true},
     {"objecttolerance", true},
-    {"gridoriginx", true},
+/*    {"gridoriginx", true},
     {"gridoriginy", true},
     {"gridspacingx", true},
     {"gridspacingy", true},
@@ -419,7 +419,7 @@ struct {char const *attr; bool supported;} const all_attrs[] = {
     {"gridopacity", true},
     {"gridempcolor", true},
     {"gridempopacity", true},
-    {"gridempspacing", true},
+    {"gridempspacing", true}, */
     {"guidecolor", true},
     {"guideopacity", true},
     {"guidehicolor", true},
index 977ab3483630a944bb4a22e894c4cd959e946ef0..5fb4a87a050f95e74970882bad9db95fd8be7d56 100644 (file)
@@ -61,6 +61,7 @@ static SPStyleProp const props[] = {
     /* SPNamedView */
     {SP_ATTR_VIEWONLY, "viewonly"},
     {SP_ATTR_SHOWGUIDES, "showguides"},
+    {SP_ATTR_SHOWGRIDS, "showgrid"},
     {SP_ATTR_GRIDTOLERANCE, "gridtolerance"},
     {SP_ATTR_GUIDETOLERANCE, "guidetolerance"},
     {SP_ATTR_OBJECTTOLERANCE, "objecttolerance"},
index 4a2970830d414dbe5e250030a2415d5c3c0f008c..6d05361f2b991b38b0b069c27d2147415f765766 100644 (file)
@@ -62,6 +62,7 @@ enum SPAttributeEnum {
     /* SPNamedView */
     SP_ATTR_VIEWONLY,
     SP_ATTR_SHOWGUIDES,
+    SP_ATTR_SHOWGRIDS,
     SP_ATTR_GRIDTOLERANCE,
     SP_ATTR_GUIDETOLERANCE,
     SP_ATTR_OBJECTTOLERANCE,
index 4b4d1fe5bcf8358b803cd97e41a2b8b670b26e16..4d2cd2fcb0c91d353e5655e274d0e1bb3603247d 100644 (file)
@@ -146,7 +146,7 @@ SPDesktop::SPDesktop() :
     _w2d(),
     _d2w(),
     _doc2dt( NR::Matrix(NR::scale(1, -1)) ),
-    grids_visible( true )
+    grids_visible( false )
 {
     _d2w.set_identity();
     _w2d.set_identity();
@@ -308,7 +308,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     //   (Setting up after the connections are all in place, as it may use some of them)
     layer_manager = new Inkscape::LayerManager( this );
 
-    grids_visible = true;
+    showGrids(namedview->grids_visible);
 }
 
 
@@ -1176,23 +1176,29 @@ void SPDesktop::clearWaitingCursor()
       sp_event_context_update_cursor(sp_desktop_event_context(this));
 }
 
-void SPDesktop::toggleGrid()
+void SPDesktop::toggleGrids()
 {
     if (namedview->grids) {
         if(gridgroup) {
-            grids_visible = !grids_visible;
-            if (grids_visible) {
-                sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup));
-            } else {
-                sp_canvas_item_hide(SP_CANVAS_ITEM(gridgroup));
-            }
+            showGrids(!grids_visible);
         }
     } else {
         //there is no grid present at the moment. add a rectangular grid and make it visible
         Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview);
         Inkscape::CanvasGrid::writeNewGridToRepr(repr, sp_desktop_document(this), Inkscape::GRID_RECTANGULAR);
-        grids_visible = true;
+        showGrids(true);
+    }
+}
+
+void SPDesktop::showGrids(bool show)
+{
+    grids_visible = show;
+    g_message(show?"show":"hide");
+    sp_namedview_show_grids(namedview, grids_visible);
+    if (show) {
         sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup));
+    } else {
+        sp_canvas_item_hide(SP_CANVAS_ITEM(gridgroup));
     }
 }
 
index bc80336de4eb0b9d8de05e972dd4e7cbd6f64286..2a811a72383e4e1edc3367891495d70d1f77327f 100644 (file)
@@ -260,9 +260,10 @@ struct SPDesktop : public Inkscape::UI::View::View
     void setWaitingCursor();
     void clearWaitingCursor();
     
-    void toggleGrid();
+    void toggleGrids();
     bool gridsEnabled() { return grids_visible; }
-    
+    void showGrids(bool show);
+
     bool is_iconified();
     bool is_maximized();
     bool is_fullscreen();
@@ -286,8 +287,8 @@ struct SPDesktop : public Inkscape::UI::View::View
     virtual void mouseover() {}
     virtual void mouseout() {}
 
-       virtual bool onDeleteUI (GdkEventAny*);
-       virtual bool onWindowStateEvent (GdkEventWindowState* event);
+    virtual bool onDeleteUI (GdkEventAny*);
+    virtual bool onWindowStateEvent (GdkEventWindowState* event);
 
 private:
     Inkscape::UI::View::EditWidgetInterface       *_widget;
@@ -297,9 +298,10 @@ private:
     NR::Matrix _w2d;
     NR::Matrix _d2w;
     NR::Matrix _doc2dt;
-    
-    bool grids_visible;
-    
+
+    bool grids_visible; /* don't set this variable directly, use the method below */
+    void set_grids_visible(bool visible);
+
     void push_current_zoom (GList**);
 
     sigc::signal<void,SPDesktop*,SPDocument*>     _document_replaced_signal;
@@ -307,7 +309,7 @@ private:
     sigc::signal<void>                 _deactivate_signal;
     sigc::signal<void,SPDesktop*,SPEventContext*> _event_context_changed_signal;
     sigc::signal<void, gpointer>       _tool_subselection_changed;
-  
+
     sigc::connection _activate_connection;
     sigc::connection _deactivate_connection;
     sigc::connection _sel_modified_connection;
@@ -316,7 +318,7 @@ private:
     sigc::connection _reconstruction_finish_connection;
     sigc::connection _commit_connection;
     sigc::connection _modified_connection;
-    
+
     virtual void onPositionSet (double, double);
     virtual void onResized (double, double);
     virtual void onRedrawRequested();
index b6086db270f64bee8d93b2ce19b50f4ece48573e..846d3699a9e846e6a0799df11e7fbca576484adc 100644 (file)
@@ -265,7 +265,8 @@ GridCanvasItem *
 CanvasGrid::createCanvasItem(SPDesktop * desktop)
 {
     if (!desktop) return NULL;
-    //Johan: I think for multiple desktops it is best if each has their own canvasitem, but share the same CanvasGrid object; that is what this function is for.
+//    Johan: I think for multiple desktops it is best if each has their own canvasitem,
+//           but share the same CanvasGrid object; that is what this function is for.
 
     // check if there is already a canvasitem on this desktop linking to this grid
     for (GSList *l = canvasitems; l != NULL; l = l->next) {
index 15ba663bee81a5c39af0c23370b75896d758031c..db1064511dccf966254cad639ec82c1d56d7cfc1 100644 (file)
@@ -25,7 +25,7 @@
 #include "verbs.h"
 #include "document.h"
 
-#define LPEPATHPARAM_DEBUG
+// needed for on-canvas editting:
 #include "tools-switch.h"
 #include "shape-editor.h"
 #include "node-context.h"
@@ -110,9 +110,6 @@ PathParam::param_getWidget()
         static_cast<Gtk::HBox*>(_widget)->pack_start(*pButton, true, true);
         _tooltips->set_tip(*pButton, _("Edit on-canvas"));
         edit_button = pButton;
-#ifndef LPEPATHPARAM_DEBUG
-        edit_button->set_sensitive(false);
-#endif
 
         pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) );
         pButton = Gtk::manage(new Gtk::Button());
index fa41060c2cd26267f2616936a38a20415ccef00d..c019910cb8ccffa4ade4cbda59fcc0fbac820a89 100644 (file)
@@ -127,10 +127,11 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape:
     if (((SPObjectClass *) (parent_class))->build) {
         (* ((SPObjectClass *) (parent_class))->build)(object, document, repr);
     }
-
+g_message("tijdens laden %d", nv->viewcount);
     sp_object_read_attr(object, "inkscape:document-units");
     sp_object_read_attr(object, "viewonly");
     sp_object_read_attr(object, "showguides");
+    sp_object_read_attr(object, "showgrid");
     sp_object_read_attr(object, "gridtolerance");
     sp_object_read_attr(object, "guidetolerance");
     sp_object_read_attr(object, "objecttolerance");
@@ -206,7 +207,7 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
             nv->editable = (!value);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             break;
-       case SP_ATTR_SHOWGUIDES:
+    case SP_ATTR_SHOWGUIDES:
             if (!value) { // show guides if not specified, for backwards compatibility
                 nv->showguides = TRUE;
             } else {
@@ -215,7 +216,17 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
             sp_namedview_setup_guides(nv);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             break;
-       case SP_ATTR_GRIDTOLERANCE:
+    case SP_ATTR_SHOWGRIDS:
+            if (!value) { // show grids if not specified, for backwards compatibility
+                nv->grids_visible = false;
+            } else {
+                nv->grids_visible = sp_str_to_bool(value);
+                g_message("set attr : %s", value);
+            }
+            g_message("set attr %s", nv->grids_visible ? "true":"false");
+            object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+            break;
+    case SP_ATTR_GRIDTOLERANCE:
             nv->gridtoleranceunit = &px;
             nv->gridtolerance = DEFAULTTOLERANCE;
             if (value) {
@@ -441,7 +452,7 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des
             break;
         }
     }
-    
+
     if (!grid) {
         //create grid object
         Inkscape::GridType gridtype = Inkscape::CanvasGrid::getGridTypeFromSVGName(repr->attribute("type"));
@@ -590,6 +601,8 @@ void SPNamedView::show(SPDesktop *desktop)
             }
         }
     }
+
+    desktop->showGrids(grids_visible);
 }
 
 #define MIN_ONSCREEN_DISTANCE 50
@@ -761,6 +774,22 @@ void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr)
     sp_document_set_undo_sensitive(doc, saved);
 }
 
+void sp_namedview_show_grids(SPNamedView * namedview, bool show)
+{
+    namedview->grids_visible = show;
+
+    SPDocument *doc = SP_OBJECT_DOCUMENT (namedview);
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview);
+
+    bool saved = sp_document_get_undo_sensitive(doc);
+    sp_document_set_undo_sensitive(doc, false);
+
+    sp_repr_set_boolean(repr, "showgrid", namedview->grids_visible);
+
+    doc->rroot->setAttribute("sodipodi:modified", "true");
+    sp_document_set_undo_sensitive(doc, saved);
+}
+
 gchar const *SPNamedView::getName() const
 {
     SPException ex;
index 7eefdfae53cf345fd6d65281c2273cf3e69b6510..8b6dbcc920bff986192124b82154b73b7b137329 100644 (file)
@@ -51,6 +51,7 @@ struct SPNamedView : public SPObjectGroup {
 
     SnapManager snap_manager;
     GSList * grids;
+    bool grids_visible;
 
     SPUnit const *doc_units;
 
@@ -75,7 +76,7 @@ struct SPNamedView : public SPObjectGroup {
 
     GSList *guides;
     GSList *views;
-    
+
     gint viewcount;
 
     void show(SPDesktop *desktop);
@@ -100,6 +101,7 @@ void sp_namedview_document_from_window(SPDesktop *desktop);
 void sp_namedview_update_layers_from_document (SPDesktop *desktop);
 
 void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr);
+void sp_namedview_show_grids(SPNamedView *namedview, bool show);
 
 #endif /* !INKSCAPE_SP_NAMEDVIEW_H */
 
index abf834c47f4fe180c62bfeff1fababd75f913f4c..32e0c46af55b323c914796271207e7a797cf537c 100644 (file)
@@ -999,6 +999,19 @@ EditVerb::perform(SPAction *action, void *data, void *pdata)
                 sp_desktop_selection(dt)->clear();
             }
             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.
+            //}
+            break;
         default:
             break;
     }
@@ -1646,7 +1659,7 @@ ZoomVerb::perform(SPAction *action, void *data, void *pdata)
             sp_namedview_toggle_guides(doc, repr);
             break;
         case SP_VERB_TOGGLE_GRID:
-            dt->toggleGrid();
+            dt->toggleGrids();
             break;
 #ifdef HAVE_GTK_WINDOW_FULLSCREEN
         case SP_VERB_FULLSCREEN:
@@ -2246,6 +2259,8 @@ Verb *Verb::_base_verbs[] = {
                  N_("Select previous object or node"), NULL),
     new EditVerb(SP_VERB_EDIT_DESELECT, "EditDeselect", N_("D_eselect"),
                  N_("Deselect any selected objects or nodes"), "selection_deselect"),
+    new EditVerb(SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER, "EditNextPathEffectParameter", N_("Next Path Effect Parameter"),
+                 N_("Show next Path Effect parameter for editting"), NULL),
 
     /* Selection */
     new SelectionVerb(SP_VERB_SELECTION_TO_FRONT, "SelectionToFront", N_("Raise to _Top"),
index 34a633b2f082a520cadedef4bbf05482b7dc0210..ccb63daddc866832676ef53126e1b2f427d49b99 100644 (file)
@@ -78,6 +78,7 @@ enum {
     SP_VERB_EDIT_SELECT_NEXT,
     SP_VERB_EDIT_SELECT_PREV,
     SP_VERB_EDIT_DESELECT,
+    SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER,
     /* Selection */
     SP_VERB_SELECTION_TO_FRONT,
     SP_VERB_SELECTION_TO_BACK,