Warning, file /office/calligra/libs/main/KoPrintingDialog.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 #ifndef KOPRINTINGDIALOG_H
0020 #define KOPRINTINGDIALOG_H
0021 
0022 #include <KoPrintJob.h>
0023 #include <QList>
0024 #include "komain_export.h"
0025 
0026 class KoShapeManager;
0027 class KoShape;
0028 class KoPrintingDialogPrivate;
0029 
0030 /**
0031  * Dialog that will allow you to print any flake-based document, with full interaction and ability to stop.
0032  * Using this class allows any application to print a set of shapes that are contained in the shapeManager()
0033  * in a thread-safe manner, while ensuring that the full content is present before printing.  A requirement
0034  * for any shape that may use the network or simply use a lot of processing power to prepare its content
0035  * before it can be painted.
0036  * This class is of the type of 'create and forget'. Meaning that you create the dialog, initialize it with
0037  * data and then call show() on it.  It then continues to print and delete itself when ready.
0038  * @code
0039     KoPrintingDialog *dia = new KoPrintingDialog(myWidget);
0040     dia->printer().setOutputFormat(QPrinter::PdfFormat);
0041     dia->printer().setOutputFileName("output.pdf");
0042     dia->printer().setResolution(600);
0043     dia->printer().setFullPage(true); // ignore printer margins
0044     dia->setShapeManager(m_canvas->shapeManager())
0045     QList<int> pages;
0046     pages.append(1);
0047     dia->setPageRange(pages);
0048     dia->startPrinting();
0049     @endcode
0050  * The dialog works by looping over all pages in the page-range and sequentially calling preparePage(int) and
0051  * then using the shapeManager() to actually print the shapes.
0052  *
0053  * Since preparePage(int) is pure virtual the application wanting to implement printing should inherit from
0054  * this class and make sure that after the preparePage returns a simple paint can be called on the shapeManager
0055  * with the painter().
0056  *
0057  * XXX: preparePage(int) is no longer pure virtual! Only Calligra Sheets reimplements it -- what should be changed
0058  *      to the docs? (BSAR)
0059  *
0060  * This typically means that the preparePage() makes sure the shapeManager is updated and the correct cliprect
0061  * is set on the painter().
0062  */
0063 class KOMAIN_EXPORT KoPrintingDialog : public KoPrintJob {
0064     Q_OBJECT
0065 public:
0066     /**
0067      * Create a new dialog.
0068      * @param parent the widget this dialog will use as a child.
0069      */
0070     explicit KoPrintingDialog(QWidget *parent);
0071     ~KoPrintingDialog() override;
0072 
0073     /**
0074      * Set the shape manager that should be used to print.
0075      * @param sm the shapeManager used for the next page(s)
0076      */
0077     void setShapeManager(KoShapeManager *sm);
0078     /**
0079      * Set a list of all the pages that should be used to loop over and print.
0080      * Note that any calls made to this method after printing started are ignored.
0081      * @param pages a list of page numbers that the preparePage() gets passed.
0082      */
0083     void setPageRange(const QList<int> &pages);
0084 
0085     /**
0086      * Return the printer used to print.
0087      * @return the printer used to print.
0088      */
0089     QPrinter &printer() override;
0090 
0091 public Q_SLOTS:
0092 
0093     /**
0094      * @see KoPrintJob::startPrinting
0095      */
0096     void startPrinting(RemovePolicy removePolicy = DoNotDelete) override;
0097 
0098 protected:
0099     /**
0100      * Reimplement this method to setup the shapeManager and painter and maybe the shapes for
0101      * printing the passed in page number.  The printing itself will not happen in this method.
0102      * This method will be called in a thread that is not the main-thread. So the processing can take
0103      * a reasonably long time within posing problems for user interaction.
0104      * @param pageNumber the number of the page to prepare.
0105      * @see isStopped() printPage()
0106      * @returns a cliprect. If the rect is valid then it will be set on the painter right after
0107      *   newPage is called.
0108      */
0109     virtual QRectF preparePage(int pageNumber);
0110 
0111     /**
0112      * This is a similar method to preparePage(), but is guaranteed to be called in the Ui thread.
0113      * @param pageNumber the number of the page to prepare.
0114      * @param painter the painter.
0115      * @see isStopped()
0116      */
0117     virtual void printPage(int pageNumber, QPainter &painter);
0118 
0119     /**
0120      * Implement to return the shapes on the requested page.
0121      */
0122     virtual QList<KoShape*> shapesOnPage(int pageNumber) = 0;
0123 
0124     /**
0125      * @returns the shapeManager.
0126      * Returns the shapeManager as it has been set on the setShapeManager()
0127      * @see setShapeManager
0128      */
0129     KoShapeManager *shapeManager() const;
0130 
0131     /**
0132      * Return the painter that will be used to print the shape data.
0133      */
0134     QPainter &painter() const;
0135 
0136     /**
0137      * Return true if the user pressed stop.
0138      * It is suggested to query this setting in long loops and abort the process as soon at it returns yes.
0139      */
0140     bool isStopped() const;
0141 
0142     /**
0143      * This virtual hook is called at the end of the printing process, either on success of on failure.
0144      * The method is empty by default.
0145      */
0146     virtual void printingDone() { }
0147 
0148 private:
0149     KoPrintingDialogPrivate * const d;
0150     friend class KoPrintingDialogPrivate;
0151     Q_PRIVATE_SLOT(d, void preparePage(const QVariant &page))
0152     Q_PRIVATE_SLOT(d, void printPage(const QVariant &page))
0153     Q_PRIVATE_SLOT(d, void stopPressed())
0154 };
0155 
0156 
0157 
0158 
0159 
0160 #endif
0161