|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QPrinter
public class QPrinter
The QPrinter class is a paint device that paints on a printer.
This device represents a series of pages of printed output, and is used in almost exactly the same way as other paint devices such as QWidget and QPixmap. A set of additional functions are provided to manage device-specific features, such as orientation and resolution, and to step through the pages in a document as it is generated.
When printing directly to a printer on Windows or Mac OS X, QPrinter uses the built-in printer drivers. On X11, QPrinter uses the Common Unix Printing System (CUPS) or the standard Unix lpr utility to send PostScript or PDF output to the printer. As an alternative, the printProgram function can be used to specify the command or utility to use instead of the system default.
QPrinter supports a number of parameters, most of which can be changed by the end user through a print dialog. In general, QPrinter passes these functions onto the underlying QPrintEngine.
The most important parameters are:
Many of these functions can only be called before the actual printing begins (i.e., before QPainter::begin() is called). This usually makes sense because, for example, it's not possible to change the number of copies when you are halfway through printing. There are also some settings that the user sets (through the printer dialog) and that applications are expected to obey. See QAbstractPrintDialog's documentation for more details.
When QPainter::begin() is called, the QPrinter it operates on is prepared for a new page, enabling the QPainter to be used immediately to paint the first page in a document. Once the first page has been painted, newPage can be called to request a new blank page to paint on, or QPainter::end() can be called to finish printing. The second page and all following pages are prepared using a call to newPage before they are painted.
The first page in a document does not need to be preceded by a call to newPage. You only need to calling newPage after QPainter::begin() if you need to insert a blank page at the beginning of a printed document. Similarly, calling newPage after the last page in a document is painted will result in a trailing blank page appended to the end of the printed document.
If you want to abort the print job, abort will try its best to stop printing. It may cancel the entire job or just part of it.
Since QPrinter can print to any QPrintEngine subclass, it is possible to extend printing support to cover new types of printing subsystem by subclassing QPrintEngine and reimplementing its interface.
Nested Class Summary | |
---|---|
static class |
QPrinter.ColorMode
This enum type is used to indicate whether QPrinter should print in color or not. |
static class |
QPrinter.Orientation
This enum type (not to be confused with Orientation) is used to specify each page's orientation. |
static class |
QPrinter.OutputFormat
The OutputFormat enum is used to describe the format QPrinter should use for printing. |
static class |
QPrinter.PageOrder
This enum type is used by QPrinter to tell the application program how to print. |
static class |
QPrinter.PageSize
This enum type specifies what paper size QPrinter should use. |
static class |
QPrinter.PaperSource
This enum type specifies what paper source QPrinter is to use. |
static class |
QPrinter.PrinterMode
This enum describes the mode the printer should work in. |
static class |
QPrinter.PrinterState
Press link for info on QPrinter.PrinterState |
static class |
QPrinter.PrintRange
Used to specify the print range selection option. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Constructor Summary | |
---|---|
QPrinter()
Equivalent to QPrinter(ScreenResolution). |
|
QPrinter(QPrinter.PrinterMode mode)
Creates a new printer object with the given mode. |
Method Summary | |
---|---|
boolean |
abort()
Aborts the current print run. |
boolean |
collateCopies()
Returns true if collation is turned on when multiple copies is selected. |
QPrinter.ColorMode |
colorMode()
Returns the current color mode. |
java.lang.String |
creator()
Returns the name of the application that created the document. |
int |
depth()
Returns the bit depth (number of bit planes) of the paint device. |
int |
devType()
This function is reimplemented for internal reasons. |
java.lang.String |
docName()
Returns the document name. |
boolean |
doubleSidedPrinting()
Returns true if double side printing is enabled. |
boolean |
fontEmbeddingEnabled()
Returns true if font embedding is enabled. |
static QPrinter |
fromNativePointer(QNativePointer nativePointer)
This function returns the QPrinter instance pointed to by nativePointer |
int |
fromPage()
Returns the from-page setting. |
boolean |
fullPage()
Returns true if the origin of the printer's coordinate system is at the corner of the page and false if it is at the edge of the printable area. |
int |
height()
Returns the height of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget). |
int |
heightMM()
Returns the height of the paint device in millimeters. |
int |
logicalDpiX()
Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes. |
int |
logicalDpiY()
Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes. |
int |
metric(QPaintDevice.PaintDeviceMetric arg__1)
Returns the metric information for the given paint device arg__1. |
boolean |
newPage()
Tells the printer to eject the current page and to continue printing on a new page. |
int |
numColors()
Returns the number of different colors available for the paint device. |
int |
numCopies()
Returns the number of copies to be printed. |
QPrinter.Orientation |
orientation()
Returns the orientation setting. |
java.lang.String |
outputFileName()
Returns the name of the output file. |
QPrinter.OutputFormat |
outputFormat()
Returns the output format for this printer. |
QPrinter.PageOrder |
pageOrder()
Returns the current page order. |
QRect |
pageRect()
Returns the page's rectangle; this is usually smaller than the paperRect since the page normally has margins between its borders and the paper. |
QPrinter.PageSize |
pageSize()
Returns the printer page size. |
QPaintEngine |
paintEngine()
Returns the paint engine used by the printer. |
boolean |
paintingActive()
Returns true if the device is currently being painted on, i.e. someone has called QPainter::begin() but not yet called QPainter::end() for this device; otherwise returns false. |
QRect |
paperRect()
Returns the paper's rectangle; this is usually larger than the pageRect. |
QPrinter.PaperSource |
paperSource()
Returns the printer's paper source. |
int |
physicalDpiX()
Returns the horizontal resolution of the device in dots per inch. |
int |
physicalDpiY()
Returns the horizontal resolution of the device in dots per inch. |
QPrintEngine |
printEngine()
Returns the print engine used by the printer. |
java.lang.String |
printerName()
Returns the printer name. |
QPrinter.PrinterState |
printerState()
Returns the current state of the printer. |
java.lang.String |
printProgram()
Returns the name of the program that sends the print output to the printer. |
QPrinter.PrintRange |
printRange()
Returns the page range of the QPrinter. |
int |
resolution()
Returns the current assumed resolution of the printer, as set by setResolution or by the printer driver. |
void |
setCollateCopies(boolean collate)
Sets the default value for collation checkbox when the print dialog appears. |
void |
setColorMode(QPrinter.ColorMode arg__1)
Sets the printer's color mode to arg__1, which can be either Color or GrayScale. |
void |
setCreator(java.lang.String arg__1)
Sets the name of the application that created the document to arg__1. |
void |
setDocName(java.lang.String arg__1)
Sets the document name to arg__1. |
void |
setDoubleSidedPrinting(boolean enable)
Enables double sided printing if enable is true; otherwise disables it. |
protected void |
setEngines(QPrintEngine printEngine,
QPaintEngine paintEngine)
This function is used by subclasses of QPrinter to specify custom print and paint engines (printEngine and paintEngine, respectively). |
void |
setFontEmbeddingEnabled(boolean enable)
Enabled or disables font embedding depending on enable. |
void |
setFromTo(int fromPage,
int toPage)
Sets the from-page and to-page settings to fromPage and toPage respectively. |
void |
setFullPage(boolean arg__1)
If arg__1 is true, enables support for painting over the entire page; otherwise restricts painting to the printable area reported by the device. |
void |
setNumCopies(int arg__1)
Sets the number of copies to be printed to arg__1. |
void |
setOrientation(QPrinter.Orientation arg__1)
Sets the print orientation to arg__1. |
void |
setOutputFileName(java.lang.String arg__1)
Sets the name of the output file to arg__1. |
void |
setOutputFormat(QPrinter.OutputFormat format)
Sets the output format for this printer to format. |
void |
setPageOrder(QPrinter.PageOrder arg__1)
Sets the page order to arg__1. |
void |
setPageSize(QPrinter.PageSize arg__1)
Sets the printer page size to arg__1 if that size is supported. |
void |
setPaperSource(QPrinter.PaperSource arg__1)
Sets the paper source setting to arg__1. |
void |
setPrinterName(java.lang.String arg__1)
Sets the printer name to arg__1. |
void |
setPrintProgram(java.lang.String arg__1)
Sets the name of the program that should do the print job to arg__1. |
void |
setPrintRange(QPrinter.PrintRange range)
Sets the print range option in to be range. |
void |
setResolution(int arg__1)
Requests that the printer prints at arg__1 or as near to arg__1 as possible. |
java.util.List<java.lang.Integer> |
supportedResolutions()
Returns a list of the resolutions (a list of dots-per-inch integers) that the printer says it supports. |
int |
toPage()
Returns the to-page setting. |
int |
width()
Returns the width of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget). |
int |
widthMM()
Returns the width of the paint device in millimeters. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QPrinter()
Equivalent to QPrinter(ScreenResolution).
public QPrinter(QPrinter.PrinterMode mode)
Creates a new printer object with the given mode.
Method Detail |
---|
public final boolean abort()
Aborts the current print run. Returns true if the print run was successfully aborted and printerState will return QPrinter::Aborted; otherwise returns false.
It is not always possible to abort a print job. For example, all the data has gone to the printer but the printer cannot or will not cancel the job when asked to.
public final boolean collateCopies()
Returns true if collation is turned on when multiple copies is selected. Returns false if it is turned off when multiple copies is selected.
public final QPrinter.ColorMode colorMode()
Returns the current color mode.
public final java.lang.String creator()
Returns the name of the application that created the document.
public final int depth()
Returns the bit depth (number of bit planes) of the paint device.
depth
in interface QPaintDeviceInterface
public final java.lang.String docName()
Returns the document name.
public final boolean doubleSidedPrinting()
Returns true if double side printing is enabled.
Currently this option is only supported on X11.
public final boolean fontEmbeddingEnabled()
Returns true if font embedding is enabled.
Currently this option is only supported on X11.
public final int fromPage()
Returns the from-page setting. The default value is 0.
If fromPage and toPage both return 0 this signifies 'print the whole document'.
public final boolean fullPage()
Returns true if the origin of the printer's coordinate system is at the corner of the page and false if it is at the edge of the printable area.
See setFullPage for details and caveats.
public final int height()
Returns the height of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget).
height
in interface QPaintDeviceInterface
public final int heightMM()
Returns the height of the paint device in millimeters.
heightMM
in interface QPaintDeviceInterface
public final int logicalDpiX()
Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from widthMM, but it varies on Windows.
Note that if the logicalDpiX doesn't equal the physicalDpiX, the corresponding QPaintEngine must handle the resolution mapping.
logicalDpiX
in interface QPaintDeviceInterface
public final int logicalDpiY()
Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from heightMM, but it varies on Windows.
Note that if the logicalDpiY doesn't equal the physicalDpiY, the corresponding QPaintEngine must handle the resolution mapping.
logicalDpiY
in interface QPaintDeviceInterface
public final boolean newPage()
Tells the printer to eject the current page and to continue printing on a new page. Returns true if this was successful; otherwise returns false.
public final int numColors()
Returns the number of different colors available for the paint device. Since this value is an int, it will not be sufficient to represent the number of colors on 32 bit displays, in this case INT_MAX is returned instead.
numColors
in interface QPaintDeviceInterface
public final int numCopies()
Returns the number of copies to be printed. The default value is 1.
On Windows, Mac OS X and X11 systems that support CUPS, this will always return 1 as these operating systems can internally handle the number of copies.
On X11, this value will return the number of times the application is required to print in order to match the number specified in the printer setup dialog. This has been done since some printer drivers are not capable of buffering up the copies and in those cases the application must make an explicit call to the print code for each copy.
public final QPrinter.Orientation orientation()
Returns the orientation setting. This is driver-dependent, but is usually QPrinter::Portrait.
public final java.lang.String outputFileName()
Returns the name of the output file. By default, this is an empty string (indicating that the printer shouldn't print to file).
public final QPrinter.OutputFormat outputFormat()
Returns the output format for this printer.
public final QPrinter.PageOrder pageOrder()
Returns the current page order.
The default page order is FirstPageFirst.
public final QRect pageRect()
Returns the page's rectangle; this is usually smaller than the paperRect since the page normally has margins between its borders and the paper.
public final QPrinter.PageSize pageSize()
Returns the printer page size. The default value is driver-dependent.
public final boolean paintingActive()
Returns true if the device is currently being painted on, i.e. someone has called QPainter::begin() but not yet called QPainter::end() for this device; otherwise returns false.
paintingActive
in interface QPaintDeviceInterface
public final QRect paperRect()
Returns the paper's rectangle; this is usually larger than the pageRect.
public final QPrinter.PaperSource paperSource()
Returns the printer's paper source. This is Manual or a printer tray or paper cassette.
public final int physicalDpiX()
Returns the horizontal resolution of the device in dots per inch.
Note that if the physicalDpiX doesn't equal the logicalDpiX, the corresponding QPaintEngine must handle the resolution mapping.
physicalDpiX
in interface QPaintDeviceInterface
public final int physicalDpiY()
Returns the horizontal resolution of the device in dots per inch.
Note that if the physicalDpiY doesn't equal the logicalDpiY, the corresponding QPaintEngine must handle the resolution mapping.
physicalDpiY
in interface QPaintDeviceInterface
public final QPrintEngine printEngine()
Returns the print engine used by the printer.
public final java.lang.String printProgram()
Returns the name of the program that sends the print output to the printer.
The default is to return an empty string; meaning that QPrinter will try to be smart in a system-dependent way. On X11 only, you can set it to something different to use a specific print program. On the other platforms, this returns an empty string.
public final QPrinter.PrintRange printRange()
Returns the page range of the QPrinter. After the print setup dialog has been opened, this function returns the value selected by the user.
public final java.lang.String printerName()
Returns the printer name. This value is initially set to the name of the default printer.
public final QPrinter.PrinterState printerState()
Returns the current state of the printer. This may not always be accurate (for example if the printer doesn't have the capability of reporting its state to the operating system).
public final int resolution()
Returns the current assumed resolution of the printer, as set by setResolution or by the printer driver.
public final void setCollateCopies(boolean collate)
Sets the default value for collation checkbox when the print dialog appears. If collate is true, it will enable setCollateCopiesEnabled(). The default value is false. This value will be changed by what the user presses in the print dialog.
public final void setColorMode(QPrinter.ColorMode arg__1)
Sets the printer's color mode to arg__1, which can be either Color or GrayScale.
public final void setCreator(java.lang.String arg__1)
Sets the name of the application that created the document to arg__1.
This function is only applicable to the X11 version of Qt. If no creator name is specified, the creator will be set to "Qt" followed by some version number.
public final void setDocName(java.lang.String arg__1)
Sets the document name to arg__1.
public final void setDoubleSidedPrinting(boolean enable)
Enables double sided printing if enable is true; otherwise disables it.
Currently this option is only supported on X11.
protected final void setEngines(QPrintEngine printEngine, QPaintEngine paintEngine)
This function is used by subclasses of QPrinter to specify custom print and paint engines (printEngine and paintEngine, respectively).
QPrinter does not take ownership of the engines, so you need to manage these engine instances yourself.
Note that changing the engines will reset the printer state and all its properties.
public final void setFontEmbeddingEnabled(boolean enable)
Enabled or disables font embedding depending on enable.
Currently this option is only supported on X11.
public final void setFromTo(int fromPage, int toPage)
Sets the from-page and to-page settings to fromPage and toPage respectively.
The from-page and to-page settings specify what pages to print.
If from and to both return 0 this signifies 'print the whole document'.
This function is useful mostly to set a default value that the user can override in the print dialog when you call setup().
public final void setFullPage(boolean arg__1)
If arg__1 is true, enables support for painting over the entire page; otherwise restricts painting to the printable area reported by the device.
By default, full page printing is disabled. In this case, the origin of the QPrinter's coordinate system coincides with the top-left corner of the printable area.
If full page printing is enabled, the origin of the QPrinter's coordinate system coincides with the top-left corner of the paper itself. In this case, the device metrics will report the exact same dimensions as indicated by PageSize. It may not be possible to print on the entire physical page because of the printer's margins, so the application must account for the margins itself.
public final void setNumCopies(int arg__1)
Sets the number of copies to be printed to arg__1.
The printer driver reads this setting and prints the specified number of copies.
public final void setOrientation(QPrinter.Orientation arg__1)
Sets the print orientation to arg__1.
The orientation can be either QPrinter::Portrait or QPrinter::Landscape.
The printer driver reads this setting and prints using the specified orientation.
On Windows, this option can be changed while printing and will take effect from the next call to newPage.
On Mac OS X, changing the orientation during a print job has no effect.
public final void setOutputFileName(java.lang.String arg__1)
Sets the name of the output file to arg__1.
Setting a null or empty name (0 or "") disables printing to a file. Setting a non-empty name enables printing to a file.
This can change the value of outputFormat. If the file name has the suffix ".ps" then PostScript is automatically selected as output format. If the file name has the ".pdf" suffix PDF is generated. QPrinter will use Qt's cross-platform PostScript or PDF print engines respectively. If you can produce this format natively, for example Mac OS X can generate PDF's from its print engine, set the output format back to NativeFormat.
public final void setOutputFormat(QPrinter.OutputFormat format)
Sets the output format for this printer to format.
public final void setPageOrder(QPrinter.PageOrder arg__1)
Sets the page order to arg__1.
The page order can be QPrinter::FirstPageFirst or QPrinter::LastPageFirst. The application is responsible for reading the page order and printing accordingly.
This function is mostly useful for setting a default value that the user can override in the print dialog.
public final void setPageSize(QPrinter.PageSize arg__1)
Sets the printer page size to arg__1 if that size is supported. The result if undefined if arg__1 is not supported.
The default page size is driver-dependent.
This function is useful mostly for setting a default value that the user can override in the print dialog.
public final void setPaperSource(QPrinter.PaperSource arg__1)
Sets the paper source setting to arg__1.
Windows only: This option can be changed while printing and will take effect from the next call to newPage
public final void setPrintProgram(java.lang.String arg__1)
Sets the name of the program that should do the print job to arg__1.
On X11, this function sets the program to call with the PostScript output. On other platforms, it has no effect.
public final void setPrintRange(QPrinter.PrintRange range)
Sets the print range option in to be range.
public final void setPrinterName(java.lang.String arg__1)
Sets the printer name to arg__1.
public final void setResolution(int arg__1)
Requests that the printer prints at arg__1 or as near to arg__1 as possible.
This setting affects the coordinate system as returned by, for example QPainter::viewport().
This function must be called before QPainter::begin() to have an effect on all platforms.
public final java.util.List<java.lang.Integer> supportedResolutions()
Returns a list of the resolutions (a list of dots-per-inch integers) that the printer says it supports.
For X11 where all printing is directly to postscript, this function will always return a one item list containing only the postscript resolution, i.e., 72 (72 dpi -- but see PrinterMode).
public final int toPage()
Returns the to-page setting. The default value is 0.
If fromPage and toPage both return 0 this signifies 'print the whole document'.
The programmer is responsible for reading this setting and printing accordingly.
public final int width()
Returns the width of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget).
width
in interface QPaintDeviceInterface
public final int widthMM()
Returns the width of the paint device in millimeters.
widthMM
in interface QPaintDeviceInterface
public int devType()
This function is reimplemented for internal reasons.
devType
in interface QPaintDeviceInterface
public int metric(QPaintDevice.PaintDeviceMetric arg__1)
Returns the metric information for the given paint device arg__1.
metric
in interface QPaintDeviceInterface
public QPaintEngine paintEngine()
Returns the paint engine used by the printer.
paintEngine
in interface QPaintDeviceInterface
public static QPrinter fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |