kprinter.h
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License version 2 as published by the Free Software Foundation. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 **/ 00020 00021 #ifndef KPRINTER_H 00022 #define KPRINTER_H 00023 00024 #include <tqpaintdevice.h> 00025 #include <tqprinter.h> 00026 #include <tqmap.h> 00027 #include <tqstring.h> 00028 #include <tqstringlist.h> 00029 #include <tqvaluelist.h> 00030 #include <kdemacros.h> 00031 #include <kdelibs_export.h> 00032 00033 #include <kdeprint/kpreloadobject.h> 00034 00035 class KPrinterImpl; 00036 class KPrintDialogPage; 00037 class KPrinterPrivate; 00038 class DrPageSize; 00039 00088 class KDEPRINT_EXPORT KPrinter : public TQPaintDevice, public KPReloadObject 00089 { 00090 friend class KPrinterWrapper; 00091 friend class KPrinterImpl; 00092 public: 00093 // Print global settings (set via static functions) 00102 enum StandardPageType { CopiesPage = 0x01, FilesPage = 0x02, Custom = 0x10 }; 00116 enum PageSelectionType { ApplicationSide = 0x01, SystemSide = 0x02 }; 00126 enum ApplicationType { Dialog = 0x00, StandAlone = 0x01, StandAlonePersistent = 0x02 }; 00127 00128 // TQPrinter extension 00137 enum PageSetType { AllPages = 0x00, OddPages = 0x01, EvenPages = 0x02 }; 00145 enum CollateType { Collate = 0x00, Uncollate = 0x01 }; 00146 00147 // from TQPrinter class 00152 enum ColorMode { GrayScale = TQPrinter::GrayScale, Color = TQPrinter::Color }; 00157 enum Orientation { Portrait = TQPrinter::Portrait, Landscape = TQPrinter::Landscape }; 00162 enum PageOrder { FirstPageFirst = TQPrinter::FirstPageFirst, LastPageFirst = TQPrinter::LastPageFirst }; 00167 enum PageSize 00168 { 00169 A4 = TQPrinter::A4, 00170 B5 = TQPrinter::B5, 00171 Letter = TQPrinter::Letter, 00172 Legal = TQPrinter::Legal, 00173 Executive = TQPrinter::Executive, 00174 A0 = TQPrinter::A0, 00175 A1 = TQPrinter::A1, 00176 A2 = TQPrinter::A2, 00177 A3 = TQPrinter::A3, 00178 A5 = TQPrinter::A5, 00179 A6 = TQPrinter::A6, 00180 A7 = TQPrinter::A7, 00181 A8 = TQPrinter::A8, 00182 A9 = TQPrinter::A9, 00183 B0 = TQPrinter::B0, 00184 B1 = TQPrinter::B1, 00185 B10 = TQPrinter::B10, 00186 B2 = TQPrinter::B2, 00187 B3 = TQPrinter::B3, 00188 B4 = TQPrinter::B4, 00189 B6 = TQPrinter::B6, 00190 B7 = TQPrinter::B7, 00191 B8 = TQPrinter::B8, 00192 B9 = TQPrinter::B9, 00193 C5E = TQPrinter::C5E, 00194 Comm10E = TQPrinter::Comm10E, 00195 DLE = TQPrinter::DLE, 00196 Folio = TQPrinter::Folio, 00197 Ledger = TQPrinter::Ledger, 00198 Tabloid = TQPrinter::Tabloid, 00199 NPageSize = TQPrinter::NPageSize 00200 }; 00201 00202 // constructors / destructor 00210 KPrinter(bool restore = true, TQPrinter::PrinterMode m = TQPrinter::ScreenResolution ); 00214 ~KPrinter(); 00215 00216 // TQPrinter interface (+ some extensions) 00220 bool newPage(); 00224 bool abort(); 00228 bool aborted() const; 00232 bool outputToFile() const; 00236 void setOutputToFile(bool); 00240 TQString outputFileName() const; 00244 void setOutputFileName(const TQString&); 00248 TQString docName() const; 00252 void setDocName(const TQString&); 00256 TQString creator() const; 00260 void setCreator(const TQString&); 00264 bool fullPage() const; 00268 void setFullPage(bool); 00272 ColorMode colorMode() const; 00276 void setColorMode(ColorMode); 00280 int numCopies() const; 00284 void setNumCopies(int n); 00288 Orientation orientation() const; 00292 void setOrientation(Orientation); 00296 PageOrder pageOrder() const; 00300 void setPageOrder(PageOrder); 00304 CollateType collate() const; 00308 void setCollate(CollateType type); 00312 int minPage() const; 00316 int maxPage() const; 00320 void setMinMax(int, int); 00329 int fromPage() const KDE_DEPRECATED; 00338 int toPage() const; 00342 void setFromTo(int, int); 00346 PageSize pageSize() const; 00350 void setPageSize(PageSize); 00354 TQString printerName() const; 00358 void setPrinterName(const TQString&); 00365 TQString printProgram() const; 00394 void setPrintProgram(const TQString& cmd); 00398 TQString printerSelectionOption() const; 00402 void setPrinterSelectionOption(const TQString&); 00407 int currentPage() const; 00435 void setCurrentPage(int p = 0); 00439 PageSetType pageSet() const; 00447 bool setup(TQWidget *parent = 0, const TQString& caption = TQString::null, bool forceExpand = false); 00451 TQSize margins() const; 00455 void setMargins(TQSize m); 00465 TQSize realPageSize() const; 00470 void setRealPageSize( TQSize p ); 00475 void setRealDrawableArea( const TQRect& r ); 00480 TQRect realDrawableArea() const; 00481 00482 void margins( uint *top, uint *left, uint *bottom, uint *right ) const; 00483 void setMargins( uint top, uint left, uint bottom, uint right ); 00484 00491 TQValueList<int> pageList() const; 00511 void setPreviewOnly(bool on); 00516 bool previewOnly() const; 00525 void setResolution(int dpi); 00531 int resolution() const; 00532 00543 void setUsePrinterResolution( bool on ); 00544 00548 KPrinterImpl* implementation() const; 00556 bool printFiles(const TQStringList& files, bool removeafter = false, bool startviewer = true); 00557 00567 static void addDialogPage(KPrintDialogPage* _page); 00574 static void setPageSelection(PageSelectionType _mode); 00580 static PageSelectionType pageSelection(); 00587 static void setApplicationType(ApplicationType type); 00593 static ApplicationType applicationType(); 00600 static void addStandardPage(int p); 00608 static void removeStandardPage(int p); 00615 //static int addPrinterWizard(TQWidget *parent = 0); 00616 00647 const TQString& option(const TQString& key) const; 00656 void setOption(const TQString& key, const TQString& value); 00661 const TQMap<TQString,TQString>& options() const; 00668 void setOptions(const TQMap<TQString,TQString>& opts); 00675 void initOptions(const TQMap<TQString,TQString>& opts); 00676 00683 TQString searchName() const; 00689 void setSearchName(const TQString& n); 00694 TQString errorMessage() const; 00699 void setErrorMessage(const TQString& msg); 00717 bool autoConfigure(const TQString& prname = TQString::null, TQWidget *parent = 0); 00726 void setDocFileName(const TQString& filename); 00733 TQString docFileName() const; 00741 void setDocDirectory( const TQString& dir ); 00748 TQString docDirectory() const; 00749 00750 protected: 00751 virtual bool cmd(int, TQPainter*, TQPDevCmdParam*); 00752 virtual int metric(int) const; 00753 void translateQtOptions(); 00754 void loadSettings(); 00755 void saveSettings(); 00756 void preparePrinting(); 00757 void finishPrinting(); 00758 void reload(); 00759 void init(bool restore = true, TQPrinter::PrinterMode m = TQPrinter::ScreenResolution); 00760 bool doPreview(const TQString& file); 00761 void setRealPageSize(DrPageSize* p); 00762 void setOption( const TQString& key, const TQString& value, bool broadcast ); 00763 00764 protected: 00765 KPrinterPrivate *d; 00766 }; 00767 00768 //************************************************************************************** 00769 00770 // Utility functions 00771 00772 KDEPRINT_EXPORT KPrinter::PageSize pageNameToPageSize(const TQString& name); 00773 KDEPRINT_EXPORT const char* pageSizeToPageName(KPrinter::PageSize s); 00778 TQSize rangeToSize( const TQString& ); 00779 00780 #endif