Code

removed leftover debug messages. Toggling new grids now works. Almost ready to commen...
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 1 Apr 2007 22:32:34 +0000 (22:32 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 1 Apr 2007 22:32:34 +0000 (22:32 +0000)
src/desktop.cpp
src/desktop.h
src/display/canvas-grid.cpp
src/display/canvas-grid.h
src/sp-namedview.cpp
src/ui/dialog/document-properties.cpp
src/verbs.cpp

index 0d7d43646f9353752289ae27dbd04a42fc9a1c32..187dcd010d4e441a98506f926bf1eaecce1b5135 100644 (file)
@@ -1094,6 +1094,14 @@ void SPDesktop::clearWaitingCursor()
       sp_event_context_update_cursor(sp_desktop_event_context(this));
 }
 
+void SPDesktop::toggleGrid()
+{
+    for ( GSList const *l = namedview->grids; l != NULL; l = l->next) {
+        Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data;
+        grid->toggle_visibility();
+    }
+}
+
 
 //----------------------------------------------------------------------
 // Callback implementations. The virtual ones are connected by the view.
index e5f9cdacc1a1b473460d732f340efbf386effbda..1770af9f5d7b45aa84d27f4629e037fdc01d01e8 100644 (file)
@@ -245,6 +245,8 @@ struct SPDesktop : public Inkscape::UI::View::View
     void setWaitingCursor();
     void clearWaitingCursor();
     
+    void toggleGrid();
+    
     void fullscreen();
 
     void registerEditWidget (Inkscape::UI::View::EditWidgetInterface *widget)
index 643ffccdc1aac7b9ab80b77e785caec59386283a..f343077c3550c3e5aed36afc4f10ead5a5a80842 100644 (file)
@@ -143,7 +143,7 @@ CanvasGrid::CanvasGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr)
     gtk_object_ref(GTK_OBJECT(canvasitem));    // since we're keeping a copy, we need to bump up the ref count
     canvasitem->grid = this;
 
-    enabled = false;
+    snapenabled = false;
     visible = false;
 
 //    sp_canvas_item_hide(canvasitem);
@@ -166,7 +166,6 @@ CanvasGrid::~CanvasGrid()
    // deref canvasitem
    gtk_object_unref(GTK_OBJECT(canvasitem));
    g_free(canvasitem);
-   g_message("~CanvasGrid");
 }
 
 /*
@@ -217,6 +216,7 @@ CanvasGrid::hide()
 {
     sp_canvas_item_hide(canvasitem);
     visible = false;
+    disable_snapping(); // temporary hack, because at the moment visibilty and snapping are linked
 }
 
 void
@@ -224,6 +224,25 @@ CanvasGrid::show()
 {
     sp_canvas_item_show(canvasitem);
     visible = true;
+    enable_snapping(); // temporary hack, because at the moment visibilty and snapping are linked
+}
+
+void 
+CanvasGrid::set_visibility(bool visible)
+{
+    this->visible = visible;
+    if(visible) {
+        show();
+    } else {
+        hide();
+    }
+}
+
+void
+CanvasGrid::toggle_visibility()
+{
+    visible = !visible;
+    set_visibility(visible);
 }
 
 void
index c501ab3f38a9fbdc50391b3ac6b33336c48d933b..54a57d3d0dc2130dd0ec298613df3df9213dd682 100644 (file)
@@ -73,10 +73,13 @@ public:
     
     virtual Gtk::Widget & getWidget() = 0;
 
-    bool enabled;
-    bool visible;
     void hide();
     void show();
+    void set_visibility(bool visible);
+    void toggle_visibility();
+    void enable_snapping()  { snapenabled = true; snapper->setEnabled(true); } ;
+    void disable_snapping() { snapenabled = false; snapper->setEnabled(false); } ;
+    void toggle_snapping()  { snapenabled = !snapenabled; snapper->setEnabled(snapenabled);};
 
     Inkscape::XML::Node * repr;
     
@@ -90,6 +93,9 @@ protected:
     
     Gtk::VBox vbox;
 
+    bool snapenabled;
+    bool visible;
+
 private:
     CanvasGrid(const CanvasGrid&);
     CanvasGrid& operator=(const CanvasGrid&);
index 0928de19e2b1af9fa5173f53000d4f40052ca393..26c53c8e0d6b02cd5dd9dd9bfb75570d799539ee 100644 (file)
@@ -527,8 +527,6 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
 
 static void sp_namedview_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
 {
-g_message("named view:: child added");
-
     SPNamedView *nv = (SPNamedView *) object;
 
     if (((SPObjectClass *) (parent_class))->child_added) {
@@ -660,7 +658,7 @@ void SPNamedView::show(SPDesktop *desktop)
                 Inkscape::CanvasXYGrid* addedgrid = new Inkscape::CanvasXYGrid(desktop, child);
                 if (addedgrid) {
                     grids = g_slist_append(grids, addedgrid);
-                    addedgrid->enabled = true;
+                    addedgrid->enable_snapping();
                     addedgrid->show();
                 }
             }
index 3f84c18089f1e0b88a016808330dfd19a6197fdb..fff815d8c88d1baf2f1f79d7bf4dbe62eced6aa3 100644 (file)
@@ -388,11 +388,7 @@ DocumentProperties::update_gridspage()
     }
     _grids_notebook.show_all();
 
-    const Gtk::Widget* widget_array[] =
-    {
-        (Gtk::Widget*) &_grids_notebook, 0
-    };
-    attach_all (_page_grids.table(), widget_array, sizeof(widget_array),3); // FIXME: a hack to let GTK show all tabs, otherwise XML manually added grids setting widgets do no show.
+    _page_grids.table().resize_children();
 }
 
 /**
index 28e0084861f29e037d530e451dfa00b7a9d6d6ea..172b5220c321fd070d76a2827129e26e04ede083 100644 (file)
@@ -1552,6 +1552,7 @@ ZoomVerb::perform(SPAction *action, void *data, void *pdata)
             break;
         case SP_VERB_TOGGLE_GRID:
             sp_namedview_toggle_grid(doc, repr);
+            dt->toggleGrid();
             break;
 #ifdef HAVE_GTK_WINDOW_FULLSCREEN
         case SP_VERB_FULLSCREEN: