[glom] Print Layout: Moved some code around.



commit 288b263c7c2e046681c90799464c49d57488b300
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Oct 13 21:56:40 2011 +0200

    Print Layout: Moved some code around.
    
    * glom/print_layout/canvas_print_layout.[h|cc]: Moved get_page_for_y() and
    move_fully_to_page() to:
    * glom/print_layout/print_layout_utils.[h|cc]:

 ChangeLog                                |    8 ++++
 glom/print_layout/canvas_print_layout.cc |   65 +++---------------------------
 glom/print_layout/canvas_print_layout.h  |   11 -----
 glom/print_layout/print_layout_utils.cc  |   62 ++++++++++++++++++++++++++++
 glom/print_layout/print_layout_utils.h   |   12 +++++
 5 files changed, 88 insertions(+), 70 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d51af78..b32df70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2011-10-13  Murray Cumming  <murrayc murrayc com>
 
+	Print Layout: Moved some code around.
+
+	* glom/print_layout/canvas_print_layout.[h|cc]: Moved get_page_for_y() and 
+	move_fully_to_page() to:
+	* glom/print_layout/print_layout_utils.[h|cc]:
+
+2011-10-13  Murray Cumming  <murrayc murrayc com>
+
 	PrintLayout: Standard: Do not move to next page unnecessary.
 
 	* glom/print_layout/canvas_print_layout.cc: get_page_for_y(): Correct this
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 43c0f40..08dd317 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -1202,6 +1202,8 @@ void Canvas_PrintLayout::move_items_below_item(const Glib::RefPtr<CanvasLayoutIt
   canvas_item->get_width_height(item_width, item_height);
 
   double bottom_max = 0;
+  
+  const Glib::RefPtr<Gtk::PageSetup> page_Setup = get_page_setup();
 
   const int count = root->get_n_children();
   for(int i = 0; i < count; ++i)
@@ -1233,7 +1235,8 @@ void Canvas_PrintLayout::move_items_below_item(const Glib::RefPtr<CanvasLayoutIt
     y += offset;
     derived->set_xy(x, y);
     //Move it some more if necessary:
-    y = move_fully_to_page(derived);
+    y = PrintLayoutUtils::move_fully_to_page(page_Setup, property_units(), 
+     derived);
 
     //Check where the bottom is:
     const double bottom = y + height;
@@ -1241,70 +1244,14 @@ void Canvas_PrintLayout::move_items_below_item(const Glib::RefPtr<CanvasLayoutIt
   }
 
   //Add extra pages if necessary:
-  const guint page_count_needed = get_page_for_y(bottom_max);
+  const guint page_count_needed = PrintLayoutUtils::get_page_for_y(page_Setup, 
+    property_units(), bottom_max);
   if(page_count_needed > get_page_count())
   {
     set_page_count(page_count_needed);
   }
 }
 
-guint Canvas_PrintLayout::get_page_for_y(double y) const
-{
-  const double page_height = get_page_height();
-  if(!page_height)
-    return 0; //Avoid a division by zero.
-
-  const double pages = y / (double)page_height;
-  double pages_integral = 0;
-  modf(pages, &pages_integral);
-  return pages_integral;
-}
-
-double Canvas_PrintLayout::move_fully_to_page(const Glib::RefPtr<CanvasLayoutItem>& item)
-{
-  double top_margin = 0;
-  double bottom_margin = 0;
-  const double page_height = get_page_height(top_margin, bottom_margin);
-
-  double x = 0;
-  double y = 0;
-  item->get_xy(x, y);
-
-  //Ignore items that would not overlap even if they had the same y:
-  double width = 0;
-  double height = 0;
-  item->get_width_height(width, height);
-
-  const double usable_page_height = page_height - top_margin - bottom_margin;
-  if(height > usable_page_height)
-    return y; //It will always be in a margin because it is so big. We could never move it somewhere where it would not be.
-
-  bool moved = false;
-  const guint current_page = get_page_for_y(y);
-  const double usable_page_start = current_page * page_height + top_margin;
-  //std::cout << G_STRFUNC << ": debug: current_page=" << current_page << ", usable_page_start =" << usable_page_start << std::endl;
-
-  if(y < usable_page_start) //If it is in the top margin:
-  {
-    //Move it to the end of the top margin:
-    y = usable_page_start;
-    moved = true;
-  }
-
-  const double usable_page_end = (current_page + 1) * page_height - bottom_margin;
-  if((y + height) > usable_page_end) //If it is in the top margin:
-  {
-    //Move it to the start of the next page:
-    y = (current_page + 1) * page_height + top_margin;
-    moved = false;
-  }
-
-  if(moved)
-    item->set_xy(x, y);
-
-  return y;
-}
-
 double Canvas_PrintLayout::get_page_height() const
 {
   const Glib::RefPtr<const Gtk::PageSetup> page_setup = get_page_setup(); 
diff --git a/glom/print_layout/canvas_print_layout.h b/glom/print_layout/canvas_print_layout.h
index 0525aa2..8a20b04 100644
--- a/glom/print_layout/canvas_print_layout.h
+++ b/glom/print_layout/canvas_print_layout.h
@@ -132,20 +132,9 @@ private:
   
   Glib::RefPtr<Goocanvas::Polyline> create_margin_line(double x1, double y1, double x2, double y2);
 
-  /** Discover what page the y position is on:
-   */
-  guint get_page_for_y(double y) const;
-
   double get_page_height() const;
   double get_page_height(double& margin_top, double& margin_bottom) const;
 
-  /** Move the item to the start of a page, past the top margin,
-   * if it is currently in the bottom margin of a page, or in the top margin of a page.
-   *
-   * @result The new y position of the item.
-   */
-  double move_fully_to_page(const Glib::RefPtr<CanvasLayoutItem>& item);
-
   Glib::ustring m_table_name;
   bool m_modified; //TODO: Actually check this?
 
diff --git a/glom/print_layout/print_layout_utils.cc b/glom/print_layout/print_layout_utils.cc
index 70f1772..a2264a9 100644
--- a/glom/print_layout/print_layout_utils.cc
+++ b/glom/print_layout/print_layout_utils.cc
@@ -222,6 +222,68 @@ static void create_standard(const sharedptr<const LayoutGroup>& layout_group, co
   }
 }
 
+guint get_page_for_y(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, double y)
+{
+  const double page_height = get_page_height(page_setup, units);
+  if(!page_height)
+    return 0; //Avoid a division by zero.
+
+  const double pages = y / (double)page_height;
+  double pages_integral = 0;
+  modf(pages, &pages_integral);
+  return pages_integral;
+}
+
+double move_fully_to_page(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, const Glib::RefPtr<CanvasLayoutItem>& item)
+{
+  double top_margin = 0;
+  double bottom_margin = 0;
+  const double page_height = get_page_height(page_setup, units, top_margin, bottom_margin);
+
+  double x = 0;
+  double y = 0;
+  item->get_xy(x, y);
+  std::cout << G_STRFUNC << ": y=" << y << std::endl;
+  
+  //Ignore items that would not overlap even if they had the same y:
+  double width = 0;
+  double height = 0;
+  item->get_width_height(width, height);
+
+  const double usable_page_height = page_height - top_margin - bottom_margin;
+  if(height > usable_page_height)
+    return y; //It will always be in a margin because it is so big. We could never move it somewhere where it would not be.
+
+  bool moved = false;
+  const guint current_page = PrintLayoutUtils::get_page_for_y(page_setup, units, y);
+  const double usable_page_start = current_page * page_height + top_margin;
+  //std::cout << G_STRFUNC << ": debug: current_page=" << current_page << ", usable_page_start =" << usable_page_start << std::endl;
+
+  if(y < usable_page_start) //If it is in the top margin:
+  {
+    //Move it to the end of the top margin:
+    y = usable_page_start;
+    moved = true;
+  }
+
+  const double usable_page_end = (current_page + 1) * page_height - bottom_margin;
+  if((y + height) > usable_page_end) //If it is in the top margin:
+  {
+    //Move it to the start of the next page:
+    y = (current_page + 1) * page_height + top_margin;
+    moved = false;
+  }
+
+  if(moved)
+    item->set_xy(x, y);
+    
+  std::cout << G_STRFUNC << ": y moved=" << y << std::endl;
+  
+
+  return y;
+}
+
+
 sharedptr<PrintLayout> create_standard(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, const Glib::ustring& table_name, const Document* document)
 {
   sharedptr<PrintLayout> print_layout = sharedptr<PrintLayout>::create();  
diff --git a/glom/print_layout/print_layout_utils.h b/glom/print_layout/print_layout_utils.h
index a9efc3b..6931733 100644
--- a/glom/print_layout/print_layout_utils.h
+++ b/glom/print_layout/print_layout_utils.h
@@ -22,6 +22,7 @@
 #define GLOM_PRINT_LAYOUT_UTILS_H
 
 #include "config.h"
+#include <glom/print_layout/canvas_layout_item.h>
 #include <libglom/data_structure/print_layout.h>
 #include <libglom/document/document.h>
 #include <gtkmm/pagesetup.h>
@@ -47,6 +48,17 @@ void do_print_layout(const sharedptr<const PrintLayout>& print_layout, const Fou
 double get_page_height(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units);
 double get_page_height(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, double& margin_top, double& margin_bottom);
 
+/** Discover what page the y position is on:
+ */
+guint get_page_for_y(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, double y);
+
+/** Move the item to the start of a page, past the top margin,
+ * if it is currently in the bottom margin of a page, or in the top margin of a page.
+ *
+ * @result The new y position of the item.
+ */
+double move_fully_to_page(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, const Glib::RefPtr<CanvasLayoutItem>& item);
+
 } //namespace PrintLayoutUtils
 
 } //namespace Glom



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