[glom] Print Layout: Move create_standard() into a utils file.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Print Layout: Move create_standard() into a utils file.
- Date: Tue, 4 Oct 2011 08:01:28 +0000 (UTC)
commit e95c37672462e284b01584b9111aeff92f89ce1c
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Sep 30 17:17:41 2011 +0200
Print Layout: Move create_standard() into a utils file.
* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]: Move
create_standard to
* glom/print_layout_utils.[h|cc] so we can use it elsewhere too.
ChangeLog | 9 +
Makefile_glom.am | 2 +
.../print_layouts/window_print_layout_edit.cc | 207 ++------------------
.../print_layouts/window_print_layout_edit.h | 7 -
4 files changed, 25 insertions(+), 200 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bf0af2a..5e473af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-10-04 Murray Cumming <murrayc murrayc com>
+
+ Print Layout: Move create_standard() into a utils file.
+
+ * glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]: Move
+ create_standard to
+ * glom/print_layout_utils.[h|cc] so we can use it elsewhere too.
+ * Makefile_glom.am: Mentino the new file.
+
2011-10-02 Murray Cumming <murrayc murrayc com>
Find: Get criteria even when a field is on the layout twice.
diff --git a/Makefile_glom.am b/Makefile_glom.am
index 9add60b..7ee37e6 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -108,6 +108,8 @@ glom_source_files = \
glom/xsl_utils.h \
glom/printoperation_printlayout.cc \
glom/printoperation_printlayout.h \
+ glom/print_layout_utils.cc \
+ glom/print_layout_utils.h \
glom/report_builder.cc \
glom/report_builder.h \
glom/window_boxholder.cc \
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 866c3f9..c8a57de 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -1,4 +1,3 @@
-
/* Glom
*
* Copyright (C) 2001-2004 Murray Cumming
@@ -24,6 +23,7 @@
#include <glom/print_layout/canvas_layout_item.h>
#include <glom/utils_ui.h>
#include <glom/application.h>
+#include <glom/print_layout_utils.h>
#include <libglom/data_structure/layout/layoutitem_line.h>
#include <libglom/data_structure/layout/layoutitem_portal.h>
#include <libglom/utils.h> //For bold_message()).
@@ -35,12 +35,6 @@
namespace Glom
{
-const double GRID_GAP = 6.0f; //Roughly the right height for 12 point text.
-
-//Base the default item sizes on the grid gap, instead of being arbitrary:
-const double ITEM_HEIGHT = GRID_GAP;
-const double ITEM_WIDTH_WIDE = GRID_GAP * 10;
-
const char* Window_PrintLayout_Edit::glade_id("window_print_layout_edit");
const bool Window_PrintLayout_Edit::glade_developer(true);
@@ -439,7 +433,8 @@ sharedptr<LayoutItem> Window_PrintLayout_Edit::create_empty_item(PrintLayoutTool
{
sharedptr<LayoutItem_Field> layout_item_derived = sharedptr<LayoutItem_Field>::create();
layout_item = layout_item_derived;
- layout_item->set_print_layout_position(0, 0, ITEM_WIDTH_WIDE, ITEM_HEIGHT);
+ layout_item->set_print_layout_position(0, 0,
+ PrintLayoutUtils::ITEM_WIDTH_WIDE, PrintLayoutUtils::ITEM_HEIGHT);
//Don't use the field's default formatting, because that is probably only for on-screen layouts:
layout_item_derived->set_formatting_use_default(false);
@@ -451,23 +446,26 @@ sharedptr<LayoutItem> Window_PrintLayout_Edit::create_empty_item(PrintLayoutTool
// Note to translators: This is the default contents of a text item on a print layout:
layout_item_derived->set_text(_("text")); //TODO: Choose some other longer default because this is hidden under the drag icon?
layout_item = layout_item_derived;
- layout_item->set_print_layout_position(0, 0, ITEM_WIDTH_WIDE, ITEM_HEIGHT);
+ layout_item->set_print_layout_position(0, 0,
+ PrintLayoutUtils::ITEM_WIDTH_WIDE, PrintLayoutUtils::ITEM_HEIGHT);
}
else if(item_type == PrintLayoutToolbarButton::ITEM_IMAGE)
{
layout_item = sharedptr<LayoutItem_Image>::create();
- layout_item->set_print_layout_position(0, 0, ITEM_WIDTH_WIDE, ITEM_WIDTH_WIDE);
+ layout_item->set_print_layout_position(0, 0,
+ PrintLayoutUtils::ITEM_WIDTH_WIDE, PrintLayoutUtils::ITEM_WIDTH_WIDE);
}
else if(item_type == PrintLayoutToolbarButton::ITEM_LINE_HORIZONTAL)
{
sharedptr<LayoutItem_Line> layout_item_derived = sharedptr<LayoutItem_Line>::create();
- layout_item_derived->set_coordinates(0, 0, ITEM_WIDTH_WIDE * 2, 0);
+ layout_item_derived->set_coordinates(0, 0,
+ PrintLayoutUtils::ITEM_WIDTH_WIDE * 2, 0);
layout_item = layout_item_derived;
}
else if(item_type == PrintLayoutToolbarButton::ITEM_LINE_VERTICAL)
{
sharedptr<LayoutItem_Line> layout_item_derived = sharedptr<LayoutItem_Line>::create();
- layout_item_derived->set_coordinates(0, 0, 0, ITEM_WIDTH_WIDE * 2);
+ layout_item_derived->set_coordinates(0, 0, 0, PrintLayoutUtils::ITEM_WIDTH_WIDE * 2);
layout_item = layout_item_derived;
}
else if(item_type == PrintLayoutToolbarButton::ITEM_PORTAL)
@@ -475,7 +473,8 @@ sharedptr<LayoutItem> Window_PrintLayout_Edit::create_empty_item(PrintLayoutTool
sharedptr<LayoutItem_Portal> portal = sharedptr<LayoutItem_Portal>::create();
portal->set_print_layout_row_height(10); //Otherwise it will be 0, which is useless.
layout_item = portal;
- layout_item->set_print_layout_position(0, 0, ITEM_WIDTH_WIDE * 2, ITEM_WIDTH_WIDE);
+ layout_item->set_print_layout_position(0, 0,
+ PrintLayoutUtils::ITEM_WIDTH_WIDE * 2, PrintLayoutUtils::ITEM_WIDTH_WIDE);
}
else
{
@@ -927,17 +926,6 @@ void Window_PrintLayout_Edit::on_menu_insert_create_standard()
return;
}
- m_print_layout = sharedptr<PrintLayout>::create();
-
- //TODO: Use fill_layout_group_field_info()?
- const Document::type_list_layout_groups layout_groups = document->get_data_layout_groups("details", m_table_name); //TODO: layout_platform.
-
- //Start inside the border, on the next grid line:
- double y = 0;
- double max_y = 0; //ignored
- guint page_number = 0;
- get_page_y_start_and_end(page_number, y, max_y);
-
Glib::RefPtr<Gtk::PageSetup> page_setup = m_canvas.get_page_setup();
if(!page_setup)
{
@@ -945,178 +933,11 @@ void Window_PrintLayout_Edit::on_menu_insert_create_standard()
return;
}
- double x = 0;
- double x_border = 0;
- if(page_setup)
- x_border = page_setup->get_left_margin(m_canvas.property_units());
- while(x <= x_border)
- x += GRID_GAP;
-
-
- //The table title:
- const Glib::ustring title = document->get_table_title_singular(m_table_name);
- if(!title.empty())
- {
- sharedptr<LayoutItem_Text> text = sharedptr<LayoutItem_Text>::create();
- text->set_text(title);
- text->m_formatting.set_text_format_font("Sans Bold 12");
-
- const double height = ITEM_HEIGHT;
- text->set_print_layout_position(x, y, ITEM_WIDTH_WIDE, height); //TODO: Enough and no more.
- y += height + GRID_GAP; //padding.
-
- m_print_layout->m_layout_group->add_item(text);
- }
-
- //The layout:
- for(Document::type_list_layout_groups::const_iterator iter = layout_groups.begin(); iter != layout_groups.end(); ++iter)
- {
- const sharedptr<const LayoutGroup> group = *iter;
- if(!group)
- continue;
-
- create_standard(group, m_print_layout->m_layout_group, x, y, page_number);
- }
-
- //Add extra pages if necessary:
- if(page_number >= m_print_layout->get_page_count())
- {
- m_print_layout->set_page_count(page_number + 1);
- }
+ m_print_layout = PrintLayoutUtils::create_standard(page_setup, m_table_name, document);
m_canvas.set_print_layout(m_table_name, m_print_layout);
}
-void Window_PrintLayout_Edit::get_page_y_start_and_end(guint page_number, double& y1, double& y2)
-{
- y1 = 0;
- y2 = 0;
-
- Glib::RefPtr<Gtk::PageSetup> page_setup = m_canvas.get_page_setup();
- if(!page_setup)
- {
- std::cerr << G_STRFUNC << ": page_setup was null" << std::endl;
- return;
- }
-
- const Gtk::PaperSize paper_size = page_setup->get_paper_size();
- const Gtk::Unit units = m_canvas.property_units();
-
- double page_height = 0;
- if(page_setup->get_orientation() == Gtk::PAGE_ORIENTATION_PORTRAIT) //TODO: Handle the reverse orientations too?
- page_height = paper_size.get_height(units);
- else
- page_height = paper_size.get_width(units);
-
- //y1:
- y1 = page_height * (page_number);
- double y_border = page_setup->get_top_margin(units);
- while(y1 <= y_border)
- y1 += GRID_GAP;
-
- //y2:
- y2 = page_height * (page_number + 1);
- y2 -= page_setup->get_bottom_margin(units); //TODO: Handle orientation here and wherever else we use the margin?
-
- //std::cout << G_STRFUNC << "page_number=" << page_number << ", y1=" << y1 << "y2=" << y2 << std::endl;
-}
-
-void Window_PrintLayout_Edit::create_standard(const sharedptr<const LayoutGroup>& layout_group, const sharedptr<LayoutGroup>& print_layout_group, double x, double& y, guint& page_number)
-{
- if(!layout_group || !print_layout_group)
- {
- return;
- }
-
- Glib::RefPtr<Gtk::PageSetup> page_setup = m_canvas.get_page_setup();
- if(!page_setup)
- {
- std::cerr << G_STRFUNC << ": page_setup was null" << std::endl;
- return;
- }
-
- double min_y = 0; //ignored;
- double max_y = 0;
- get_page_y_start_and_end(page_number, min_y, max_y);
-
- const double height = ITEM_HEIGHT;
- const double gap = GRID_GAP;
-
- const Glib::ustring title = layout_group->get_title();
- if(!title.empty())
- {
- sharedptr<LayoutItem_Text> text = sharedptr<LayoutItem_Text>::create();
- text->set_text(title);
- text->m_formatting.set_text_format_font("Sans Bold 10");
-
- text->set_print_layout_position(x, y, ITEM_WIDTH_WIDE, height); //TODO: Enough and no more.
- y += height + gap; //padding.
-
- print_layout_group->add_item(text);
-
- //Start on the next page, if necessary:
- //TODO: Add a page if necessary:
- if( y >= max_y )
- {
- page_number += 1;
- get_page_y_start_and_end(page_number, y, max_y);
- }
- }
-
- //Recurse into the group's child items:
- for(LayoutGroup::type_list_items::const_iterator iter = layout_group->m_list_items.begin(); iter != layout_group->m_list_items.end(); ++iter)
- {
- const sharedptr<const LayoutItem> item = *iter;
- if(!item)
- continue;
-
- const sharedptr<const LayoutGroup> group = sharedptr<const LayoutGroup>::cast_dynamic(item);
- const sharedptr<const LayoutItem_Portal> portal = sharedptr<const LayoutItem_Portal>::cast_dynamic(group);
- if(portal)
- continue; //TODO: Handle these.
-
- if(group)
- {
- //Recurse: //TODO: Handle portals separately:
- create_standard(group, print_layout_group, x, y, page_number);
- }
- else
- {
- //Add field titles, if necessary:
- const double title_width = ITEM_WIDTH_WIDE; //TODO: Calculate it based on the widest in the column. Or just halve the column to start.
- const sharedptr<const LayoutItem_Field> field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
- if(field)
- {
- sharedptr<LayoutItem_Text> text = sharedptr<LayoutItem_Text>::create();
- text->set_text(field->get_title_or_name() + ":");
- text->set_print_layout_position(x, y, title_width, height); //TODO: Enough and no more.
- text->m_formatting.set_text_format_font("Sans 10");
-
- print_layout_group->add_item(text);
- }
-
- //Add the item, such as a field:
- sharedptr<LayoutItem> clone = glom_sharedptr_clone(item);
-
- double item_x = x;
- if(field)
- item_x += (title_width + gap);
-
- clone->set_print_layout_position(item_x, y, 100, height); //TODO: Enough and no more.
- y += height + gap; //padding.
-
- print_layout_group->add_item(clone);
-
- //Start on the next page, if necessary:
- //TODO: Add a page if necessary:
- if( y >= max_y )
- {
- page_number += 1;
- get_page_y_start_and_end(page_number, y, max_y);
- }
- }
- }
-}
void Window_PrintLayout_Edit::on_menu_insert_add_page()
{
@@ -1152,7 +973,7 @@ void Window_PrintLayout_Edit::on_menu_view_show_grid()
{
if(m_action_showgrid->get_active())
{
- m_canvas.set_grid_gap(GRID_GAP);
+ m_canvas.set_grid_gap(PrintLayoutUtils::GRID_GAP);
}
else
{
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 d3a51e4..84fc285 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.h
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.h
@@ -31,7 +31,6 @@
#include <gtkmm/entry.h>
#include <gtkmm/label.h>
#include <gtkmm/uimanager.h>
-//TODO: #include <gtkmm/ruler.h>
#include <glom/utility_widgets/gimpruler/gimpruler.h>
#include <gtkmm/builder.h>
@@ -131,12 +130,6 @@ private:
void canvas_convert_from_drag_pixels(double& x, double& y, bool adjust_for_scrolling = false) const;
void get_dimensions_of_multiple_selected_items(double& x, double& y, double& width, double& height);
- /* Get the start and end of the page, inside the margins.
- */
- void get_page_y_start_and_end(guint page_number, double& y1, double& y2);
-
- void create_standard(const sharedptr<const LayoutGroup>& layout_group, const sharedptr<LayoutGroup>& print_layout_group, double x, double& y, guint& page_number);
-
//Box_DB_Table_Definition* m_box;
Glib::ustring m_name_original;
Glib::ustring m_table_name;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]