Warning, file /office/calligra/libs/main/KoPrintingDialog_p.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 * Copyright (C) 2011 Boudewijn Rempt <boud@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 #ifndef KoPrintingDialog_p_h 0021 #define KoPrintingDialog_p_h 0022 0023 #include "KoPrintingDialog.h" 0024 #include "KoProgressUpdater.h" 0025 0026 #include <KoZoomHandler.h> 0027 #include <KoShapeManager.h> 0028 #include <KoShape.h> 0029 #include <KoUpdater.h> 0030 0031 #include <QCoreApplication> 0032 #include <MainDebug.h> 0033 #include <klocalizedstring.h> 0034 #include <QPainter> 0035 #include <QPrinter> 0036 #include <QGridLayout> 0037 #include <QLabel> 0038 #include <QPushButton> 0039 #include <QTimer> 0040 #include <QDialog> 0041 #include <QThread> 0042 0043 0044 class KoPrintingDialogPrivate { 0045 public: 0046 explicit KoPrintingDialogPrivate(KoPrintingDialog *dia) 0047 : parent(dia), 0048 stop(true), 0049 shapeManager(0), 0050 painter(0), 0051 printer(new QPrinter()), 0052 index(0), 0053 progress(0), 0054 dialog(0), 0055 removePolicy(KoPrintJob::DoNotDelete) 0056 { 0057 } 0058 0059 ~KoPrintingDialogPrivate() { 0060 stop = true; 0061 delete progress; 0062 if (painter && painter->isActive()) { 0063 painter->end(); 0064 } 0065 0066 updaters.clear(); 0067 0068 delete printer; 0069 delete dialog; 0070 } 0071 0072 void preparePage(const QVariant &page) { 0073 const int pageNumber = page.toInt(); 0074 0075 QPointer<KoUpdater> updater = updaters.at(index - 1); 0076 0077 if (painter) { 0078 painter->save(); // state before page preparation 0079 } 0080 0081 QRectF clipRect; 0082 0083 if (! stop) { 0084 clipRect = parent->preparePage(pageNumber); 0085 } 0086 0087 updater->setProgress(45); 0088 0089 if (!painter) { 0090 // force the painter to be created *after* the preparePage since the page 0091 // size may have been updated there and that doesn't work with the first page 0092 painter = new QPainter(printer); 0093 painter->save(); // state before page preparation (2) 0094 } 0095 if (index > 1) 0096 printer->newPage(); 0097 if (clipRect.isValid()) // make sure the clipRect is done *after* the newPage. Required for printPreview 0098 painter->setClipRect(clipRect); 0099 updater->setProgress(55); 0100 painter->save(); // state after page preparation 0101 0102 QList<KoShape*> shapes = parent->shapesOnPage(pageNumber); 0103 if (shapes.isEmpty()) { 0104 debugMain << "Printing page" << pageNumber << "I notice there are no shapes on this page"; 0105 } else { 0106 const int progressPart = 45 / shapes.count(); 0107 foreach(KoShape *shape, shapes) { 0108 debugMain << "Calling waitUntilReady on shape;" << shape; 0109 if(! stop) 0110 shape->waitUntilReady(zoomer); 0111 debugMain << "done"; 0112 updater->setProgress(updater->progress() + progressPart); 0113 } 0114 } 0115 updater->setProgress(100); 0116 } 0117 0118 void resetValues() { 0119 index = 0; 0120 updaters.clear(); 0121 if (painter && painter->isActive()) 0122 painter->end(); 0123 delete painter; 0124 painter = 0; 0125 stop = false; 0126 } 0127 0128 void printPage(const QVariant &page) { 0129 painter->restore(); // state after page preparation 0130 painter->save(); 0131 parent->printPage(page.toInt(), *painter); 0132 painter->restore(); 0133 if (!stop && shapeManager) { 0134 shapeManager->paint(*painter, zoomer, true); 0135 } 0136 painter->restore(); // state before page preparation 0137 0138 if (parent->property("blocking").toBool()) { 0139 return; 0140 } 0141 } 0142 0143 void printingDone() { 0144 0145 // printing done! 0146 painter->end(); 0147 progress->cancel(); 0148 parent->printingDone(); 0149 pageNumber->setText(i18n("Printing done")); 0150 button->setText(i18n("Close")); 0151 stop = true; 0152 QTimer::singleShot(1200, dialog, SLOT(accept())); 0153 if (removePolicy == KoPrintJob::DeleteWhenDone) { 0154 parent->deleteLater(); 0155 } 0156 else { 0157 resetValues(); 0158 } 0159 0160 } 0161 0162 void stopPressed() { 0163 if (stop) { // pressed a second time. 0164 dialog->done(0); 0165 return; 0166 } 0167 stop = true; 0168 progress->cancel(); 0169 parent->printingDone(); 0170 pageNumber->setText(i18n("Stopped")); 0171 QTimer::singleShot(1200, dialog, SLOT(accept())); 0172 if (removePolicy == KoPrintJob::DeleteWhenDone) 0173 parent->deleteLater(); 0174 else 0175 resetValues(); 0176 } 0177 0178 KoPrintingDialog *parent; 0179 KoZoomHandler zoomer; 0180 0181 volatile bool stop; 0182 KoShapeManager *shapeManager; 0183 QPainter *painter; 0184 QPrinter *printer; 0185 int index; // index in the pages list. 0186 KoProgressUpdater *progress; 0187 QLabel *pageNumber; 0188 QPushButton *button; 0189 QList<int> pageRange; ///< user requested list of pages 0190 QList<int> pages; ///< effective list of pages 0191 QList< QPointer<KoUpdater> > updaters; 0192 QDialog *dialog; 0193 KoPrintJob::RemovePolicy removePolicy; 0194 }; 0195 0196 #endif