diff --git a/src/common/KReportItemLine.cpp b/src/common/KReportItemLine.cpp index 84469276..e285f685 100644 --- a/src/common/KReportItemLine.cpp +++ b/src/common/KReportItemLine.cpp @@ -1,150 +1,150 @@ /* 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 "KReportItemLine.h" #include "KReportRenderObjects.h" #include "kreport_debug.h" #include #include KReportItemLine::KReportItemLine() { createProperties(); } KReportItemLine::KReportItemLine(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; QPointF _s, _e; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); _s.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x1"), QLatin1String("1cm")))); _s.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y1"), QLatin1String("1cm")))); _e.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x2"), QLatin1String("1cm")))); _e.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y2"), QLatin1String("2cm")))); m_start.setPointPos(_s); m_end.setPointPos(_e); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(int(ls.penStyle())); } } else { kreportWarning() << "while parsing line element encountered unknow element: " << n; } } } KReportItemLine::~KReportItemLine() { } void KReportItemLine::createProperties() { m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", (int)Qt::SolidLine, tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_start.setName(QLatin1String("Start")); m_end.setName(QLatin1String("End")); propertySet()->addProperty(m_start.property()); propertySet()->addProperty(m_end.property()); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemLine::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } int KReportItemLine::weight() const { return m_lineWeight->value().toInt(); } void KReportItemLine::setWeight(int w) { m_lineWeight->setValue(w); } QString KReportItemLine::typeName() const { return QLatin1String("line"); } int KReportItemLine::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) Q_UNUSED(data) OROLine * ln = new OROLine(); QPointF s = m_start.toScene(); QPointF e = m_end.toScene(); s += offset; e += offset; ln->setStartPoint(s); ln->setEndPoint(e); ln->setLineStyle(lineStyle()); - if (page) page->addPrimitive(ln); + if (page) page->insertPrimitive(ln); OROLine *l2 = dynamic_cast(ln->clone()); l2->setStartPoint(m_start.toPoint()); l2->setEndPoint(m_end.toPoint()); if (section) section->addPrimitive(l2); return 0; } void KReportItemLine::setUnit(const KReportUnit &u) { m_start.setUnit(u); m_end.setUnit(u); } KReportPosition KReportItemLine::startPosition() const { return m_start; } KReportPosition KReportItemLine::endPosition() const { return m_end; } diff --git a/src/common/KReportRenderObjects.cpp b/src/common/KReportRenderObjects.cpp index 4fc96b26..b4f4186e 100644 --- a/src/common/KReportRenderObjects.cpp +++ b/src/common/KReportRenderObjects.cpp @@ -1,516 +1,969 @@ /* 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 "KReportRenderObjects.h" #include "kreport_debug.h" +// Helper functions +static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2) +{ + return s1->position().x() < s2->position().x(); +} + // // ORODocument // -ORODocument::ORODocument(const QString & pTitle) - : m_title(pTitle) + +class Q_DECL_HIDDEN ORODocument::Private +{ +public: + Private(); + ~Private(); + QString title; + QList pages; + QList sections; + QPageLayout pageLayout; +}; + +ORODocument::Private::Private() +{ + +} + +ORODocument::Private::~Private() +{ + qDeleteAll(pages); + qDeleteAll(sections); +} + + +ORODocument::ORODocument(const QString& title) : d(new Private()) { + d->title = title; } ORODocument::~ORODocument() { - qDeleteAll(m_pages); - m_pages.clear(); + delete d; +} - qDeleteAll(m_sections); - m_sections.clear(); +void ORODocument::setTitle(const QString &title) +{ + d->title = title; } -void ORODocument::setTitle(const QString & pTitle) +OROPage* ORODocument::page(int index) { - m_title = pTitle; + return d->pages.value(index); } -OROPage* ORODocument::page(int pnum) +const OROPage * ORODocument::page(int index) const { - if (pnum >= 0 && pnum < m_pages.count()) { - return m_pages.at(pnum); - } - return Q_NULLPTR; + return d->pages.value(index); } void ORODocument::addPage(OROPage* p) { - if (p == 0) + if (p == 0) { return; + } - // check that this page is not already in another document + if (p->document() != 0 && p->document() != this) { + return; + } - p->m_document = this; - m_pages.append(p); + p->setDocument(this); + d->pages.append(p); } OROSection* ORODocument::section(int pnum) { - return m_sections.at(pnum); + return d->sections.value(pnum); +} + +const OROSection * ORODocument::section(int index) const +{ + return d->sections.value(index); } + void ORODocument::addSection(OROSection* s) { if (s == 0) return; - // check that this page is not already in another document - - s->m_document = this; - m_sections.append(s); + if (s->document() != 0 && s->document() != this) { + return; + } + s->setDocument(this); + d->sections.append(s); } void ORODocument::setPageLayout(const QPageLayout & options) { - m_pageLayout = options; + d->pageLayout = options; } void ORODocument::notifyChange(int pageNo) { emit(updated(pageNo)); } +QPageLayout ORODocument::pageLayout() const +{ + return d->pageLayout; +} + +int ORODocument::pageCount() const +{ + return d->pages.count(); +} + +int ORODocument::sectionCount() const +{ + return d->sections.count(); +} + +QString ORODocument::title() const +{ + return d->title; +} + +void ORODocument::removePage(OROPage* page) +{ + d->pages.removeOne(page); + delete page; +} + +void ORODocument::takePage(OROPage* page) +{ + d->pages.removeOne(page); +} + +void ORODocument::removeSection(OROSection* section) +{ + d->sections.removeOne(section); + delete section; +} + +void ORODocument::takeSection(OROSection* section) +{ + d->sections.removeOne(section); +} + +int ORODocument::pageIndex(const OROPage* page) const +{ + return d->pages.indexOf(const_cast(page)); +} + // // OROPage // -OROPage::OROPage(ORODocument * pDocument) - : m_document(pDocument) +class Q_DECL_HIDDEN OROPage::Private { +public: + Private(); + ~Private(); + ORODocument *document; + QList primitives; +}; +OROPage::Private::Private() +{ +} + +OROPage::Private::~Private() +{ + qDeleteAll(primitives); +} + +OROPage::OROPage(ORODocument * pDocument) + : d(new Private()) +{ + d->document = pDocument; } OROPage::~OROPage() { - if (m_document) { - m_document->m_pages.removeOne(this); - m_document = 0; + if (d->document) { + d->document->takePage(this); } - - qDeleteAll(m_primitives); - m_primitives.clear(); + delete d; } -int OROPage::page() const +int OROPage::pageNumber() const { - if (m_document) { - for (int i = 0; i < m_document->m_pages.size(); i++) { - if (m_document->m_pages.at(i) == this) - return i; - } + if (d->document) { + return d->document->pageIndex(this); } return -1; } -OROPrimitive* OROPage::primitive(int idx) +OROPrimitive* OROPage::primitive(int index) +{ + return d->primitives.value(index); +} + +const OROPrimitive * OROPage::primitive(int index) const { - return m_primitives.at(idx); + return d->primitives.value(index); } -void OROPage::addPrimitive(OROPrimitive* p, bool atBeginning, bool notify) + +void OROPage::insertPrimitive(OROPrimitive* p, int index) { //kreportDebug() << "Adding primitive" << p->type() << "to page" << page(); if (p == 0) return; - // check that this primitve is not already in another page - - p->m_page = this; - if (atBeginning) { - m_primitives.prepend(p); + p->setPage(this); + if (index == -1) { + d->primitives.append(p); } else { - m_primitives.append(p); + d->primitives.insert(index, p); } - + +#if 0 +//TODO if (notify) { - if (m_document) { - m_document->notifyChange(page()); + if (d->document) { + d->document->notifyChange(pageNumber()); } } +#endif +} + +ORODocument * OROPage::document() +{ + return d->document; +} + +const ORODocument * OROPage::document() const +{ + return d->document; +} + +int OROPage::primitiveCount() const +{ + return d->primitives.count(); +} + +void OROPage::setDocument(ORODocument* doc) +{ + d->document = doc; +} + +void OROPage::removePrimitive(OROPrimitive* primitive) +{ + d->primitives.removeOne(primitive); + delete primitive; +} + +void OROPage::takePrimitive(OROPrimitive* primitive) +{ + d->primitives.removeOne(primitive); } // // OROSection // -OROSection::OROSection(ORODocument * pDocument) - : m_document(pDocument) + +class Q_DECL_HIDDEN OROSection::Private +{ +public: + Private(); + ~Private(); + ORODocument * document; + QList primitives; + qint64 row; + int height; + KReportSectionData::Section type; + QColor backgroundColor; +}; + +OROSection::Private::Private() +{ + height = 0; + backgroundColor = Qt::white; +} + +OROSection::Private::~Private() { - m_height = 0; - m_backgroundColor = Qt::white; + qDeleteAll(primitives); + primitives.clear(); +} + +OROSection::OROSection(ORODocument* doc) : d(new Private()) +{ + d->document = doc; } OROSection::~OROSection() { - if (m_document) { - m_document->m_sections.removeOne(this); - m_document = 0; + if (d->document) { + d->document->takeSection(this); } + + delete d; +} - qDeleteAll(m_primitives); - m_primitives.clear(); +OROPrimitive* OROSection::primitive(int index) +{ + return d->primitives.value(index); } -OROPrimitive* OROSection::primitive(int idx) +const OROPrimitive * OROSection::primitive(int index) const { - return m_primitives.at(idx); + return d->primitives.value(index); } -void OROSection::addPrimitive(OROPrimitive* p) +void OROSection::addPrimitive(OROPrimitive* primitive) { - if (p == 0) + if (primitive == 0) return; - m_primitives.append(p); + d->primitives.append(primitive); } void OROSection::setHeight(int h) { - m_height = h; + d->height = h; } -int OROSection::height() +int OROSection::height() const { - return m_height; + return d->height; } -void OROSection::setBackgroundColor(const QColor &c) +void OROSection::setBackgroundColor(const QColor& color) { - m_backgroundColor = c; + d->backgroundColor = color; } -QColor OROSection::backgroundColor() +QColor OROSection::backgroundColor() const { - return m_backgroundColor; + return d->backgroundColor; } -void OROSection::sortPrimatives(Sort s) +void OROSection::sortPrimitives(Qt::Orientation orientation) { - if (s == SortX) { - qSort(m_primitives.begin(), m_primitives.end(), xLessThan); + if (orientation == Qt::Horizontal) { + qSort(d->primitives.begin(), d->primitives.end(), xLessThan); } } -bool OROSection::xLessThan(OROPrimitive* s1, OROPrimitive* s2) +ORODocument * OROSection::document() { - return s1->position().x() < s2->position().x(); + return d->document; +} + +const ORODocument * OROSection::document() const +{ + return d->document; +} + + +int OROSection::primitiveCount() const +{ + return d->primitives.count(); +} + +void OROSection::setType(KReportSectionData::Section t) +{ + d->type = t; +} + +KReportSectionData::Section OROSection::type() const +{ + return d->type; +} + +void OROSection::setDocument(ORODocument* doc) +{ + d->document = doc; } // // OROPrimitive // -OROPrimitive::OROPrimitive(int pType) - : m_type(pType) + +class Q_DECL_HIDDEN OROPrimitive::Private { - m_page = 0; +public: + OROPage * page; + QPointF position; + QSizeF size; +}; + +OROPrimitive::OROPrimitive() + : d(new Private()) +{ + d->page = 0; } OROPrimitive::~OROPrimitive() { - if (m_page) { - m_page->m_primitives.removeAt(m_page->m_primitives.indexOf(this)); - m_page = 0; + if (d->page) { + d->page->takePrimitive(this); } + + delete d; } -void OROPrimitive::setPosition(const QPointF & p) +void OROPrimitive::setPosition(const QPointF& pos) { - m_position = p; + d->position = pos; } void OROPrimitive::setSize(const QSizeF & s) { - m_size = s; + d->size = s; +} + +OROPage * OROPrimitive::page() +{ + return d->page; +} + +const OROPage * OROPrimitive::page() const +{ + return d->page; +} + +QPointF OROPrimitive::position() const +{ + return d->position; +} + +QSizeF OROPrimitive::size() const +{ + return d->size; +} + +void OROPrimitive::setPage(OROPage* page) +{ + d->page = page; } // // OROTextBox // -const int OROTextBox::TextBox = 1; -OROTextBox::OROTextBox() - : OROPrimitive(OROTextBox::TextBox) + +class Q_DECL_HIDDEN OROTextBox::Private +{ +public: + Private(); + ~Private(); + QString text; + KRTextStyleData textStyle; + KReportLineStyle lineStyle; + Qt::Alignment alignment; + int flags; // Qt::AlignmentFlag and Qt::TextFlag OR'd + bool wordWrap; + bool canGrow; + bool requiresPostProcessing; + +}; + +OROTextBox::Private::Private() { - m_flags = 0; + flags = 0; + wordWrap = false; + canGrow = false; + requiresPostProcessing = false; + + lineStyle.setColor(Qt::black); + lineStyle.setWidth(0); + lineStyle.setPenStyle(Qt::NoPen); +} - m_lineStyle.setColor(Qt::black); - m_lineStyle.setWidth(0); - m_lineStyle.setPenStyle(Qt::NoPen); +OROTextBox::Private::~Private() +{ +} - m_requiresPostProcessing = false; +OROTextBox::OROTextBox() : d(new Private()) +{ - m_wordWrap = false; - m_canGrow = false; } OROTextBox::~OROTextBox() { + delete d; } void OROTextBox::setText(const QString & s) { - m_text = s; + d->text = s; } void OROTextBox::setTextStyle(const KRTextStyleData & ts) { - m_textStyle = ts; + d->textStyle = ts; } void OROTextBox::setLineStyle(const KReportLineStyle & ls) { - m_lineStyle = ls; + d->lineStyle = ls; } void OROTextBox::setFont(const QFont & f) { - m_textStyle.font = f; + d->textStyle.font = f; } void OROTextBox::setFlags(int f) { - m_flags = f; + d->flags = f; +} + +bool OROTextBox::canGrow() const +{ + return d->canGrow; +} + +int OROTextBox::flags() const +{ + return d->flags; +} + +KReportLineStyle OROTextBox::lineStyle() const +{ + return d->lineStyle; +} + +bool OROTextBox::requiresPostProcessing() const +{ + return d->requiresPostProcessing; +} + +void OROTextBox::setCanGrow(bool grow) +{ + d->canGrow = grow; } -OROPrimitive* OROTextBox::clone() +void OROTextBox::setRequiresPostProcessing(bool pp) +{ + d->requiresPostProcessing = pp; +} + +void OROTextBox::setWordWrap(bool ww) +{ + d->wordWrap = ww; +} + +QString OROTextBox::text() const +{ + return d->text; +} + +KRTextStyleData OROTextBox::textStyle() const +{ + return d->textStyle; +} + +bool OROTextBox::wordWrap() const +{ + return d->wordWrap; +} + +OROPrimitive* OROTextBox::clone() const { OROTextBox *theClone = new OROTextBox(); - theClone->setSize(m_size); - theClone->setPosition(m_position); - theClone->setText(m_text); - theClone->setTextStyle(m_textStyle); - theClone->setLineStyle(m_lineStyle); - theClone->setFlags(m_alignment); + theClone->setSize(size()); + theClone->setPosition(position()); + theClone->setText(text()); + theClone->setTextStyle(textStyle()); + theClone->setLineStyle(lineStyle()); + theClone->setFlags(flags()); + theClone->setCanGrow(canGrow()); + theClone->setWordWrap(wordWrap()); + theClone->setRequiresPostProcessing(requiresPostProcessing()); return theClone; } // // OROLine // -const int OROLine::Line = 2; -OROLine::OROLine() - : OROPrimitive(OROLine::Line) +class Q_DECL_HIDDEN OROLine::Private +{ +public: + QPointF endPoint; + KReportLineStyle lineStyle; +}; + +OROLine::OROLine() : d(new Private()) { } OROLine::~OROLine() { + delete d; } void OROLine::setStartPoint(const QPointF & p) { setPosition(p); } void OROLine::setEndPoint(const QPointF & p) { - m_endPoint = p; + d->endPoint = p; +} + +void OROLine::setLineStyle(const KReportLineStyle& style) +{ + d->lineStyle = style; } -void OROLine::setLineStyle(const KReportLineStyle& ls) +QPointF OROLine::endPoint() const { - m_lineStyle = ls; + return d->endPoint; } +KReportLineStyle OROLine::lineStyle() const +{ + return d->lineStyle; +} -OROPrimitive* OROLine::clone() +OROPrimitive* OROLine::clone() const { OROLine *theClone = new OROLine(); - theClone->setStartPoint(m_position); - theClone->setEndPoint(m_endPoint); - theClone->setLineStyle(m_lineStyle); + theClone->setStartPoint(position()); + theClone->setEndPoint(endPoint()); + theClone->setLineStyle(lineStyle()); return theClone; } // // OROImage // -const int OROImage::Image = 3; -OROImage::OROImage() - : OROPrimitive(OROImage::Image) +class Q_DECL_HIDDEN OROImage::Private +{ +public: + QImage image; + bool scaled; + Qt::TransformationMode transformFlags; + Qt::AspectRatioMode aspectFlags; +}; + +OROImage::OROImage() : d(new Private()) { - m_scaled = false; - m_transformFlags = Qt::FastTransformation; - m_aspectFlags = Qt::IgnoreAspectRatio; + d->scaled = false; + d->transformFlags = Qt::FastTransformation; + d->aspectFlags = Qt::IgnoreAspectRatio; } OROImage::~OROImage() { + delete d; } void OROImage::setImage(const QImage & img) { - m_image = img; + d->image = img; } void OROImage::setScaled(bool b) { - m_scaled = b; + d->scaled = b; +} + +void OROImage::setTransformationMode(Qt::TransformationMode transformation) +{ + d->transformFlags = transformation; +} + +void OROImage::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode) +{ + d->aspectFlags = aspectRatioMode; +} + +Qt::AspectRatioMode OROImage::aspectRatioMode() const +{ + return d->aspectFlags; +} + +QImage OROImage::image() const +{ + return d->image; } -void OROImage::setTransformationMode(int tm) +bool OROImage::isScaled() const { - m_transformFlags = tm; + return d->scaled; } -void OROImage::setAspectRatioMode(int arm) +Qt::TransformationMode OROImage::transformationMode() const { - m_aspectFlags = arm; + return d->transformFlags; } -OROPrimitive* OROImage::clone() +OROPrimitive* OROImage::clone() const { OROImage *theClone = new OROImage(); - theClone->setSize(m_size); - theClone->setPosition(m_position); - theClone->setImage(m_image); - theClone->setScaled(m_scaled); - theClone->setTransformationMode(m_transformFlags); - theClone->setAspectRatioMode(m_aspectFlags); + theClone->setSize(size()); + theClone->setPosition(position()); + theClone->setImage(image()); + theClone->setScaled(isScaled()); + theClone->setTransformationMode(transformationMode()); + theClone->setAspectRatioMode(aspectRatioMode()); return theClone; } // // OROPicture // -const int OROPicture::Picture = 6; -OROPicture::OROPicture() - : OROPrimitive(OROPicture::Picture) +class Q_DECL_HIDDEN OROPicture::Private +{ +public: + QPicture picture; +}; + +OROPicture::OROPicture() : d(new Private()) { } OROPicture::~OROPicture() { + delete d; } -OROPrimitive* OROPicture::clone() +OROPrimitive* OROPicture::clone() const { OROPicture *theClone = new OROPicture(); - theClone->setSize(m_size); - theClone->setPosition(m_position); - theClone->setPicture(m_picture); + theClone->setSize(size()); + theClone->setPosition(position()); +// theClone->setPicture(*(picture()ddddddds)); return theClone; } +QPicture* OROPicture::picture() +{ + return &d->picture; +} + +void OROPicture::setPicture(const QPicture& p) +{ + d->picture = p; +} + // // ORORect // -const int ORORect::Rect = 4; -ORORect::ORORect() - : OROPrimitive(ORORect::Rect) +class Q_DECL_HIDDEN ORORect::Private +{ +public: + QPen pen; + QBrush brush; +}; + +ORORect::ORORect() : d(new Private()) { } ORORect::~ORORect() { + delete d; } void ORORect::setRect(const QRectF & r) { setPosition(r.topLeft()); setSize(r.size()); } void ORORect::setPen(const QPen & p) { - m_pen = p; + d->pen = p; } void ORORect::setBrush(const QBrush & b) { - m_brush = b; + d->brush = b; +} + +QBrush ORORect::brush() const +{ + return d->brush; +} + +QPen ORORect::pen() const +{ + return d->pen; +} + +QRectF ORORect::rect() const +{ + return QRectF(position(), size()); } -OROPrimitive* ORORect::clone() +OROPrimitive* ORORect::clone() const { ORORect *theClone = new ORORect(); - theClone->setSize(m_size); - theClone->setPosition(m_position); - theClone->setPen(m_pen); - theClone->setBrush(m_brush); + theClone->setSize(size()); + theClone->setPosition(position()); + theClone->setPen(pen()); + theClone->setBrush(brush()); return theClone; } // // OROEllipse // -const int OROEllipse::Ellipse = 5; -OROEllipse::OROEllipse() - : OROPrimitive(OROEllipse::Ellipse) +class Q_DECL_HIDDEN OROEllipse::Private +{ +public: + QPen pen; + QBrush brush; +}; + +OROEllipse::OROEllipse() : d(new Private()) { } OROEllipse::~OROEllipse() { + delete d; } void OROEllipse::setRect(const QRectF & r) { setPosition(r.topLeft()); setSize(r.size()); } void OROEllipse::setPen(const QPen & p) { - m_pen = p; + d->pen = p; } void OROEllipse::setBrush(const QBrush & b) { - m_brush = b; + d->brush = b; +} + +QBrush OROEllipse::brush() const +{ + return d->brush; +} + +QPen OROEllipse::pen() const +{ + return d->pen; } -OROPrimitive* OROEllipse::clone() +QRectF OROEllipse::rect() const +{ + return QRectF(position(), size()); +} + +OROPrimitive* OROEllipse::clone() const { OROEllipse *theClone = new OROEllipse(); - theClone->setSize(m_size); - theClone->setPosition(m_position); - theClone->setPen(m_pen); - theClone->setBrush(m_brush); + theClone->setSize(size()); + theClone->setPosition(position()); + theClone->setPen(pen()); + theClone->setBrush(brush()); return theClone; } -const int OROCheck::Check = 7; +// +// OROCheck +// + +class Q_DECL_HIDDEN OROCheckBox::Private +{ +public: + OROCheckBox::Type checkType; + bool value; + KReportLineStyle lineStyle; + QColor foregroundColor; +}; + +OROCheckBox::OROCheckBox() : d(new Private()) +{ + d->value = false; +} + +OROCheckBox::~OROCheckBox() +{ + delete d; +} -OROCheck::OROCheck() - : OROPrimitive(OROCheck::Check) - , m_value(false) +OROCheckBox::Type OROCheckBox::checkType() const { + return d->checkType; +} +QColor OROCheckBox::foregroundColor() const +{ + return d->foregroundColor; } -OROCheck::~OROCheck() +KReportLineStyle OROCheckBox::lineStyle() const { + return d->lineStyle; +} +void OROCheckBox::setForegroundColor(const QColor& fg) +{ + d->foregroundColor = fg; +} + +void OROCheckBox::setLineStyle(const KReportLineStyle& ls) +{ + d->lineStyle = ls; +} + +void OROCheckBox::setValue(bool v) +{ + d->value = v; +} + +bool OROCheckBox::value() const +{ + return d->value; +} + +void OROCheckBox::setCheckType(Type type) +{ + if (type == Cross || type == Tick || type == Dot) { + d->checkType = type; + } else { + d->checkType = Cross; + } } -OROPrimitive* OROCheck::clone() +OROPrimitive* OROCheckBox::clone() const { - OROCheck *theClone = new OROCheck(); - theClone->setSize(m_size); - theClone->setPosition(m_position); - theClone->setLineStyle(m_lineStyle); - theClone->setForegroundColor(m_fgColor); - theClone->setValue(m_value); + OROCheckBox *theClone = new OROCheckBox(); + theClone->setSize(size()); + theClone->setPosition(position()); + theClone->setLineStyle(lineStyle()); + theClone->setForegroundColor(foregroundColor()); + theClone->setValue(value()); + theClone->setCheckType(checkType()); return theClone; } diff --git a/src/common/KReportRenderObjects.h b/src/common/KReportRenderObjects.h index bed2b9e6..6cd19c2d 100644 --- a/src/common/KReportRenderObjects.h +++ b/src/common/KReportRenderObjects.h @@ -1,487 +1,462 @@ /* 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 . */ #ifndef KREPORTRENDEROBJECTS_H #define KREPORTRENDEROBJECTS_H #include #include #include #include #include #include #include #include #include #include #include "KReportData.h" #include "KReportItemBase.h" #include "KReportSectionData.h" #include "KReportLineStyle.h" class ORODocument; class OROPage; class OROPrimitive; class OROTextBox; class OROLine; class OROImage; class OROSection; // // ORODocument // This object is a single document containing one or more OROPage elements // class KREPORT_EXPORT ORODocument : public QObject { Q_OBJECT - friend class OROPage; - friend class OROSection; - public: - explicit ORODocument(const QString & = QString()); + explicit ORODocument(const QString &title = QString()); ~ORODocument(); - QString title() const { - return m_title; - }; - void setTitle(const QString &); - - int pages() const { - return m_pages.count(); - }; - OROPage* page(int); - void addPage(OROPage*); - - int sections() const { - return m_sections.count(); - }; - OROSection* section(int); - void addSection(OROSection*); - - void setPageLayout(const QPageLayout &); - QPageLayout pageLayout() const { - return m_pageLayout; - }; + QString title() const; + void setTitle(const QString &title); + + + /** + * @brief Return the total number of pages in the document + * + */ + int pageCount() const; + + /** + * @brief Return a pointer to a given page + * + * @param index page number to find + * @return OROPage* + */ + OROPage* page(int index); + const OROPage* page(int index) const; + + /** + * @brief Adds the supplied page to this document + * + * Ownership of the page is tranferred the document + * + * @param page an OROPage* to be added + */ + void addPage(OROPage* page); + + /** + * @brief Returns the index of the supplied page in the document + * + * @param page OROPage* to find + * @return int page index + */ + int pageIndex(const OROPage* page) const; + + /** + * @brief Removes the given page from the document + * + * The page is also deleted + * + * @param page OROPage* to delete + */ + void removePage(OROPage* page); + + /** + * @brief Takes the page from the document but does not delete it + * + * @param page OROPage* to take from the document + */ + void takePage(OROPage *page); + + /** + * @brief Return the total number of sections in the document + * + */ + int sectionCount() const; + + /** + * @brief Return a pointer to a given section + * + * @param index section number to find + * @return OROSection* + */ + OROSection* section(int index); + const OROSection* section(int index) const; + + /** + * @brief Adds the supplied sectin to the document + * + * Ownership of the section is transferred to the document + * + * @param section OROSection* to add to the document + */ + void addSection(OROSection* section); + + /** + * @brief Removes the supplied section from the document + * + * The section will also be deleted + * + * @param section OROSection* to remove and delete + */ + void removeSection(OROSection *section); + + /** + * @brief Takes the section from the document but does not delete it + * + * @param page OROSection* to take from the document + */ + void takeSection(OROSection *section); + + void setPageLayout(const QPageLayout &layout); + QPageLayout pageLayout() const; void notifyChange(int pageNo); - -protected: - QString m_title; - QList m_pages; - QList m_sections; - QPageLayout m_pageLayout; - + Q_SIGNALS: void updated(int pageNo); + +private: + class Private; + Private * const d; }; // // OROPage // This object is a single page in a document and may contain zero or more // OROPrimitive objects all of which represent some form of mark to made on // a page. // class KREPORT_EXPORT OROPage { - friend class ORODocument; - friend class OROPrimitive; - public: - explicit OROPage(ORODocument * = 0); + explicit OROPage(ORODocument * doc = 0); ~OROPage(); - ORODocument* document() const { - return m_document; - }; - int page() const; // returns this pages current page number + ORODocument* document(); + const ORODocument* document() const; + void setDocument(ORODocument *doc); + + int pageNumber() const; // returns this pages current page number + + int primitiveCount() const; + + OROPrimitive* primitive(int index); + const OROPrimitive* primitive(int index) const; + + void insertPrimitive(OROPrimitive* primitive, int index = -1); + void removePrimitive(OROPrimitive *primitive); + void takePrimitive(OROPrimitive *primitive); - int primitives() const { - return m_primitives.count(); - }; - OROPrimitive* primitive(int); - void addPrimitive(OROPrimitive*, bool atBeginning = false, bool notify = false); - -protected: - ORODocument * m_document; - QList m_primitives; +private: + class Private; + Private * const d; }; // // OROSection // This object is a single row in a document and may contain zero or more // OROPrimitives // class KREPORT_EXPORT OROSection { - friend class ORODocument; - friend class OROPrimitive; - public: - enum Sort { - SortX = 1, - SortY, - SortZ - }; - - explicit OROSection(ORODocument * = 0); + explicit OROSection(ORODocument* doc = 0); ~OROSection(); void setHeight(int); - int height(); + int height() const; - void setBackgroundColor(const QColor&L); - QColor backgroundColor(); + void setBackgroundColor(const QColor& color); + QColor backgroundColor() const; - ORODocument* document() const { - return m_document; - }; + ORODocument* document(); + const ORODocument* document() const; + void setDocument(ORODocument *doc); - void setType(KReportSectionData::Section t) { - m_type = t; - } - KReportSectionData::Section type() { - return m_type; - } + void setType(KReportSectionData::Section t); + KReportSectionData::Section type() const; - int primitives() const { - return m_primitives.count(); - }; - OROPrimitive* primitive(int); - void addPrimitive(OROPrimitive*); - - void sortPrimatives(Sort); -protected: - ORODocument * m_document; - QList m_primitives; - long m_row; - int m_height; - KReportSectionData::Section m_type; - QColor m_backgroundColor; + int primitiveCount() const; + OROPrimitive* primitive(int index); + const OROPrimitive* primitive(int index) const; + void addPrimitive(OROPrimitive* primitive); + void sortPrimitives(Qt::Orientation orientation); private: - static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2); + class Private; + Private * const d; }; // // OROPrimitive // This object represents the basic primitive with a position and type. // Other primitives are subclasses with a defined type and any additional // information they require to define that primitive. // class KREPORT_EXPORT OROPrimitive { - friend class OROPage; - public: virtual ~OROPrimitive(); - // Returns the type of the primitive which should be - // set by the subclass - int type() const { - return m_type; - }; - OROPage * page() const { - return m_page; - }; + OROPage* page(); + const OROPage* page() const; + void setPage(OROPage *page); - QPointF position() const { - return m_position; - }; - void setPosition(const QPointF &); - QSizeF size() const { return m_size; } + QPointF position() const; + void setPosition(const QPointF &pos); + + QSizeF size() const; void setSize(const QSizeF &s); - virtual OROPrimitive* clone() = 0; - + virtual OROPrimitive* clone() const = 0; + protected: - OROPrimitive(int); - - OROPage * m_page; - int m_type; - QPointF m_position; - QSizeF m_size; + OROPrimitive(); + +private: + class Private; + Private * const d; }; // // OROTextBox // This is a text box primitive it defines a box region and text that will // be rendered inside that region. It also contains information for font // and positioning of the text. // class KREPORT_EXPORT OROTextBox : public OROPrimitive { public: OROTextBox(); virtual ~OROTextBox(); - QString text() const { - return m_text; - }; - void setText(const QString &); + QString text() const; + void setText(const QString &text); - KRTextStyleData textStyle() const { - return m_textStyle; - } + KRTextStyleData textStyle() const; void setTextStyle(const KRTextStyleData&); - KReportLineStyle lineStyle() const { - return m_lineStyle; - } + KReportLineStyle lineStyle() const; void setLineStyle(const KReportLineStyle&); - void setFont(const QFont &); - - int flags() const { - return m_flags; - }; - void setFlags(int); + void setFont(const QFont &font); - static const int TextBox; + int flags() const; + void setFlags(int flags); - virtual OROPrimitive* clone(); + virtual OROPrimitive* clone() const; - bool requiresPostProcessing(){return m_requiresPostProcessing;} - void setRequiresPostProcessing(bool pp = true){m_requiresPostProcessing = pp;} + bool requiresPostProcessing() const; + void setRequiresPostProcessing(bool pp); - bool wordWrap() const {return m_wordWrap;} - void setWordWrap(bool ww){m_wordWrap = ww;} + bool wordWrap() const; + void setWordWrap(bool ww); - bool canGrow() const {return m_canGrow;} - void setCanGrow(bool cg){m_canGrow = cg;} - -protected: - QString m_text; - KRTextStyleData m_textStyle; - KReportLineStyle m_lineStyle; - Qt::Alignment m_alignment; - int m_flags; // Qt::AlignmentFlag and Qt::TextFlag OR'd - bool m_wordWrap; - bool m_canGrow; - bool m_requiresPostProcessing; + bool canGrow() const; + void setCanGrow(bool grow); + +private: + class Private; + Private * const d; }; // // OROLine // This primitive defines a line with a width/weight. // class KREPORT_EXPORT OROLine : public OROPrimitive { public: OROLine(); virtual ~OROLine(); QPointF startPoint() const { return position(); }; - void setStartPoint(const QPointF &); + void setStartPoint(const QPointF &start); - QPointF endPoint() const { - return m_endPoint; - }; - void setEndPoint(const QPointF &); + QPointF endPoint() const; + void setEndPoint(const QPointF &end); - KReportLineStyle lineStyle() const { - return m_lineStyle; - }; - void setLineStyle(const KReportLineStyle&); + KReportLineStyle lineStyle() const; + void setLineStyle(const KReportLineStyle& style); - static const int Line; - virtual OROPrimitive* clone(); -protected: - QPointF m_endPoint; - KReportLineStyle m_lineStyle; + virtual OROPrimitive* clone() const; + +private: + class Private; + Private * const d; }; // // OROImage // This primitive defines an image // class KREPORT_EXPORT OROImage: public OROPrimitive { public: OROImage(); virtual ~OROImage(); - QImage image() const { - return m_image; - }; - void setImage(const QImage &); + QImage image() const; + void setImage(const QImage &img); - bool scaled() const { - return m_scaled; - }; - void setScaled(bool); - - int transformationMode() const { - return m_transformFlags; - }; - void setTransformationMode(int); + bool isScaled() const; + void setScaled(bool scaled); - int aspectRatioMode() const { - return m_aspectFlags; - }; - void setAspectRatioMode(int); + Qt::TransformationMode transformationMode() const; + void setTransformationMode(Qt::TransformationMode transformation); - static const int Image; - virtual OROPrimitive* clone(); + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode aspect); -protected: - QImage m_image; - bool m_scaled; - int m_transformFlags; - int m_aspectFlags; + virtual OROPrimitive* clone() const; + +private: + class Private; + Private * const d; }; +// +// OROPicture +// This primitive defines a picture +// class KREPORT_EXPORT OROPicture: public OROPrimitive { public: OROPicture(); virtual ~OROPicture(); - void setPicture(const QPicture& p) { - m_picture = p; - } - QPicture* picture() { - return &m_picture; - }; + void setPicture(const QPicture& pic); + QPicture* picture(); - static const int Picture; - virtual OROPrimitive* clone(); -protected: - QPicture m_picture; + virtual OROPrimitive* clone() const; + +private: + class Private; + Private * const d; }; // // ORORect // This primitive defines a drawn rectangle // class KREPORT_EXPORT ORORect: public OROPrimitive { public: ORORect(); virtual ~ORORect(); - QRectF rect() const { - return QRectF(m_position, m_size); - }; - void setRect(const QRectF &); + QRectF rect() const; + void setRect(const QRectF &rectangle); - QPen pen() const { - return m_pen; - }; - void setPen(const QPen &); + QPen pen() const; + void setPen(const QPen &pen); - QBrush brush() const { - return m_brush; - }; - void setBrush(const QBrush &); + QBrush brush() const; + void setBrush(const QBrush &brush); - static const int Rect; - virtual OROPrimitive* clone(); -protected: - QPen m_pen; - QBrush m_brush; + virtual OROPrimitive* clone() const; + +private: + class Private; + Private * const d; }; // // ORORect // This primitive defines a drawn rectangle // class KREPORT_EXPORT OROEllipse: public OROPrimitive { public: OROEllipse(); virtual ~OROEllipse(); - QRectF rect() const { - return QRectF(m_position, m_size); - }; - void setRect(const QRectF &); + QRectF rect() const; + void setRect(const QRectF &rectangle); - QPen pen() const { - return m_pen; - }; - void setPen(const QPen &); - - QBrush brush() const { - return m_brush; - }; - void setBrush(const QBrush &); + QPen pen() const; + void setPen(const QPen &pen); - static const int Ellipse; - virtual OROPrimitive* clone(); + QBrush brush() const; + void setBrush(const QBrush &brush); -protected: - QSizeF m_size; - QPen m_pen; - QBrush m_brush; + virtual OROPrimitive* clone() const; + +private: + class Private; + Private * const d; }; -class KREPORT_EXPORT OROCheck : public OROPrimitive +class KREPORT_EXPORT OROCheckBox : public OROPrimitive { public: - OROCheck(); - virtual ~OROCheck(); - virtual OROPrimitive* clone(); - static const int Check; - - void setCheckType(const QString& t) { - if (t == QLatin1String("Cross") || t == QLatin1String("Tick") || t == QLatin1String("Dot")) { - m_checkType = t; - } else { - m_checkType = QLatin1String("Cross"); - } - } - - QString checkType() const { - return m_checkType; + enum Type { + Cross = 1, + Tick, + Dot }; + + OROCheckBox(); + virtual ~OROCheckBox(); + virtual OROPrimitive* clone() const; - void setValue(bool v) { - m_value = v; - } - bool value() const { - return m_value; - } - - void setLineStyle(const KReportLineStyle& ls) { - m_lineStyle = ls; - } - - KReportLineStyle lineStyle() const { - return m_lineStyle; - } - void setForegroundColor(const QColor& fg) { - m_fgColor = fg; - } - QColor foregroundColor() const { - return m_fgColor; - } + void setCheckType(Type type); + Type checkType() const; -protected: - QSizeF m_size; - QString m_checkType; - bool m_value; - KReportLineStyle m_lineStyle; - QColor m_fgColor; + void setValue(bool val); + bool value() const; + void setLineStyle(const KReportLineStyle& ls); + KReportLineStyle lineStyle() const; + + void setForegroundColor(const QColor& fg); + QColor foregroundColor() const; + +private: + class Private; + Private * const d; }; #endif // __RENDEROBJECTS_H__ diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp index c9b2232e..385f7ce2 100644 --- a/src/items/check/KReportItemCheck.cpp +++ b/src/items/check/KReportItemCheck.cpp @@ -1,186 +1,192 @@ /* This file is part of the KDE project * Copyright (C) 2009-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 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 "KReportItemCheck.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #ifdef KREPORT_SCRIPTING #include "renderer/scripting/KReportScriptHandler.h" #endif #include #include #include KReportItemCheckBox::KReportItemCheckBox() { createProperties(); } KReportItemCheckBox::KReportItemCheckBox(const QDomNode &element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_foregroundColor->setValue(QColor(element.toElement().attribute(QLatin1String("fo:foreground-color")))); m_checkStyle->setValue(element.toElement().attribute(QLatin1String("report:check-style"))); m_staticValue->setValue(QVariant(element.toElement().attribute(QLatin1String("report:value"))).toBool()); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing check element encountered unknow element: " << n; } } } KReportItemCheckBox::~KReportItemCheckBox() { } void KReportItemCheckBox::createProperties() { QStringList keys, strings; keys << QLatin1String("Cross") << QLatin1String("Tick") << QLatin1String("Dot"); strings << tr("Cross") << tr("Tick") << tr("Dot"); m_checkStyle = new KProperty("check-style", keys, strings, QLatin1String("Cross"), tr("Style")); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::SolidLine), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_staticValue = new KProperty("value", QVariant(false), tr("Value"), tr("Value used if not bound to a field")); propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_staticValue); propertySet()->addProperty(m_checkStyle); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemCheckBox::lineStyle() { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } QString KReportItemCheckBox::itemDataSource() const { return m_controlSource->value().toString(); } // RTTI QString KReportItemCheckBox::typeName() const { return QLatin1String("check"); } int KReportItemCheckBox::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { - OROCheck *chk = new OROCheck(); + OROCheckBox *chk = new OROCheckBox(); chk->setPosition(scenePosition(position()) + offset); chk->setSize(sceneSize(size())); chk->setLineStyle(lineStyle()); chk->setForegroundColor(m_foregroundColor->value().value()); - chk->setCheckType(m_checkStyle->value().toString()); - + if (m_checkStyle->value().toString() == QLatin1String("Cross")) { + chk->setCheckType(OROCheckBox::Cross); + } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) { + chk->setCheckType(OROCheckBox::Dot); + } else { + chk->setCheckType(OROCheckBox::Tick); + } + QString str; bool v = false; QString cs = itemDataSource(); //kreportpluginDebug() << "ControlSource:" << cs; if (!cs.isEmpty()) { #ifdef KREPORT_SCRIPTING if (cs.left(1) == QLatin1String("=") && script) { str = script->evaluate(cs.mid(1)).toString(); } else #else Q_UNUSED(script); #endif { str = data.toString(); } str = str.toLower(); //kreportpluginDebug() << "Check Value:" << str; if (str == QLatin1String("t") || str == QLatin1String("y") || str == QLatin1String("true") || str == QLatin1String("1")) v = true; } else { v = value(); } chk->setValue(v); if (page) { - page->addPrimitive(chk); + page->insertPrimitive(chk); } if (section) { - OROCheck *chk2 = dynamic_cast(chk->clone()); + OROCheckBox *chk2 = dynamic_cast(chk->clone()); chk2->setPosition(scenePosition(position())); section->addPrimitive(chk2); } if (!page) { delete chk; } return 0; //Item doesn't stretch the section height } bool KReportItemCheckBox::value() const { return m_staticValue->value().toBool(); } void KReportItemCheckBox::setValue(bool v) { m_staticValue->setValue(v); } diff --git a/src/items/field/KReportItemField.cpp b/src/items/field/KReportItemField.cpp index 4034fe7b..0f737d5e 100644 --- a/src/items/field/KReportItemField.cpp +++ b/src/items/field/KReportItemField.cpp @@ -1,287 +1,287 @@ /* 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 "KReportItemField.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #ifdef KREPORT_SCRIPTING #include "renderer/scripting/KReportScriptHandler.h" #endif #include #include #include #include #include KReportItemField::KReportItemField() { createProperties(); } KReportItemField::KReportItemField(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); m_canGrow->setValue(element.toElement().attribute(QLatin1String("report:can-grow"))); m_wordWrap->setValue(element.toElement().attribute(QLatin1String("report:word-wrap"))); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; } } } KReportItemField::~KReportItemField() { } void KReportItemField::createProperties() { QStringList keys, strings; m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_wordWrap = new KProperty("word-wrap", QVariant(false), tr("Word Wrap")); m_canGrow = new KProperty("can-grow", QVariant(false), tr("Can Grow")); //! @todo I do not think we need these #if 0 //Field Totals m_trackTotal = new KProperty("trackTotal", QVariant(false), futureI18n("Track Total")); m_trackBuiltinFormat = new KProperty("trackBuiltinFormat", QVariant(false), futureI18n("Track Builtin Format")); _useSubTotal = new KProperty("useSubTotal", QVariant(false), futureI18n("Use Sub Total"_)); _trackTotalFormat = new KProperty("trackTotalFormat", QString(), futureI18n("Track Total Format")); #endif propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); propertySet()->addProperty(m_wordWrap); propertySet()->addProperty(m_canGrow); //_set->addProperty ( _trackTotal ); //_set->addProperty ( _trackBuiltinFormat ); //_set->addProperty ( _useSubTotal ); //_set->addProperty ( _trackTotalFormat ); } int KReportItemField::textFlags() const { int flags; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) flags = Qt::AlignHCenter; else if (t == QLatin1String("right")) flags = Qt::AlignRight; else flags = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) flags |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) flags |= Qt::AlignBottom; else flags |= Qt::AlignTop; if (m_wordWrap->value().toBool() == true) { flags |= Qt::TextWordWrap; } return flags; } KRTextStyleData KReportItemField::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } QString KReportItemField::itemDataSource() const { return m_controlSource->value().toString(); } void KReportItemField::setItemDataSource(const QString& t) { if (m_controlSource->value() != t) { m_controlSource->setValue(t); } //kreportpluginDebug() << "Field: " << entityName() << "is" << itemDataSource(); } KReportLineStyle KReportItemField::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemField::typeName() const { return QLatin1String("field"); } int KReportItemField::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); tb->setCanGrow(m_canGrow->value().toBool()); tb->setWordWrap(m_wordWrap->value().toBool()); QString str; QString ids = itemDataSource(); if (!ids.isEmpty()) { #ifdef KREPORT_SCRIPTING if (ids.left(1) == QLatin1String("=") && script) { //Everything after = is treated as code if (!ids.contains(QLatin1String("PageTotal()"))) { QVariant v = script->evaluate(ids.mid(1)); str = v.toString(); } else { str = ids.mid(1); - tb->setRequiresPostProcessing(); + tb->setRequiresPostProcessing(true); } } else #else Q_UNUSED(script); #endif if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string str = ids.mid(1); } else { str = data.toString(); } } else { str = m_itemValue->value().toString(); } tb->setText(str); //Work out the size of the text if (tb->canGrow()) { QRect r; if (tb->wordWrap()) { //Grow vertically QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), tb->size().width(), 5000); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } else { //Grow Horizontally QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), 5000, tb->size().height()); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } tb->setSize(r.size() + QSize(4,4)); } if (page) { - page->addPrimitive(tb); + page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } int height = scenePosition(position()).y() + tb->size().height(); //If there is no page to add the item to, delete it now because it wont be deleted later if (!page) { delete tb; } return height; } diff --git a/src/items/image/KReportItemImage.cpp b/src/items/image/KReportItemImage.cpp index 69bb2302..3615d479 100644 --- a/src/items/image/KReportItemImage.cpp +++ b/src/items/image/KReportItemImage.cpp @@ -1,188 +1,188 @@ /* 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 "KReportItemImage.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include KReportItemImage::KReportItemImage() { createProperties(); } KReportItemImage::KReportItemImage(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_resizeMode->setValue(element.toElement().attribute(QLatin1String("report:resize-mode"), QLatin1String("stretch"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:inline-image-data")) { setInlineImageData(node.firstChild().nodeValue().toLatin1()); } else { kreportpluginWarning() << "while parsing image element encountered unknow element: " << n; } } } KReportItemImage::~KReportItemImage() { } bool KReportItemImage::isInline() const { return !(inlineImageData().isEmpty()); } QByteArray KReportItemImage::inlineImageData() const { QPixmap pixmap = m_staticImage->value().value(); QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::ReadWrite); pixmap.save(&buffer, "PNG"); // writes pixmap into ba in PNG format, //! @todo should I remember the format used, or save as PNG as its lossless? return buffer.buffer().toBase64(); } void KReportItemImage::setInlineImageData(const QByteArray &dat, const QString &fn) { if (!fn.isEmpty()) { QPixmap pix(fn); if (!pix.isNull()) m_staticImage->setValue(pix); else { QPixmap blank(1, 1); blank.fill(); m_staticImage->setValue(blank); } } else { const QByteArray binaryStream(QByteArray::fromBase64(dat)); const QPixmap pix(QPixmap::fromImage(QImage::fromData(binaryStream), Qt::ColorOnly)); m_staticImage->setValue(pix); } } QString KReportItemImage::mode() const { return m_resizeMode->value().toString(); } void KReportItemImage::setMode(const QString &m) { if (mode() != m) { m_resizeMode->setValue(m); } } void KReportItemImage::createProperties() { m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); QStringList keys, strings; keys << QLatin1String("clip") << QLatin1String("stretch"); strings << tr("Clip") << tr("Stretch"); m_resizeMode = new KProperty("resize-mode", keys, strings, QLatin1String("clip"), tr("Resize Mode")); m_staticImage = new KProperty("static-image", QPixmap(), tr("Value"), tr("Value used if not bound to a field")); propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_resizeMode); propertySet()->addProperty(m_staticImage); } void KReportItemImage::setColumn(const QString &c) { m_controlSource->setValue(c); } QString KReportItemImage::itemDataSource() const { return m_controlSource->value().toString(); } QString KReportItemImage::typeName() const { return QLatin1String("image"); } int KReportItemImage::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) QByteArray uudata; QByteArray imgdata; if (!isInline()) { imgdata = data.toByteArray(); } else { uudata = inlineImageData(); imgdata = QByteArray::fromBase64(uudata); } QImage img; img.loadFromData(imgdata); OROImage * id = new OROImage(); id->setImage(img); if (mode().toLower() == QLatin1String("stretch")) { id->setScaled(true); id->setAspectRatioMode(Qt::KeepAspectRatio); id->setTransformationMode(Qt::SmoothTransformation); } id->setPosition(scenePosition(position()) + offset); id->setSize(sceneSize(size())); if (page) { - page->addPrimitive(id); + page->insertPrimitive(id); } if (section) { OROImage *i2 = dynamic_cast(id->clone()); i2->setPosition(scenePosition(position())); section->addPrimitive(i2); } if (!page) { delete id; } return 0; //Item doesn't stretch the section height } diff --git a/src/items/label/KReportItemLabel.cpp b/src/items/label/KReportItemLabel.cpp index 335e2867..68f1a561 100644 --- a/src/items/label/KReportItemLabel.cpp +++ b/src/items/label/KReportItemLabel.cpp @@ -1,208 +1,208 @@ /* 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 "KReportItemLabel.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include KReportItemLabel::KReportItemLabel() { createProperties(); } KReportItemLabel::KReportItemLabel(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_text->setValue(element.toElement().attribute(QLatin1String("report:caption"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing label element encountered unknow element: " << n; } } } KReportItemLabel::~KReportItemLabel() { } QString KReportItemLabel::text() const { return m_text->value().toString(); } void KReportItemLabel::setText(const QString& t) { m_text->setValue(t); } void KReportItemLabel::createProperties() { m_text = new KProperty("caption", QLatin1String("Label"), tr("Caption")); QStringList keys, strings; keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); propertySet()->addProperty(m_text); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } Qt::Alignment KReportItemLabel::textFlags() const { Qt::Alignment align; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) align = Qt::AlignHCenter; else if (t == QLatin1String("right")) align = Qt::AlignRight; else align = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) align |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) align |= Qt::AlignBottom; else align |= Qt::AlignTop; return align; } KRTextStyleData KReportItemLabel::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemLabel::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemLabel::typeName() const { return QLatin1String("label"); } int KReportItemLabel::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(data) Q_UNUSED(script) OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setText(text()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { - page->addPrimitive(tb); + page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } if (!page) { delete tb; } return 0; //Item doesn't stretch the section height } diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp index 64836116..bcbdb294 100644 --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -1,315 +1,315 @@ /* 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 "KReportItemText.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include #include #include KReportItemText::KReportItemText() : KReportItemText(QDomNode()) { } KReportItemText::KReportItemText(const QDomNode & element) : m_bottomPadding(0.0) { QDomNodeList nl = element.childNodes(); QString n; QDomNode node; createProperties(); nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); m_bottomPadding = element.toElement().attribute(QLatin1String("report:bottom-padding")).toDouble(); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; } } } KReportItemText::~KReportItemText() { } Qt::Alignment KReportItemText::textFlags() const { Qt::Alignment align; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) align = Qt::AlignHCenter; else if (t == QLatin1String("right")) align = Qt::AlignRight; else align = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) align |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) align |= Qt::AlignBottom; else align |= Qt::AlignTop; return align; } void KReportItemText::createProperties() { //connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) ); QStringList keys, strings; //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" ); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } QString KReportItemText::itemDataSource() const { return m_controlSource->value().toString(); } qreal KReportItemText::bottomPadding() const { return m_bottomPadding; } void KReportItemText::setBottomPadding(qreal bp) { if (m_bottomPadding != bp) { m_bottomPadding = bp; } } KRTextStyleData KReportItemText::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemText::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemText::typeName() const { return QLatin1String("text"); } int KReportItemText::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script); QString qstrValue; QString cs = itemDataSource(); if (!cs.isEmpty()) { if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string qstrValue = cs.mid(1); } else { qstrValue = data.toString(); } } else { qstrValue = m_itemValue->value().toString(); } QPointF pos = scenePosition(position()); QSizeF siz = sceneSize(size()); pos += offset; QRectF trf(pos, siz); qreal intStretch = trf.top() - offset.y(); if (qstrValue.length()) { QRectF rect = trf; int pos = 0; QChar separator; QRegExp re(QLatin1String("\\s")); QPrinter prnt(QPrinter::HighResolution); QFontMetrics fm(font(), &prnt); // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; int intRectWidth = (int)((size().width() / 72) * prnt.resolution()); int intLineCounter = 0; qreal intBaseTop = trf.top(); qreal intRectHeight = trf.height(); while (qstrValue.length()) { int idx = re.indexIn(qstrValue, pos); if (idx == -1) { idx = qstrValue.length(); separator = QLatin1Char('\n'); } else separator = qstrValue.at(idx); if (fm.boundingRect(qstrValue.left(idx)).width() < intRectWidth || pos == 0) { pos = idx + 1; if (separator == QLatin1Char('\n')) { QString line = qstrValue.left(idx); qstrValue.remove(0, idx + 1); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { - page->addPrimitive(tb); + page->insertPrimitive(tb); } if (section) { OROTextBox *tb2 = dynamic_cast(tb->clone()); tb2->setPosition(scenePosition(position())); section->addPrimitive(tb2); } if (!page) { delete tb; } intStretch += intRectHeight; intLineCounter++; } } else { QString line = qstrValue.left(pos - 1); qstrValue.remove(0, pos); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { - page->addPrimitive(tb); + page->insertPrimitive(tb); } else { delete tb; } intStretch += intRectHeight; intLineCounter++; } } intStretch += (m_bottomPadding / 100.0); } return intStretch; //Item returns its required section height } diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index cc69ff28..b9a2f14d 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -1,15 +1,15 @@ -ecm_optional_add_subdirectory(barcode) +#ecm_optional_add_subdirectory(barcode) if(NOT WIN32) #todo ecm_optional_add_subdirectory(chart) endif() find_package(Marble) if(Marble_FOUND) ecm_optional_add_subdirectory(maps) endif() find_package(Qt5WebKitWidgets) if(Qt5WebKitWidgets_FOUND) ecm_optional_add_subdirectory(web) endif() diff --git a/src/plugins/barcode/3of9.cpp b/src/plugins/barcode/3of9.cpp index 0ddc03db..598f9337 100644 --- a/src/plugins/barcode/3of9.cpp +++ b/src/plugins/barcode/3of9.cpp @@ -1,186 +1,186 @@ /* 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 . */ /* * This file contains the implementation of the 3of9 barcode renderer. * All this code assumes a 100dpi rendering surface for it's calculations. */ #include "KReportRenderObjects.h" #include #include #include #include #include "kreportplugin_debug.h" struct code3of9 { char code; int values[9]; }; const struct code3of9 _3of9codes[] = { { '0', { 0, 0, 0, 1, 1, 0, 1, 0, 0 } }, { '1', { 1, 0, 0, 1, 0, 0, 0, 0, 1 } }, { '2', { 0, 0, 1, 1, 0, 0, 0, 0, 1 } }, { '3', { 1, 0, 1, 1, 0, 0, 0, 0, 0 } }, { '4', { 0, 0, 0, 1, 1, 0, 0, 0, 1 } }, { '5', { 1, 0, 0, 1, 1, 0, 0, 0, 0 } }, { '6', { 0, 0, 1, 1, 1, 0, 0, 0, 0 } }, { '7', { 0, 0, 0, 1, 0, 0, 1, 0, 1 } }, { '8', { 1, 0, 0, 1, 0, 0, 1, 0, 0 } }, { '9', { 0, 0, 1, 1, 0, 0, 1, 0, 0 } }, { 'A', { 1, 0, 0, 0, 0, 1, 0, 0, 1 } }, { 'B', { 0, 0, 1, 0, 0, 1, 0, 0, 1 } }, { 'C', { 1, 0, 1, 0, 0, 1, 0, 0, 0 } }, { 'D', { 0, 0, 0, 0, 1, 1, 0, 0, 1 } }, { 'E', { 1, 0, 0, 0, 1, 1, 0, 0, 0 } }, { 'F', { 0, 0, 1, 0, 1, 1, 0, 0, 0 } }, { 'G', { 0, 0, 0, 0, 0, 1, 1, 0, 1 } }, { 'H', { 1, 0, 0, 0, 0, 1, 1, 0, 0 } }, { 'I', { 0, 0, 1, 0, 0, 1, 1, 0, 0 } }, { 'J', { 0, 0, 0, 0, 1, 1, 1, 0, 0 } }, { 'K', { 1, 0, 0, 0, 0, 0, 0, 1, 1 } }, { 'L', { 0, 0, 1, 0, 0, 0, 0, 1, 1 } }, { 'M', { 1, 0, 1, 0, 0, 0, 0, 1, 0 } }, { 'N', { 0, 0, 0, 0, 1, 0, 0, 1, 1 } }, { 'O', { 1, 0, 0, 0, 1, 0, 0, 1, 0 } }, { 'P', { 0, 0, 1, 0, 1, 0, 0, 1, 0 } }, { 'Q', { 0, 0, 0, 0, 0, 0, 1, 1, 1 } }, { 'R', { 1, 0, 0, 0, 0, 0, 1, 1, 0 } }, { 'S', { 0, 0, 1, 0, 0, 0, 1, 1, 0 } }, { 'T', { 0, 0, 0, 0, 1, 0, 1, 1, 0 } }, { 'U', { 1, 1, 0, 0, 0, 0, 0, 0, 1 } }, { 'V', { 0, 1, 1, 0, 0, 0, 0, 0, 1 } }, { 'W', { 1, 1, 1, 0, 0, 0, 0, 0, 0 } }, { 'X', { 0, 1, 0, 0, 1, 0, 0, 0, 1 } }, { 'Y', { 1, 1, 0, 0, 1, 0, 0, 0, 0 } }, { 'Z', { 0, 1, 1, 0, 1, 0, 0, 0, 0 } }, { '-', { 0, 1, 0, 0, 0, 0, 1, 0, 1 } }, { '.', { 1, 1, 0, 0, 0, 0, 1, 0, 0 } }, { ' ', { 0, 1, 1, 0, 0, 0, 1, 0, 0 } }, { '$', { 0, 1, 0, 1, 0, 1, 0, 0, 0 } }, { '/', { 0, 1, 0, 1, 0, 0, 0, 1, 0 } }, { '+', { 0, 1, 0, 0, 0, 1, 0, 1, 0 } }, { '%', { 0, 0, 0, 1, 0, 1, 0, 1, 0 } }, { '*', { 0, 1, 0, 0, 1, 0, 1, 0, 0 } }, // this is a special start/stop character { '\0', { 0, 0, 0, 0, 0, 0, 0, 0, 0 } } // null termininator of list }; int codeIndex(QChar code) { // we are a case insensitive search const char latin1Code = code.toUpper().toLatin1(); for (int idx = 0; _3of9codes[idx].code != '\0'; idx++) { if (_3of9codes[idx].code == latin1Code) return idx; } return -1; // couldn't find it } void render3of9(OROPage * page, const QRectF & r, const QString & _str, int align) { QString str = _str; // lets determine some core attributes about this barcode qreal narrow_bar = 1; // a narrow bar is 1/100th inch wide qreal interchange_gap = narrow_bar; // the space between each 'set' of bars int bar_width_mult = 2; // the wide bar width multiple of the narrow bar // this is our mandatory minimum quiet zone qreal quiet_zone = narrow_bar * 10; if (quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height(); // how long is the value we need to encode? int val_length = str.length(); // L = (C + 2)(3N + 6)X + (C + 1)I // L length of barcode (excluding quite zone) in units same as X and I // C the number of characters in the value excluding the start/stop // N the bar width multiple for wide bars // X the width of a bar (pixels in our case) // I the interchange gap in the same units as X (value is same as X for our case) qreal L; qreal C = val_length; qreal N = bar_width_mult; qreal X = narrow_bar; qreal I = interchange_gap; L = ((C + 2.0) * (3.0 * N + 6.0) * X) + ((C + 1.0) * I); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if (align == 1) { // center qreal nqz = (draw_width - L) / 2.0; if (nqz > quiet_zone) quiet_zone = nqz; } else if (align > 1) // right quiet_zone = draw_width - (L + quiet_zone); //else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); // ok we need to prepend and append the str with a * //str = QString().sprintf("*%s*",(const char*)str); str = QLatin1Char('*') + str + QLatin1Char('*'); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); for (int i = 0; i < str.length(); i++) { // loop through each char and render the barcode QChar c = str.at(i); int idx = codeIndex(c); //kreportpluginDebug() << idx; if (idx == -1) { kreportpluginWarning() << "Encountered a non-compliant character while rendering a 3of9 barcode -- skipping"; continue; } bool space = false; for (int b = 0; b < 9; b++, space = !space) { qreal w = (_3of9codes[idx].values[b] == 1 ? narrow_bar * bar_width_mult : narrow_bar); //kreportpluginDebug() << w << space; if (!space) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, w, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += w; } pos += interchange_gap; } } diff --git a/src/plugins/barcode/code128.cpp b/src/plugins/barcode/code128.cpp index 3ed828fd..5ca017f5 100644 --- a/src/plugins/barcode/code128.cpp +++ b/src/plugins/barcode/code128.cpp @@ -1,345 +1,345 @@ /* 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 . */ /* * This file contains the implementation of the Code 128 barcode renderer. * All this code assumes a 100dpi rendering surface for it's calculations. */ #include #include #include #include #include #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" static const int SETA = 0; static const int SETB = 1; static const int SETC = 2; static const char FNC1 = (char)130; static const char FNC2 = (char)131; static const char FNC3 = (char)132; static const char FNC4 = (char)133; static const char SHIFT = (char)134; static const char CODEA = (char)135; static const char CODEB = (char)136; static const char CODEC = (char)137; static const char STARTA = (char)138; static const char STARTB = (char)139; static const char STARTC = (char)140; struct code128 { char codea; char codeb; char codec; int values[6]; bool _null; }; static const struct code128 _128codes[] = { // A , B , C , { B S B S B S }, NULL? }, { ' ', ' ', 0, { 2, 1, 2, 2, 2, 2 }, false }, { '!', '!', 1, { 2, 2, 2, 1, 2, 2 }, false }, { '"', '"', 2, { 2, 2, 2, 2, 2, 1 }, false }, { '#', '#', 3, { 1, 2, 1, 2, 2, 3 }, false }, { '$', '$', 4, { 1, 2, 1, 3, 2, 2 }, false }, { '%', '%', 5, { 1, 3, 1, 2, 2, 2 }, false }, { '&', '&', 6, { 1, 2, 2, 2, 1, 3 }, false }, { '\'', '\'', 7, { 1, 2, 2, 3, 1, 2 }, false }, { '(', '(', 8, { 1, 3, 2, 2, 1, 2 }, false }, { ')', ')', 9, { 2, 2, 1, 2, 1, 3 }, false }, { '*', '*', 10, { 2, 2, 1, 3, 1, 2 }, false }, { '+', '+', 11, { 2, 3, 1, 2, 1, 2 }, false }, { ',', ',', 12, { 1, 1, 2, 2, 3, 2 }, false }, { '-', '-', 13, { 1, 2, 2, 1, 3, 2 }, false }, { '.', '.', 14, { 1, 2, 2, 2, 3, 1 }, false }, { '/', '/', 15, { 1, 1, 3, 2, 2, 2 }, false }, { '0', '0', 16, { 1, 2, 3, 1, 2, 2 }, false }, { '1', '1', 17, { 1, 2, 3, 2, 2, 1 }, false }, { '2', '2', 18, { 2, 2, 3, 2, 1, 1 }, false }, { '3', '3', 19, { 2, 2, 1, 1, 3, 2 }, false }, { '4', '4', 20, { 2, 2, 1, 2, 3, 1 }, false }, { '5', '5', 21, { 2, 1, 3, 2, 1, 2 }, false }, { '6', '6', 22, { 2, 2, 3, 1, 1, 2 }, false }, { '7', '7', 23, { 3, 1, 2, 1, 3, 1 }, false }, { '8', '8', 24, { 3, 1, 1, 2, 2, 2 }, false }, { '9', '9', 25, { 3, 2, 1, 1, 2, 2 }, false }, { ':', ':', 26, { 3, 2, 1, 2, 2, 1 }, false }, { ';', ';', 27, { 3, 1, 2, 2, 1, 2 }, false }, { '<', '<', 28, { 3, 2, 2, 1, 1, 2 }, false }, { '=', '=', 29, { 3, 2, 2, 2, 1, 1 }, false }, { '>', '>', 30, { 2, 1, 2, 1, 2, 3 }, false }, { '?', '?', 31, { 2, 1, 2, 3, 2, 1 }, false }, { '@', '@', 32, { 2, 3, 2, 1, 2, 1 }, false }, { 'A', 'A', 33, { 1, 1, 1, 3, 2, 3 }, false }, { 'B', 'B', 34, { 1, 3, 1, 1, 2, 3 }, false }, { 'C', 'C', 35, { 1, 3, 1, 3, 2, 1 }, false }, { 'D', 'D', 36, { 1, 1, 2, 3, 1, 3 }, false }, { 'E', 'E', 37, { 1, 3, 2, 1, 1, 3 }, false }, { 'F', 'F', 38, { 1, 3, 2, 3, 1, 1 }, false }, { 'G', 'G', 39, { 2, 1, 1, 3, 1, 3 }, false }, { 'H', 'H', 40, { 2, 3, 1, 1, 1, 3 }, false }, { 'I', 'I', 41, { 2, 3, 1, 3, 1, 1 }, false }, { 'J', 'J', 42, { 1, 1, 2, 1, 3, 3 }, false }, { 'K', 'K', 43, { 1, 1, 2, 3, 3, 1 }, false }, { 'L', 'L', 44, { 1, 3, 2, 1, 3, 1 }, false }, { 'M', 'M', 45, { 1, 1, 3, 1, 2, 3 }, false }, { 'N', 'N', 46, { 1, 1, 3, 3, 2, 1 }, false }, { 'O', 'O', 47, { 1, 3, 3, 1, 2, 1 }, false }, { 'P', 'P', 48, { 3, 1, 3, 1, 2, 1 }, false }, { 'Q', 'Q', 49, { 2, 1, 1, 3, 3, 1 }, false }, { 'R', 'R', 50, { 2, 3, 1, 1, 3, 1 }, false }, { 'S', 'S', 51, { 2, 1, 3, 1, 1, 3 }, false }, { 'T', 'T', 52, { 2, 1, 3, 3, 1, 1 }, false }, { 'U', 'U', 53, { 2, 1, 3, 1, 3, 1 }, false }, { 'V', 'V', 54, { 3, 1, 1, 1, 2, 3 }, false }, { 'W', 'W', 55, { 3, 1, 1, 3, 2, 1 }, false }, { 'X', 'X', 56, { 3, 3, 1, 1, 2, 1 }, false }, { 'Y', 'Y', 57, { 3, 1, 2, 1, 1, 3 }, false }, { 'Z', 'Z', 58, { 3, 1, 2, 3, 1, 1 }, false }, { '[', '[', 59, { 3, 3, 2, 1, 1, 1 }, false }, { '\\', '\\', 60, { 3, 1, 4, 1, 1, 1 }, false }, { ']', ']', 61, { 2, 2, 1, 4, 1, 1 }, false }, { '^', '^', 62, { 4, 3, 1, 1, 1, 1 }, false }, { '_', '_', 63, { 1, 1, 1, 2, 2, 4 }, false }, { 0x00, '`', 64, { 1, 1, 1, 4, 2, 2 }, false }, // NUL { 0x01, 'a', 65, { 1, 2, 1, 1, 2, 4 }, false }, // SOH { 0x02, 'b', 66, { 1, 2, 1, 4, 2, 1 }, false }, // STX { 0x03, 'c', 67, { 1, 4, 1, 1, 2, 2 }, false }, // ETX { 0x04, 'd', 68, { 1, 4, 1, 2, 2, 1 }, false }, // EOT { 0x05, 'e', 69, { 1, 1, 2, 2, 1, 4 }, false }, // ENQ { 0x06, 'f', 70, { 1, 1, 2, 4, 1, 2 }, false }, // ACK { 0x07, 'g', 71, { 1, 2, 2, 1, 1, 4 }, false }, // BEL { 0x08, 'h', 72, { 1, 2, 2, 4, 1, 1 }, false }, // BS { 0x09, 'i', 73, { 1, 4, 2, 1, 1, 2 }, false }, // HT { 0x0A, 'j', 74, { 1, 4, 2, 2, 1, 1 }, false }, // LF { 0x0B, 'k', 75, { 2, 4, 1, 2, 1, 1 }, false }, // VT { 0x0C, 'l', 76, { 2, 2, 1, 1, 1, 4 }, false }, // FF { 0x0D, 'm', 77, { 4, 1, 3, 1, 1, 1 }, false }, // CR { 0x0E, 'n', 78, { 2, 4, 1, 1, 1, 2 }, false }, // SO { 0x0F, 'o', 79, { 1, 3, 4, 1, 1, 1 }, false }, // SI { 0x10, 'p', 80, { 1, 1, 1, 2, 4, 2 }, false }, // DLE { 0x11, 'q', 81, { 1, 2, 1, 1, 4, 2 }, false }, // DC1 { 0x12, 'r', 82, { 1, 2, 1, 2, 4, 1 }, false }, // DC2 { 0x13, 's', 83, { 1, 1, 4, 2, 1, 2 }, false }, // DC3 { 0x14, 't', 84, { 1, 2, 4, 1, 1, 2 }, false }, // DC4 { 0x15, 'u', 85, { 1, 2, 4, 2, 1, 1 }, false }, // NAK { 0x16, 'v', 86, { 4, 1, 1, 2, 1, 2 }, false }, // SYN { 0x17, 'w', 87, { 4, 2, 1, 1, 1, 2 }, false }, // ETB { 0x18, 'x', 88, { 4, 2, 1, 2, 1, 1 }, false }, // CAN { 0x19, 'y', 89, { 2, 1, 2, 1, 4, 1 }, false }, // EM { 0x1A, 'z', 90, { 2, 1, 4, 1, 2, 1 }, false }, // SUB { 0x1B, '{', 91, { 4, 1, 2, 1, 2, 1 }, false }, // ESC { 0x1C, '|', 92, { 1, 1, 1, 1, 4, 3 }, false }, // FS { 0x1D, '}', 93, { 1, 1, 1, 3, 4, 1 }, false }, // GS { 0x1E, '~', 94, { 1, 3, 1, 1, 4, 1 }, false }, // RS { 0x1F, 0x7F, 95, { 1, 1, 4, 1, 1, 3 }, false }, // US DEL { FNC3, FNC3, 96, { 1, 1, 4, 3, 1, 1 }, false }, // FNC3 FNC3 { FNC2, FNC2, 97, { 4, 1, 1, 1, 1, 3 }, false }, // FNC2 FNC2 { SHIFT, SHIFT, 98, { 4, 1, 1, 3, 1, 1 }, false }, // SHIFT SHIFT { CODEC, CODEC, 99, { 1, 1, 3, 1, 4, 1 }, false }, // CODEC CODEC { CODEB, FNC4, CODEB, { 1, 1, 4, 1, 3, 1 }, false }, // CODEB FNC4 CODEB { FNC4, CODEA, CODEA, { 3, 1, 1, 1, 4, 1 }, false }, // FNC4 CODEA CODEA { FNC1, FNC1, FNC1, { 4, 1, 1, 1, 3, 1 }, false }, // FNC1 FNC1 FNC1 { STARTA, STARTA, STARTA, { 2, 1, 1, 4, 1, 2 }, false }, // STARTA { STARTB, STARTB, STARTB, { 2, 1, 1, 2, 1, 4 }, false }, // STARTB { STARTC, STARTC, STARTC, { 2, 1, 1, 2, 3, 2 }, false }, // STARTC { '\0', '\0', '\0', { 0, 0, 0, 0, 0, 0 }, true } // null termininator of list }; // STOP CHARACTER { 2 3 3 1 1 1 2 } int code128Index(QChar code, int set) { const char latin1Code = code.toLatin1(); for (int idx = 0; _128codes[idx]._null == false; ++idx) { if (set == SETA && _128codes[idx].codea == latin1Code) return idx; if (set == SETB && _128codes[idx].codeb == latin1Code) return idx; if (set == SETC && _128codes[idx].codec == latin1Code) return idx; } return -1; // couldn't find it } void renderCode128(OROPage * page, const QRectF & r, const QString & _str, int align) { QVector str; // create the list.. if the list is empty then just set a start code and move on if (_str.isEmpty()) str.push_back(104); else { int rank_a = 0; int rank_b = 0; int rank_c = 0; QChar c; for (int i = 0; i < _str.length(); ++i) { c = _str.at(i); rank_a += (code128Index(c, SETA) != -1 ? 1 : 0); rank_b += (code128Index(c, SETB) != -1 ? 1 : 0); rank_c += (c >= QLatin1Char('0') && c <= QLatin1Char('9') ? 1 : 0); } if (rank_c == _str.length() && ((rank_c % 2) == 0 || rank_c > 4)) { // every value in the is a digit so we are going to go with mode C // and we have an even number or we have more than 4 values int i; if ((rank_c % 2) == 1) { str.push_back(104); // START B c = _str.at(0); str.push_back(code128Index(c, SETB)); str.push_back(99); // MODE C i = 1; } else { str.push_back(105); // START C i = 0; } for (; i < _str.length(); i += 2) { char a, b; c = _str.at(i); a = c.toLatin1(); a -= 48; c = _str.at(i + 1); b = c.toLatin1(); b -= 48; str.push_back(int((a * 10) + b)); } } else { // start in the mode that had the higher number of hits and then // just shift into the opposite mode as needed int set = (rank_a > rank_b ? SETA : SETB); str.push_back((rank_a > rank_b ? 103 : 104)); for (int i = 0; i < _str.length(); ++i) { c = _str.at(i); int v = code128Index(c, set); if (v == -1) { v = code128Index(c, (set == SETA ? SETB : SETA)); if (v != -1) { str.push_back(98); // SHIFT str.push_back(v); } } else str.push_back(v); } } } // calculate and append the checksum value to the list int checksum = str.at(0); for (int i = 1; i < str.size(); ++i) checksum += (str.at(i) * i); checksum = checksum % 103; str.push_back(checksum); // lets determine some core attributes about this barcode qreal bar_width = 1; // the width of the base unit bar 1/100 inch // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; if (quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height(); // how long is the value we need to encode? int val_length = str.size() - 2; // we include start and checksum in are list so // subtract them out for our calculations // L = (11C + 35)X // L length of barcode (excluding quite zone) in units same as X and I // C the number of characters in the value excluding the start/stop and checksum characters // X the width of a bar (pixels in our case) qreal L; qreal C = val_length; qreal X = bar_width; L = (((11.0 * C) + 35.0) * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if (align == 1) { // center qreal nqz = (draw_width - L) / 2.0; if (nqz > quiet_zone) quiet_zone = nqz; } else if (align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); bool space = false; for (int i = 0; i < str.size(); ++i) { // loop through each value and render the barcode const int idx = str.at(i); if (idx < 0 || idx > 105) { kreportpluginWarning() << "Encountered a non-compliant element while rendering a 3of9 barcode -- skipping"; continue; } space = false; for (int b = 0; b < 6; ++b, space = !space) { qreal w = _128codes[idx].values[b] * bar_width; if (!space) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, w, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += w; } } // we have to do the stop character separately like this because it has // 7 elements in it's bar sequence rather than 6 like the others int STOP_CHARACTER[] = { 2, 3, 3, 1, 1, 1, 2 }; space = false; for (int b = 0; b < 7; ++b, space = !space) { qreal w = STOP_CHARACTER[b] * bar_width; if (!space) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, w, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += w; } } diff --git a/src/plugins/barcode/codeean.cpp b/src/plugins/barcode/codeean.cpp index a71cc7eb..7704dcb5 100644 --- a/src/plugins/barcode/codeean.cpp +++ b/src/plugins/barcode/codeean.cpp @@ -1,842 +1,842 @@ /* 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 . */ /* * This file contains the implementation of the Code EAN and similar * formats for rendering purposes. All this code assumes a 100dpi * rendering surface for it's calculations. */ #include #include #include #include #include "KReportRenderObjects.h" static const int LEFTHAND_ODD = 0; static const int LEFTHAND_EVEN = 1; static const int RIGHTHAND = 2; static const int _encodings[10][3][7] = { /* LEFTHAND_ODD */ /* LEFTHAND_EVEN */ /* RIGHTHAND */ { { 0, 0, 0, 1, 1, 0, 1}, { 0, 1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, 1, 0 } }, // 0 { { 0, 0, 1, 1, 0, 0, 1}, { 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0 } }, // 1 { { 0, 0, 1, 0, 0, 1, 1}, { 0, 0, 1, 1, 0, 1, 1 }, { 1, 1, 0, 1, 1, 0, 0 } }, // 2 { { 0, 1, 1, 1, 1, 0, 1}, { 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1, 0 } }, // 3 { { 0, 1, 0, 0, 0, 1, 1}, { 0, 0, 1, 1, 1, 0, 1 }, { 1, 0, 1, 1, 1, 0, 0 } }, // 4 { { 0, 1, 1, 0, 0, 0, 1}, { 0, 1, 1, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1, 1, 0 } }, // 5 { { 0, 1, 0, 1, 1, 1, 1}, { 0, 0, 0, 0, 1, 0, 1 }, { 1, 0, 1, 0, 0, 0, 0 } }, // 6 { { 0, 1, 1, 1, 0, 1, 1}, { 0, 0, 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1, 0, 0 } }, // 7 { { 0, 1, 1, 0, 1, 1, 1}, { 0, 0, 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0 } }, // 8 { { 0, 0, 0, 1, 0, 1, 1}, { 0, 0, 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 1, 0, 0 } } // 9 }; static const int odd = LEFTHAND_ODD; static const int even = LEFTHAND_EVEN; static const int _parity[10][6] = { { odd, odd, odd, odd, odd, odd }, // 0 { odd, odd, even, odd, even, even }, // 1 { odd, odd, even, even, odd, even }, // 2 { odd, odd, even, even, even, odd }, // 3 { odd, even, odd, odd, even, even }, // 4 { odd, even, even, odd, odd, even }, // 5 { odd, even, even, even, odd, odd }, // 6 { odd, even, odd, even, odd, even }, // 7 { odd, even, odd, even, even, odd }, // 8 { odd, even, even, odd, even, odd } // 9 }; static const int _upcparenc[10][2][6] = { /* PARITY 0 */ /* PARITY 1 */ { { even, even, even, odd, odd, odd }, { odd, odd, odd, even, even, even } }, // 0 { { even, even, odd, even, odd, odd }, { odd, odd, even, odd, even, even } }, // 1 { { even, even, odd, odd, even, odd }, { odd, odd, even, even, odd, even } }, // 2 { { even, even, odd, odd, odd, even }, { odd, odd, even, even, even, odd } }, // 3 { { even, odd, even, even, odd, odd }, { odd, even, odd, odd, even, even } }, // 4 { { even, odd, odd, even, even, odd }, { odd, even, even, odd, odd, even } }, // 5 { { even, odd, odd, odd, even, even }, { odd, even, even, even, odd, odd } }, // 6 { { even, odd, even, odd, even, odd }, { odd, even, odd, even, odd, even } }, // 7 { { even, odd, even, odd, odd, even }, { odd, even, odd, even, even, odd } }, // 8 { { even, odd, odd, even, odd, even }, { odd, even, even, odd, even, odd } } // 9 }; // //! @todo New Renderer Functions //////////////////////////////////////////////////////// void renderCodeEAN13(OROPage * page, const QRectF & r, const QString & _str, int align) { int val[13]; // initialize all the values just so we can be predictable for (int i = 0; i < 13; ++i) val[i] = -1; // verify that the passed in string is valid // if it's not either twelve or thirteen characters // then it must be invalid to begin with if (_str.length() != 12 && _str.length() != 13) return; // loop through and convert each char to a digit. // if we can't convert all characters then this is // an invalid number for (int i = 0; i < _str.length(); ++i) { val[i] = ((QChar)_str.at(i)).digitValue(); if (val[i] == -1) return; } // calculate and append the checksum value int old_sum = val[12]; // get the old check sum value (-1 if none was set) int checksum = 0; for (int i = 0; i < 12; ++i) { checksum += val[i] * ((i % 2) ? 3 : 1); } checksum = (checksum % 10); if (checksum) checksum = 10 - checksum; val[12] = checksum; // if we had an old checksum value and if it doesn't match what we came // up with then the string must be invalid so we will bail if (old_sum != -1 && old_sum != checksum) return; // lets determine some core attributes about this barcode qreal bar_width = 1; // the width of the base unit bar 1/100 inch // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; if (quiet_zone < 10) quiet_zone = 10; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height() - 2; // L = 95X // L length of barcode (excluding quite zone) in units same as X and I // X the width of a bar (pixels in our case) qreal L; qreal X = bar_width; L = (95.0 * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if (align == 1) { // center qreal nqz = (draw_width - L) / 2; if (nqz > quiet_zone) quiet_zone = nqz; } else if (align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); // render open guard ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += bar_width; // render first set for (int i = 0; i < 6; ++i) { int b = val[i+1]; for (int w = 0; w < 7; ++w) { if (_encodings[b][_parity[val[0]][i]][w]) { rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.07)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += bar_width; } } // render center guard pos += bar_width; rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); // render last set for (int i = 0; i < 6; ++i) { int b = val[i+7]; for (int w = 0; w < 7; ++w) { if (_encodings[b][RIGHTHAND][w]) { rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.07)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += bar_width; } } // render close guard rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); QString parstr = QString::fromLatin1("%1").arg(val[0]); QString leftstr = QString().sprintf("%d%d%d%d%d%d", val[1], val[2], val[3], val[4], val[5], val[6]); QString rightstr = QString().sprintf("%d%d%d%d%d%d", val[7], val[8], val[9], val[10], val[11], val[12]); QFont font(QLatin1String("Arial"), 6); OROTextBox * tb = new OROTextBox(); tb->setPosition(QPointF(r.left(), r.top() + draw_height - 0.12)); tb->setSize(QSizeF(quiet_zone - 0.02, 0.12)); tb->setFont(font); tb->setText(parstr); tb->setFlags(Qt::AlignRight | Qt::AlignTop); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.07)); tb->setSize(QSizeF(0.42, 0.1)); tb->setFont(font); tb->setText(leftstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 0.5, (r.top() + draw_height) - 0.07)); tb->setSize(QSizeF(0.42, 0.1)); tb->setFont(font); tb->setText(rightstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); - page->addPrimitive(tb); + page->insertPrimitive(tb); } void renderCodeUPCA(OROPage * page, const QRectF & r, const QString & _str, int align) { int val[13]; // initialize all the values just so we can be predictable for (int i = 0; i < 13; ++i) { val[i] = -1; } // verify that the passed in string is valid // if it's not either twelve or thirteen characters // then it must be invalid to begin with if (_str.length() != 11 && _str.length() != 12) return; // loop through and convert each char to a digit. // if we can't convert all characters then this is // an invalid number val[0] = 0; for (int i = 0; i < _str.length(); ++i) { val[i+1] = ((QChar)_str.at(i)).digitValue(); if (val[i+1] == -1) return; } // calculate and append the checksum value int old_sum = val[12]; // get the old check sum value (-1 if none was set) int checksum = 0; for (int i = 0; i < 12; ++i) { checksum += val[i] * ((i % 2) ? 3 : 1); } checksum = (checksum % 10); if (checksum) checksum = 10 - checksum; val[12] = checksum; // if we had an old checksum value and if it doesn't match what we came // up with then the string must be invalid so we will bail if (old_sum != -1 && old_sum != checksum) return; // lets determine some core attributes about this barcode qreal bar_width = 1; // the width of the base unit bar // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; //if (quiet_zone < 10) quiet_zone = 10; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height() - 2; // L = 95X // L length of barcode (excluding quite zone) in units same as X and I // X the width of a bar (pixels in our case) qreal L; qreal X = bar_width; L = (95.0 * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if (align == 1) { // center qreal nqz = (draw_width - L) / 2; if (nqz > quiet_zone) quiet_zone = nqz; } else if (align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); // render open guard ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += bar_width; // render first set for (int i = 0; i < 6; ++i) { int b = val[i+1]; for (int w = 0; w < 7; ++w) { if (_encodings[b][_parity[val[0]][i]][w]) { rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height - (i == 0 ? 0 : 0.07))); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += bar_width; } } // render center guard pos += bar_width; rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); // render last set for (int i = 0; i < 6; ++i) { int b = val[i+7]; for (int w = 0; w < 7; ++w) { if (_encodings[b][RIGHTHAND][w]) { rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height - (i == 5 ? 0 : 0.07))); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += bar_width; } } // render close guard rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); QString parstr = QString::number(val[1]); QString chkstr = QString::number(val[12]); QString leftstr = QString().sprintf("%d%d%d%d%d", val[2], val[3], val[4], val[5], val[6]); QString rightstr = QString().sprintf("%d%d%d%d%d", val[7], val[8], val[9], val[10], val[11]); QFont font(QLatin1String("Arial"), 6); KRTextStyleData ts; ts.backgroundColor = Qt::white; ts.font = font; ts.foregroundColor = Qt::black; ts.backgroundOpacity = 100; ts.alignment = Qt::AlignRight | Qt::AlignTop; OROTextBox * tb = new OROTextBox(); tb->setPosition(QPointF(r.left(), r.top() + draw_height - 12)); tb->setSize(QSizeF(quiet_zone - 2, 12)); tb->setTextStyle(ts); tb->setText(parstr); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 10, (r.top() + draw_height) - 7)); tb->setSize(QSizeF(35, 10)); tb->setTextStyle(ts); tb->setText(leftstr); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 50, (r.top() + draw_height) - 7)); tb->setSize(QSizeF(35, 10)); tb->setTextStyle(ts); tb->setText(rightstr); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + L + 2, (r.top() + draw_height) - 12)); tb->setSize(QSizeF(8, 12)); tb->setTextStyle(ts); tb->setText(chkstr); - page->addPrimitive(tb); + page->insertPrimitive(tb); } void renderCodeEAN8(OROPage * page, const QRectF & r, const QString & _str, int align) { int val[8]; // initialize all the values just so we can be predictable for (int i = 0; i < 8; ++i) { val[i] = -1; } // verify that the passed in string is valid // if it's not either twelve or thirteen characters // then it must be invalid to begin with if (_str.length() != 7 && _str.length() != 8) return; // loop through and convert each char to a digit. // if we can't convert all characters then this is // an invalid number for (int i = 0; i < _str.length(); ++i) { val[i] = ((QChar)_str.at(i)).digitValue(); if (val[i] == -1) return; } // calculate and append the checksum value int old_sum = val[7]; // get the old check sum value (-1 if none was set) int checksum = 0; for (int i = 0; i < 7; ++i) { checksum += val[i] * ((i % 2) ? 1 : 3); } checksum = (checksum % 10); if (checksum) checksum = 10 - checksum; val[7] = checksum; // if we had an old checksum value and if it doesn't match what we came // up with then the string must be invalid so we will bail if (old_sum != -1 && old_sum != checksum) return; // lets determine some core attributes about this barcode qreal bar_width = 1; // the width of the base unit bar // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; if (quiet_zone < 10) quiet_zone = 10; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height() - 0.02; // L = 60X // L length of barcode (excluding quite zone) in units same as X and I // X the width of a bar (pixels in our case) qreal L; qreal X = bar_width; L = (67.0 * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if (align == 1) { // center qreal nqz = (draw_width - L) / 2; if (nqz > quiet_zone) quiet_zone = nqz; } else if (align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); // render open guard ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += bar_width; // render first set for (int i = 0; i < 4; ++i) { int b = val[i]; for (int w = 0; w < 7; ++w) { if (_encodings[b][LEFTHAND_ODD][w]) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.06)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += bar_width; } } // render center guard pos += bar_width; rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); // render last set for (int i = 0; i < 4; ++i) { int b = val[i+4]; for (int w = 0; w < 7; ++w) { if (_encodings[b][RIGHTHAND][w]) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.06)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += bar_width; } } // render close guard rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); QString leftstr = QString().sprintf("%d%d%d%d", val[0], val[1], val[2], val[3]); QString rightstr = QString().sprintf("%d%d%d%d", val[4], val[5], val[6], val[7]); QFont font(QLatin1String("Arial"), 6); OROTextBox * tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.06)); tb->setSize(QSizeF(0.28, 0.10)); tb->setFont(font); tb->setText(leftstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 0.36, (r.top() + draw_height) - 0.06)); tb->setSize(QSizeF(0.28, 0.10)); tb->setFont(font); tb->setText(rightstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); - page->addPrimitive(tb); + page->insertPrimitive(tb); } void renderCodeUPCE(OROPage * page, const QRectF & r, const QString & _str, int align) { int val[8]; // initialize all the values just so we can be predictable for (int i = 0; i < 8; ++i) { val[i] = -1; } // verify that the passed in string is valid // if it's not either twelve or thirteen characters // then it must be invalid to begin with if (_str.length() != 8) return; // loop through and convert each char to a digit. // if we can't convert all characters then this is // an invalid number for (int i = 0; i < _str.length(); ++i) { val[i] = ((QChar)_str.at(i)).digitValue(); if (val[i] == -1) return; } // calculate and append the checksum value // because everything is so messed up we don't calculate // the checksum and require that it be passed in already // however we do have to verify that the first digit is // either 0 or 1 as that is our parity if (val[0] != 0 && val[0] != 1) return; // lets determine some core attributes about this barcode qreal bar_width = 1; // the width of the base unit bar // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 0.10; if (quiet_zone < 0.10) quiet_zone = 0.10; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height() - 2; // L = 51X // L length of barcode (excluding quite zone) in units same as X and I // X the width of a bar (pixels in our case) qreal L; qreal X = bar_width; L = (51.0 * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if (align == 1) { // center qreal nqz = (draw_width - L) / 2; if (nqz > quiet_zone) quiet_zone = nqz; } else if (align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); // render open guard ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += bar_width; // render first set for (int i = 0; i < 6; ++i) { int b = val[i+1]; for (int w = 0; w < 7; ++w) { if (_encodings[b][_upcparenc[val[7]][val[0]][i]][w]) { rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height - 7)); - page->addPrimitive(rect); + page->insertPrimitive(rect); } pos += bar_width; } } // render center guard pos += bar_width; rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); pos += (bar_width * 2.0); // render close guard rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, bar_width, draw_height)); - page->addPrimitive(rect); + page->insertPrimitive(rect); QString parstr = QString::number(val[0]); QString chkstr = QString::number(val[7]); QString leftstr = QString().sprintf("%d%d%d%d%d%d", val[1], val[2], val[3], val[4], val[5], val[6]); QFont font(QLatin1String("Arial"), 6); KRTextStyleData ts; ts.backgroundColor = Qt::white; ts.font = font; ts.foregroundColor = Qt::black; ts.backgroundOpacity = 100; ts.alignment = Qt::AlignRight | Qt::AlignTop; OROTextBox * tb = new OROTextBox(); tb->setPosition(QPointF(r.left(), r.top() + draw_height - 12)); tb->setSize(QSizeF(quiet_zone - 2, 12)); tb->setTextStyle(ts); tb->setText(parstr); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 3, (r.top() + draw_height) - 7)); tb->setSize(QSizeF(42, 10)); tb->setTextStyle(ts); tb->setText(leftstr); - page->addPrimitive(tb); + page->insertPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + L + 2, r.top() + draw_height - 12)); tb->setSize(QSizeF(8, 12)); tb->setTextStyle(ts); tb->setText(chkstr); - page->addPrimitive(tb); + page->insertPrimitive(tb); } diff --git a/src/plugins/barcode/i2of5.cpp b/src/plugins/barcode/i2of5.cpp index fec790ae..e1a7c50d 100644 --- a/src/plugins/barcode/i2of5.cpp +++ b/src/plugins/barcode/i2of5.cpp @@ -1,152 +1,152 @@ /* This file is part of the KDE project * Copyright (C) 2001-2012 by OpenMFG, LLC * * 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Please contact info@openmfg.com with any questions on this license. */ /* * This file contains the implementation of the interleaved 2 of 5 barcode renderer. * All this code assumes a 100dpi rendering surface for it's calculations. */ #include #include #include #include #include "KReportRenderObjects.h" const char* _i2of5charmap[] = { "NNWWN", "WNNNW", "NWNNW", "WWNNN", "NNWNW", "WNWNN", "NWWNN", "NNNWW", "WNNWN", "NWNWN" }; static QPointF addElement(OROPage * page, const QRectF &r, QPointF startPos, qreal width, bool isSpace) { QPen pen(Qt::NoPen); QBrush brush(QColor("black")); if (!isSpace) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(startPos.x(),startPos.y(), width, r.height())); //rect->setRotationAxis(bc->rect.topLeft()); //!< @todo check this - page->addPrimitive(rect); + page->insertPrimitive(rect); } return QPointF(startPos.x() + width, startPos.y()); } static QPointF addBar(OROPage * page, const QRectF &r, QPointF startPos, qreal width) { return addElement(page, r, startPos, width, false); } static QPointF addSpace(OROPage * page, const QRectF &r, QPointF startPos, qreal width) { return addElement(page, r, startPos, width, true); } void renderI2of5(OROPage * page, const QRectF &r, const QString & _str, int align) { QString str = _str; qreal narrow_bar = 1; // a narrow bar is 1/100th inch wide qreal bar_width_mult = 2.5; // the wide bar width multiple of the narrow bar qreal wide_bar = narrow_bar * bar_width_mult; if (str.length() % 2) { str = QLatin1Char('0') + str; // padding zero if number of characters is not even } // this is our mandatory minimum quiet zone qreal quiet_zone = narrow_bar * 10; if (quiet_zone < 0.1) { quiet_zone = 0.1; } // what kind of area do we have to work with qreal draw_width = r.width(); // how long is the value we need to encode? int val_length = str.length(); // L = (C(2N+3)+6+N)X // L length of barcode (excluding quite zone // C the number of characters in the value excluding the start/stop // N the bar width multiple for wide bars // X the width of a bar (pixels in our case) qreal L; qreal C = val_length; qreal N = bar_width_mult; qreal X = narrow_bar; L = (C * (2.0*N + 3.0) + 6.0 + N) * X; // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area) // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option if (align == 1) { // center qreal nqz = (draw_width - L) / 2.0; if (nqz > quiet_zone) { quiet_zone = nqz; } } else if (align > 1) { // right quiet_zone = draw_width - (L + quiet_zone); } //else if (align < 1) {} // left : do nothing QPointF pos(r.left() + quiet_zone, r.top()); // start character pos = addBar(page, r, pos, narrow_bar); pos = addSpace(page, r, pos, narrow_bar); pos = addBar(page, r, pos, narrow_bar); pos = addSpace(page, r, pos, narrow_bar); for (int i = 0; i < str.length()-1; i+=2) { for (int iElt = 0; _i2of5charmap [0][iElt] != '\0'; iElt++) { for (int offset=0; offset<=1; offset++) { QChar c = str.at(i+offset); if (!c.isDigit()) { break; // invalid character } int iChar = c.digitValue(); qreal width = _i2of5charmap[iChar][iElt] == 'W' ? wide_bar : narrow_bar; pos = addElement(page, r, pos, width, offset==1); } } } // stop character pos = addBar(page, r, pos, wide_bar); pos = addSpace(page, r, pos, narrow_bar); pos = addBar(page, r, pos, narrow_bar); } diff --git a/src/plugins/maps/KReportItemMaps.cpp b/src/plugins/maps/KReportItemMaps.cpp index 6c540a3a..e6c5a82b 100644 --- a/src/plugins/maps/KReportItemMaps.cpp +++ b/src/plugins/maps/KReportItemMaps.cpp @@ -1,228 +1,228 @@ /* * Copyright (C) 2007-2016 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 2011-2015 by Radoslaw Wicik (radoslaw@wicik.pl) * * 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 "KReportItemMaps.h" #include #include #include #include #define myDebug() if (0) kDebug(44021) //! @todo replace with ReportItemMaps(const QDomNode &element = QDomNode()) KReportItemMaps::KReportItemMaps() : KReportItemMaps(QDomNode()) { } KReportItemMaps::KReportItemMaps(const QDomNode &element) : m_longtitude(0) , m_latitude(0) , m_zoom(1200) , m_pageId(0) , m_sectionId(0) , m_oroPicture(0) , m_longDataSetFromScript(false) , m_latDataSetFromScript(false) , m_zoomDataSetFromScript(false) { createProperties(); nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_latitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:latitude")).toDouble()); m_longitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:longitude")).toDouble()); m_zoomProperty->setValue(element.toElement().attribute(QLatin1String("report:zoom")).toInt()); QString themeId(element.toElement().attribute(QLatin1String("report:theme"))); themeId = themeId.isEmpty() ? m_themeManager.mapThemeIds()[0] : themeId; m_themeProperty->setValue(themeId); parseReportRect(element.toElement()); } KReportItemMaps::~KReportItemMaps() { } void KReportItemMaps::createProperties() { m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_latitudeProperty = new KProperty("latitude", 0.0, tr("Latitude"), tr("Latitude"), KProperty::Double); m_latitudeProperty->setOption("min", -90); m_latitudeProperty->setOption("max", 90); m_latitudeProperty->setOption("unit", QString::fromUtf8("°")); m_latitudeProperty->setOption("precision", 7); m_longitudeProperty = new KProperty("longitude", 0.0, tr("Longitude"), tr("Longitude"), KProperty::Double); m_longitudeProperty->setOption("min", -180); m_longitudeProperty->setOption("max", 180); m_longitudeProperty->setOption("unit", QString::fromUtf8("°")); m_longitudeProperty->setOption("precision", 7); m_zoomProperty = new KProperty("zoom", 1000, tr("Zoom"), tr("Zoom") ); m_zoomProperty->setOption("min", 0); m_zoomProperty->setOption("max", 4000); m_zoomProperty->setOption("step", 100); m_zoomProperty->setOption("slider", true); QStringList mapThemIds(m_themeManager.mapThemeIds()); m_themeProperty = new KProperty("theme", mapThemIds, mapThemIds, mapThemIds[1]); if (mapThemIds.contains(QLatin1String("earth/srtm/srtm.dgml"))) { m_themeProperty->setValue(QLatin1String("earth/srtm/srtm.dgml"), false); } propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_latitudeProperty); propertySet()->addProperty(m_longitudeProperty); propertySet()->addProperty(m_zoomProperty); propertySet()->addProperty(m_themeProperty); } void KReportItemMaps::setColumn(const QString &c) { m_controlSource->setValue(c); } QString KReportItemMaps::itemDataSource() const { return m_controlSource->value().toString(); } QString KReportItemMaps::typeName() const { return QLatin1String("maps"); } int KReportItemMaps::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) deserializeData(data); m_pageId = page; m_sectionId = section; m_offset = offset; m_oroPicture = new OROPicture(); m_oroPicture->setPosition(scenePosition(position()) + m_offset); m_oroPicture->setSize(sceneSize(size())); if (m_pageId) { - m_pageId->addPrimitive(m_oroPicture); + m_pageId->insertPrimitive(m_oroPicture); } if (m_sectionId) { OROPicture *i2 = dynamic_cast(m_oroPicture->clone()); if (i2) { i2->setPosition(scenePosition(position())); } } m_mapRenderer.renderJob(this); return 0; //Item doesn't stretch the section height } void KReportItemMaps::deserializeData(const QVariant& serialized) { //kreportpluginDebug() << "Map data for this record is" << serialized; QStringList dataList = serialized.toString().split(QLatin1Char(';')); if (dataList.size() == 3) { m_latitude = dataList[0].toDouble(); m_longtitude = dataList[1].toDouble(); m_zoom = dataList[2].toInt(); } else { m_latitude = m_latitudeProperty->value().toReal(); m_longtitude = m_longitudeProperty->value().toReal(); m_zoom = m_zoomProperty->value().toInt(); } } void KReportItemMaps::renderFinished() { emit finishedRendering(); } OROPicture* KReportItemMaps::oroImage() { return m_oroPicture; } qreal KReportItemMaps::longtitude() const { return m_longtitude; } qreal KReportItemMaps::latitude() const { return m_latitude; } int KReportItemMaps::zoom() const { return m_zoom; } QString KReportItemMaps::themeId() const { return m_themeProperty->value().toString(); } QVariant KReportItemMaps::realItemData(const QVariant& itemData) const { double lat, lon; int zoom; QStringList dataList = itemData.toString().split(QLatin1Char(';')); if (dataList.size() == 3) { lat = dataList[0].toDouble(); lon = dataList[1].toDouble(); zoom = dataList[2].toInt(); } else if (dataList.size() == 2) { lat = dataList[0].toDouble(); lon = dataList[1].toDouble(); zoom = m_zoomProperty->value().toInt(); } else { lat = m_latitudeProperty->value().toReal(); lon = m_longitudeProperty->value().toReal(); zoom = m_zoomProperty->value().toInt(); } if (m_longDataSetFromScript) { lon = m_longtitude; } if (m_latDataSetFromScript) { lat = m_latitude; } if (m_zoomDataSetFromScript) { zoom = m_zoom; } return QString(QLatin1String("%1;%2;%3")).arg(lat).arg(lon).arg(zoom); } diff --git a/src/plugins/web/KReportItemWeb.cpp b/src/plugins/web/KReportItemWeb.cpp index 8264d5ef..b538d950 100644 --- a/src/plugins/web/KReportItemWeb.cpp +++ b/src/plugins/web/KReportItemWeb.cpp @@ -1,144 +1,144 @@ /* This file is part of the KDE project Copyright Shreya Pandit Copyright 2011 Adam Pigg 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 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 "KReportItemWeb.h" #include #include #include #include #include #include #include #include #include "kreportplugin_debug.h" KReportItemWeb::KReportItemWeb(): m_rendering(false) { createProperties(); init(); } KReportItemWeb::KReportItemWeb(const QDomNode &element) { createProperties(); init(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; QDomElement e = element.toElement(); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); } } void KReportItemWeb::init() { m_webPage = new QWebPage(); connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); } void KReportItemWeb::createProperties() { m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); propertySet()->addProperty(m_controlSource); } KReportItemWeb::~KReportItemWeb() { } QString KReportItemWeb::typeName() const { return QLatin1String("web"); } void KReportItemWeb::loadFinished(bool) { //kreportpluginDebug() << m_rendering; if (m_rendering) { OROPicture * pic = new OROPicture(); m_webPage->setViewportSize(sceneSize(size()).toSize()); m_webPage->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); m_webPage->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); QPainter p(pic->picture()); m_webPage->mainFrame()->render(&p); QPointF pos = scenePosition(position()); QSizeF siz = sceneSize(size()); pos += m_targetOffset; pic->setPosition(pos); pic->setSize(siz); - if (m_targetPage) m_targetPage->addPrimitive(pic, false, true); + if (m_targetPage) m_targetPage->insertPrimitive(pic); OROPicture *p2 = dynamic_cast(pic->clone()); if (p2) { p2->setPosition(scenePosition(position())); if (m_targetSection) { m_targetSection->addPrimitive(p2); } } m_rendering = false; emit(finishedRendering()); } } int KReportItemWeb::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script); m_rendering = true; //kreportpluginDebug() << data; m_targetPage = page; m_targetSection = section; m_targetOffset = offset; QUrl url = QUrl::fromUserInput(data.toString()); if (url.isValid()) { m_webPage->mainFrame()->load(url); } else { m_webPage->mainFrame()->setHtml(data.toString()); } return 0; //Item doesn't stretch the section height } QString KReportItemWeb::itemDataSource() const { return m_controlSource->value().toString(); } diff --git a/src/renderer/KReportHTMLCSSRenderer_p.cpp b/src/renderer/KReportHTMLCSSRenderer_p.cpp index 7ed7cf53..15c4576b 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; 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 (long s = 0; s < document->sections(); s++) { + 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->sections() - 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 + (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->primitives(); i++) { + for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); //kreportDebug() << "Got object type" << prim->type(); - if (prim->type() == OROTextBox::TextBox) { - OROTextBox * tb = (OROTextBox*) prim; + 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 (prim->type() == OROImage::Image) { + } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving an image"; - OROImage * im = (OROImage*) prim; + 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 (prim->type() == OROPicture::Picture) { + } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving a picture"; - OROPicture * im = (OROPicture*) prim; + 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" << prim->type(); + 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; } -} \ No newline at end of file +} diff --git a/src/renderer/KReportHTMLTableRenderer_p.cpp b/src/renderer/KReportHTMLTableRenderer_p.cpp index 3ee1ee57..b8b84294 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; 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 (long s = 0; s < document->sections(); s++) { + for (int s = 0; s < document->sectionCount(); s++) { OROSection *section = document->section(s); - section->sortPrimatives(OROSection::SortX); + 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->sections() - 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 + (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->primitives(); i++) { + for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); - if (prim->type() == OROTextBox::TextBox) { - OROTextBox * tb = (OROTextBox*) prim; + if (dynamic_cast(prim)) { + OROTextBox * tb = dynamic_cast(prim); tr += QLatin1String("\n"); - } else if (prim->type() == OROImage::Image) { + } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving an image"; - OROImage * im = (OROImage*) prim; + 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 (prim->type() == OROPicture::Picture) { + } else if (dynamic_cast(prim)) { //kreportDebug() << "Saving a picture"; - OROPicture * im = (OROPicture*) prim; + 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/KReportKSpreadRenderer.cpp b/src/renderer/KReportKSpreadRenderer.cpp index 6d0bffaf..38b58250 100644 --- a/src/renderer/KReportKSpreadRenderer.cpp +++ b/src/renderer/KReportKSpreadRenderer.cpp @@ -1,117 +1,117 @@ /* 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 "KReportKSpreadRenderer.h" #include "ods/KoSimpleOdsDocument.h" #include "ods/KoSimpleOdsCell.h" #include "ods/KoSimpleOdsSheet.h" #include "KReportRenderObjects.h" #include "kreport_debug.h" KoReportKSpreadRenderer::KoReportKSpreadRenderer() { } KoReportKSpreadRenderer::~KoReportKSpreadRenderer() { } bool KoReportKSpreadRenderer::render(const KoReportRendererContext& context, ORODocument* document, int page) { Q_UNUSED(page); KoSimpleOdsDocument *doc = new KoSimpleOdsDocument(); KoSimpleOdsSheet *sht = new KoSimpleOdsSheet(); //kreportDebug() << "Setting name to:" << document->title(); sht->setName(document->title()); bool renderedPageHeader = false; bool renderedPageFooter = false; // Render Each Section - for (long s = 0; s < document->sections(); s++) { + for (int s = 0; s < document->sectionCount(); s++) { OROSection *section = document->section(s); - section->sortPrimatives(OROSection::SortX); + section->sortPrimitives(OROSection::SortX); 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->sections() - 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 + (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; //Render the objects in each section - for (int i = 0; i < section->primitives(); i++) { + for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); if (prim->type() == OROTextBox::TextBox) { OROTextBox * tb = (OROTextBox*) prim; sht->addCell(s, i, new KoSimpleOdsCell(tb->text())); } /* else if (prim->type() == OROImage::Image) { kreportDebug() << "Saving an image"; OROImage * im = ( OROImage* ) prim; tr += "" "" "\n"; im->image().save(saveDir + "/object" + QString::number(s) + QString::number(i) + ".png"); } else if (prim->type() == OROPicture::Picture) { kreportDebug() << "Saving a picture"; OROPicture * im = ( OROPicture* ) prim; tr += "" "" "\n"; QImage image(im->size().toSize(), QImage::Format_RGB32); QPainter painter(&image); im->picture()->play(&painter); image.save(saveDir + "/object" + QString::number(s) + QString::number(i) + ".png"); }*/ else { kreportWarning() << "unhandled primitive type"; } } } } doc->addSheet(sht); bool status; if (doc->saveDocument(context.destinationUrl.path()) == QFile::NoError) { status = true; } else { status = false; } delete doc; return status; } diff --git a/src/renderer/KReportPreRenderer.cpp b/src/renderer/KReportPreRenderer.cpp index 6a23217e..ca565063 100644 --- a/src/renderer/KReportPreRenderer.cpp +++ b/src/renderer/KReportPreRenderer.cpp @@ -1,698 +1,698 @@ /* 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 "KReportPreRenderer.h" #include "KReportPreRenderer_p.h" #include "KReportAsyncItemManager_p.h" #include "KReportOneRecordData_p.h" #include "KReportRenderObjects.h" #include "KReportData.h" #include "KReportItemBase.h" #include "KReportDocument.h" #include "KReportDetailSectionData.h" #include "KReportLabelSizeInfo.h" #include "KReportPageSize.h" #include "KReportDpi.h" #ifdef KREPORT_SCRIPTING #include "scripting/KReportScriptHandler.h" #include "scripting/KReportGroupTracker.h" #endif #include #include #include "kreport_debug.h" KReportPreRendererPrivate::KReportPreRendererPrivate(KReportPreRenderer *preRenderer) : m_preRenderer(preRenderer) { m_valid = false; m_document = 0; m_reportDocument = 0; m_page = 0; m_yOffset = 0.0; m_topMargin = m_bottomMargin = 0.0; m_leftMargin = m_rightMargin = 0.0; m_pageCounter = 0; m_maxHeight = m_maxWidth = 0.0; m_oneRecord = new KReportPrivate::OneRecordData(); m_kodata = 0; #ifdef KREPORT_SCRIPTING m_scriptHandler = 0; #endif asyncManager = new KReportPrivate::AsyncItemManager(this); connect(asyncManager, SIGNAL(finished()), this, SLOT(asyncItemsFinished())); } KReportPreRendererPrivate::~KReportPreRendererPrivate() { delete m_reportDocument; delete m_document; delete m_oneRecord; m_postProcText.clear(); } void KReportPreRendererPrivate::createNewPage() { //kreportDebug(); if (m_pageCounter > 0) finishCurPage(); m_pageCounter++; #ifdef KREPORT_SCRIPTING //Update the page count script value m_scriptHandler->setPageNumber(m_pageCounter); m_scriptHandler->newPage(); #endif m_page = new OROPage(0); m_document->addPage(m_page); //! @todo calculate past page bool lastPage = false; m_yOffset = m_topMargin; if (m_pageCounter == 1 && m_reportDocument->m_pageHeaderFirst) renderSection(*(m_reportDocument->m_pageHeaderFirst)); else if (lastPage == true && m_reportDocument->m_pageHeaderLast) renderSection(*(m_reportDocument->m_pageHeaderLast)); else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageHeaderOdd) renderSection(*(m_reportDocument->m_pageHeaderOdd)); else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageHeaderAny) renderSection(*(m_reportDocument->m_pageHeaderAny)); else if (m_reportDocument->m_pageHeaderAny) renderSection(*(m_reportDocument->m_pageHeaderAny)); } qreal KReportPreRendererPrivate::finishCurPageSize(bool lastPage) { qreal retval = 0.0; if (lastPage && m_reportDocument->m_pageFooterLast) retval = renderSectionSize(* (m_reportDocument->m_pageFooterLast)); else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst) retval = renderSectionSize(* (m_reportDocument->m_pageFooterFirst)); else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd) retval = renderSectionSize(* (m_reportDocument->m_pageFooterOdd)); else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven) retval = renderSectionSize(* (m_reportDocument->m_pageFooterEven)); else if (m_reportDocument->m_pageFooterAny) retval = renderSectionSize(* (m_reportDocument->m_pageFooterAny)); //kreportDebug() << retval; return retval; } qreal KReportPreRendererPrivate::finishCurPage(bool lastPage) { qreal offset = m_maxHeight - m_bottomMargin; qreal retval = 0.0; //kreportDebug() << offset; if (lastPage && m_reportDocument->m_pageFooterLast) { //kreportDebug() << "Last Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterLast)); retval = renderSection(* (m_reportDocument->m_pageFooterLast)); } else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst) { //kreportDebug() << "First Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterFirst)); retval = renderSection(* (m_reportDocument->m_pageFooterFirst)); } else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd) { //kreportDebug() << "Odd Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterOdd)); retval = renderSection(* (m_reportDocument->m_pageFooterOdd)); } else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven) { //kreportDebug() << "Even Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterEven)); retval = renderSection(* (m_reportDocument->m_pageFooterEven)); } else if (m_reportDocument->m_pageFooterAny) { //kreportDebug() << "Any Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterAny)); retval = renderSection(* (m_reportDocument->m_pageFooterAny)); } return retval; } void KReportPreRendererPrivate::renderDetailSection(KReportDetailSectionData *detailData) { if (detailData->m_detailSection) { if (m_kodata/* && !curs->eof()*/) { QStringList keys; QStringList keyValues; QList shownGroups; KReportDetailGroupSectionData * grp = 0; bool status = m_kodata->moveFirst(); int recordCount = m_kodata->recordCount(); //kreportDebug() << "Record Count:" << recordCount; for (int i = 0; i < (int) detailData->m_groupList.count(); ++i) { grp = detailData->m_groupList[i]; //If the group has a header or footer, then emit a change of group value if(grp->m_groupFooter || grp->m_groupHeader) { // we get here only if group is *shown* shownGroups << i; keys.append(grp->m_column); if (!keys.last().isEmpty()) keyValues.append(m_kodata->value(m_kodata->fieldNumber(keys.last())).toString()); else keyValues.append(QString()); //Tell interested parties we're about to render a header emit(enteredGroup(keys.last(), keyValues.last())); } if (grp->m_groupHeader) renderSection(*(grp->m_groupHeader)); } while (status) { const qint64 pos = m_kodata->at(); //kreportDebug() << "At:" << l << "Y:" << m_yOffset << "Max Height:" << m_maxHeight; if ((renderSectionSize(*detailData->m_detailSection) + finishCurPageSize((pos + 1 == recordCount)) + m_bottomMargin + m_yOffset) >= m_maxHeight) { //kreportDebug() << "Next section is too big for this page"; if (pos > 0) { m_kodata->movePrevious(); createNewPage(); m_kodata->moveNext(); } } renderSection(*(detailData->m_detailSection)); if (m_kodata) status = m_kodata->moveNext(); if (status == true && keys.count() > 0) { // check to see where it is we need to start int pos = -1; // if it's still -1 by the time we are done then no keyValues changed for (int i = 0; i < keys.count(); ++i) { if (keyValues[i] != m_kodata->value(m_kodata->fieldNumber(keys[i])).toString()) { pos = i; break; } } // don't bother if nothing has changed if (pos != -1) { // roll back the query and go ahead if all is good status = m_kodata->movePrevious(); if (status == true) { // print the footers as needed // any changes made in this for loop need to be duplicated // below where the footers are finished. bool do_break = false; for (int i = shownGroups.count() - 1; i >= 0; i--) { if (do_break) createNewPage(); do_break = false; grp = detailData->m_groupList[shownGroups.at(i)]; if (grp->m_groupFooter) { if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight) createNewPage(); renderSection(*(grp->m_groupFooter)); } if (KReportDetailGroupSectionData::BreakAfterGroupFooter == grp->m_pagebreak) do_break = true; } // step ahead to where we should be and print the needed headers // if all is good status = m_kodata->moveNext(); if (do_break) createNewPage(); if (status == true) { for (int i = 0; i < shownGroups.count(); ++i) { grp = detailData->m_groupList[shownGroups.at(i)]; if (grp->m_groupHeader) { if (renderSectionSize(*(grp->m_groupHeader)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight) { m_kodata->movePrevious(); createNewPage(); m_kodata->moveNext(); } if (!keys[i].isEmpty()) keyValues[i] = m_kodata->value(m_kodata->fieldNumber(keys[i])).toString(); //Tell interested parties thak key values changed renderSection(*(grp->m_groupHeader)); } } } } } } } if (keys.size() > 0 && m_kodata->movePrevious()) { // finish footers // duplicated changes from above here for (int i = shownGroups.count() - 1; i >= 0; i--) { grp = detailData->m_groupList[shownGroups.at(i)]; if (grp->m_groupFooter) { if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight) createNewPage(); renderSection(*(grp->m_groupFooter)); emit(exitedGroup(keys[i], keyValues[i])); } } } } if (KReportDetailSectionData::BreakAtEnd == detailData->m_pageBreak) createNewPage(); } } qreal KReportPreRendererPrivate::renderSectionSize(const KReportSectionData & sectionData) { qreal intHeight = POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX(); int itemHeight = 0; if (sectionData.objects().count() == 0) return intHeight; QList objects = sectionData.objects(); foreach(KReportItemBase *ob, objects) { QPointF offset(m_leftMargin, m_yOffset); QVariant itemData = m_kodata->value(ob->itemDataSource()); //ASync objects cannot alter the section height KReportAsyncItemBase *async_ob = qobject_cast(ob); if (!async_ob) { itemHeight = ob->renderSimpleData(0, 0, offset, itemData, m_scriptHandler); if (itemHeight > intHeight) { intHeight = itemHeight; } } } return intHeight; } qreal KReportPreRendererPrivate::renderSection(const KReportSectionData & sectionData) { qreal sectionHeight = POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX(); int itemHeight = 0; //kreportDebug() << "Name: " << sectionData.name() << " Height: " << sectionHeight // << "Objects: " << sectionData.objects().count(); emit(renderingSection(const_cast(§ionData), m_page, QPointF(m_leftMargin, m_yOffset))); //Create a pre-rendered section for this section and add it to the document OROSection *sec = new OROSection(m_document); sec->setHeight(sectionData.height()); sec->setBackgroundColor(sectionData.backgroundColor()); sec->setType(sectionData.type()); m_document->addSection(sec); //Render section background ORORect* bg = new ORORect(); bg->setPen(QPen(Qt::NoPen)); bg->setBrush(sectionData.backgroundColor()); qreal w = m_page->document()->pageLayout().fullRectPixels(KReportDpi::dpiX()).width() - m_page->document()->pageLayout().marginsPixels(KReportDpi::dpiX()).right() - m_leftMargin; bg->setRect(QRectF(m_leftMargin, m_yOffset, w, sectionHeight)); - m_page->addPrimitive(bg, true); + m_page->insertPrimitive(bg, true); QList objects = sectionData.objects(); foreach(KReportItemBase *ob, objects) { QPointF offset(m_leftMargin, m_yOffset); QVariant itemData = m_kodata->value(ob->itemDataSource()); if (ob->supportsSubQuery()) { itemHeight = ob->renderReportData(m_page, sec, offset, m_kodata, m_scriptHandler); } else { KReportAsyncItemBase *async_ob = qobject_cast(ob); if (async_ob){ //kreportDebug() << "async object"; asyncManager->addItem(async_ob, m_page, sec, offset, itemData, m_scriptHandler); } else { //kreportDebug() << "sync object"; itemHeight = ob->renderSimpleData(m_page, sec, offset, itemData, m_scriptHandler); } } if (itemHeight > sectionHeight) { sectionHeight = itemHeight; } } - for (int i = 0; i < m_page->primitives(); ++i) { + for (int i = 0; i < m_page->primitiveCount(); ++i) { OROPrimitive *prim = m_page->primitive(i); - if (prim->type() == OROTextBox::TextBox) { - OROTextBox *text = static_cast(prim); + if (dynamic_cast(prim)) { + OROTextBox *text = dynamic_cast(prim); if (text->requiresPostProcessing()) { m_postProcText.append(text); } } } m_yOffset += sectionHeight; return sectionHeight; } #ifdef KREPORT_SCRIPTING void KReportPreRendererPrivate::initEngine() { delete m_scriptHandler; m_scriptHandler = new KReportScriptHandler(m_kodata, m_reportDocument); connect(this, SIGNAL(enteredGroup(QString,QVariant)), m_scriptHandler, SLOT(slotEnteredGroup(QString,QVariant))); connect(this, SIGNAL(exitedGroup(QString,QVariant)), m_scriptHandler, SLOT(slotExitedGroup(QString,QVariant))); connect(this, SIGNAL(renderingSection(KReportSectionData*,OROPage*,QPointF)), m_scriptHandler, SLOT(slotEnteredSection(KReportSectionData*,OROPage*,QPointF))); } #endif void KReportPreRendererPrivate::asyncItemsFinished() { //kreportDebug() << "Finished rendering async items"; asyncManager->deleteLater(); emit finishedAllASyncItems(); } bool KReportPreRendererPrivate::generateDocument() { if (!m_kodata) { m_kodata = m_oneRecord; } if (!m_valid || !m_reportDocument) { return false; } // Do this check now so we don't have to undo a lot of work later if it fails KReportLabelSizeInfo label; if (m_reportDocument->pageSize() == QLatin1String("Labels")) { label = KReportLabelSizeInfo::find(m_reportDocument->labelType()); if (label.isNull()) { return false; } } //kreportDebug() << "Creating Document"; m_document = new ORODocument(m_reportDocument->title()); m_pageCounter = 0; m_yOffset = 0.0; //kreportDebug() << "Calculating Margins"; if (!label.isNull()) { if (m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) { m_topMargin = (label.startY() / 100.0); m_bottomMargin = 0; m_rightMargin = 0; m_leftMargin = (label.startX() / 100.0); } else { m_topMargin = (label.startX() / 100.0); m_bottomMargin = 0; m_rightMargin = 0; m_leftMargin = (label.startY() / 100.0); } } else { m_topMargin = m_reportDocument->pageLayout().marginsPoints().top(); m_bottomMargin = m_reportDocument->pageLayout().marginsPoints().bottom(); m_rightMargin = m_reportDocument->pageLayout().marginsPoints().right(); m_leftMargin = m_reportDocument->pageLayout().marginsPoints().left(); //kreportDebug() << "Margins:" << m_topMargin << m_bottomMargin << m_rightMargin << m_leftMargin; } //kreportDebug() << "Calculating Page Size"; QPageLayout layout = m_reportDocument->pageLayout(); // This should reflect the information of the report page size if (m_reportDocument->pageSize() == QLatin1String("Custom")) { m_maxWidth = m_reportDocument->pageLayout().fullRectPoints().width(); m_maxHeight = m_reportDocument->pageLayout().fullRectPoints().height(); } else { if (!label.isNull()) { m_maxWidth = label.width(); m_maxHeight = label.height(); m_reportDocument->pageLayout().setPageSize(QPageSize(KReportPageSize::pageSize(label.paper()))); } else { // lookup the correct size information for the specified size paper QSizeF pageSizePx = m_reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).size(); m_maxWidth = pageSizePx.width(); m_maxHeight = pageSizePx.height(); } } if (m_reportDocument->pageLayout().orientation() == QPageLayout::Landscape) { qreal tmp = m_maxWidth; m_maxWidth = m_maxHeight; m_maxHeight = tmp; } //kreportDebug() << "Page Size:" << m_maxWidth << m_maxHeight; m_document->setPageLayout(m_reportDocument->pageLayout()); m_kodata->setSorting(m_reportDocument->m_detailSection->m_sortedFields); if (!m_kodata->open()) { return false; } #ifdef KREPORT_SCRIPTING initEngine(); connect(m_scriptHandler, SIGNAL(groupChanged(QMap)), m_preRenderer, SIGNAL(groupChanged(QMap))); //Loop through all abjects that have been registered, and register them with the script handler if (m_scriptHandler) { QMapIterator i(m_scriptObjects); while (i.hasNext()) { i.next(); m_scriptHandler->registerScriptObject(i.value(), i.key()); } //execute the script, if it fails, abort and return the empty document if (!m_scriptHandler->trigger()) { m_scriptHandler->displayErrors(); return m_document; } } #endif createNewPage(); if (!label.isNull()) { // Label Print Run // remember the initial margin setting as we will be modifying // the value and restoring it as we move around qreal margin = m_leftMargin; m_yOffset = m_topMargin; qreal w = (label.width() / 100.0); qreal wg = (label.xGap() / 100.0); qreal h = (label.height() / 100.0); qreal hg = (label.yGap() / 100.0); int numCols = label.columns(); int numRows = label.rows(); qreal tmp; // flip the value around if we are printing landscape if (!m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) { w = (label.height() / 100.0); wg = (label.yGap() / 100.0); h = (label.width() / 100.0); hg = (label.xGap() / 100.0); numCols = label.rows(); numRows = label.columns(); } KReportDetailSectionData * detailData = m_reportDocument->m_detailSection; if (detailData->m_detailSection) { KReportData *mydata = m_kodata; if (mydata && mydata->recordCount() > 0) { /* && !((query = orqThis->getQuery())->eof()))*/ if (!mydata->moveFirst()) { return false; } int row = 0; int col = 0; do { tmp = m_yOffset; // store the value as renderSection changes it renderSection(*(detailData->m_detailSection)); m_yOffset = tmp; // restore the value that renderSection modified col++; m_leftMargin += w + wg; if (col >= numCols) { m_leftMargin = margin; // reset back to original value col = 0; row++; m_yOffset += h + hg; if (row >= numRows) { m_yOffset = m_topMargin; row = 0; createNewPage(); } } } while (mydata->moveNext()); } } } else { // Normal Print Run if (m_reportDocument->m_reportHeader) { renderSection(*(m_reportDocument->m_reportHeader)); } if (m_reportDocument->m_detailSection) { renderDetailSection(m_reportDocument->m_detailSection); } if (m_reportDocument->m_reportFooter) { if (renderSectionSize(*(m_reportDocument->m_reportFooter)) + finishCurPageSize(true) + m_bottomMargin + m_yOffset >= m_maxHeight) { createNewPage(); } renderSection(*(m_reportDocument->m_reportFooter)); } } finishCurPage(true); #ifdef KREPORT_SCRIPTING // _postProcText contains those text boxes that need to be updated // with information that wasn't available at the time it was added to the document - m_scriptHandler->setPageTotal(m_document->pages()); + m_scriptHandler->setPageTotal(m_document->pageCount()); for (int i = 0; i < m_postProcText.size(); i++) { OROTextBox * tb = m_postProcText.at(i); - m_scriptHandler->setPageNumber(tb->page()->page() + 1); + m_scriptHandler->setPageNumber(tb->page()->pageNumber() + 1); tb->setText(m_scriptHandler->evaluate(tb->text()).toString()); } #endif asyncManager->startRendering(); #ifdef KREPORT_SCRIPTING m_scriptHandler->displayErrors(); #endif if (!m_kodata->close()) { return false; } #ifdef KREPORT_SCRIPTING delete m_scriptHandler; m_scriptHandler = 0; #endif if (m_kodata != m_oneRecord) { delete m_kodata; m_kodata = 0; } m_postProcText.clear(); return true; } //===========================KReportPreRenderer=============================== KReportPreRenderer::KReportPreRenderer(const QDomElement &document) : d(new KReportPreRendererPrivate(this)) { setDocument(document); connect(d, &KReportPreRendererPrivate::finishedAllASyncItems, this, &KReportPreRenderer::finishedAllASyncItems); } KReportPreRenderer::~KReportPreRenderer() { delete d; } void KReportPreRenderer::setName(const QString &n) { d->m_reportDocument->setName(n); } bool KReportPreRenderer::isValid() const { if (d && d->m_valid) return true; return false; } ORODocument* KReportPreRenderer::document() { return d->m_document; } bool KReportPreRenderer::generateDocument() { // delete d->m_document; if (!d->generateDocument()) { delete d->m_document; d->m_document = 0; } return d->m_document; } void KReportPreRenderer::setSourceData(KReportData *data) { if (d && data != d->m_kodata) { delete d->m_kodata; d->m_kodata = data; } } bool KReportPreRenderer::setDocument(const QDomElement &document) { delete d->m_document; d->m_valid = false; if (document.tagName() != QLatin1String("report:content")) { kreportWarning() << "report schema is invalid"; return false; } d->m_reportDocument = new KReportDocument(document); d->m_valid = d->m_reportDocument->isValid(); return isValid(); } #ifdef KREPORT_SCRIPTING void KReportPreRenderer::registerScriptObject(QObject* obj, const QString& name) { //kreportDebug() << name; d->m_scriptObjects[name] = obj; } KReportScriptHandler *KReportPreRenderer::scriptHandler() { return d->m_scriptHandler; } #endif const KReportDocument* KReportPreRenderer::reportData() const { return d->m_reportDocument; } diff --git a/src/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp index e1f33368..e125da27 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) return false; setupPrinter(document, context.printer); bool endWhenComplete = false; if (!context.painter->isActive()) { endWhenComplete = true; if (!context.painter->begin(context.printer)) return false; } int fromPage = context.printer->fromPage(); if (fromPage > 0) fromPage -= 1; int toPage = context.printer->toPage(); - if (toPage == 0 || toPage > document->pages()) - toPage = document->pages(); + 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()); for (int copy = 0; copy < context.printer->numCopies(); copy++) { for (int page = fromPage; page < toPage; page++) { if (page > fromPage) context.printer->newPage(); OROPage * p = document->page(page); if (context.printer->pageOrder() == QPrinter::LastPageFirst) p = document->page(toPage - 1 - page); // Render Page Objects - for (int i = 0; i < p->primitives(); i++) { + 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 (prim->type() == OROTextBox::TextBox) { + if (dynamic_cast(prim)) { //kreportDebug() << "Text Box"; - OROTextBox * tb = (OROTextBox*) 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(); //Background QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); //_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()); //outer line 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(); - } else if (prim->type() == OROLine::Line) { + } else if (dynamic_cast(prim)) { //kreportDebug() << "Line"; - OROLine * ln = (OROLine*) prim; + 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(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(); - } else if (prim->type() == OROImage::Image) { + } else if (dynamic_cast(prim)) { //kreportDebug() << "Image"; - OROImage * im = (OROImage*) 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->scaled()) + 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); - } else if (prim->type() == ORORect::Rect) { + } else if (dynamic_cast(prim)) { //kreportDebug() << "Rect"; - ORORect * re = (ORORect*) 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(); - } else if (prim->type() == OROEllipse::Ellipse) { - OROEllipse * re = (OROEllipse*) prim; + } 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(); - } else if (prim->type() == OROPicture::Picture) { - OROPicture * im = (OROPicture*) prim; + } 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())); - } else if (prim->type() == OROCheck::Check) { - OROCheck * chk = (OROCheck*) prim; + } 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->setBackgroundMode(Qt::OpaqueMode); context.painter->setRenderHint(QPainter::Antialiasing); context.painter->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { context.painter->setPen(QPen(Qt::lightGray)); } else { 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() == QLatin1String("Cross")) { + if (chk->checkType() == OROCheckBox::Cross) { 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); } - } else if (chk->checkType() == QLatin1String("Dot")) { + } else if (chk->checkType() == OROCheckBox::Dot) { //Radio Style 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); } } else { //Tickbox Style 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->restore(); } } } } if (endWhenComplete) context.painter->end(); return true; } } diff --git a/src/renderer/KReportScreenRenderer_p.cpp b/src/renderer/KReportScreenRenderer_p.cpp index 8a1338f2..4df0c90b 100644 --- a/src/renderer/KReportScreenRenderer_p.cpp +++ b/src/renderer/KReportScreenRenderer_p.cpp @@ -1,224 +1,224 @@ /* 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) return false; OROPage *p = document->page(page); if (!p) { return false; } // Render Page Objects - for (int i = 0; i < p->primitives(); i++) { + for (int i = 0; i < p->primitiveCount(); i++) { OROPrimitive *prim = p->primitive(i); - if (prim->type() == OROTextBox::TextBox) { + 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(); //Background context.painter->setBackgroundMode(Qt::TransparentMode); QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); 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()); //outer line 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(); } - else if (prim->type() == OROLine::Line) { + 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(); } - else if (prim->type() == ORORect::Rect) { + 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(); } - else if (prim->type() == OROEllipse::Ellipse) { + 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(); } - else if (prim->type() == OROImage::Image) { + 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->scaled()) + 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); } - else if (prim->type() == OROPicture::Picture) { + 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(); } - else if (prim->type() == OROCheck::Check) { - OROCheck * chk = dynamic_cast(prim); + 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->setBackgroundMode(Qt::OpaqueMode); context.painter->setRenderHint(QPainter::Antialiasing); context.painter->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { context.painter->setPen(QPen(Qt::lightGray)); } else { 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() == QLatin1String("Cross")) { + if (chk->checkType() == OROCheckBox::Cross) { 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); } } - else if (chk->checkType() == QLatin1String("Dot")) { + else if (chk->checkType() == OROCheckBox::Dot) { //Radio Style 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); } } else { //Tickbox Style 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->restore(); } else { kreportWarning() << "unrecognized primitive type"; } } return true; } } diff --git a/src/renderer/KReportView.cpp b/src/renderer/KReportView.cpp index 769128c6..4f9ab784 100644 --- a/src/renderer/KReportView.cpp +++ b/src/renderer/KReportView.cpp @@ -1,166 +1,166 @@ /* This file is part of the KDE project Copyright (C) 2015 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 "KReportView.h" #include "KReportPage.h" #include "KReportRenderObjects.h" #include "KReportPreRenderer.h" #include "KReportRendererBase.h" #include "kreport_debug.h" #include #include #include #include #include #include #include #include #include #include //! @internal class Q_DECL_HIDDEN KReportView::Private { public: explicit Private() : reportDocument(0) , reportPage(0) , currentPage(1) , pageCount(0) {} ~Private() {} ORODocument *reportDocument; QGraphicsView *reportView; QGraphicsScene *reportScene; KReportPage *reportPage; int currentPage; int pageCount; KReportRendererFactory factory; }; KReportView::KReportView(QWidget *parent) : QWidget(parent), d(new Private()) { setObjectName(QLatin1String("KReportView")); d->reportView = new QGraphicsView(this); // page selector should be always visible: d->reportView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); QVBoxLayout *l = new QVBoxLayout; l->setMargin(0); setLayout(l); layout()->addWidget(d->reportView); d->reportScene = new QGraphicsScene(this); d->reportScene->setSceneRect(0,0,1000,2000); d->reportView->setScene(d->reportScene); d->reportScene->setBackgroundBrush(palette().brush(QPalette::Dark)); } KReportView::~KReportView() { //kreportDebug(); delete d; } void KReportView::moveToFirstPage() { if (d->currentPage != 1) { d->currentPage = 1; d->reportPage->renderPage(d->currentPage); } } void KReportView::moveToLastPage() { if (d->currentPage != d->pageCount) { d->currentPage = d->pageCount; d->reportPage->renderPage(d->currentPage); } } void KReportView::moveToNextPage() { if (d->currentPage < d->pageCount) { d->currentPage++; d->reportPage->renderPage(d->currentPage); } } void KReportView::moveToPreviousPage() { if (d->currentPage > 1) { d->currentPage--; d->reportPage->renderPage(d->currentPage); } } int KReportView::currentPage() const { return d->currentPage; } int KReportView::pageCount() const { return d->pageCount; } void KReportView::setDocument(ORODocument* doc) { d->reportDocument = doc; if (d->reportPage) { delete d->reportPage; } - d->pageCount = doc->pages(); + d->pageCount = doc->pageCount(); d->reportPage = new KReportPage(this, d->reportDocument); d->reportPage->setObjectName(QLatin1String("KReportPage")); d->reportScene->setSceneRect(0,0,d->reportPage->rect().width() + 40, d->reportPage->rect().height() + 40); d->reportScene->addItem(d->reportPage); d->reportPage->setPos(20,20); d->reportView->centerOn(0,0); } QAbstractScrollArea* KReportView::scrollArea() { return d->reportView; } void KReportView::refreshCurrentPage() { //qDebug() << "Refreshing current page" << d->currentPage; if (d->reportPage) { d->reportPage->renderPage(d->currentPage); } } diff --git a/src/renderer/odtframe/KoOdtFrameReportCheckBox.cpp b/src/renderer/odtframe/KoOdtFrameReportCheckBox.cpp index b2e460eb..f5a87e34 100644 --- a/src/renderer/odtframe/KoOdtFrameReportCheckBox.cpp +++ b/src/renderer/odtframe/KoOdtFrameReportCheckBox.cpp @@ -1,180 +1,180 @@ /* This file is part of the KDE project Copyright (C) 2011, 2012 by Dag Andersen (danders@get2net.dk) 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 "KoOdtFrameReportCheckBox.h" #include #include #include #include #include #include #include #include "KReportRenderObjects.h" #include #include #include #include "kreport_debug.h" #include #include -KoOdtFrameReportCheckBox::KoOdtFrameReportCheckBox(OROCheck *primitive) +KoOdtFrameReportCheckBox::KoOdtFrameReportCheckBox(OROCheckBox *primitive) : KoOdtFrameReportPrimitive(primitive) { } KoOdtFrameReportCheckBox::~KoOdtFrameReportCheckBox() { } -OROCheck *KoOdtFrameReportCheckBox::checkBox() const +OROCheckBox *KoOdtFrameReportCheckBox::checkBox() const { - return static_cast(m_primitive); + return static_cast(m_primitive); } void KoOdtFrameReportCheckBox::createStyle(KoGenStyles *coll) { KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic"); gs.addProperty("draw:fill", "none"); gs.addPropertyPt("fo:margin", 0); gs.addProperty("style:horizontal-pos", "from-left"); gs.addProperty("style:horizontal-rel", "page"); gs.addProperty("style:vertical-pos", "from-top"); gs.addProperty("style:vertical-rel", "page"); gs.addProperty("style:wrap", "dynamic"); gs.addPropertyPt("style:wrap-dynamic-threshold", 0); QPen pen; qreal weight = checkBox()->lineStyle().weight; if (weight < 1.0) { weight = 1.0; } pen.setWidthF(weight); pen.setColor(checkBox()->lineStyle().lineColor); pen.setStyle(checkBox()->lineStyle().style); KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen); m_frameStyleName = coll->insert(gs, "F"); } void KoOdtFrameReportCheckBox::createBody(KoXmlWriter *bodyWriter) const { bodyWriter->startElement("draw:frame"); bodyWriter->addAttribute("draw:id", itemName()); bodyWriter->addAttribute("xml:id", itemName()); bodyWriter->addAttribute("draw:name", itemName()); bodyWriter->addAttribute("text:anchor-type", "page"); bodyWriter->addAttribute("text:anchor-page-number", pageNumber()); bodyWriter->addAttribute("draw:style-name", m_frameStyleName); commonAttributes(bodyWriter); bodyWriter->startElement("draw:image"); bodyWriter->addAttribute("xlink:href", "Pictures/" + imageName()); bodyWriter->addAttribute("xlink:type", "simple"); bodyWriter->addAttribute("xlink:show", "embed"); bodyWriter->addAttribute("xlink:actuate", "onLoad"); bodyWriter->endElement(); // draw:image bodyWriter->endElement(); // draw:frame } QString KoOdtFrameReportCheckBox::imageName() const { return QString("Checkbox_%1.png").arg(m_uid); } bool KoOdtFrameReportCheckBox::saveData(KoStore* store, KoXmlWriter* manifestWriter) const { QString name = "Pictures/" + imageName(); if (!store->open(name)) { return false; } - OROCheck * chk = checkBox(); + OROCheckBox * chk = checkBox(); QSizeF sz = chk->size(); QPen fpen; // frame pen if (chk->lineStyle().style == Qt::NoPen || chk->lineStyle().weight <= 0) { fpen = QPen(Qt::lightGray); } else { fpen = QPen(chk->lineStyle().lineColor, chk->lineStyle().weight, chk->lineStyle().style); } QPointF ps(fpen.widthF(), fpen.widthF()); QRectF rc = QRectF(0, 0, sz.width() + (ps.x()*2), sz.height() + (ps.y()*2)); QPainter painter; QImage image(rc.size().toSize(), QImage::Format_ARGB32); image.fill(0); painter.begin(&image); painter.setBackgroundMode(Qt::OpaqueMode); painter.setRenderHint(QPainter::Antialiasing); qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == "Cross") { painter.drawRoundedRect(rc.adjusted(ps.x(), ps.y(), -ps.x(), -ps.y()), sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); painter.setPen(lp); QRectF r = rc.adjusted(ox + ps.x(), oy + ps.y(), -(ox + ps.x()), -(oy + ps.y())); painter.drawLine(r.topLeft(), r.bottomRight()); painter.drawLine(r.bottomLeft(), r.topRight()); } } else if (chk->checkType() == "Dot") { //Radio Style painter.drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); painter.setBrush(lb); painter.setPen(Qt::NoPen); painter.drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style painter.drawRoundedRect(rc.adjusted(ps.x(), ps.y(), -ps.x(), -ps.y()), sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); painter.setPen(lp); painter.drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); painter.drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } painter.end(); KoStoreDevice device(store); bool ok = image.save(&device, "PNG"); if (ok) { QMimeDatabase db; const QString mimetype(db.mimeTypeForFile(name, QMimeDatabase::MatchExtension).name()); manifestWriter->addManifestEntry(name, mimetype); //kreportDebug() << "manifest:" << mimetype; } bool cl = store->close(); //kreportDebug()< #include #include #include KoOdtFrameReportPrimitive::KoOdtFrameReportPrimitive(OROPrimitive *primitive) : m_primitive(primitive) , m_uid(0) { } KoOdtFrameReportPrimitive::~KoOdtFrameReportPrimitive() { } bool KoOdtFrameReportPrimitive::isValid() const { return (bool)m_primitive; } void KoOdtFrameReportPrimitive::setPrimitive(OROPrimitive *primitive) { m_primitive = primitive; } int KoOdtFrameReportPrimitive::pageNumber() const { - return isValid() && m_primitive->page() ? m_primitive->page()->page() + 1 : 0; + return isValid() && m_primitive->page() ? m_primitive->page()->pageNumber() + 1 : 0; } void KoOdtFrameReportPrimitive::setUID(int uid) { m_uid = uid; } int KoOdtFrameReportPrimitive::uid() const { return m_uid; } QString KoOdtFrameReportPrimitive::itemName() const { return QString("Item_%1").arg(m_uid); } void KoOdtFrameReportPrimitive::createStyle(KoGenStyles *coll) { KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic"); gs.addProperty("draw:fill", "none"); gs.addPropertyPt("fo:margin", 0); gs.addProperty("style:horizontal-pos", "from-left"); gs.addProperty("style:horizontal-rel", "page"); gs.addProperty("style:vertical-pos", "from-top"); gs.addProperty("style:vertical-rel", "page"); gs.addProperty("style:wrap", "dynamic"); gs.addPropertyPt("style:wrap-dynamic-threshold", 0); m_frameStyleName = coll->insert(gs, "F"); } void KoOdtFrameReportPrimitive::createBody(KoXmlWriter *bodyWriter) const { Q_UNUSED(bodyWriter); } void KoOdtFrameReportPrimitive::commonAttributes(KoXmlWriter *bodyWriter) const { // convert to inches qreal x = m_primitive->position().x() / KReportDpi::dpiX(); qreal y = m_primitive->position().y() / KReportDpi::dpiX(); qreal w = m_primitive->size().width() / KReportDpi::dpiX(); qreal h = m_primitive->size().height() / KReportDpi::dpiY(); bodyWriter->addAttribute("svg:x", QString("%1in").arg(x)); bodyWriter->addAttribute("svg:y", QString("%1in").arg(y)); bodyWriter->addAttribute("svg:width", QString("%1in").arg(w)); bodyWriter->addAttribute("svg:height", QString("%1in").arg(h)); bodyWriter->addAttribute("draw:z-index", "3"); } bool KoOdtFrameReportPrimitive::saveData(KoStore */*store*/, KoXmlWriter*) const { return true; } diff --git a/src/renderer/scripting/KReportScriptDraw.cpp b/src/renderer/scripting/KReportScriptDraw.cpp index c9d0ace1..fe1196f2 100644 --- a/src/renderer/scripting/KReportScriptDraw.cpp +++ b/src/renderer/scripting/KReportScriptDraw.cpp @@ -1,147 +1,147 @@ /* 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 "KReportScriptDraw.h" #include "KReportRenderObjects.h" #include "KReportPosition.h" #include "KReportSize.h" #include #include KReportScriptDraw::KReportScriptDraw(QObject *parent) : QObject(parent) { m_curPage = 0; } KReportScriptDraw::~KReportScriptDraw() { } void KReportScriptDraw::setPage(OROPage *p) { m_curPage = p; } void KReportScriptDraw::setOffset(QPointF off) { m_curOffset = off; } void KReportScriptDraw::rectangle(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a) { if (m_curPage) { ORORect *r = new ORORect(); KReportPosition p; KReportSize s; p.setPointPos(QPointF(x, y)); s.setPointSize(QSizeF(w, h)); r->setRect(QRectF(p.toScene() + m_curOffset, s.toScene())); QPen pen(QColor(lc), lw); QColor c(fc); c.setAlpha(a); QBrush bru(c); r->setBrush(bru); r->setPen(pen); - m_curPage->addPrimitive(r); + m_curPage->insertPrimitive(r); } } void KReportScriptDraw::ellipse(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a) { if (m_curPage) { OROEllipse *e = new OROEllipse(); KReportPosition p; KReportSize s; p.setPointPos(QPointF(x, y)); s.setPointSize(QSizeF(w, h)); e->setRect(QRectF(p.toScene() + m_curOffset, s.toScene())); QPen pen(QColor(lc), lw); QColor c(fc); c.setAlpha(a); QBrush bru(c); e->setBrush(bru); e->setPen(pen); - m_curPage->addPrimitive(e); + m_curPage->insertPrimitive(e); } } void KReportScriptDraw::line(qreal x1, qreal y1, qreal x2, qreal y2, const QString& lc) { if (m_curPage) { OROLine *ln = new OROLine(); KReportPosition s; KReportPosition e; s.setPointPos(QPointF(x1, y1)); e.setPointPos(QPointF(x2, y2)); ln->setStartPoint(s.toScene() + m_curOffset); ln->setEndPoint(e.toScene() + m_curOffset); KReportLineStyle ls; ls.setColor(QColor(lc)); ls.setWidth(1); ls.setPenStyle(Qt::SolidLine); ln->setLineStyle(ls); - m_curPage->addPrimitive(ln); + m_curPage->insertPrimitive(ln); } } void KReportScriptDraw::text(qreal x, qreal y, const QString &txt, const QString &fnt, int pt, const QString &fc, const QString&bc, const QString &lc, qreal lw, int o) { if (m_curPage) { QFont f(fnt, pt); QRectF r = QFontMetrics(f).boundingRect(txt); KRTextStyleData ts; ts.font = f; ts.backgroundColor = QColor(bc); ts.foregroundColor = QColor(fc); ts.backgroundOpacity = o; KReportLineStyle ls; ls.setColor(QColor(lc)); ls.setWidth(lw); if (lw <= 0) ls.setPenStyle(Qt::NoPen); else ls.setPenStyle(Qt::SolidLine); OROTextBox *tb = new OROTextBox(); tb->setPosition(QPointF(x, y) + m_curOffset); tb->setSize(r.size()); tb->setTextStyle(ts); tb->setLineStyle(ls); tb->setText(txt); - m_curPage->addPrimitive(tb); + m_curPage->insertPrimitive(tb); } }