Back to index

texmacs  1.0.7.15
QTMPrinterSettings.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  * MODULE     : QTMPrinterSettings.hpp
00004  * DESCRIPTION: 
00005  * COPYRIGHT  : (C) 2010 Miguel de Benito Delgado
00006  *******************************************************************************
00007  * This software falls under the GNU general public license version 3 or later.
00008  * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009  * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010  ******************************************************************************/
00011 
00012 #ifndef QTMPRINTERSETTINGS_HPP
00013 #define QTMPRINTERSETTINGS_HPP
00014 
00015 #include <QObject>
00016 
00017 #include <QPrinter>  // Provides QPrinter::PaperSize
00018 #include <QProcess>
00019 #include <QHash>
00020 
00021 class tm_ostream;
00022 
00023 /* Mock Interface of the Asynchronous command stuff
00024 class QTMAsynchronousCommand {
00025 public:
00026   QTMAsynchronousCommand();
00027   
00028   virtual bool slotStart() = 0;
00029   virtual void signalDone() = 0;
00030 protected:
00031   virtual void signalFinished() = 0;
00032 };
00033 */
00034  
00048 class QTMPrinterSettings : public QObject {
00049   Q_OBJECT
00050   
00051 public:
00053   enum PagePrintingOrder { LR_TB, RL_TB, TB_LR, TB_RL,
00054                            LR_BT, RL_BT, BT_LR, BT_RL};
00055   
00057   enum PageOrientation { Portrait        = 3, Landscape        = 4,
00058                          ReversePortrait = 5, ReverseLandscape = 6 }; 
00059   
00062   enum DriverChoices { PageSize, Resolution, Duplex, ColorModel, Collate };
00063   
00065   enum ColorMode { Monochrome, Gray8Bit, Color};
00066   
00067   bool   collateCopies;
00068   bool      blackWhite;  
00069   QString  printerName;
00070   QString     fileName;
00071   QString    paperSize;
00072   QString printProgram;  
00073   int              dpi;
00074   int        firstPage;  
00075   int         lastPage;
00076   bool   printOddPages;
00077   bool  printEvenPages;
00078   bool       fitToPage;
00079   int        copyCount;
00080   bool          duplex;  
00081   int     pagesPerSide;  
00082   PagePrintingOrder pagesOrder;
00083   PageOrientation  orientation;
00084   
00085 public:
00086   QTMPrinterSettings();
00087   
00088   void getFromQPrinter(const QPrinter&);
00089   void setToQPrinter(QPrinter&) const;
00090   
00091   QStringList getChoices(DriverChoices _which, int& _default);
00092   
00094   virtual QString toSystemCommand() const = 0;
00095   
00102   virtual QList<QPair<QString,QString> > availablePrinters() = 0;
00103   
00104   static QString qtPaperSizeToQString(const QPrinter::PaperSize);
00105   static QPrinter::PaperSize qStringToQtPaperSize(const QString&);
00106 
00107 signals:
00108   void doneReading();
00109 
00110 public slots:
00111   void startReadingSystemConfig(const QString& pname) { fromSystemConfig(pname); }
00112 
00113 protected slots:
00114   virtual void systemCommandFinished(int exitCode,
00115                                      QProcess::ExitStatus exitStatus) = 0;
00116   
00117 protected:
00119   virtual bool fromSystemConfig(const QString& printer) = 0;
00120   
00121   QProcess* configProgram;
00122   QHash<QString, QString> printerOptions;
00123 };
00124 
00125 #if defined(Q_WS_MAC) || defined (Q_WS_X11)
00126 
00133 class CupsQTMPrinterSettings : public QTMPrinterSettings {
00134   // Q_OBJECT
00135   // MOC does not support conditional compilation    
00136 public:
00137   CupsQTMPrinterSettings();
00138   QString toSystemCommand() const;
00139   QList<QPair<QString,QString> > availablePrinters();
00140 protected:
00141   bool fromSystemConfig(const QString& printer);
00142   void systemCommandFinished(int exitCode, QProcess::ExitStatus exitStatus);
00143   };
00144 
00145 #endif  // defined(Q_WS_MAC) || defined (Q_WS_X11)
00146 
00147 #ifdef Q_WS_WIN
00148 
00164 class WinQTMPrinterSettings : public QTMPrinterSettings {
00165   // Q_OBJECT
00166   // MOC does not support conditional compilation  
00167 public:
00168   WinQTMPrinterSettings();
00169   QString toSystemCommand() const;
00170   QList<QPair<QString,QString> > availablePrinters();
00171 protected:
00172   bool fromSystemConfig(const QString& printer);
00173   void systemCommandFinished(int exitCode, QProcess::ExitStatus exitStatus);
00174 };
00175 
00176 #endif // Q_WS_WIN
00177 
00178 #endif  // QTMPRINTERSETTINGS_HPP