TextPrinter Class Reference

#include <textprinter.h>

List of all members.

Public Member Functions

 TextPrinter (QObject *parent=0)
 Default constructor.
 ~TextPrinter ()
 Destructor.
void print (const QTextDocument *document, const QString &caption=QString())
 Print the document.
void exportPdf (const QTextDocument *document, const QString &caption=QString(), const QString &filename=QString())
 Export the document to PDF.
void preview (const QTextDocument *document, const QString &caption=QString())
 Display the document in a preview dialog.
QPrinter::PageSize pageSize () const
 Get page size.
void setPageSize (QPrinter::PageSize size)
 Set page size.
QPrinter::Orientation orientation () const
 Get page orientation.
void setOrientation (QPrinter::Orientation orientation)
 Set page orientation.
double leftMargin () const
 Get left margin width.
void setLeftMargin (double margin)
 Set left margin width.
double rightMargin () const
 Get right margin width.
void setRightMargin (double margin)
 Set right margin width.
double topMargin () const
 Get top margin width.
void setTopMargin (double margin)
 Set top margin width.
double bottomMargin () const
 Get bottom margin width.
void setBottomMargin (double margin)
 Set bottom margin width.
void setMargins (double margin)
 Set all margins.
double spacing () const
 Get spacing between content and header and footer.
void setSpacing (double spacing)
 Set spacing between content and header and footer.
double headerSize () const
 Get header size.
void setHeaderSize (double size)
 Set header size.
double headerRule () const
 Set header rule size.
void setHeaderRule (double pointsize)
 Get header rule size.
const QString & headerText () const
 Get header text.
void setHeaderText (const QString &text)
 Set header text.
double footerSize () const
 Get footer size.
void setFooterSize (double size)
 Set footer size.
double footerRule () const
 Get footer rule size.
void setFooterRule (double pointsize)
 Set footer rule size.
const QString & footerText () const
 Get footer text.
void setFooterText (const QString &text)
 Set footer text.
const QString & dateFormat () const
 Get date format.
void setDateFormat (const QString &format)
 Set date format.

Private Slots

void print (QPrinter *printer)

Private Member Functions

 TextPrinter (const TextPrinter &)
TextPrinteroperator= (const TextPrinter &)
QRectF paperRect (QPaintDevice *device)
QRectF contentRect (QPaintDevice *device)
QRectF headerRect (QPaintDevice *device)
QRectF footerRect (QPaintDevice *device)
void paintPage (QPainter *painter, QTextDocument *document, int pagenum)

Private Attributes

QWidget * parent_
QPrinter * printer_
QTextDocument * tempdoc_
double leftmargin_
double rightmargin_
double topmargin_
double bottommargin_
double spacing_
double headersize_
double headerrule_
QString headertext_
double footersize_
double footerrule_
QString footertext_
QString dateformat_


Detailed Description

Version:
0.3
TextPrinter is a printing utility class. It provides methods to print, preview, and export to PDF. The page format, including header and footers, can be defined. The content to be printed is provided as a QTextDocument object.

Constructor & Destructor Documentation

TextPrinter::TextPrinter ( QObject *  parent = 0  )  [explicit]

Default constructor.

Constructs a TextPrinter object. Any related dialogs will be displayed centered over the parent, if it is a QWidget object.

TextPrinter::~TextPrinter (  ) 

Destructor.

Destroys the TextPrinter object.


Member Function Documentation

double TextPrinter::bottomMargin (  )  const

Get bottom margin width.

Return the bottom page margin size in millimeters.

const QString & TextPrinter::dateFormat (  )  const

Get date format.

Return the currently set date format string.

void TextPrinter::exportPdf ( const QTextDocument *  document,
const QString &  caption = QString(),
const QString &  filename = QString() 
)

Export the document to PDF.

Export the document in PDF format. If caption is not empty, it will be used as the title for the dialog. If filename is empty, a standard file selection dialog will be displayed.

double TextPrinter::footerRule (  )  const

Get footer rule size.

Return the size of the footer rule in points. One point is 1/72 inch.

double TextPrinter::footerSize (  )  const

Get footer size.

Return the height of the footer block in millimeters.

const QString & TextPrinter::footerText (  )  const

Get footer text.

Return the text for the footer.

double TextPrinter::headerRule (  )  const

Set header rule size.

Return the size of the header rule in points. One point is 1/72 inch.

double TextPrinter::headerSize (  )  const

Get header size.

Return the height of the header block in millimeters.

const QString & TextPrinter::headerText (  )  const

Get header text.

Return the text for the header.

double TextPrinter::leftMargin (  )  const

Get left margin width.

Return the left page margin width in millimeters.

QPrinter::Orientation TextPrinter::orientation (  )  const

Get page orientation.

Return the page orientation. This is defined by the QPrinterOrientation enumeration.

QPrinter::PageSize TextPrinter::pageSize (  )  const

Get page size.

Return the page size. This is defined by the QPrinter::PageSize enumeration.

void TextPrinter::preview ( const QTextDocument *  document,
const QString &  caption = QString() 
)

Display the document in a preview dialog.

Displays a print preview dialog. If caption is not empty, it will be used as the title of the dialog.

void TextPrinter::print ( const QTextDocument *  document,
const QString &  caption = QString() 
)

Print the document.

Print a document. A standard print dialog will be displayed. If a QPrinter is not provided, a temporary printer object will be used. If the caption parameter is not empty, it will be used as the title for the print dialog.

Todo:
add overload taking html string

double TextPrinter::rightMargin (  )  const

Get right margin width.

Return the right page margin width in millimeters.

void TextPrinter::setBottomMargin ( double  margin  ) 

Set bottom margin width.

Set the bottom margin size in millimeters. The default value is 15mm.

void TextPrinter::setDateFormat ( const QString &  format  ) 

Set date format.

Set the date format to be used for the &date; page variable. The format is the same as that used by QDate::toString(). If no format is set, the format defaults to Qt::TextDate.

void TextPrinter::setFooterRule ( double  pointsize  ) 

Set footer rule size.

Set the footer rule size in points. By default, the footer rule is one half point (1/144 inch). To turn off the rule, set the rule size to 0. The rule will be drawn just above the footer area.

void TextPrinter::setFooterSize ( double  size  ) 

Set footer size.

Set the height of the footer in millimeters. The default is zero (no header).

void TextPrinter::setFooterText ( const QString &  text  ) 

Set footer text.

Set the text for the footer. Rich text is supported. HTML tags may be used to format the text and align elements. The following page variables may be included in the text:

  • &page; - Insert current page number
  • &date; - Insert current date, using the format set with setPageFormat()

void TextPrinter::setHeaderRule ( double  pointsize  ) 

Get header rule size.

Set the header rule size in points. By default, the header rule is one half point (1/144 inch). To turn off the rule, set the rule size to 0. The rule will be drawn below the header area.

void TextPrinter::setHeaderSize ( double  size  ) 

Set header size.

Set the height of the header in millimeters. The default is zero (no header).

void TextPrinter::setHeaderText ( const QString &  text  ) 

Set header text.

Set the text for the header. Rich text is supported. HTML tags may be used to format the text and align elements. The following page variables may be included in the text:

  • &page; - Insert current page number
  • &date; - Insert current date, using the format set with setPageFormat()

void TextPrinter::setLeftMargin ( double  margin  ) 

Set left margin width.

Set the left margin width in millimeters. The default value is 15mm.

void TextPrinter::setMargins ( double  margin  ) 

Set all margins.

Set all margins to have the identical size. The default value is 15mm.

void TextPrinter::setOrientation ( QPrinter::Orientation  orientation  ) 

Set page orientation.

Set the page orientation. Orientation is defined by the QPrinter::Orientation enumeration, and can be QPrinter::Portrait (the default) or QPrinter::Landscape.

void TextPrinter::setPageSize ( QPrinter::PageSize  size  ) 

Set page size.

Set the page size. Size is defined by the QPrinter::PageSize enumeration. By default, this is QPrinter::Letter in US and Canada locales, and QPrinter::A4 in other locales.

void TextPrinter::setRightMargin ( double  margin  ) 

Set right margin width.

Set the right margin width in millimeters. The default value is 15mm.

void TextPrinter::setSpacing ( double  spacing  ) 

Set spacing between content and header and footer.

Set the spacing between the page content and the header and footer blocks. The default value is 5mm.

void TextPrinter::setTopMargin ( double  margin  ) 

Set top margin width.

Set the top margin size in millimeters. The default value is 15mm.

double TextPrinter::spacing (  )  const

Get spacing between content and header and footer.

Return the spacing between the page content and the header and footer blocks. This is defined in millimeters.

double TextPrinter::topMargin (  )  const

Get top margin width.

Return the top page margin size in millimeters.


The documentation for this class was generated from the following files:

doxygen