[glom] Print Layout: Add an Align menu.



commit b1394abcb192dc026926ca1937cdbc864d4aaba0
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Sep 22 10:39:04 2011 +0200

    Print Layout: Add an Align menu.
    
    	* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]: Add
    	menu items for align top, bottom, left, and right. I don't much like the
    	copy/pasteness of the code, but it works.

 ChangeLog                                          |    8 +
 .../print_layouts/window_print_layout_edit.cc      |  194 ++++++++++++++++++++
 .../print_layouts/window_print_layout_edit.h       |    9 +
 3 files changed, 211 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1349eba..da2fbe3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2011-09-22  Murray Cumming  <murrayc murrayc com>
 
+	Print Layout: Add an Align menu.
+
+	* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]: Add 
+	menu items for align top, bottom, left, and right. I don't much like the 
+	copy/pasteness of the code, but it works.
+
+2011-09-22  Murray Cumming  <murrayc murrayc com>
+
 	Layout window: Correct the vertical order of Add buttons.
 
 	* ui/developer/window_data_layout.glade: This has been mixed up since some 
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 b0841b5..68c8e86 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -239,6 +239,26 @@ void Window_PrintLayout_Edit::init_menu()
   m_action_group->add(Gtk::Action::create("Action_Menu_Insert_LineVertical", _("Insert _Vertical Line")),
                         sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_insert_line_vertical) );
 
+
+  m_action_group->add(Gtk::Action::create("Menu_Align", _("_Align")));
+
+  m_action_align_top = Gtk::Action::create("Action_Menu_Align_Top", _("Align _Top"));
+  m_action_group->add(m_action_align_top,
+    sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_align_top) );
+
+  m_action_align_bottom = Gtk::Action::create("Action_Menu_Align_Bottom", _("Align _Bottom"));
+  m_action_group->add(m_action_align_bottom,
+    sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_align_bottom) );
+  
+  m_action_align_left = Gtk::Action::create("Action_Menu_Align_Left", _("Align _Left"));
+  m_action_group->add(m_action_align_left,
+    sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_align_left) );
+
+  m_action_align_right = Gtk::Action::create("Action_Menu_Align_Right", _("Align _Right"));
+  m_action_group->add(m_action_align_right,
+    sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_align_right) );
+
+
   m_action_group->add(Gtk::Action::create("Menu_View", _("_View")));
   m_action_showgrid = Gtk::ToggleAction::create("Action_Menu_View_ShowGrid", _("Show Grid"));
   m_action_group->add(m_action_showgrid, sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_view_show_grid));
@@ -294,6 +314,12 @@ void Window_PrintLayout_Edit::init_menu()
     "        <menuitem action='Action_Menu_Insert_LineHorizontal' />"
     "        <menuitem action='Action_Menu_Insert_LineVertical' />"
     "      </menu>"
+    "      <menu action='Menu_Align'>"
+    "        <menuitem action='Action_Menu_Align_Top' />"
+    "        <menuitem action='Action_Menu_Align_Bottom' />"
+    "        <menuitem action='Action_Menu_Align_Left' />"
+    "        <menuitem action='Action_Menu_Align_Right' />"
+    "      </menu>"
     "      <menu action='Menu_View'>"
     "        <menuitem action='Action_Menu_View_ShowGrid' />"
     "        <menuitem action='Action_Menu_View_ShowRules' />"
@@ -1063,6 +1089,174 @@ void Window_PrintLayout_Edit::on_menu_edit_unselectall()
   m_canvas.select_all(false);
 }
 
+void Window_PrintLayout_Edit::on_menu_align_top()
+{
+  //Get the top-most position:
+  double top = 0;
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+
+    if(iter == m_layout_items_selected.begin())
+      top = y;
+    else if(y < top)
+      top = y;
+  }
+  
+  //Give all items the same top position:
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+    selected_item->set_xy(x, top);
+  }
+}
+
+void Window_PrintLayout_Edit::on_menu_align_bottom()
+{
+  //Get the bottom-most position:
+  double bottom = 0;
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+    
+    double width = 0;
+    double height = 0;
+    selected_item->get_width_height(width, height);
+    const double this_bottom = y + height;
+
+    if(iter == m_layout_items_selected.begin())
+      bottom = this_bottom;
+    else if(this_bottom > bottom)
+      bottom = this_bottom;
+  }
+  
+  //Give all items the same top position:
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+    
+    double width = 0;
+    double height = 0;
+    selected_item->get_width_height(width, height);
+    const double this_bottom = y + height;
+
+    const double new_y = y + (bottom - this_bottom);
+    selected_item->set_xy(x, new_y);
+  }
+}
+
+void Window_PrintLayout_Edit::on_menu_align_left()
+{
+  //Get the left-most position:
+  double left = 0;
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+
+    if(iter == m_layout_items_selected.begin())
+      left = x;
+    else if(x < left)
+      left = x;
+  }
+  
+  //Give all items the same left position:
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+    selected_item->set_xy(left, y);
+  }
+}
+
+void Window_PrintLayout_Edit::on_menu_align_right()
+{
+  //Get the right-most position:
+  double right = 0;
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+    
+    double width = 0;
+    double height = 0;
+    selected_item->get_width_height(width, height);
+    const double this_right = x + width;
+
+    if(iter == m_layout_items_selected.begin())
+      right = this_right;
+    else if(this_right > right)
+      right = this_right;
+  }
+  
+  //Give all items the same top position:
+  for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+    iter != m_layout_items_selected.end(); ++iter)
+  {
+    Glib::RefPtr<CanvasLayoutItem> selected_item = *iter;
+    if(!selected_item)
+      continue;
+
+    double x = 0;
+    double y = 0;
+    selected_item->get_xy(x, y);
+    
+    double width = 0;
+    double height = 0;
+    selected_item->get_width_height(width, height);
+    const double this_right = x + width;
+
+    const double new_x = x + (right - this_right);
+    selected_item->set_xy(new_x, y);
+  }
+}
+
 static void spinbutton_set_max(Gtk::SpinButton& spinbutton, double max)
 {
   spinbutton.set_range(0, max);
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.h b/glom/mode_design/print_layouts/window_print_layout_edit.h
index 0c34378..4900ea0 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.h
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.h
@@ -82,6 +82,11 @@ private:
   void on_menu_edit_delete();
   void on_menu_edit_selectall();
   void on_menu_edit_unselectall();
+  
+  void on_menu_align_top();
+  void on_menu_align_bottom();
+  void on_menu_align_left();
+  void on_menu_align_right();
 
   bool on_canvas_motion_notify_event(GdkEventMotion* event);
   void on_canvas_show_context_menu(guint button, guint32 activate_time);
@@ -180,6 +185,10 @@ private:
   //Edit menu:
   Glib::RefPtr<Gtk::Action> m_action_edit_cut, m_action_edit_copy, 
     m_action_edit_paste, m_action_edit_delete;
+    
+  //Align menu:
+  Glib::RefPtr<Gtk::Action> m_action_align_top, m_action_align_bottom, 
+    m_action_align_left, m_action_align_right;
 
   //Toolbar:
   Gtk::HandleBox* m_palette_handle_box; //TODO: The toolbar is already a HandleBox.



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