KReport

KReportPage.cpp
1 /* This file is part of the KDE project
2  * Copyright (C) 2007-2008 by Adam Pigg ([email protected])
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "KReportPage.h"
19 
20 #include "KReportRendererBase.h"
21 #include "KReportUnit.h"
22 #include "KReportRenderObjects.h"
23 #include "KReportUtils_p.h"
24 #include "kreport_debug.h"
25 
26 #include <QPainter>
27 #include <QPixmap>
28 #include <QPointer>
29 #include <QTimer>
30 #include <QWidget>
31 
32 //! @internal
33 class Q_DECL_HIDDEN KReportPage::Private
34 {
35 public:
36  explicit Private(ORODocument *document)
37  : reportDocument(document)
38  {}
39 
40  ~Private()
41  {
42  delete renderer;
43  }
44 
45  QPointer<ORODocument> reportDocument;
46  int page;
47  QPixmap pixmap;
48  KReportRendererFactory factory;
49  KReportRendererBase *renderer;
50  QTimer renderTimer;
51 };
52 
53 
54 KReportPage::KReportPage(QWidget *parent, ORODocument *document)
55  : QObject(parent), QGraphicsRectItem()
56  , d(new Private(document))
57 {
58  Q_ASSERT(document);
59 
60  int pageWidth;
61  int pageHeight;
62 
63  pageWidth = d->reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).width();
64  pageHeight = d->reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).height();
65 
66  setRect(0, 0, pageWidth, pageHeight);
67  //kreportDebug() << "PAGE IS " << pageWidth << "x" << pageHeight;
68  d->pixmap = QPixmap(pageWidth, pageHeight);
69  d->renderer = d->factory.createInstance(QLatin1String("screen"));
70  connect(d->reportDocument, SIGNAL(updated(int)), this, SLOT(pageUpdated(int)));
71 
72  d->renderTimer.setSingleShot(true);
73  connect(&d->renderTimer, SIGNAL(timeout()), this, SLOT(renderCurrentPage()));
74 
75  renderPage(1);
76 }
77 
78 KReportPage::~KReportPage()
79 {
80  delete d;
81 }
82 
83 void KReportPage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
84 {
85  Q_UNUSED(option);
86  Q_UNUSED(widget);
87  painter->drawPixmap(QPoint(0, 0), d->pixmap);
88 }
89 
91 {
92  d->page = page - 1;
93  d->pixmap.fill();
94  QPainter qp(&d->pixmap);
95  if (d->reportDocument) {
97  cxt.setPainter(&qp);
98  (void)d->renderer->render(cxt, d->reportDocument, d->page);
99  }
100  update();
101 }
102 
103 void KReportPage::pageUpdated(int pageNo)
104 {
105  //kreportDebug() << pageNo << d->page;
106  //Refresh this page if it changes
107  if (pageNo == d->page) {
108  //kreportDebug() << "Current page updated";
109  d->renderTimer.start(100);
110  }
111 }
112 
113 void KReportPage::renderCurrentPage()
114 {
115  renderPage(d->page + 1);
116 }
Factory for creating renderers.
Provides a widget that renders a specific page of an ORODocument The widget is sized to the document ...
Definition: KReportPage.h:33
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
void update(const QRectF &rect)
Represents a single document containing one or more OROPage elements.
void renderPage(int page)
Renders page page (counted from 1).
Definition: KReportPage.cpp:90
Base class for report renderers.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:17:37 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.