[glom] Relationships Overview: Make snap to grid work.



commit 92dafc65a916b782dcb6becb1384817af56b6085
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Aug 8 22:57:12 2011 +0200

    Relationships Overview: Make snap to grid work.
    
    * glom/utility_widgets/canvas/canvas_editable.[h|cc]:
    Add associate_with_grid().
    * glom/mode_design/relationships_overview/dialog_relationships_over
    view.cc: draw_tables(): Use it so that the items' snap_position()
    methods have a grid to snap to.
    The whole grid association/add idea is generally hacky, but this makes it
    work.

 ChangeLog                                          |   12 ++++++++++++
 .../dialog_relationships_overview.cc               |    1 +
 glom/utility_widgets/canvas/canvas_editable.cc     |    7 +++++++
 glom/utility_widgets/canvas/canvas_editable.h      |    5 +++++
 4 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 52e5097..8dd1c63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2011-08-08  Murray Cumming  <murrayc murrayc com>
 
+	Relationships Overview: Make snap to grid work.
+
+	* glom/utility_widgets/canvas/canvas_editable.[h|cc]:
+	Add associate_with_grid().
+	* glom/mode_design/relationships_overview/dialog_relationships_over
+	view.cc: draw_tables(): Use it so that the items' snap_position() 
+	methods have a grid to snap to.
+	The whole grid association/add idea is generally hacky, but this makes it 
+	work.
+
+2011-08-08  Murray Cumming  <murrayc murrayc com>
+
 	Print Layout: Deselect all items when clicking on the background.
 
 	* glom/print_layout/canvas_print_layout.[h|cc]: 
diff --git a/glom/mode_design/relationships_overview/dialog_relationships_overview.cc b/glom/mode_design/relationships_overview/dialog_relationships_overview.cc
index 1f2c151..189878c 100644
--- a/glom/mode_design/relationships_overview/dialog_relationships_overview.cc
+++ b/glom/mode_design/relationships_overview/dialog_relationships_overview.cc
@@ -205,6 +205,7 @@ void Dialog_RelationshipsOverview::draw_tables()
       Glib::RefPtr<CanvasGroupDbTable> table_group =
         CanvasGroupDbTable::create(info->get_name(), info->get_title_or_name(), fields, table_x, table_y);
       m_group_tables->add_child(table_group);
+      m_canvas.associate_with_grid(table_group); //Make snapping work.
 
       table_group->signal_moved().connect(
         sigc::mem_fun(*this, &Dialog_RelationshipsOverview::on_table_moved));
diff --git a/glom/utility_widgets/canvas/canvas_editable.cc b/glom/utility_widgets/canvas/canvas_editable.cc
index 7e2f6dd..d82019c 100644
--- a/glom/utility_widgets/canvas/canvas_editable.cc
+++ b/glom/utility_widgets/canvas/canvas_editable.cc
@@ -172,6 +172,13 @@ void CanvasEditable::remove_grid()
   m_grid->remove_grid();
 }
 
+void CanvasEditable::associate_with_grid(const Glib::RefPtr<Goocanvas::Item>& item)
+{
+  Glib::RefPtr<CanvasItemMovable> movable = CanvasItemMovable::cast_to_movable(item);
+  if(movable)
+    movable->set_grid(m_grid);
+}
+
 CanvasEditable::type_signal_show_context CanvasEditable::signal_show_context()
 {
   return m_signal_show_context;
diff --git a/glom/utility_widgets/canvas/canvas_editable.h b/glom/utility_widgets/canvas/canvas_editable.h
index 4aade57..1d0a5ac 100644
--- a/glom/utility_widgets/canvas/canvas_editable.h
+++ b/glom/utility_widgets/canvas/canvas_editable.h
@@ -57,6 +57,11 @@ public:
   void add_vertical_rule(double x);
   void add_horizontal_rule(double x);
 
+  /** For items not added directly via add_item(),
+   * but which need to snap to the grid.
+   */
+  void associate_with_grid(const Glib::RefPtr<Goocanvas::Item>& item);
+
 
   typedef std::vector< Glib::RefPtr<CanvasItemMovable> > type_vec_items;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]