KoPrintingDialog Class Reference

Dialog that will allow you to print any flake-based document, with full interaction and ability to stop. More...

#include <KoPrintingDialog.h>

Inheritance diagram for KoPrintingDialog:

KoPrintJob List of all members.

Public Slots

virtual void startPrinting (RemovePolicy removePolicy=DoNotDelete)

Public Member Functions

 KoPrintingDialog (QWidget *parent)
 Create a new dialog.
void setShapeManager (KoShapeManager *sm)
 Set the shape manager that should be used to print.
void setPageRange (const QList< int > &pages)
 Set a list of all the pages that should be used to loop over and print.
QPrinter & printer ()
 Return the printer used to print.

Protected Member Functions

virtual void preparePage (int pageNumber)
 Reimplement this method to setup the shapeManager and painter and maybe the shapes for printing the passed in page number.
virtual void printPage (int pageNumber, QPainter &painter)
 This is a similar method to preparePage(), but is guaranteed to be called in the Ui thread.
virtual QList< KoShape * > shapesOnPage (int pageNumber)=0
 Implement to return the shapes on the requested page.
KoShapeManagershapeManager () const
QPainter & painter () const
 Return the painter that will be used to print the shape data.
bool isStopped () const
 Return true if the user pressed stop.
virtual void printingDone ()
 This virtual hook is called at the end of the printing process, either on success of on failure.

Friends

class KoPrintingDialogPrivate

Detailed Description

Dialog that will allow you to print any flake-based document, with full interaction and ability to stop.

Using this class allows any application to print a set of shapes that are contained in the shapeManager() in a thread-safe manner, while ensuring that the full content is present before printing. A requirement for any shape that may use the network or simply use a lot of processing power to prepare its content before it can be painted. This class is of the type of 'create and forget'. Meaning that you create the dialog, initialize it with data and then call show() on it. It then continues to print and delete itself when ready.

    KoPrintingDialog *dia = new KoPrintingDialog(myWidget);
    dia->printer().setOutputFormat(QPrinter::PdfFormat);
    dia->printer().setOutputFileName("output.pdf");
    dia->printer().setResolution(600);
    dia->printer().setFullPage(true); // ignore printer margins
    dia->setShapeManager(m_canvas->shapeManager())
    QList<int> pages;
    pages.append(1);
    dia->setPageRange(pages);
    dia->startPrinting();
The dialog works by looping over all pages in the page-range and sequentially calling preparePage(int) and then using the shapeManager() to actually print the shapes. Since preparePage(int) is pure virtual the application wanting to implement printing should inherit from this class and make sure that after the preparePage returns a simple paint can be called on the shapeManager with the painter(). This typically means that the preparePage() makes sure the shapeManager is updated and the correct cliprect is set on the painter().


Constructor & Destructor Documentation

KoPrintingDialog::KoPrintingDialog ( QWidget *  parent  ) 

Create a new dialog.

Parameters:
parent the widget this dialog will use as a child.


Member Function Documentation

bool KoPrintingDialog::isStopped (  )  const [protected]

Return true if the user pressed stop.

It is suggested to query this setting in long loops and abort the process as soon at it retuns yes.

void KoPrintingDialog::preparePage ( int  pageNumber  )  [protected, virtual]

Reimplement this method to setup the shapeManager and painter and maybe the shapes for printing the passed in page number.

The printing itself will not happen in this method. This method will be called in a thread that is not the main-thread. So the processing can take a reasonably long time withing posing problems for user interaction.

Parameters:
pageNumber the number of the page to prepare.
See also:
isStopped() printPage()

QPrinter & KoPrintingDialog::printer (  )  [virtual]

Return the printer used to print.

Returns:
the printer used to print.

Implements KoPrintJob.

virtual void KoPrintingDialog::printingDone (  )  [inline, protected, virtual]

This virtual hook is called at the end of the printing process, either on success of on failure.

The method is empty by default.

void KoPrintingDialog::printPage ( int  pageNumber,
QPainter &  painter 
) [protected, virtual]

This is a similar method to preparePage(), but is guaranteed to be called in the Ui thread.

Parameters:
pageNumber the number of the page to prepare.
See also:
isStopped()

void KoPrintingDialog::setPageRange ( const QList< int > &  pages  ) 

Set a list of all the pages that should be used to loop over and print.

Note that any calls made to this method after printing started are ignored.

Parameters:
pages a list of page numbers that the preparePage() gets passed.

void KoPrintingDialog::setShapeManager ( KoShapeManager sm  ) 

Set the shape manager that should be used to print.

Parameters:
sm the shapeManager used for the next page(s)

KoShapeManager * KoPrintingDialog::shapeManager (  )  const [protected]

Returns:
the shapeManager. Retuns the shapeManager as it has been set on the setShapeManager()
See also:
setShapeManager


The documentation for this class was generated from the following files:
Generated on Sun May 11 22:36:11 2008 for libs by  doxygen 1.4.7