KReport

KReportView.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2015 by Adam Pigg (adam@piggz.co.uk)
3 Copyright (C) 2017 Jarosław Staniek <staniek@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "KReportView.h"
22#include "KReportPage.h"
23#include "KReportRenderObjects.h"
24#include "KReportPreRenderer.h"
25#include "KReportRendererBase.h"
26#include "kreport_debug.h"
27
28#include <QLabel>
29#include <QBoxLayout>
30#include <QScrollArea>
31#include <QLayout>
32#include <QPainter>
33#include <QPointer>
34#include <QGraphicsView>
35#include <QGraphicsScene>
36#include <QScrollBar>
37
38//! @internal
39class Q_DECL_HIDDEN KReportView::Private
40{
41public:
42 explicit Private()
43 : reportPage(nullptr)
44 , currentPage(1)
45 , pageCount(0)
46 {}
47
48 ~Private()
49 {}
50
51 //! Move to page @a page (counted from 1)
52 void moveToPage(int page)
53 {
54 if (page != currentPage && page >= 1 && page <= pageCount) {
55 currentPage = page;
56 reportPage->renderPage(currentPage);
57 }
58 }
59
60 QPointer<ORODocument> reportDocument;
61 QGraphicsView *reportView;
62 QGraphicsScene *reportScene;
63 KReportPage *reportPage;
64
65 int currentPage;
66 int pageCount;
67
69};
70
71
72KReportView::KReportView(QWidget *parent)
73 : QWidget(parent), d(new Private())
74{
75 setObjectName(QLatin1String("KReportView"));
76
77 d->reportView = new QGraphicsView(this);
78 // page selector should be always visible:
79 d->reportView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
80
81 QVBoxLayout *l = new QVBoxLayout;
82 l->setMargin(0);
83 setLayout(l);
84
85 layout()->addWidget(d->reportView);
86
87 d->reportScene = new QGraphicsScene(this);
88 d->reportScene->setSceneRect(0,0,1000,2000);
89 d->reportView->setScene(d->reportScene);
90
91 d->reportScene->setBackgroundBrush(palette().brush(QPalette::Dark));
92}
93
94KReportView::~KReportView()
95{
96 //kreportDebug();
97 delete d;
98}
99
100void KReportView::moveToFirstPage()
101{
102 d->moveToPage(1);
103}
104
105void KReportView::moveToLastPage()
106{
107 d->moveToPage(d->pageCount);
108}
109
110void KReportView::moveToNextPage()
111{
112 d->moveToPage(d->currentPage + 1);
113}
114
115void KReportView::moveToPreviousPage()
116{
117 d->moveToPage(d->currentPage - 1);
118}
119
121{
122 d->moveToPage(page);
123}
124
126{
127 return d->currentPage;
128}
129
130int KReportView::pageCount() const
131{
132 return d->pageCount;
133}
134
135void KReportView::setDocument(ORODocument* doc)
136{
137 d->reportDocument = doc;
138
139 if (d->reportPage) {
140 delete d->reportPage;
141 }
142
143 d->pageCount = doc->pageCount();
144
145 d->reportPage = new KReportPage(this, d->reportDocument);
146 d->reportPage->setObjectName(QLatin1String("KReportPage"));
147
148 d->reportScene->setSceneRect(0,0,d->reportPage->rect().width() + 40, d->reportPage->rect().height() + 40);
149 d->reportScene->addItem(d->reportPage);
150 d->reportPage->setPos(20,20);
151 d->reportView->centerOn(0,0);
152
153}
154
155QAbstractScrollArea* KReportView::scrollArea()
156{
157 return d->reportView;
158}
159
160void KReportView::refreshCurrentPage()
161{
162 //kreportDebug() << "Refreshing current page" << d->currentPage;
163 if (d->reportPage) {
164 d->reportPage->renderPage(d->currentPage);
165 }
166}
167
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).
Factory for creating renderers.
Provides a simple widget for viewing a rendered report on screen.
Definition KReportView.h:35
int currentPage() const
void moveToPage(int page)
Moves to page page (counted from 1)
Represents a single document containing one or more OROPage elements.
int pageCount() const
Return the total number of pages in the document.
void setPos(const QPointF &pos)
QRectF rect() const const
void addItem(QGraphicsItem *item)
void setSceneRect(const QRectF &rect)
void centerOn(const QGraphicsItem *item)
void setObjectName(QAnyStringView name)
qreal height() const const
qreal width() const const
ScrollBarAlwaysOn
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.