# HG changeset patch
# User John Donoghue <john.donoghue@ieee.org>
# Date 1365128537 14400
# Node ID e0b763c93bb6c12d0baab46ead570000a7315a1e
# Parent  39847dcd25681af07af96620c87893c5ff3b0886
Add editor print menu/toolbutton implementation

* libgui/src/icons/print.png: New file.

* file-editor-tab.cc, file-editor-tab.h (file_editor_tab::print_file): New function.
 (includes): Added include for Qsci/qsciprinter.h, QPrintDialog.

* file-editor.cc, file-editor.h (file_editor::request_print_file): New function.
 (file_editor::construct): Add new print QAction to menu and toolbar.
 (file::editor::fetab_print_file): New signal.

* libgui/src/resource.qrc: Added print.png as a resource.

diff -r 39847dcd2568 -r e0b763c93bb6 libgui/src/icons/print.png
Binary file libgui/src/icons/print.png has changed
diff -r 39847dcd2568 -r e0b763c93bb6 libgui/src/m-editor/file-editor-tab.cc
--- a/libgui/src/m-editor/file-editor-tab.cc	Thu Apr 04 17:18:16 2013 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Thu Apr 04 22:22:17 2013 -0400
@@ -35,6 +35,7 @@
 #include <Qsci/qscilexerperl.h>
 #include <Qsci/qscilexerbatch.h>
 #include <Qsci/qscilexerdiff.h>
+#include <Qsci/qsciprinter.h>
 #include "resource-manager.h"
 #include <QApplication>
 #include <QFileDialog>
@@ -42,6 +43,7 @@
 #include <QTextStream>
 #include <QVBoxLayout>
 #include <QInputDialog>
+#include <QPrintDialog>
 
 #include "file-editor-tab.h"
 #include "file-editor.h"
@@ -332,6 +334,24 @@
 }
 
 void
+file_editor_tab::print_file (const QWidget* ID)
+{
+  if (ID != this)
+    return;
+
+  QsciPrinter * printer = new QsciPrinter( QPrinter::HighResolution );
+
+  QPrintDialog printDlg(printer, this);
+
+  if(printDlg.exec() == QDialog::Accepted) 
+    {
+       printer->printRange(_edit_area);
+    }
+  delete printer;
+}
+
+
+void
 file_editor_tab::run_file_callback (void)
 {
   // Maybe someday we will do something here?
diff -r 39847dcd2568 -r e0b763c93bb6 libgui/src/m-editor/file-editor-tab.h
--- a/libgui/src/m-editor/file-editor-tab.h	Thu Apr 04 17:18:16 2013 -0400
+++ b/libgui/src/m-editor/file-editor-tab.h	Thu Apr 04 22:22:17 2013 -0400
@@ -62,6 +62,7 @@
   void save_file (const QWidget* ID);
   void save_file (const QWidget* ID, const QString& fileName, bool remove_on_success);
   void save_file_as (const QWidget* ID);
+  void print_file (const QWidget* ID);
   void run_file (const QWidget* ID);
   void toggle_bookmark (const QWidget* ID);
   void next_bookmark (const QWidget* ID);
diff -r 39847dcd2568 -r e0b763c93bb6 libgui/src/m-editor/file-editor.cc
--- a/libgui/src/m-editor/file-editor.cc	Thu Apr 04 17:18:16 2013 -0400
+++ b/libgui/src/m-editor/file-editor.cc	Thu Apr 04 22:22:17 2013 -0400
@@ -397,6 +397,13 @@
 }
 
 void
+file_editor::request_print_file ()
+{
+   emit fetab_print_file (_tab_widget->currentWidget ());
+}
+
+
+void
 file_editor::request_run_file ()
 {
   emit fetab_run_file (_tab_widget->currentWidget ());
@@ -626,6 +633,10 @@
     = new QAction (QIcon(":/actions/icons/filesaveas.png"),
                    tr("Save File &As"), _tool_bar);
 
+  QAction *print_action 
+    = new QAction ( QIcon(":/actions/icons/print.png"),
+                    tr ("Print"), _tool_bar);
+
   QAction *undo_action = new QAction (QIcon(":/actions/icons/undo.png"),
                                       tr("&Undo"), _tool_bar);
 
@@ -689,6 +700,10 @@
   save_action->setShortcutContext               (Qt::WindowShortcut);
   save_as_action->setShortcut                   (QKeySequence::SaveAs);
   save_as_action->setShortcutContext            (Qt::WindowShortcut);
+
+  print_action->setShortcut                      (Qt::ControlModifier+ Qt::Key_P);
+  print_action->setShortcutContext               (Qt::WindowShortcut);
+
   next_bookmark_action->setShortcut             (Qt::Key_F2);
   next_bookmark_action->setShortcutContext      (Qt::WindowShortcut);
   previous_bookmark_action->setShortcut         (Qt::SHIFT + Qt::Key_F2);
@@ -710,6 +725,8 @@
   _tool_bar->addAction (save_action);
   _tool_bar->addAction (save_as_action);
   _tool_bar->addSeparator ();
+  _tool_bar->addAction(print_action);
+  _tool_bar->addSeparator ();
   _tool_bar->addAction (undo_action);
   _tool_bar->addAction (redo_action);
   _tool_bar->addAction (_copy_action);
@@ -739,6 +756,9 @@
   fileMenu->addMenu (_mru_file_menu);
   _menu_bar->addMenu (fileMenu);
 
+  fileMenu->addSeparator ();
+  fileMenu->addAction (print_action);
+
   QMenu *editMenu = new QMenu (tr ("&Edit"), _menu_bar);
   editMenu->addAction (undo_action);
   editMenu->addAction (redo_action);
@@ -799,6 +819,8 @@
            SIGNAL (triggered ()), this, SLOT (request_save_file ()));
   connect (save_as_action,
            SIGNAL (triggered ()), this, SLOT (request_save_file_as ()));
+  connect (print_action,
+           SIGNAL (triggered ()), this, SLOT (request_print_file ()));
   connect (_run_action,
            SIGNAL (triggered ()), this, SLOT (request_run_file ()));
   connect (toggle_bookmark_action,
@@ -899,6 +921,8 @@
            f, SLOT (save_file (const QWidget*)));
   connect (this, SIGNAL (fetab_save_file_as (const QWidget*)),
            f, SLOT (save_file_as (const QWidget*)));
+  connect (this, SIGNAL (fetab_print_file (const QWidget*)),
+           f, SLOT (print_file (const QWidget*)));
   connect (this, SIGNAL (fetab_run_file (const QWidget*)),
            f, SLOT (run_file (const QWidget*)));
   connect (this, SIGNAL (fetab_toggle_bookmark (const QWidget*)),
diff -r 39847dcd2568 -r e0b763c93bb6 libgui/src/m-editor/file-editor.h
--- a/libgui/src/m-editor/file-editor.h	Thu Apr 04 17:18:16 2013 -0400
+++ b/libgui/src/m-editor/file-editor.h	Thu Apr 04 22:22:17 2013 -0400
@@ -76,6 +76,7 @@
   void fetab_paste (const QWidget* ID);
   void fetab_save_file (const QWidget* ID);
   void fetab_save_file_as (const QWidget* ID);
+  void fetab_print_file (const QWidget* ID);
   void fetab_run_file (const QWidget* ID);
   void fetab_toggle_bookmark (const QWidget* ID);
   void fetab_next_bookmark (const QWidget* ID);
@@ -98,6 +99,7 @@
   void request_new_file ();
   void request_open_file ();
   void request_mru_open_file ();
+  void request_print_file ();
 
   void request_undo ();
   void request_redo ();
diff -r 39847dcd2568 -r e0b763c93bb6 libgui/src/resource.qrc
--- a/libgui/src/resource.qrc	Thu Apr 04 17:18:16 2013 -0400
+++ b/libgui/src/resource.qrc	Thu Apr 04 22:22:17 2013 -0400
@@ -7,6 +7,7 @@
         <file>icons/filenew.png</file>
         <file>icons/fileopen.png</file>
         <file>icons/filesave.png</file>
+        <file>icons/print.png</file>
         <file>icons/redo.png</file>
         <file>icons/search.png</file>
         <file>icons/undo.png</file>
