Back to index

texmacs  1.0.7.15
qt_printer_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  * MODULE     : qt_printer_widget.cpp
00004  * DESCRIPTION: A dialog to manage printing of the document. All printing
00005  *              options set by the user at this stage are applied as a
00006  *              postprocessing of an already typeset postscript document.
00007  * COPYRIGHT  : (C) 2010 Miguel de Benito Delgado
00008  *******************************************************************************
00009  * This software falls under the GNU general public license version 3 or later.
00010  * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00011  * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00012  ******************************************************************************/
00013 
00014 #include "qt_printer_widget.hpp"
00015 #include "qt_utilities.hpp"      // TYPE_CHECK and NOT_IMPLEMENTED
00016 #include "message.hpp"           // slot definitions
00017 #include "qt_sys_utils.hpp"      // qt_system(string)
00018 #include "QTMPrintDialog.hpp"
00019 #include "QTMPrinterSettings.hpp"
00020 
00021 QTMPrinterSettings* qt_printer_widget_rep::_settings = NULL;
00022 
00026 qt_printer_widget_rep::qt_printer_widget_rep (command _cmd, url _file)
00027 : commandAfterExecution(_cmd) {
00028 #if defined(Q_WS_MAC) || defined(Q_WS_X11)
00029   if (!_settings)
00030     _settings = new CupsQTMPrinterSettings();
00031 #endif
00032 #ifdef Q_WS_WIN
00033   if (!_settings)
00034     _settings = new WinQTMPrinterSettings();
00035 #endif
00036   _settings->fileName = to_qstring(as_string(_file));
00037 }
00038 
00039 
00040 
00044 void
00045 qt_printer_widget_rep::send (slot s, blackbox val) {
00046   if (DEBUG_QT)
00047     cout << "qt_printer_widget_rep::send " << slot_name(s) << LF;
00048   switch (s) {
00049     case SLOT_VISIBILITY:   // Activates the widget
00050       TYPE_CHECK (type_box (val) == type_helper<bool>::id);
00051       if (open_box<bool>(val) == true)
00052         showDialog();
00053       break;
00054     case SLOT_REFRESH:   // ignore: this widget doesn't need refreshing.
00055       break;
00056     default:  // unsupported slots
00057       qt_widget_rep::send (s, val);  // throws FAILED()
00058       break;
00059   }
00060 }
00061 
00062 
00063 
00065 widget
00066 qt_printer_widget_rep::plain_window_widget (string s, command q)
00067 {
00068   // Identify ourselves as already being a top-level window, even though
00069   // the dialog won't be displayed until later.
00070   //view->setProperty ("texmacs_window_widget",
00071   //                 QVariant::fromValue ((void*) this));
00072   (void) s;
00073   commandAfterExecution = q;
00074 
00075   return this;
00076 }
00077 
00078 
00079 
00086 void
00087 qt_printer_widget_rep::showDialog () {
00088   
00089   QString _cmd;
00090   QTMPrintDialog pDialog(_settings);
00091   
00092   if (pDialog.exec() != QDialog::Accepted)
00093     return; // TODO: display message in the status bar.
00094   
00095   _cmd = _settings->toSystemCommand();
00096   
00097   // Send the document to the printer
00098   cout << "qt_printer_dialog_rep] Running command: " << from_qstring(_cmd) 
00099        << "\n";
00100   qt_system(from_qstring(_cmd));  // FIXME? qt_system is synchronous (blocking!)
00101   
00102   // execute the scheme closure 
00103   commandAfterExecution ();
00104 }
00105 
00106