1 /* This file is part of the KDE project
2  * Copyright (C) 2007 Thomas Zander <zander@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef KOPRINTJOB_H
21 #define KOPRINTJOB_H
22 
23 #include <QObject>
24 #include <QList>
25 #include <QAbstractPrintDialog>
26 #include <QPrinter>
27 
28 #include "komain_export.h"
29 
30 class QWidget;
31 
32 /**
33  * A print job is an interface that the KoView uses to create an application-specific
34  * class that can take care of printing.
35  * The printjob should be able to print again after a print job has been completed,
36  * using the same QPrinter to allow the user to alter settings on the QPrinter and
37  * call print again.
38  * The printjob can thus see startPrinting() called more than once, and the implementation
39  * of that signal should honor the removePolicy passed to it.
40  */
41 class KOMAIN_EXPORT KoPrintJob : public QObject
42 {
43     Q_OBJECT
44 public:
45     /**
46      * Constructor.
47      * @param parent the parent qobject that is passed for memory management purposes.
48      */
49     explicit KoPrintJob(QObject *parent = 0);
50     ~KoPrintJob() override;
51 
52     /// A policy to allow the printjob to delete itself after its done printing.
53     enum RemovePolicy {
54         DeleteWhenDone, ///< Delete the job when its done with printing.
55         DoNotDelete     ///< Keep the job around so it can be started again.
56     };
57 
58     /// Returns the printer that is used for this print job so others can alter the details of the print-job.
59     virtual QPrinter &printer() = 0;
60     /// If this print job is used in combination with a printdialog the option widgets this method
61     /// returns will be shown in the print dialog.
62     virtual QList<QWidget*> createOptionWidgets() const = 0;
63 
documentFirstPage()64     virtual int documentFirstPage() const {
65         return 1;
66     }
documentLastPage()67     virtual int documentLastPage() const {
68         return 1;
69     }
documentCurrentPage()70     virtual int documentCurrentPage() const {
71         return 1;
72     }
73 
74     virtual QAbstractPrintDialog::PrintDialogOptions printDialogOptions() const;
75 
76     /**
77      *@brief Check if the painter can print to the printer
78      *@returns true if the print job can print to the given printer
79      */
80     virtual bool canPrint();
81 
82 public Q_SLOTS:
83     /**
84      * This is called every time the job should be executed.
85      * When called the document should be printed a new painter using the printer
86      * of this printJob in order to honor the settings the user made on the printer.
87      * canPrint() should be called before startPrinting to check if the painter can print
88      * to the printer
89      * @param removePolicy a policy that should be honored so the caller can make sure
90      *   this job doesn't leak memory after being used.
91      */
92     virtual void startPrinting(RemovePolicy removePolicy = DoNotDelete);
93 };
94 
95 #endif
96