[glom] Print Layout: Add a Print Preview menu item.



commit 1fb08953a46b0533242eec62de92684f8f125f82
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Aug 11 13:51:05 2011 +0200

    Print Layout: Add a Print Preview menu item.
    
    * glom/frame_glom.[h|cc]: on_menu_print_layout_selected():
    Move this into a do_print_layout() method, with optional preview
    and transient-for window.
    * glom/application.[h|cc]: Added do_print_layout() so we can do this
    from other parts of the code.
    * glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]:
    Add a Print Preview menu item that calls the method on the
    application, though transient to this window.
    It shows data from the currently-selected record, even though that
    might not be very visible to the user.

 ChangeLog                                          |   15 +++++++++++
 glom/application.cc                                |    5 +++
 glom/application.h                                 |    1 +
 glom/frame_glom.cc                                 |   24 +++++++++++++++--
 glom/frame_glom.h                                  |    2 +
 .../print_layouts/window_print_layout_edit.cc      |   27 +++++++++++++++++++-
 .../print_layouts/window_print_layout_edit.h       |    1 +
 7 files changed, 71 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 361832c..37f1446 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2011-08-11  Murray Cumming  <murrayc murrayc com>
 
+	Print Layout: Add a Print Preview menu item.
+
+	* glom/frame_glom.[h|cc]: on_menu_print_layout_selected(): 
+	Move this into a do_print_layout() method, with optional preview 
+	and transient-for window.
+	* glom/application.[h|cc]: Added do_print_layout() so we can do this 
+	from other parts of the code.
+	* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]:
+	Add a Print Preview menu item that calls the method on the 
+	application, though transient to this window.
+	It shows data from the currently-selected record, even though that 
+	might not be very visible to the user.
+
+2011-08-11  Murray Cumming  <murrayc murrayc com>
+
 	Print Layout: Make text formatting work for field items.
 
 	* glom/print_layout/canvas_print_layout.cc: on_context_menu_edit(), 
diff --git a/glom/application.cc b/glom/application.cc
index 1893f22..7faa25e 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -2880,6 +2880,11 @@ void Application::on_menu_developer_restore_backup()
   do_restore_backup(uri_tarball);
 }
 
+void Application::do_print_layout(const Glib::ustring& print_layout_name, bool preview, Gtk::Window* transient_for)
+{
+  m_pFrame->do_print_layout(print_layout_name, preview, transient_for);
+}
+
 bool Application::do_restore_backup(const Glib::ustring& backup_uri)
 {
   // We cannot use an uri here, because we cannot untar remote files.
diff --git a/glom/application.h b/glom/application.h
index 8c972ca..3b347c0 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -112,6 +112,7 @@ public:
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   void do_menu_developer_fields(Gtk::Window& parent, const Glib::ustring table_name);
   void do_menu_developer_relationships(Gtk::Window& parent, const Glib::ustring table_name);
+  void do_print_layout(const Glib::ustring& print_layout_name, bool preview = false, Gtk::Window* transient_for = 0);
   bool do_restore_backup(const Glib::ustring& backup_uri);
 #endif //GLOM_ENABLE_CLIENT_ONLY
 
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 93b3406..d421aaa 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2397,8 +2397,14 @@ void Frame_Glom::on_menu_report_selected(const Glib::ustring& report_name)
 }
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
+
 void Frame_Glom::on_menu_print_layout_selected(const Glib::ustring& print_layout_name)
 {
+  do_print_layout(print_layout_name, false /* not preview */);
+}
+
+void Frame_Glom::do_print_layout(const Glib::ustring& print_layout_name, bool preview, Gtk::Window* transient_for)
+{
   const Privileges table_privs = Privs::get_current_privs(m_table_name);
 
   //Don't try to print tables that the user can't view.
@@ -2417,6 +2423,12 @@ void Frame_Glom::on_menu_print_layout_selected(const Glib::ustring& print_layout
   add_view(&canvas); //So it has access to the document.
   canvas.set_print_layout(m_table_name, print_layout);
 
+  //Do not show things that are only for editing the print layout:
+
+  canvas.remove_grid();
+  canvas.set_rules_visibility(false);
+  canvas.set_outlines_visibility(false);
+
   //Create a new PrintOperation with our PageSetup and PrintSettings:
   //(We use our derived PrintOperation class)
   Glib::RefPtr<PrintOperationPrintLayout> print = PrintOperationPrintLayout::create();
@@ -2447,9 +2459,15 @@ void Frame_Glom::on_menu_print_layout_selected(const Glib::ustring& print_layout
 
   try
   {
-    Application* pApp = dynamic_cast<Application*>(get_app_window());
-    if(pApp)
-      print->run(Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG, *pApp);
+    if(!transient_for)
+      transient_for = get_app_window();
+
+    if(transient_for)
+    {
+      print->run(
+        (preview ? Gtk::PRINT_OPERATION_ACTION_PREVIEW : Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG),
+        *transient_for);
+    }
   }
   catch (const Gtk::PrintError& ex)
   {
diff --git a/glom/frame_glom.h b/glom/frame_glom.h
index 0132ada..d593d12 100644
--- a/glom/frame_glom.h
+++ b/glom/frame_glom.h
@@ -72,6 +72,8 @@ public:
 
   void set_databases_selected(const Glib::ustring& strName);
 
+  void do_print_layout(const Glib::ustring& print_layout_name, bool preview = false, Gtk::Window* transient_for = 0);
+
   void on_box_tables_selected(const Glib::ustring& strName);
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
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 b5ef30a..baaaacc 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -23,6 +23,7 @@
 #include <glom/box_db_table.h>
 #include <glom/print_layout/canvas_layout_item.h>
 #include <glom/utils_ui.h>
+#include <glom/application.h>
 #include <libglom/data_structure/layout/layoutitem_line.h>
 #include <libglom/data_structure/layout/layoutitem_portal.h>
 #include <libglom/utils.h> //For bold_message()).
@@ -186,8 +187,10 @@ void Window_PrintLayout_Edit::init_menu()
   m_action_group = Gtk::ActionGroup::create();
 
   m_action_group->add(Gtk::Action::create("Menu_File", _("_File")));
-  m_action_group->add(Gtk::Action::create("Action_Menu_File_PageSetup", _("Page _Setup")),
+  m_action_group->add(Gtk::Action::create("Action_Menu_File_PageSetup", Gtk::Stock::PAGE_SETUP),
     sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_file_page_setup));
+  m_action_group->add(Gtk::Action::create("Action_Menu_File_PrintPreview", Gtk::Stock::PRINT_PREVIEW),
+    sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_file_print_preview));
 
 
   m_action_group->add(Gtk::Action::create("Menu_Edit", Gtk::Stock::EDIT));
@@ -267,6 +270,7 @@ void Window_PrintLayout_Edit::init_menu()
     "  <menubar name='Menubar'>"
     "      <menu action='Menu_File'>"
     "        <menuitem action='Action_Menu_File_PageSetup' />"
+    "        <menuitem action='Action_Menu_File_PrintPreview' />"
     "      </menu>"
     "      <menu action='Menu_Edit'>"
     "        <menuitem action='Action_Menu_Edit_Cut' />"
@@ -921,6 +925,27 @@ void Window_PrintLayout_Edit::on_menu_file_page_setup()
   set_ruler_sizes();
 }
 
+void Window_PrintLayout_Edit::on_menu_file_print_preview()
+{
+  //Save any recent changes in the document,
+  //so that the preview will show them:
+  Document* document = dynamic_cast<Document*>(get_document());
+  if(!document)
+    return;
+
+  const Glib::ustring original_name = get_original_name();
+  sharedptr<PrintLayout> print_layout = get_print_layout();
+  if(print_layout && (original_name != get_name()))
+    document->remove_report(m_table_name, original_name);
+
+  document->set_print_layout(m_table_name, print_layout);
+
+  //Show the print preview window:
+  Application* app = Application::get_application();
+  if(app)
+    app->do_print_layout(m_print_layout->get_name(), true /* preview */, this);
+}
+
 void Window_PrintLayout_Edit::on_menu_edit_cut()
 {
   on_menu_edit_copy();
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 0c96afb..b975c3f 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.h
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.h
@@ -63,6 +63,7 @@ private:
   sharedptr<LayoutItem> create_empty_item(PrintLayoutToolbarButton::enumItems item_type);
 
   void on_menu_file_page_setup();
+  void on_menu_file_print_preview();
   void on_menu_insert_field();
   void on_menu_insert_text();
   void on_menu_insert_image();



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