KReport

KReportPage.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
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
33class Q_DECL_HIDDEN KReportPage::Private
34{
35public:
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;
49 KReportRendererBase *renderer;
50 QTimer renderTimer;
51};
52
53
54KReportPage::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
78KReportPage::~KReportPage()
79{
80 delete d;
81}
82
83void 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
103void 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
113void KReportPage::renderCurrentPage()
114{
115 renderPage(d->page + 1);
116}
Provides a widget that renders a specific page of an ORODocument The widget is sized to the document ...
Definition KReportPage.h:34
void renderPage(int page)
Renders page page (counted from 1).
Base class for report renderers.
virtual bool render(const KReportRendererContext &context, ORODocument *document, int page=-1)=0
Render the page of the given document within the given context.
Factory for creating renderers.
Represents a single document containing one or more OROPage elements.
void update(const QRectF &rect)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void fill(const QColor &color)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.