diff --git a/src/renderer/KReportHTMLCSSRenderer_p.cpp b/src/renderer/KReportHTMLCSSRenderer_p.cpp index 15c4576b..cc9e83cc 100644 --- a/src/renderer/KReportHTMLCSSRenderer_p.cpp +++ b/src/renderer/KReportHTMLCSSRenderer_p.cpp @@ -1,221 +1,221 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportHTMLCSSRenderer_p.h" #include "KReportRenderObjects.h" #include "kreport_debug.h" #include #include #include #include namespace KReportPrivate { HTMLCSSRenderer::HTMLCSSRenderer() { } HTMLCSSRenderer::~HTMLCSSRenderer() { } bool HTMLCSSRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) { Q_UNUSED(page); QTemporaryFile tempHtmlFile; // auto removed by default on destruction if (!tempHtmlFile.open()) { kreportWarning() << "Couldn't create temporary file to write into"; return false; } QTextStream out(&tempHtmlFile); QString dirSuffix = QLatin1String(".files"); QDir tempDir; QFileInfo fi(tempHtmlFile); QString tempFileName = fi.absoluteFilePath(); m_tempDirName = tempFileName + dirSuffix; - m_actualDirName = context.destinationUrl.fileName() + dirSuffix; + m_actualDirName = context.url().fileName() + dirSuffix; if (!tempDir.mkpath(m_tempDirName)) return false; out << renderCSS(document); out.flush(); tempHtmlFile.close(); bool status = true; //!< @todo KIO // if (KIO::NetAccess::upload(tempFileName, context.destinationUrl, 0) && KIO::NetAccess::dircopy(QUrl(m_tempDirName), QUrl(context.destinationUrl.url() + dirSuffix), 0)) { // status = true; // } // cleanup the temporary directory tempDir.setPath(m_tempDirName); QStringList fileList = tempDir.entryList(); foreach(const QString& fileName, fileList) { tempDir.remove(fileName); } tempDir.rmdir(m_tempDirName); return status; } //! @todo use QTextStream for efficiency QString HTMLCSSRenderer::renderCSS(ORODocument *document) { QString html; QString body; QString style; QStringList styles; int styleindex; bool renderedPageHead = false; bool renderedPageFoot = false; QDir d(m_tempDirName); // Render Each Section for (int s = 0; s < document->sectionCount(); s++) { OROSection *section = document->section(s); if (section->type() == KReportSectionData::GroupHeader || section->type() == KReportSectionData::GroupFooter || section->type() == KReportSectionData::Detail || section->type() == KReportSectionData::ReportHeader || section->type() == KReportSectionData::ReportFooter || (section->type() == KReportSectionData::PageHeaderAny && !renderedPageHead) || (section->type() == KReportSectionData::PageFooterAny && !renderedPageFoot && s > document->sectionCount() - 2)) { //render the page foot right at the end, it will either be the last or second last section if there is a report footer if (section->type() == KReportSectionData::PageHeaderAny) renderedPageHead = true; if (section->type() == KReportSectionData::PageFooterAny) renderedPageFoot = true; style = QLatin1String("position: relative; top: 0pt; left: 0pt; background-color: ") + section->backgroundColor().name() + QLatin1String("; height: ") + QString::number(section->height()) + QLatin1String("pt;"); if (!styles.contains(style)) { styles << style; } styleindex = styles.indexOf(style); body += QLatin1String("
\n"); //Render the objects in each section for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); //kreportDebug() << "Got object type" << prim->type(); if (dynamic_cast(prim)) { OROTextBox * tb = dynamic_cast(prim); QColor bg = tb->textStyle().backgroundColor; style = QLatin1String("position: absolute; ") + QLatin1String("background-color: ") + QString::fromLatin1("rgba(%1,%2,%3,%4)") .arg(bg.red()) .arg(bg.green()) .arg(bg.blue()) .arg(0.01 * tb->textStyle().backgroundOpacity) +QLatin1String( "; ") + QLatin1String("top: ") + QString::number(tb->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(tb->position().x()) + QLatin1String("pt; ") + QLatin1String("font-size: ") + QString::number(tb->textStyle().font.pointSize()) + QLatin1String("pt; ") + QLatin1String("color: ") + tb->textStyle().foregroundColor.name() + QLatin1String("; ") + QLatin1String("width: ") + QString::number(tb->size().width()) + QLatin1String("px;") + QLatin1String("height: ") + QString::number(tb->size().height()) + QLatin1String("px;") ; //! @todo opaque text + translucent background //it looks a pain to implement //http://developer.mozilla.org/en/docs/Useful_CSS_tips:Color_and_Background //style += "filter:alpha(opacity=" + QString::number((tb->textStyle().bgOpacity / 255) * 100) + ");"; //ie opacity //style += "opacity: " + QString::number(tb->textStyle().bgOpacity / 255.0) + ";"; if (!styles.contains(style)) { styles << style; } styleindex = styles.indexOf(style); body += QLatin1String("
") + tb->text() + QLatin1String("
\n"); } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving an image"; OROImage * im = dynamic_cast(prim); style = QLatin1String("position: absolute; ") + QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); if (!styles.contains(style)) { styles << style; } styleindex = styles.indexOf(style); body += QLatin1String("
") + QLatin1String("size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\">") + QLatin1String("
\n"); im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving a picture"; OROPicture * im = dynamic_cast(prim); style = QLatin1String("position: absolute; ") + QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); if (!styles.contains(style)) { styles << style; } styleindex = styles.indexOf(style); body += QLatin1String("
") + QLatin1String("size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\">") + QLatin1String("
\n"); QImage image(im->size().toSize(), QImage::Format_RGB32); QPainter painter(&image); im->picture()->play(&painter); image.save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else { kreportWarning() << "unrecognized primitive type"; } } body += QLatin1String("
\n"); } } //! @todo add option for creating separate css file html = QLatin1String("\n" "\n" "\n" "\n") + QLatin1String("") + document->title() + QLatin1String("\n") + QLatin1String("\n") + QLatin1String("\n") + QLatin1String("\n") + QLatin1String("\n") + body + QLatin1String("\n\n") + QLatin1String("\n"); return html; } } diff --git a/src/renderer/KReportHTMLTableRenderer_p.cpp b/src/renderer/KReportHTMLTableRenderer_p.cpp index b8b84294..78dc4053 100644 --- a/src/renderer/KReportHTMLTableRenderer_p.cpp +++ b/src/renderer/KReportHTMLTableRenderer_p.cpp @@ -1,172 +1,172 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportHTMLTableRenderer_p.h" #include "KReportRenderObjects.h" #include #include "kreport_debug.h" #include #include #include namespace KReportPrivate { HTMLTableRenderer::HTMLTableRenderer() { } HTMLTableRenderer::~HTMLTableRenderer() { } bool HTMLTableRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) { Q_UNUSED(page); QTemporaryFile tempHtmlFile; // auto removed by default on destruction if (!tempHtmlFile.open()) { kreportWarning() << "Couldn't create temporary file to write into"; return false; } QTextStream out(&tempHtmlFile); QString dirSuffix = QLatin1String(".files"); QDir tempDir; QFileInfo fi(tempHtmlFile); QString tempFileName = fi.absoluteFilePath(); m_tempDirName = tempFileName + dirSuffix; - m_actualDirName = context.destinationUrl.fileName() + dirSuffix; + m_actualDirName = context.url().fileName() + dirSuffix; if (!tempDir.mkpath(m_tempDirName)) return false; out << renderTable(document); out.flush(); tempHtmlFile.close(); bool status = true; //! @todo port KIO; // if (KIO::NetAccess::upload(tempFileName, context.destinationUrl, 0) && KIO::NetAccess::dircopy(QUrl(m_tempDirName), QUrl(context.destinationUrl.url() + dirSuffix), 0)) { // status = true; // } // cleanup the temporary directory tempDir.setPath(m_tempDirName); QStringList fileList = tempDir.entryList(); foreach(const QString& fileName, fileList) { tempDir.remove(fileName); } tempDir.rmdir(m_tempDirName); return status; } QString HTMLTableRenderer::renderTable(ORODocument *document) { QString html; QString body; QString tr; bool renderedPageHeader = false; bool renderedPageFooter = false; QDir d(m_tempDirName); // Render Each Section body = QLatin1String("\n"); for (int s = 0; s < document->sectionCount(); s++) { OROSection *section = document->section(s); section->sortPrimitives(Qt::Horizontal); if (section->type() == KReportSectionData::GroupHeader || section->type() == KReportSectionData::GroupFooter || section->type() == KReportSectionData::Detail || section->type() == KReportSectionData::ReportHeader || section->type() == KReportSectionData::ReportFooter || (section->type() == KReportSectionData::PageHeaderAny && !renderedPageHeader) || (section->type() == KReportSectionData::PageFooterAny && !renderedPageFooter && s > document->sectionCount() - 2)) { //render the page foot right at the end, it will either be the last or second last section if there is a report footer if (section->type() == KReportSectionData::PageHeaderAny) renderedPageHeader = true; if (section->type() == KReportSectionData::PageFooterAny) renderedPageFooter = true; tr = QLatin1String("backgroundColor().name() + QLatin1String("\">\n"); //Render the objects in each section for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); if (dynamic_cast(prim)) { OROTextBox * tb = dynamic_cast(prim); tr += QLatin1String("\n"); } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving an image"; OROImage * im = dynamic_cast(prim); tr += QLatin1String("\n"); im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving a picture"; OROPicture * im = dynamic_cast(prim); tr += QLatin1String("\n"); QImage image(im->size().toSize(), QImage::Format_RGB32); QPainter painter(&image); im->picture()->play(&painter); image.save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else { kreportWarning() << "unhandled primitive type"; } } tr += QLatin1String("\n"); if (tr.contains(QLatin1String("
") + tb->text() + QLatin1String("" "" "" "" "
"))) { body += tr; } } } body += QLatin1String("
\n"); html = QLatin1String("\n" "\n" "\n" "") + document->title() + QLatin1String("\n" "\n" "\n" "\n" "\n") + body + QLatin1String("\n\n" "\n"); return html; } } diff --git a/src/renderer/KReportPage.cpp b/src/renderer/KReportPage.cpp index 42f4782e..cd3b2230 100644 --- a/src/renderer/KReportPage.cpp +++ b/src/renderer/KReportPage.cpp @@ -1,131 +1,131 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportPage.h" #include "KReportRendererBase.h" #include "KReportUnit.h" #include "KReportRenderObjects.h" #include "KReportDpi.h" #include "kreport_debug.h" #include #include #include #include //! @internal class Q_DECL_HIDDEN KReportPage::Private { public: explicit Private(ORODocument *document) : reportDocument(document) , page(0) {} ~Private() { delete renderer; } ORODocument *reportDocument; int page; QPixmap pixmap; KReportRendererFactory factory; KReportRendererBase *renderer; QTimer renderTimer; }; KReportPage::KReportPage(QWidget *parent, ORODocument *document) : QObject(parent), QGraphicsRectItem() , d(new Private(document)) { Q_ASSERT(document); int pageWidth; int pageHeight; QString pageSize = d->reportDocument->pageLayout().pageSize().name(); pageWidth = d->reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).width(); pageHeight = d->reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).height(); //TODO remove after check #if 0 if (pageSize == QLatin1String("Custom")) { // if this is custom sized sheet of paper we will just use those values } else { // lookup the correct size information for the specified size paper pageWidth = d->reportDocument->pageOptions().pixelSize().width(); pageHeight = d->reportDocument->pageOptions().pixelSize().height(); } #endif setRect(0, 0, pageWidth, pageHeight); //kreportDebug() << "PAGE IS " << pageWidth << "x" << pageHeight; d->pixmap = QPixmap(pageWidth, pageHeight); d->renderer = d->factory.createInstance(QLatin1String("screen")); connect(d->reportDocument, SIGNAL(updated(int)), this, SLOT(pageUpdated(int))); d->renderTimer.setSingleShot(true); connect(&d->renderTimer, SIGNAL(timeout()), this, SLOT(renderCurrentPage())); renderPage(1); } KReportPage::~KReportPage() { delete d; } void KReportPage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->drawPixmap(QPoint(0, 0), d->pixmap); } void KReportPage::renderPage(int page) { d->page = page - 1; d->pixmap.fill(); QPainter qp(&d->pixmap); if (d->reportDocument) { KReportRendererContext cxt; - cxt.painter = &qp; + cxt.setPainter(&qp); d->renderer->render(cxt, d->reportDocument, d->page); } update(); } void KReportPage::pageUpdated(int pageNo) { //kreportDebug() << pageNo << d->page; //Refresh this page if it changes if (pageNo == d->page) { //kreportDebug() << "Current page updated"; d->renderTimer.start(100); } } void KReportPage::renderCurrentPage() { renderPage(d->page + 1); } diff --git a/src/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp index e125da27..ead0dbd9 100644 --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -1,261 +1,261 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportPrintRenderer_p.h" #include "kreport_debug.h" #include "KReportRenderObjects.h" #include "KReportPageSize.h" #include "KReportDpi.h" #include #include #include namespace KReportPrivate { PrintRenderer::PrintRenderer() { } PrintRenderer::~PrintRenderer() { } bool PrintRenderer::setupPrinter( ORODocument * document, QPrinter * pPrinter) { if (document == 0 || pPrinter == 0) return false; pPrinter->setCreator(QLatin1String("KReport Print Renderer")); pPrinter->setDocName(document->title()); pPrinter->setFullPage(true); pPrinter->setOrientation((document->pageLayout().orientation() == QPageLayout::Portrait ? QPrinter::Portrait : QPrinter::Landscape)); pPrinter->setPageOrder(QPrinter::FirstPageFirst); if (!document->pageLayout().pageSize().isValid()) { pPrinter->setPageSize(QPrinter::Custom); } else { pPrinter->setPageSize(QPageSize(document->pageLayout().pageSize())); } return true; } bool PrintRenderer::render(const KReportRendererContext &context, ORODocument *document, int page) { Q_UNUSED(page); - if (document == 0 || context.printer == 0 || context.painter == 0) + if (document == 0 || context.printer() == 0 || context.painter() == 0) return false; - setupPrinter(document, context.printer); + setupPrinter(document, context.printer()); bool endWhenComplete = false; - if (!context.painter->isActive()) { + if (!context.painter()->isActive()) { endWhenComplete = true; - if (!context.painter->begin(context.printer)) + if (!context.painter()->begin(context.printer())) return false; } - int fromPage = context.printer->fromPage(); + int fromPage = context.printer()->fromPage(); if (fromPage > 0) fromPage -= 1; - int toPage = context.printer->toPage(); + int toPage = context.printer()->toPage(); if (toPage == 0 || toPage > document->pageCount()) toPage = document->pageCount(); - qreal scaleX = context.printer->resolution() / qreal(KReportDpi::dpiX()); - qreal scaleY = context.printer->resolution() / qreal(KReportDpi::dpiY()); + qreal scaleX = context.printer()->resolution() / qreal(KReportDpi::dpiX()); + qreal scaleY = context.printer()->resolution() / qreal(KReportDpi::dpiY()); - for (int copy = 0; copy < context.printer->numCopies(); copy++) { + for (int copy = 0; copy < context.printer()->numCopies(); copy++) { for (int page = fromPage; page < toPage; page++) { if (page > fromPage) - context.printer->newPage(); + context.printer()->newPage(); OROPage * p = document->page(page); - if (context.printer->pageOrder() == QPrinter::LastPageFirst) + if (context.printer()->pageOrder() == QPrinter::LastPageFirst) p = document->page(toPage - 1 - page); // Render Page Objects for (int i = 0; i < p->primitiveCount(); i++) { OROPrimitive * prim = p->primitive(i); prim->setPosition(QPointF(prim->position().x() * scaleX, prim->position().y() * scaleY)); prim->setSize(QSizeF(prim->size().width() * scaleX, prim->size().height() * scaleY)); //kreportDebug() << "Rendering object" << i << "type" << prim->type(); if (dynamic_cast(prim)) { //kreportDebug() << "Text Box"; OROTextBox * tb = dynamic_cast(prim); QPointF ps = tb->position(); QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); //Background QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); - //_painter->setBackgroundMode(Qt::OpaqueMode); - context.painter->fillRect(rc, bg); + //_painter()->setBackgroundMode(Qt::OpaqueMode); + context.painter()->fillRect(rc, bg); //Text - context.painter->setBackgroundMode(Qt::TransparentMode); - context.painter->setFont(tb->textStyle().font); - context.painter->setPen(tb->textStyle().foregroundColor); - context.painter->drawText(rc, tb->flags(), tb->text()); + context.painter()->setBackgroundMode(Qt::TransparentMode); + context.painter()->setFont(tb->textStyle().font); + context.painter()->setPen(tb->textStyle().foregroundColor); + context.painter()->drawText(rc, tb->flags(), tb->text()); //outer line - context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * scaleX, tb->lineStyle().penStyle())); - context.painter->drawRect(rc); + context.painter()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * scaleX, tb->lineStyle().penStyle())); + context.painter()->drawRect(rc); //Reset back to defaults for next element - context.painter->restore(); + context.painter()->restore(); } else if (dynamic_cast(prim)) { //kreportDebug() << "Line"; OROLine * ln = dynamic_cast(prim); QPointF s = ln->startPoint(); QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * scaleY); - //QPen pen ( _painter->pen() ); + //QPen pen ( _painter()->pen() ); QPen pen(ln->lineStyle().color(), ln->lineStyle().width() * scaleX, ln->lineStyle().penStyle()); - context.painter->save(); - context.painter->setRenderHint(QPainter::Antialiasing, true); - context.painter->setPen(pen); - context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); - context.painter->setRenderHint(QPainter::Antialiasing, false); - context.painter->restore(); + context.painter()->save(); + context.painter()->setRenderHint(QPainter::Antialiasing, true); + context.painter()->setPen(pen); + context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); + context.painter()->setRenderHint(QPainter::Antialiasing, false); + context.painter()->restore(); } else if (dynamic_cast(prim)) { //kreportDebug() << "Image"; OROImage * im = dynamic_cast(prim); QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); QImage img = im->image(); if (im->isScaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); - context.painter->drawImage(rc.topLeft(), img, sr); + context.painter()->drawImage(rc.topLeft(), img, sr); } else if (dynamic_cast(prim)) { //kreportDebug() << "Rect"; ORORect * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawRect(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawRect(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROEllipse * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawEllipse(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawEllipse(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROPicture * im = dynamic_cast(prim); QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->drawPicture(rc.topLeft(), *(im->picture())); + context.painter()->drawPicture(rc.topLeft(), *(im->picture())); } else if (dynamic_cast(prim)) { OROCheckBox * chk = dynamic_cast(prim); QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); - context.painter->setBackgroundMode(Qt::OpaqueMode); - context.painter->setRenderHint(QPainter::Antialiasing); + context.painter()->setBackgroundMode(Qt::OpaqueMode); + context.painter()->setRenderHint(QPainter::Antialiasing); - context.painter->setPen(chk->foregroundColor()); + context.painter()->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { - context.painter->setPen(QPen(Qt::lightGray)); + context.painter()->setPen(QPen(Qt::lightGray)); } else { - context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); + context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == OROCheckBox::Cross) { - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); - context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); + context.painter()->setPen(lp); + context.painter()->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); + context.painter()->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); } } else if (chk->checkType() == OROCheckBox::Dot) { //Radio Style - context.painter->drawEllipse(rc); + context.painter()->drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); - context.painter->setBrush(lb); - context.painter->setPen(Qt::NoPen); - context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); + context.painter()->setBrush(lb); + context.painter()->setPen(Qt::NoPen); + context.painter()->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); - context.painter->drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); + context.painter()->setPen(lp); + context.painter()->drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); + context.painter()->drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } - context.painter->restore(); + context.painter()->restore(); } } } } if (endWhenComplete) - context.painter->end(); + context.painter()->end(); return true; } } diff --git a/src/renderer/KReportRendererBase.cpp b/src/renderer/KReportRendererBase.cpp index 82713b11..72eef79f 100644 --- a/src/renderer/KReportRendererBase.cpp +++ b/src/renderer/KReportRendererBase.cpp @@ -1,77 +1,154 @@ /* This file is part of the KDE project Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KReportRendererBase.h" #include "KReportScreenRenderer_p.h" #include "KReportPrintRenderer_p.h" #include "KReportKSpreadRenderer.h" #include "KReportHTMLTableRenderer_p.h" #include "KReportHTMLCSSRenderer_p.h" //! @todo port #include "KReportODTRenderer.h" //! @todo port #include "KOdtFrameReportRenderer.h" +class Q_DECL_HIDDEN KReportRendererContext::Private +{ +public: + Private(); + ~Private(); + QUrl destinationUrl; + QPainter *painter = nullptr; + QPrinter *printer = nullptr; +}; + +KReportRendererContext::Private::Private() +{ +} + +KReportRendererContext::Private::~Private() +{ +} + + KReportRendererContext::KReportRendererContext() - : painter(0), printer(0) + : d(new Private()) +{ +} + +KReportRendererContext::~KReportRendererContext() +{ + delete d; +} + +QPainter * KReportRendererContext::painter() const +{ + return d->painter; +} + +QPrinter * KReportRendererContext::printer() const +{ + return d->printer; +} + + +QPainter * KReportRendererContext::painter() { + return d->painter; } +QPrinter * KReportRendererContext::printer() +{ + return d->printer; +} + +void KReportRendererContext::setUrl(const QUrl& url) +{ + d->destinationUrl = url; +} + +void KReportRendererContext::setPainter(QPainter* painter) +{ + d->painter = painter; +} + +void KReportRendererContext::setPrinter(QPrinter* printer) +{ + d->printer = printer; +} + +QUrl KReportRendererContext::url() const +{ + return d->destinationUrl; +} + + KReportRendererBase::KReportRendererBase() { } KReportRendererBase::~KReportRendererBase() { } -KReportRendererFactory::KReportRendererFactory() +class KReportRendererFactory::Private +{ +public: + bool dummy = true; +}; + +KReportRendererFactory::KReportRendererFactory() : d(new Private()) +{ +} + +KReportRendererFactory::~KReportRendererFactory() { + delete d; } KReportRendererBase* KReportRendererFactory::createInstance(const QString& key) { const QString lowerKey = key.toLower(); if (lowerKey == QLatin1String("screen")) { return new KReportPrivate::ScreenRenderer(); } if (lowerKey == QLatin1String("print")) { return new KReportPrivate::PrintRenderer(); } //! @todo port #if 0 if (lowerKey == QLatin1String("ods")) { return new KReportKSpreadRenderer(); } #endif if (lowerKey == QLatin1String("htmltable")) { return new KReportPrivate::HTMLTableRenderer(); } if (lowerKey == QLatin1String("htmlcss")) { return new KReportPrivate::HTMLCSSRenderer(); } //! @todo port #if 0 if (lowerKey == QLatin1String("odttable") || lowerKey == QLatin1String("odt")) { return new KReportODTRenderer(); } if (lowerKey == QLatin1String("odtframes")) { return new KReportOdtFrameReportRenderer(); } #endif return 0; } diff --git a/src/renderer/KReportRendererBase.h b/src/renderer/KReportRendererBase.h index cf5975eb..b4eef63e 100644 --- a/src/renderer/KReportRendererBase.h +++ b/src/renderer/KReportRendererBase.h @@ -1,64 +1,84 @@ /* This file is part of the KDE project Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KREPORTRENDERERBASE_H #define KREPORTRENDERERBASE_H #include #include "kreport_export.h" class QPainter; class QPrinter; class ORODocument; //! Context for executing rendering. class KREPORT_EXPORT KReportRendererContext { public: KReportRendererContext(); - QUrl destinationUrl; - QPainter *painter; - QPrinter *printer; + ~KReportRendererContext(); + + void setUrl(const QUrl& url); + void setPainter(QPainter* painter); + void setPrinter(QPrinter* printer); + + QPrinter *printer(); + QPainter *painter(); + QPrinter *printer() const; + QPainter *painter() const; + + QUrl url() const; + + private: + Q_DISABLE_COPY(KReportRendererContext) + class Private; + Private * const d; }; //! Base class for report renderers. class KREPORT_EXPORT KReportRendererBase { public: KReportRendererBase(); virtual ~KReportRendererBase(); //! Render the page of the given document within the given context. //! If page == -1, renders the entire document. virtual bool render(const KReportRendererContext& context, ORODocument *document, int page = -1) = 0; }; //! Factory for creating renderers //! @todo make it use plugins class KREPORT_EXPORT KReportRendererFactory { public: KReportRendererFactory(); - + ~KReportRendererFactory(); + KReportRendererBase* createInstance(const QString& key); + + private: + Q_DISABLE_COPY(KReportRendererFactory) + class Private; + Private * const d; }; #endif // KREPORTRENDERERBASE_H diff --git a/src/renderer/KReportScreenRenderer_p.cpp b/src/renderer/KReportScreenRenderer_p.cpp index 4df0c90b..838c0e18 100644 --- a/src/renderer/KReportScreenRenderer_p.cpp +++ b/src/renderer/KReportScreenRenderer_p.cpp @@ -1,224 +1,219 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportScreenRenderer_p.h" #include "KReportRenderObjects.h" #include "KReportUnit.h" #include "kreport_debug.h" namespace KReportPrivate { ScreenRenderer::ScreenRenderer() { } ScreenRenderer::~ScreenRenderer() { } -//void KRScreenRender::setPainter(QPainter * pPainter) -//{ -// context.painter = pPainter; -//} - bool ScreenRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) { if (!document) return false; - if (!context.painter) + if (!context.painter()) return false; OROPage *p = document->page(page); if (!p) { return false; } // Render Page Objects for (int i = 0; i < p->primitiveCount(); i++) { OROPrimitive *prim = p->primitive(i); if (dynamic_cast(prim)) { OROTextBox *tb = dynamic_cast(prim); QPointF ps = tb->position(); QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); //Background - context.painter->setBackgroundMode(Qt::TransparentMode); + context.painter()->setBackgroundMode(Qt::TransparentMode); QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); - context.painter->fillRect(rc, bg); + context.painter()->fillRect(rc, bg); //Text - context.painter->setFont(tb->textStyle().font); - context.painter->setPen(tb->textStyle().foregroundColor); - context.painter->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text()); + context.painter()->setFont(tb->textStyle().font); + context.painter()->setPen(tb->textStyle().foregroundColor); + context.painter()->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text()); //outer line - context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width(), tb->lineStyle().penStyle())); - context.painter->drawRect(rc); + context.painter()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width(), tb->lineStyle().penStyle())); + context.painter()->drawRect(rc); //Reset back to defaults for next element - context.painter->restore(); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROLine * ln = dynamic_cast(prim); QPointF s = ln->startPoint(); QPointF e = ln->endPoint(); //QPen pen ( _painter->pen() ); QPen pen(ln->lineStyle().color(), ln->lineStyle().width(), ln->lineStyle().penStyle()); - context.painter->save(); - context.painter->setRenderHint(QPainter::Antialiasing, true); - context.painter->setPen(pen); - context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); - context.painter->setRenderHint(QPainter::Antialiasing, false); - context.painter->restore(); + context.painter()->save(); + context.painter()->setRenderHint(QPainter::Antialiasing, true); + context.painter()->setPen(pen); + context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); + context.painter()->setRenderHint(QPainter::Antialiasing, false); + context.painter()->restore(); } else if (dynamic_cast(prim)) { ORORect * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawRect(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawRect(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROEllipse * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawEllipse(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawEllipse(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROImage * im = dynamic_cast(prim); QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); QImage img = im->image(); if (im->isScaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); - context.painter->drawImage(rc.topLeft(), img, sr); + context.painter()->drawImage(rc.topLeft(), img, sr); } else if (dynamic_cast(prim)) { OROPicture * im = dynamic_cast(prim); QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->drawPicture(rc.topLeft(), *(im->picture())); - context.painter->restore(); + context.painter()->save(); + context.painter()->drawPicture(rc.topLeft(), *(im->picture())); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROCheckBox * chk = dynamic_cast(prim); QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); - context.painter->setBackgroundMode(Qt::OpaqueMode); - context.painter->setRenderHint(QPainter::Antialiasing); + context.painter()->setBackgroundMode(Qt::OpaqueMode); + context.painter()->setRenderHint(QPainter::Antialiasing); - context.painter->setPen(chk->foregroundColor()); + context.painter()->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { - context.painter->setPen(QPen(Qt::lightGray)); + context.painter()->setPen(QPen(Qt::lightGray)); } else { - context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width(), chk->lineStyle().penStyle())); + context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width(), chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == OROCheckBox::Cross) { - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); - context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); + context.painter()->setPen(lp); + context.painter()->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); + context.painter()->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); } } else if (chk->checkType() == OROCheckBox::Dot) { //Radio Style - context.painter->drawEllipse(rc); + context.painter()->drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); - context.painter->setBrush(lb); - context.painter->setPen(Qt::NoPen); - context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); + context.painter()->setBrush(lb); + context.painter()->setPen(Qt::NoPen); + context.painter()->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine( + context.painter()->setPen(lp); + context.painter()->drawLine( QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); - context.painter->drawLine( + context.painter()->drawLine( QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } - context.painter->restore(); + context.painter()->restore(); } else { kreportWarning() << "unrecognized primitive type"; } } return true; } }