File indexing completed on 2024-05-05 04:43:23
0001 /* This file is part of the KDE project 0002 Copyright (C) 2015 by Adam Pigg (adam@piggz.co.uk) 0003 Copyright (C) 2017 Jarosław Staniek <staniek@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.1 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 0021 #include "KReportView.h" 0022 #include "KReportPage.h" 0023 #include "KReportRenderObjects.h" 0024 #include "KReportPreRenderer.h" 0025 #include "KReportRendererBase.h" 0026 #include "kreport_debug.h" 0027 0028 #include <QLabel> 0029 #include <QBoxLayout> 0030 #include <QScrollArea> 0031 #include <QLayout> 0032 #include <QPainter> 0033 #include <QPointer> 0034 #include <QGraphicsView> 0035 #include <QGraphicsScene> 0036 #include <QScrollBar> 0037 0038 //! @internal 0039 class Q_DECL_HIDDEN KReportView::Private 0040 { 0041 public: 0042 explicit Private() 0043 : reportPage(nullptr) 0044 , currentPage(1) 0045 , pageCount(0) 0046 {} 0047 0048 ~Private() 0049 {} 0050 0051 //! Move to page @a page (counted from 1) 0052 void moveToPage(int page) 0053 { 0054 if (page != currentPage && page >= 1 && page <= pageCount) { 0055 currentPage = page; 0056 reportPage->renderPage(currentPage); 0057 } 0058 } 0059 0060 QPointer<ORODocument> reportDocument; 0061 QGraphicsView *reportView; 0062 QGraphicsScene *reportScene; 0063 KReportPage *reportPage; 0064 0065 int currentPage; 0066 int pageCount; 0067 0068 KReportRendererFactory factory; 0069 }; 0070 0071 0072 KReportView::KReportView(QWidget *parent) 0073 : QWidget(parent), d(new Private()) 0074 { 0075 setObjectName(QLatin1String("KReportView")); 0076 0077 d->reportView = new QGraphicsView(this); 0078 // page selector should be always visible: 0079 d->reportView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 0080 0081 QVBoxLayout *l = new QVBoxLayout; 0082 l->setMargin(0); 0083 setLayout(l); 0084 0085 layout()->addWidget(d->reportView); 0086 0087 d->reportScene = new QGraphicsScene(this); 0088 d->reportScene->setSceneRect(0,0,1000,2000); 0089 d->reportView->setScene(d->reportScene); 0090 0091 d->reportScene->setBackgroundBrush(palette().brush(QPalette::Dark)); 0092 } 0093 0094 KReportView::~KReportView() 0095 { 0096 //kreportDebug(); 0097 delete d; 0098 } 0099 0100 void KReportView::moveToFirstPage() 0101 { 0102 d->moveToPage(1); 0103 } 0104 0105 void KReportView::moveToLastPage() 0106 { 0107 d->moveToPage(d->pageCount); 0108 } 0109 0110 void KReportView::moveToNextPage() 0111 { 0112 d->moveToPage(d->currentPage + 1); 0113 } 0114 0115 void KReportView::moveToPreviousPage() 0116 { 0117 d->moveToPage(d->currentPage - 1); 0118 } 0119 0120 void KReportView::moveToPage(int page) 0121 { 0122 d->moveToPage(page); 0123 } 0124 0125 int KReportView::currentPage() const 0126 { 0127 return d->currentPage; 0128 } 0129 0130 int KReportView::pageCount() const 0131 { 0132 return d->pageCount; 0133 } 0134 0135 void KReportView::setDocument(ORODocument* doc) 0136 { 0137 d->reportDocument = doc; 0138 0139 if (d->reportPage) { 0140 delete d->reportPage; 0141 } 0142 0143 d->pageCount = doc->pageCount(); 0144 0145 d->reportPage = new KReportPage(this, d->reportDocument); 0146 d->reportPage->setObjectName(QLatin1String("KReportPage")); 0147 0148 d->reportScene->setSceneRect(0,0,d->reportPage->rect().width() + 40, d->reportPage->rect().height() + 40); 0149 d->reportScene->addItem(d->reportPage); 0150 d->reportPage->setPos(20,20); 0151 d->reportView->centerOn(0,0); 0152 0153 } 0154 0155 QAbstractScrollArea* KReportView::scrollArea() 0156 { 0157 return d->reportView; 0158 } 0159 0160 void KReportView::refreshCurrentPage() 0161 { 0162 //kreportDebug() << "Refreshing current page" << d->currentPage; 0163 if (d->reportPage) { 0164 d->reportPage->renderPage(d->currentPage); 0165 } 0166 } 0167