[glom] Print Layout: Actually show rules, if there are some.



commit 019b606db9139fde08836fc2a6dcc549f6aef226
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Aug 9 19:37:27 2011 +0200

    Print Layout: Actually show rules, if there are some.
    
    	* glom/utility_widgets/canvas/canvas_group_grid.[h|cc]:
    	create_lines(): Split this into two methods, and make sure that
    	the z order is correct, so that we can really show the grid and
    	rules independently, without needing to recreate both at the
    	same time.
    	Added set_rules_visiblity() to do so.
    	add_horizontal_rule(), add_vertical_rule(): Actually create
    	the rules.
    	* glom/utility_widgets/canvas/canvas_editable.[h|cc]:
    	Added set_rules_visibility() which just calls the same method
    	in the grid.
    	* glom/mode_design/print_layouts/window_print_layout_edit.cc:
    	on_action_menu_view_showrules(): Call it.
    
    	Of course, there is no way to add a rule yet.

 ChangeLog                                          |   20 +++++
 .../print_layouts/window_print_layout_edit.cc      |    3 +-
 glom/utility_widgets/canvas/canvas_editable.cc     |    6 ++
 glom/utility_widgets/canvas/canvas_editable.h      |    2 +
 glom/utility_widgets/canvas/canvas_group_grid.cc   |   79 ++++++++++++++------
 glom/utility_widgets/canvas/canvas_group_grid.h    |    5 +-
 6 files changed, 90 insertions(+), 25 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5ba65bb..850b103 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2011-08-09  Murray Cumming  <murrayc murrayc com>
 
+	Print Layout: Actually show rules, if there are some.
+
+	* glom/utility_widgets/canvas/canvas_group_grid.[h|cc]:
+	create_lines(): Split this into two methods, and make sure that 
+	the z order is correct, so that we can really show the grid and 
+	rules independently, without needing to recreate both at the 
+	same time.
+	Added set_rules_visiblity() to do so.
+	add_horizontal_rule(), add_vertical_rule(): Actually create 
+	the rules.
+	* glom/utility_widgets/canvas/canvas_editable.[h|cc]:
+	Added set_rules_visibility() which just calls the same method 
+	in the grid.
+	* glom/mode_design/print_layouts/window_print_layout_edit.cc:
+	on_action_menu_view_showrules(): Call it.
+
+	Of course, there is no way to add a rule yet.
+
+2011-08-09  Murray Cumming  <murrayc murrayc com>
+
 	Print Layout: Make the window bigger by default.
 
 2011-08-09  Murray Cumming  <murrayc murrayc com>
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.cc b/glom/mode_design/print_layouts/window_print_layout_edit.cc
index e89b2e8..269d019 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -883,7 +883,8 @@ void Window_PrintLayout_Edit::on_menu_view_show_grid()
 
 void Window_PrintLayout_Edit::on_menu_view_show_rules()
 {
-  //TODO:
+  m_canvas.set_rules_visibility(
+    m_action_showrules->get_active());
 }
 
 
diff --git a/glom/utility_widgets/canvas/canvas_editable.cc b/glom/utility_widgets/canvas/canvas_editable.cc
index d82019c..0a6d0b4 100644
--- a/glom/utility_widgets/canvas/canvas_editable.cc
+++ b/glom/utility_widgets/canvas/canvas_editable.cc
@@ -217,4 +217,10 @@ CanvasEditable::type_vec_items CanvasEditable::get_selected_items()
   return type_vec_items();
 }
 
+void CanvasEditable::set_rules_visibility(bool visible)
+{
+  m_grid->set_rules_visibility(visible);  
+}
+
+
 } //namespace Glom
diff --git a/glom/utility_widgets/canvas/canvas_editable.h b/glom/utility_widgets/canvas/canvas_editable.h
index 1d0a5ac..907fc36 100644
--- a/glom/utility_widgets/canvas/canvas_editable.h
+++ b/glom/utility_widgets/canvas/canvas_editable.h
@@ -54,6 +54,8 @@ public:
    */
   void remove_grid();
 
+  void set_rules_visibility(bool visible = true);
+
   void add_vertical_rule(double x);
   void add_horizontal_rule(double x);
 
diff --git a/glom/utility_widgets/canvas/canvas_group_grid.cc b/glom/utility_widgets/canvas/canvas_group_grid.cc
index e15c418..2e2b1d8 100644
--- a/glom/utility_widgets/canvas/canvas_group_grid.cc
+++ b/glom/utility_widgets/canvas/canvas_group_grid.cc
@@ -62,7 +62,6 @@ inline void division_and_remainder(double a, double b, double& whole, double& re
 bool CanvasGroupGrid::is_close(double a, double b) const
 {
   return (std::abs((long)(a - b)) < m_grid_sensitivity);
-
 }
 
 double CanvasGroupGrid::snap_position_rules(const type_vec_double& rules, double a) const
@@ -178,28 +177,67 @@ Glib::RefPtr<Goocanvas::Polyline> CanvasGroupGrid::create_rule_line(double x1, d
 void CanvasGroupGrid::add_vertical_rule(double x)
 {
   m_rules_x.push_back(x);
+
+  create_rules();
 }
 
 void CanvasGroupGrid::add_horizontal_rule(double y)
 {
   m_rules_y.push_back(y);
+
+  create_rules();
 }
 
 void CanvasGroupGrid::set_grid_gap(double gap)
 {
   m_grid_gap = gap;
 
-  create_lines();
+  create_grid_lines();
 }
 
 void CanvasGroupGrid::remove_grid()
 {
   m_grid_gap = 0.0;
 
-  create_lines();
+  create_grid_lines();
 }
 
-void CanvasGroupGrid::create_lines()
+void CanvasGroupGrid::create_rules()
+{
+  while(m_grid_rules_group && m_grid_rules_group->get_n_children())
+    m_grid_rules_group->remove_child(0);
+
+  //Fill the parent canvas with lines:
+  double left = 0.0;
+  double top = 0.0;
+  double right = 0.0;
+  double bottom = 0.0;
+  Goocanvas::Canvas* canvas = get_canvas();
+  if(canvas)
+    canvas->get_bounds(left, top, right, bottom);
+
+  //Vertical rules:
+  for(CanvasGroupGrid::type_vec_double::const_iterator iter = m_rules_x.begin(); iter != m_rules_x.end(); ++iter)
+  {
+    const double x = *iter;
+    Glib::RefPtr<Goocanvas::Polyline> line = create_rule_line(x, top, x, bottom);
+    m_grid_rules_group->add_child(line);
+  }
+
+  //Horizontal rules:
+  for(CanvasGroupGrid::type_vec_double::const_iterator iter = m_rules_y.begin(); iter != m_rules_y.end(); ++iter)
+  {
+    const double y = *iter;
+    Glib::RefPtr<Goocanvas::Polyline> line = create_rule_line(left, y, right, y);
+    m_grid_rules_group->add_child(line);
+  }
+
+  //Make sure that the grid is below the rules, so that the rules are visible:
+  if(m_grid_lines && m_grid_rules_group)
+    m_grid_lines->lower(m_grid_rules_group);
+}
+
+void CanvasGroupGrid::create_grid_lines()
 {
   //Remove any existing lines:
   if(m_grid_lines)
@@ -208,9 +246,6 @@ void CanvasGroupGrid::create_lines()
     m_grid_lines.reset(); //Null the RefPtr.
   }
 
-  while(m_grid_rules_group && m_grid_rules_group->get_n_children())
-    m_grid_rules_group->remove_child(0);
-
   //Fill the parent canvas with lines:
   double left = 0.0;
   double top = 0.0;
@@ -234,24 +269,22 @@ void CanvasGroupGrid::create_lines()
     add_child(m_grid_lines);
   }
 
-  //Vertical rules:
-  for(CanvasGroupGrid::type_vec_double::const_iterator iter = m_rules_x.begin(); iter != m_rules_x.end(); ++iter)
-  {
-    const double x = *iter;
-    Glib::RefPtr<Goocanvas::Polyline> line = create_rule_line(x, top, x, bottom);
-    m_grid_rules_group->add_child(line);
-  }
-
-  //Horizontal rules:
-  for(CanvasGroupGrid::type_vec_double::const_iterator iter = m_rules_y.begin(); iter != m_rules_y.end(); ++iter)
-  {
-    const double y = *iter;
-    Glib::RefPtr<Goocanvas::Polyline> line = create_rule_line(left, y, right, y);
-    m_grid_rules_group->add_child(line);
-  }
+  //Make sure that the grid is below the rules, so that the rules are visible:
+  if(m_grid_lines && m_grid_rules_group)
+    m_grid_lines->lower(m_grid_rules_group);
 }
 
-
+void CanvasGroupGrid::set_rules_visibility(bool visible)
+{
+  if(m_grid_rules_group)
+    m_grid_rules_group->property_visibility() = (visible ? Goocanvas::ITEM_VISIBLE : Goocanvas::ITEM_INVISIBLE);
+  else
+    std::cerr << G_STRFUNC << ": m_grid_rules_group was null." << std::endl;
+
+  //Make sure that the gris is below the rules, so that the rules are visible:
+  if(m_grid_lines && m_grid_rules_group)
+    m_grid_lines->lower(m_grid_rules_group);
+}
 
 } //namespace Glom
 
diff --git a/glom/utility_widgets/canvas/canvas_group_grid.h b/glom/utility_widgets/canvas/canvas_group_grid.h
index d1f6606..8c814d7 100644
--- a/glom/utility_widgets/canvas/canvas_group_grid.h
+++ b/glom/utility_widgets/canvas/canvas_group_grid.h
@@ -70,8 +70,11 @@ public:
   void add_vertical_rule(double x);
   void add_horizontal_rule(double x);
 
+  void set_rules_visibility(bool visible = true);
+
 private:
-  void create_lines();
+  void create_grid_lines();
+  void create_rules();
   Glib::RefPtr<Goocanvas::Polyline> create_rule_line(double x1, double y1, double x2, double y2);
 
   double snap_position_grid(double a) const;



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