Warning, file /office/calligra/libs/pageapp/KoPAPrintJob.cpp 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) 2009 Thorsten Zachmann <zachmann@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 
0020 #include "KoPAPrintJob.h"
0021 
0022 #include <KoText.h>
0023 #include "KoPAView.h"
0024 #include "KoPADocument.h"
0025 #include "KoPAUtil.h"
0026 #include "KoPAPageBase.h"
0027 #include "KoPAPageProvider.h"
0028 #include <KoZoomHandler.h>
0029 
0030 #include <QPainter>
0031 
0032 KoPAPrintJob::KoPAPrintJob(KoPAView * view)
0033 : KoPrintJob(view)
0034 , m_pages(view->kopaDocument()->pages())
0035 {
0036     QVariant var = view->kopaDocument()->resourceManager()->resource(KoText::PageProvider);
0037     m_pageProvider = static_cast<KoPAPageProvider*>(var.value<void*>());
0038     // TODO this feels wrong
0039     printer().setFromTo(1, m_pages.size());
0040 }
0041 
0042 KoPAPrintJob::~KoPAPrintJob()
0043 {
0044 }
0045 
0046 QPrinter & KoPAPrintJob::printer()
0047 {
0048     return m_printer;
0049 }
0050 
0051 QList<QWidget*> KoPAPrintJob::createOptionWidgets() const
0052 {
0053     return QList<QWidget*>();
0054 }
0055 
0056 // TODO create a lot of fancy options for printing
0057 // e.g. print also notes
0058 // For now we print to the center of the page honoring the margins
0059 // The page is zoomed to be as big as possible
0060 void KoPAPrintJob::startPrinting(RemovePolicy removePolicy)
0061 {
0062     int fromPage = m_printer.fromPage() ? m_printer.fromPage() - 1: 0;
0063     int toPage = m_printer.toPage() ? m_printer.toPage() - 1: m_pages.size() - 1;
0064 
0065     Q_ASSERT( fromPage >= 0 && fromPage < m_pages.size() );
0066     Q_ASSERT( toPage >= 0 && toPage < m_pages.size() );
0067 
0068     KoZoomHandler zoomHandler;
0069     zoomHandler.setResolution( m_printer.resolution(), m_printer.resolution() );
0070 
0071     QSize size = m_printer.pageRect().size();
0072 
0073     QPainter painter( &m_printer );
0074     for ( int i = fromPage; i <= toPage; ++i ) {
0075         painter.save();
0076         if (i != fromPage) {
0077             m_printer.newPage();
0078         }
0079 
0080         KoPAPageBase * page = m_pages.at(i);
0081         const KoPageLayout & layout = page->pageLayout();
0082         KoPAUtil::setZoom( layout, size, zoomHandler );
0083         QRect pageRect( KoPAUtil::pageRect( layout, size, zoomHandler ) );
0084 
0085         painter.setClipRect( pageRect );
0086         painter.setRenderHint( QPainter::Antialiasing );
0087         painter.translate( pageRect.topLeft() );
0088         m_pageProvider->setPageData(i + 1, page);
0089         page->paintPage( painter, zoomHandler );
0090         painter.restore();
0091     }
0092 
0093     if ( removePolicy == DeleteWhenDone ) {
0094         deleteLater();
0095     }
0096 }