diff --git a/autotests/ElementsTest.cpp b/autotests/ElementsTest.cpp index 2b6080d9..95918777 100644 --- a/autotests/ElementsTest.cpp +++ b/autotests/ElementsTest.cpp @@ -1,231 +1,231 @@ /* This file is part of the KDE project * Copyright (C) 2015 Jarosław Staniek * * 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 "ElementsTest.h" #include "KReportTestUtils.h" #include #include #include #include #include QTEST_MAIN(ElementsTest) Q_DECLARE_METATYPE(KReportElement) Q_DECLARE_METATYPE(KReportLabelElement) Q_DECLARE_METATYPE(KReportSection) void ElementsTest::testElements() { KReportElement e; QCOMPARE(e, e); QCOMPARE(e.name(), ""); QCOMPARE(e.rect(), QRectF()); QCOMPARE(e.z(), 0.0); QCOMPARE(e.backgroundColor(), QColor()); QCOMPARE(e.foregroundColor(), QColor()); QCOMPARE(e.backgroundOpacity(), 0.0); e.setZ(10.3); QCOMPARE(e.z(), 10.3); e.setName("element1"); QCOMPARE(e.name(), "element1"); e.setRect(QRect(1, 2, 3, 4)); QCOMPARE(e.rect(), QRectF(1, 2, 3, 4)); e.setBackgroundColor(Qt::red); QCOMPARE(e.backgroundColor(), QColor(Qt::red)); e.setForegroundColor(Qt::white); QCOMPARE(e.foregroundColor(), QColor(Qt::white)); QCOMPARE(e, e); KReportElement e2 = e; e.setName(""); QCOMPARE(e, e2); QCOMPARE(e.name(), e2.name()); QCOMPARE(e.rect(), e2.rect()); e2.setName("element2"); KReportLabelElement lbl1(e2); QCOMPARE(e2.name(), lbl1.name()); e2.setName(""); QCOMPARE(lbl1.name(), "element2"); lbl1.setText("label1"); QCOMPARE(lbl1.text(), "label1"); e = lbl1; KReportLabelElement lbl2(e); // e points to lbl1 so shares lbl1 in fact QCOMPARE(lbl1, lbl2); QCOMPARE(KReportLabelElement(e), lbl2); lbl2 = e; QCOMPARE(KReportLabelElement(e), lbl2); lbl1 = KReportLabelElement(); QCOMPARE(lbl1.alignment(), Qt::AlignLeft | Qt::AlignVCenter); // defaults lbl1.setAlignment(Qt::AlignHCenter|Qt::AlignBottom); QCOMPARE(lbl1.alignment(), Qt::AlignHCenter|Qt::AlignBottom); lbl1.setBackgroundOpacity(20.0); QCOMPARE(lbl1.backgroundOpacity(), 1.0); // 1.0 is max lbl1.setBackgroundOpacity(-100.10); QCOMPARE(lbl1.backgroundOpacity(), 0.0); // 0.0 is min lbl1.setFont(QApplication::font()); QFont f = lbl1.font(); QCOMPARE(f, QApplication::font()); - QCOMPARE(lbl1.borderStyle().width(), 0.0); // default + QCOMPARE(lbl1.borderStyle().weight(), 0.0); // default QCOMPARE(lbl1.borderStyle().penStyle(), Qt::NoPen); // default QCOMPARE(lbl1.borderStyle().color(), QColor()); // default KReportLineStyle lineStyle; - lineStyle.setWidth(2.0); + lineStyle.setWeight(2.0); lineStyle.setPenStyle(Qt::DashLine); lineStyle.setColor(QColor("brown")); lbl1.setBorderStyle(lineStyle); QCOMPARE(lbl1.borderStyle(), lineStyle); lineStyle.setColor(Qt::yellow); QCOMPARE(lbl1.borderStyle().color(), QColor(Qt::yellow)); // shared } void ElementsTest::testElementCloning() { KReportLabelElement lbl1("text1"), lbl2; lbl1.setName("label1"); lbl2 = lbl1.clone(); QVERIFY(lbl1 != lbl2); // a deep copy, not equal lbl1.setText(""); QCOMPARE(lbl1.name(), lbl2.name()); QCOMPARE(lbl1.text(), ""); QCOMPARE(lbl2.text(), "text1"); // this is another copy, not affected by lbl1.setText("") lbl1.setName("label1"); lbl1.setText("text1"); KReportElement e1 = lbl1; KReportElement e2 = e1.clone(); QVERIFY2(e1 != e2, "Cloned element not equal to the original"); QCOMPARE(e1.name(), "label1"); QCOMPARE(e2.name(), "label1"); QVERIFY2(KReportLabelElement(e2) != lbl1, "Reference to original not equal to a clone"); QVERIFY2(KReportLabelElement(e2) != KReportLabelElement(e1), "Reference to original not equal to reference to a clone"); lbl1.setName(""); lbl1.setText(""); QCOMPARE(e1.name(), ""); // shared with lbl1 QCOMPARE(e2.name(), "label1"); // shared with lbl1's clone QCOMPARE(KReportLabelElement(e1).text(), ""); QCOMPARE(KReportLabelElement(e2).text(), "text1"); KReportLabelElement lbl3 = e2; // e2 points to a lbl1's clone with name=label1, text=text1, so: KReportLabelElement(e2).setText("text2"); // This affect e2 and lbl2 because // KReportLabelElement(e2) upcasts it to the KReportLabelElement type QCOMPARE(KReportLabelElement(e2).text(), "text2"); QCOMPARE(lbl3.text(), "text2"); QCOMPARE(lbl1.text(), ""); // lbl1 unaffected } void ElementsTest::testSections() { // types KReportSection sec1; QCOMPARE(sec1.type(), KReportSection::InvalidType); QCOMPARE(KReportSection(sec1).type(), KReportSection::InvalidType); sec1.setType(KReportSection::PageFooterFirst); KReportSection sec2(sec1); QCOMPARE(sec1.type(), sec2.type()); QCOMPARE(sec1, sec2); sec1.setType(KReportSection::PageFooterEven); QCOMPARE(sec1.type(), sec2.type()); // shared QCOMPARE(sec1, sec2); // shared // height KReportSection::setDefaultHeight(-1); // sanity: reset QCOMPARE(sec1.height(), KReportSection::defaultHeight()); // initially: default height KReportSection::setDefaultHeight(CM_TO_POINT(10.0)); // sanity: reset QCOMPARE(KReportSection::defaultHeight(), CM_TO_POINT(10.0)); QCOMPARE(sec1.height(), KReportSection::defaultHeight()); // still default height KReportSection::setDefaultHeight(-1); // reset QCOMPARE(sec1.height(), KReportSection::defaultHeight()); // still default height sec1.setHeight(CM_TO_POINT(7.0)); QCOMPARE(sec1.height(), CM_TO_POINT(7.0)); // custom height // background color KReportSection::setDefaultBackgroundColor(QColor()); // sanity: reset QCOMPARE(sec1.backgroundColor(), KReportSection::defaultBackgroundColor()); // initially: default color KReportSection::setDefaultBackgroundColor(Qt::yellow); // sanity: reset QCOMPARE(KReportSection::defaultBackgroundColor(), QColor(Qt::yellow)); QCOMPARE(sec1.backgroundColor(), KReportSection::defaultBackgroundColor()); // still default color KReportSection::setDefaultBackgroundColor(QColor()); // reset QCOMPARE(sec1.backgroundColor(), KReportSection::defaultBackgroundColor()); // still default color sec1.setBackgroundColor(Qt::lightGray); QCOMPARE(sec1.backgroundColor(), QColor(Qt::lightGray)); // custom color // elements QVERIFY2(sec1.elements().isEmpty(), "Initially section has no elements inside"); QVERIFY2(sec2.elements().isEmpty(), "Initially section has no elements inside"); KReportLabelElement lbl1("text1"); QVERIFY(sec1.addElement(lbl1)); QCOMPARE(sec1.elements().count(), 1); QCOMPARE(sec2.elements().count(), 1); QCOMPARE(sec1.elements().first(), sec1.elements().last()); QCOMPARE(KReportLabelElement(sec1.elements().first()), lbl1); QCOMPARE(KReportLabelElement(sec1.elements().at(0)), lbl1); QVERIFY2(!sec1.addElement(lbl1), "Adding the same element twice isn't possible"); QCOMPARE(sec1.elements().count(), 1); KReportLabelElement lbl2("text2"); QVERIFY2(!sec1.removeElement(lbl2), "Removing not added element isn't possible"); QCOMPARE(sec1.elements().count(), 1); QVERIFY(sec1.removeElement(lbl1)); QCOMPARE(sec1.elements().count(), 0); QCOMPARE(sec2.elements().count(), 0); lbl2 = lbl1.clone(); QVERIFY(sec1.addElement(lbl1)); QVERIFY(sec1.addElement(lbl2)); QCOMPARE(sec1.elements().count(), 2); QCOMPARE(sec2.elements().count(), 2); // insert sec1 = KReportSection(); QVERIFY(sec1.insertElement(0, lbl1)); QVERIFY2(!sec1.insertElement(0, lbl1), "Cannot insert the same element twice"); QVERIFY2(!sec1.insertElement(2, lbl2), "Cannot insert element at position 2"); QVERIFY2(!sec1.insertElement(-1, lbl2), "Cannot insert element at position -1"); QVERIFY(sec1.insertElement(0, lbl2)); // indexOf QCOMPARE(sec1.elements().indexOf(lbl1), 1); QCOMPARE(sec1.elements().indexOf(lbl2), 0); QCOMPARE(KReportLabelElement(sec1.elements().last()), lbl1); // removeAt QVERIFY2(!sec1.removeElementAt(2), "Cannot remove element at position 2"); QVERIFY2(!sec1.removeElementAt(-1), "Cannot remove element at position -1"); QVERIFY(sec1.removeElementAt(1)); QVERIFY(sec1.removeElementAt(0)); // cloning sections sec1 = KReportSection(); QVERIFY(sec1.addElement(lbl1)); QVERIFY(sec1.addElement(lbl2)); sec2 = sec1.clone(); QCOMPARE(sec1.elements().count(), sec2.elements().count()); QVERIFY2(sec1.elements() != sec2.elements(), "Cloned sections have different sets of elements"); QVERIFY2(sec1 != sec2, "Cloned section not equal to the original"); QVERIFY2(sec1.elements().first() != sec2.elements().first(), "Elements of cloned sections have different sets of elements"); } diff --git a/autotests/format/FormatTest.cpp b/autotests/format/FormatTest.cpp index 566b472a..805b84f0 100644 --- a/autotests/format/FormatTest.cpp +++ b/autotests/format/FormatTest.cpp @@ -1,218 +1,218 @@ /* This file is part of the KDE project * Copyright (C) 2012 Dag Andersen * Copyright (C) 2015 Jarosław Staniek * * QFUZZYCOMPARE() from marble/tests/TestUtils.h: * Copyright (C) 2013 Dennis Nienhüser * * 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 "FormatTest.h" #include "KReportTestUtils.h" #include "KReportPreRenderer.h" #include "KReportDesigner.h" #include "KReportLabelElement.h" #include "KReportDocument.h" #include "KReportDesignerSectionDetail.h" #include "KReportSection.h" #include "KReportDesignerItemLine.h" #include "KReportItemLine.h" #include "KReportDesignerItemRectBase.h" #include "KReportUnit.h" #include #include #include #include #include #include #include #include QTEST_MAIN(FormatTest) static bool openDesignFile(KReportDesign *design, QString *errorMessage) { const QString dir(QFile::decodeName(FILES_DATA_DIR)); const QString fname(QLatin1String(QTest::currentTestFunction()) + QLatin1String(".kreport")); QFile file(dir + QDir::separator() + fname); bool ok = file.open(QFile::ReadOnly | QFile::Text); if (!ok) { *errorMessage = QString::fromLatin1("Could not open file %1: ").arg(file.fileName()) + file.errorString(); return false; } QString content = file.readAll(); if (file.error() != QFileDevice::NoError) { *errorMessage = QString::fromLatin1("Error reading file %1: ").arg(file.fileName()) + file.errorString(); return false; } KReportDesignReadingStatus status; if (!design->setContent(content, &status)) { QString message; QDebug(&message) << status; *errorMessage = QLatin1String("Failed to load content. ") + message; return false; } errorMessage->clear(); return true; } void FormatTest::testPageLayout() { KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } const QPageLayout pageLayout = design.pageLayout(); QVERIFY(pageLayout.isValid()); QCOMPARE(pageLayout.pageSize().id(), QPageSize::A5); QCOMPARE(pageLayout.pageSize().sizePoints(), QPageSize(QPageSize::A5).sizePoints()); QCOMPARE(pageLayout.orientation(), QPageLayout::Portrait); QCOMPARE(pageLayout.margins(QPageLayout::Millimeter), QMarginsF(30.0, 20.0, 40.0, 15.0)); //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer; QCOMPARE(designer.propertySet()->property("page-size").value().toString(), QLatin1String("A5")); QCOMPARE(designer.propertySet()->property("margin-bottom").value().toDouble(), KReportUnit::parseValue("1.5cm")); QCOMPARE(designer.propertySet()->property("margin-top").value().toDouble(), KReportUnit::parseValue("2.0cm")); QCOMPARE(designer.propertySet()->property("margin-left").value().toDouble(), KReportUnit::parseValue("3.0cm")); QCOMPARE(designer.propertySet()->property("margin-right").value().toDouble(), KReportUnit::parseValue("4.0cm")); KReportPreRenderer renderer( designer.document() ); renderer.generate(); ReportPageOptions opt = renderer.reportData()->pageOptions(); QCOMPARE(opt.getPageSize(), QString("A5")); QScreen *srn = QApplication::screens().at(0); const qreal dpiY = srn->logicalDotsPerInchY(); qDebug() << opt.getMarginBottom() << INCH_TO_POINT(opt.getMarginBottom()) << KReportPrivate::dpiY() << dpiY << KReportUnit::parseValue("1.5cm"); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginBottom()) / KReportPrivate::dpiY(), KReportUnit::parseValue("1.5cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginTop()) / KReportPrivate::dpiY(), KReportUnit::parseValue("2.0cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginLeft()) / KReportPrivate::dpiX(), KReportUnit::parseValue("3.0cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginRight()) / KReportPrivate::dpiX(), KReportUnit::parseValue("4.0cm"), 0.3); #endif } void FormatTest::testLineElement() { #if 0 // todo KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } #endif //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer; ReportSectionDetail *ds = designer.detailSection(); ReportSection *sec = ds->detailSection(); KReportItemLine *l = dynamic_cast(sec->items().first()); QVERIFY(l != 0); QCOMPARE(l->Z, 1.5); KReportPosition start = l->startPosition(); KReportPosition end = l->endPosition(); QCOMPARE(start.toPoint(), QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm"))); QCOMPARE(end.toPoint(), QPointF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("2.5cm"))); KReportPreRenderer renderer( designer.document() ); renderer.generate(); l = dynamic_cast(renderer.reportData()->object("line1")); QVERIFY(l != 0); QCOMPARE(l->Z, 1.5); start = l->startPosition(); end = l->endPosition(); QCOMPARE(start.toPoint(), QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm"))); QCOMPARE(end.toPoint(), QPointF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("2.5cm"))); #endif } void FormatTest::testLabelElement() { KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } QCOMPARE(design.title(), QLatin1String("Label Element Test Report")); QVERIFY(design.hasSection(KReportSection::Detail)); KReportSection detailSection = design.section(KReportSection::Detail); QCOMPARE(detailSection.type(), KReportSection::Detail); QCOMPARE(detailSection.height(), CM_TO_POINT(5.0)); QCOMPARE(detailSection.backgroundColor(), QColor("#eeeeee")); QList elements = detailSection.elements(); QCOMPARE(elements.count(), 1); KReportElement element = elements.first(); QCOMPARE(element.name(), QLatin1String("label1")); KReportLabelElement label1(elements.first()); QCOMPARE(label1.text(), "Label"); QCOMPARE(label1.z(), 2.5); const QRectF rect(CM_TO_POINT(1.5), CM_TO_POINT(0.5), CM_TO_POINT(4.5), CM_TO_POINT(0.75)); QCOMPARE(label1.rect(), rect); QCOMPARE(label1.backgroundColor(), QColor("#dddddd")); QCOMPARE(label1.foregroundColor(), QColor("#101010")); QCOMPARE(label1.backgroundOpacity(), 0.9); QCOMPARE(label1.alignment(), Qt::AlignRight | Qt::AlignBottom); QCOMPARE(label1.font().capitalization(), QFont::AllLowercase); QCOMPARE(label1.font().bold(), true); QCOMPARE(label1.font().weight(), 99); QCOMPARE(label1.font().italic(), true); QCOMPARE(label1.font().fixedPitch(), true); QCOMPARE(label1.font().family(), "Ubuntu"); QCOMPARE(label1.font().kerning(), true); QCOMPARE(label1.font().underline(), true); QCOMPARE(label1.font().strikeOut(), true); QCOMPARE(label1.font().pointSizeF(), 9.0); QCOMPARE(label1.font().letterSpacing(), 110.0); QCOMPARE(label1.font().letterSpacingType(), QFont::PercentageSpacing); - QCOMPARE(label1.borderStyle().width(), 1.0); + QCOMPARE(label1.borderStyle().weight(), 1.0); QCOMPARE(label1.borderStyle().color(), QColor("#400000")); QCOMPARE(label1.borderStyle().penStyle(), Qt::DashLine); //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer;//, doc.documentElement()); ReportSectionDetail *ds = designer.detailSection(); ReportSection *sec = ds->detailSection(); QVERIFY(sec->items().count() == 1); KReportDesignerItemRectBase *rect = dynamic_cast(sec->items().first()); QVERIFY(rect != 0); QRectF expected( QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm")), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); QCOMPARE(rect->pointRect(), expected); KReportPreRenderer renderer( designer.document() ); renderer.generate(); KReportItemBase *item = dynamic_cast(renderer.reportData()->object("label1")); QVERIFY(item != 0); KReportPosition pos = item->position(); KReportSize size = item->size(); QCOMPARE(pos.toPoint().x(), KReportUnit::parseValue("1.5cm")); QCOMPARE(pos.toPoint().y(), KReportUnit::parseValue("0.5cm")); QCOMPARE(size.toPoint(), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); QCOMPARE(size.toPoint(), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); #endif } diff --git a/src/common/KReportItemLine.cpp b/src/common/KReportItemLine.cpp index f7aab2b0..03c4bebd 100644 --- a/src/common/KReportItemLine.cpp +++ b/src/common/KReportItemLine.cpp @@ -1,159 +1,159 @@ /* 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 #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->setValue(_s); m_end->setValue(_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_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(int(ls.penStyle())); } } else { kreportWarning() << "while parsing line element encountered unknown element: " << n; } } } KReportItemLine::~KReportItemLine() { } void KReportItemLine::createProperties() { m_start = new KProperty("startposition", QPointF(), QCoreApplication::translate("StartPosition", "Start Position")); m_end = new KProperty("endposition", QPointF(), QCoreApplication::translate("EndPosition", "End Position")); m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); 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); //Remove the unused properies from KReportItemBase propertySet()->removeProperty("size"); propertySet()->removeProperty("position"); propertySet()->addProperty(m_start); propertySet()->addProperty(m_end); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemLine::lineStyle() const { KReportLineStyle ls; - ls.setWidth(m_lineWeight->value().toReal()); + ls.setWeight(m_lineWeight->value().toReal()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } qreal KReportItemLine::weight() const { return m_lineWeight->value().toReal(); } void KReportItemLine::setWeight(qreal 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 = scenePosition(m_start->value().toPointF()); QPointF e = scenePosition(m_end->value().toPointF()); s += offset; e += offset; ln->setStartPoint(s); ln->setEndPoint(e); ln->setLineStyle(lineStyle()); if (page) page->insertPrimitive(ln); OROLine *l2 = dynamic_cast(ln->clone()); if (l2) { l2->setStartPoint(m_start->value().toPointF()); l2->setEndPoint(m_end->value().toPointF()); if (section) section->addPrimitive(l2); } return 0; } void KReportItemLine::setUnit(const KReportUnit &u) { m_start->setOption("unit", u.symbol()); m_end->setOption("unit", u.symbol()); } QPointF KReportItemLine::startPosition() const { return m_start->value().toPointF(); } QPointF KReportItemLine::endPosition() const { return m_end->value().toPointF(); } diff --git a/src/common/KReportLineStyle.shared.h b/src/common/KReportLineStyle.shared.h index 177bad7a..ff64d5eb 100644 --- a/src/common/KReportLineStyle.shared.h +++ b/src/common/KReportLineStyle.shared.h @@ -1,54 +1,54 @@ /* This file is part of the KDE project * Copyright (C) 2015 Jarosław Staniek * * 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 KREPORTLINESTYLE_H #define KREPORTLINESTYLE_H #include "kreport_export.h" #include //! @brief The KReportLineStyle class represents line style class KREPORT_EXPORT KReportLineStyle //SDC: explicit operator== virtual_dtor { public: /*! @getter @return Line's width in points. The default is 0 points. @setter Sets the line's width to @a width. */ - qreal width; //SDC: default=0.0 + qreal weight; //SDC: default=0.0 /*! @getter @return Line's color. The default is invalid color. @setter Sets the line's color to @a color. */ QColor color; //SDC: /*! @getter @return Line's pen style. The default is Qt::NoPen. @setter Sets the line's color to @a color. */ Qt::PenStyle penStyle; //SDC: default=Qt::NoPen }; #endif // KREPORTLABELELEMENT_H diff --git a/src/common/KReportRenderObjects.cpp b/src/common/KReportRenderObjects.cpp index 5a25a70c..c3fe1d8b 100644 --- a/src/common/KReportRenderObjects.cpp +++ b/src/common/KReportRenderObjects.cpp @@ -1,968 +1,968 @@ /* 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 "KReportUtils_p.h" #include "kreport_debug.h" // Helper functions static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2) { return s1->position().x() < s2->position().x(); } // // ORODocument // class Q_DECL_HIDDEN ORODocument::Private { public: Private(); ~Private(); QString title; QList pages; QList sections; - KReportPrivate::PageLayout pageLayout; + KReportPrivate::PageLayout pageLayout; }; ORODocument::Private::Private() { - + } ORODocument::Private::~Private() { qDeleteAll(pages); qDeleteAll(sections); } ORODocument::ORODocument(const QString& title) : d(new Private()) { d->title = title; } ORODocument::~ORODocument() { delete d; } void ORODocument::setTitle(const QString &title) { d->title = title; } OROPage* ORODocument::page(int index) { return d->pages.value(index); } const OROPage * ORODocument::page(int index) const { return d->pages.value(index); } void ORODocument::addPage(OROPage* p) { if (p == 0) { return; } if (p->document() != 0 && p->document() != this) { return; } p->setDocument(this); d->pages.append(p); } OROSection* ORODocument::section(int 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; if (s->document() != 0 && s->document() != this) { return; } s->setDocument(this); d->sections.append(s); } void ORODocument::setPageLayout(const QPageLayout & 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 // 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 (d->document) { d->document->takePage(this); } delete d; } int OROPage::pageNumber() const { if (d->document) { return d->document->pageIndex(this); } return -1; } OROPrimitive* OROPage::primitive(int index) { return d->primitives.value(index); } const OROPrimitive * OROPage::primitive(int index) const { return d->primitives.value(index); } void OROPage::insertPrimitive(OROPrimitive* p, int index) { //kreportDebug() << "Adding primitive" << p->type() << "to page" << page(); if (p == 0) return; p->setPage(this); if (index == -1) { d->primitives.append(p); } else { d->primitives.insert(index, p); } - + #if 0 //TODO if (notify) { 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 // class Q_DECL_HIDDEN OROSection::Private { public: Private(); ~Private(); ORODocument * document; QList primitives; qint64 row = 0; int height = 0; KReportSectionData::Section type = KReportSectionData::None; QColor backgroundColor = Qt::white; }; OROSection::Private::Private() { } OROSection::Private::~Private() { qDeleteAll(primitives); primitives.clear(); } OROSection::OROSection(ORODocument* doc) : d(new Private()) { d->document = doc; } OROSection::~OROSection() { if (d->document) { d->document->takeSection(this); } - + delete d; } OROPrimitive* OROSection::primitive(int index) { return d->primitives.value(index); } const OROPrimitive * OROSection::primitive(int index) const { return d->primitives.value(index); } void OROSection::addPrimitive(OROPrimitive* primitive) { if (primitive == 0) return; d->primitives.append(primitive); } void OROSection::setHeight(int h) { d->height = h; } int OROSection::height() const { return d->height; } void OROSection::setBackgroundColor(const QColor& color) { d->backgroundColor = color; } QColor OROSection::backgroundColor() const { return d->backgroundColor; } void OROSection::sortPrimitives(Qt::Orientation orientation) { if (orientation == Qt::Horizontal) { qSort(d->primitives.begin(), d->primitives.end(), xLessThan); } } ORODocument * OROSection::document() { 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 // class Q_DECL_HIDDEN OROPrimitive::Private { public: OROPage * page = nullptr; QPointF position; QSizeF size; }; OROPrimitive::OROPrimitive() : d(new Private()) { } OROPrimitive::~OROPrimitive() { if (d->page) { d->page->takePrimitive(this); } - + delete d; } void OROPrimitive::setPosition(const QPointF& pos) { d->position = pos; } void OROPrimitive::setSize(const QSizeF & 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 // 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() { flags = 0; wordWrap = false; canGrow = false; requiresPostProcessing = false; - + lineStyle.setColor(Qt::black); - lineStyle.setWidth(0); + lineStyle.setWeight(0); lineStyle.setPenStyle(Qt::NoPen); } OROTextBox::Private::~Private() { } OROTextBox::OROTextBox() : d(new Private()) { } OROTextBox::~OROTextBox() { delete d; } void OROTextBox::setText(const QString & s) { d->text = s; } void OROTextBox::setTextStyle(const KRTextStyleData & ts) { d->textStyle = ts; } void OROTextBox::setLineStyle(const KReportLineStyle & ls) { d->lineStyle = ls; } void OROTextBox::setFont(const QFont & f) { d->textStyle.font = f; } void OROTextBox::setFlags(int 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; } 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(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 // 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) { d->endPoint = p; } void OROLine::setLineStyle(const KReportLineStyle& style) { d->lineStyle = style; } QPointF OROLine::endPoint() const { return d->endPoint; } KReportLineStyle OROLine::lineStyle() const { return d->lineStyle; } OROPrimitive* OROLine::clone() const { OROLine *theClone = new OROLine(); theClone->setStartPoint(position()); theClone->setEndPoint(endPoint()); theClone->setLineStyle(lineStyle()); return theClone; } // // OROImage // class Q_DECL_HIDDEN OROImage::Private { public: QImage image; bool scaled; Qt::TransformationMode transformFlags; Qt::AspectRatioMode aspectFlags; }; OROImage::OROImage() : d(new Private()) { d->scaled = false; d->transformFlags = Qt::FastTransformation; d->aspectFlags = Qt::IgnoreAspectRatio; } OROImage::~OROImage() { delete d; } void OROImage::setImage(const QImage & img) { d->image = img; } void OROImage::setScaled(bool 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; } bool OROImage::isScaled() const { return d->scaled; } Qt::TransformationMode OROImage::transformationMode() const { return d->transformFlags; } OROPrimitive* OROImage::clone() const { OROImage *theClone = new OROImage(); theClone->setSize(size()); theClone->setPosition(position()); theClone->setImage(image()); theClone->setScaled(isScaled()); theClone->setTransformationMode(transformationMode()); theClone->setAspectRatioMode(aspectRatioMode()); return theClone; } // // OROPicture // class Q_DECL_HIDDEN OROPicture::Private { public: - QPicture picture; + QPicture picture; }; OROPicture::OROPicture() : d(new Private()) { } OROPicture::~OROPicture() { delete d; } OROPrimitive* OROPicture::clone() const { OROPicture *theClone = new OROPicture(); 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 // 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) { d->pen = p; } void ORORect::setBrush(const QBrush & 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() const { ORORect *theClone = new ORORect(); theClone->setSize(size()); theClone->setPosition(position()); theClone->setPen(pen()); theClone->setBrush(brush()); return theClone; } // // OROEllipse // 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) { d->pen = p; } void OROEllipse::setBrush(const QBrush & b) { d->brush = b; } QBrush OROEllipse::brush() const { return d->brush; } QPen OROEllipse::pen() const { return d->pen; } QRectF OROEllipse::rect() const { return QRectF(position(), size()); } OROPrimitive* OROEllipse::clone() const { OROEllipse *theClone = new OROEllipse(); theClone->setSize(size()); theClone->setPosition(position()); theClone->setPen(pen()); theClone->setBrush(brush()); return theClone; } // // 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; } OROCheckBox::Type OROCheckBox::checkType() const { return d->checkType; } QColor OROCheckBox::foregroundColor() const { return d->foregroundColor; } 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* OROCheckBox::clone() const { 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/KReportUtils.cpp b/src/common/KReportUtils.cpp index e770cb10..1afd0eca 100644 --- a/src/common/KReportUtils.cpp +++ b/src/common/KReportUtils.cpp @@ -1,555 +1,555 @@ /* This file is part of the KDE project Copyright (C) 2010-2015 Jarosław Staniek 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 "KReportUtils.h" #include "KReportUnit.h" #include "KReportItemBase.h" #include "KReportLineStyle.h" #include #include #include #include QString KReportUtils::attr(const QDomElement &el, const char *attrName, const QString &defaultValue) { const QString val = el.attribute(QLatin1String(attrName)); return val.isEmpty() ? defaultValue : val; } QByteArray KReportUtils::attr(const QDomElement &el, const char *attrName, const QByteArray &defaultValue) { const QByteArray val = el.attribute(QLatin1String(attrName)).toLatin1(); return val.isEmpty() ? defaultValue : val; } bool KReportUtils::attr(const QDomElement &el, const char *attrName, bool defaultValue) { const QString val = el.attribute(QLatin1String(attrName)); return val.isEmpty() ? defaultValue : QVariant(val).toBool(); } int KReportUtils::attr(const QDomElement &el, const char *attrName, int defaultValue) { const QString val = el.attribute(QLatin1String(attrName)); if (val.isEmpty()) { return defaultValue; } bool ok; const int result = QVariant(val).toInt(&ok); return ok ? result : defaultValue; } qreal KReportUtils::attr(const QDomElement &el, const char *attrName, qreal defaultValue) { const QString val = el.attribute(QLatin1String(attrName)); return KReportUnit::parseValue(val, defaultValue); } QColor KReportUtils::attr(const QDomElement &el, const char *attrName, const QColor &defaultValue) { const QString val = el.attribute(QLatin1String(attrName)); if (val.isEmpty()) { return defaultValue; } return QColor(val); } qreal KReportUtils::attrPercent(const QDomElement& el, const char* attrName, qreal defaultValue) { QString str(el.attribute(QLatin1String(attrName))); if (str.isEmpty() || !str.endsWith(QLatin1Char('%'))) { return defaultValue; } str.chop(1); bool ok; const qreal result = QVariant(str).toReal(&ok) / 100.0; if (!ok) { return defaultValue; } return result; } Qt::PenStyle KReportUtils::penStyle(const QString& str, Qt::PenStyle defaultValue) { const QByteArray s(str.toLatin1()); if (s == "nopen" || s == "none") { return Qt::NoPen; } else if (s == "solid") { return Qt::SolidLine; } else if (s == "dash" || s == "wave" /*we have nothing better for now*/) { return Qt::DashLine; } else if (s == "dot" || s == "dotted") { return Qt::DotLine; } else if (s == "dashdot" || s == "dot-dash") { return Qt::DashDotLine; } else if (s == "dashdotdot" || s == "dot-dot-dash") { return Qt::DashDotDotLine; } else { return defaultValue; } } Qt::Alignment KReportUtils::verticalAlignment(const QString &str, Qt::Alignment defaultValue) { const QByteArray s(str.toLatin1()); if (s == "center") { return Qt::AlignVCenter; } else if (s == "top") { return Qt::AlignTop; } else if (s == "bottom") { return Qt::AlignBottom; } else { return defaultValue; } } Qt::Alignment KReportUtils::horizontalAlignment(const QString &str, Qt::Alignment defaultValue) { const QByteArray s(str.toLatin1()); if (s == "center") { return Qt::AlignHCenter; } else if (s == "right") { return Qt::AlignRight; } else if (s == "left") { return Qt::AlignLeft; } else { return defaultValue; } } QString KReportUtils::verticalToString(Qt::Alignment alignment) { if (alignment.testFlag(Qt::AlignVCenter)) { return QLatin1String("center"); } else if (alignment.testFlag(Qt::AlignTop)) { return QLatin1String("top"); } else if (alignment.testFlag(Qt::AlignBottom)) { return QLatin1String("bottom"); } return QString(); } QString KReportUtils::horizontalToString(Qt::Alignment alignment) { if (alignment.testFlag(Qt::AlignHCenter)) { return QLatin1String("center"); } else if (alignment.testFlag(Qt::AlignLeft)) { return QLatin1String("left"); } else if (alignment.testFlag(Qt::AlignRight)) { return QLatin1String("right"); } return QString(); } QRectF KReportUtils::readRectAttributes(const QDomElement &el, const QRectF &defaultValue) { QRectF val; val.setX(attr(el, "svg:x", defaultValue.x())); val.setY(attr(el, "svg:y", defaultValue.y())); val.setWidth(attr(el, "svg:width", defaultValue.width())); val.setHeight(attr(el, "svg:height", defaultValue.height())); return val; } int KReportUtils::readPercent(const QDomElement& el, const char* name, int defaultPercentValue, bool *ok) { Q_ASSERT(name); QString percent(el.attribute(QLatin1String(name))); if (percent.isEmpty()) { if (ok) *ok = true; return defaultPercentValue; } if (!percent.endsWith(QLatin1Char('%'))) { if (ok) *ok = false; return 0; } percent.chop(1); if (ok) *ok = true; return percent.toInt(ok); } //! @return string representation of @a value, cuts of zeros; precision is set to 2 static QString roundValueToString(qreal value) { QString s(QString::number(value, 'g', 2)); if (s.endsWith(QLatin1String(".00"))) return QString::number(qRound(value)); return s; } //! Used by readFontAttributes() static QFont::Capitalization readFontCapitalization(const QByteArray& fontVariant, const QByteArray& textTransform) { if (fontVariant == "small-caps") return QFont::SmallCaps; if (textTransform == "uppercase") return QFont::AllUppercase; if (textTransform == "lowercase") return QFont::AllLowercase; if (textTransform == "capitalize") return QFont::Capitalize; // default, "normal" return QFont::MixedCase; } void KReportUtils::readFontAttributes(const QDomElement& el, QFont *font) { Q_ASSERT(font); const QFont::Capitalization cap = readFontCapitalization( attr(el, "fo:font-variant", QByteArray()), attr(el, "fo:text-transform", QByteArray())); font->setCapitalization(cap); // weight const QByteArray fontWeight(attr(el, "fo:font-weight", QByteArray())); int weight = -1; if (fontWeight == "bold") { weight = QFont::Bold; } if (fontWeight == "normal") { weight = QFont::Normal; } else if (!fontWeight.isEmpty()) { // Remember : Qt and CSS/XSL doesn't have the same scale. It's 100-900 instead of Qt's 0-100 // See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#font-weight // and http://www.w3.org/TR/CSS2/fonts.html#font-boldness bool ok; qreal boldness = fontWeight.toUInt(&ok); if (ok) { boldness = qMin(boldness, 900.0); boldness = qMax(boldness, 100.0); weight = (boldness - 100.0) * 0.12375 /*== 99/800*/; // 0..99 } } if (weight >= 0) { font->setWeight(weight); } font->setItalic(attr(el, "fo:font-style", QByteArray()) == "italic"); font->setFixedPitch(attr(el, "style:font-pitch", QByteArray()) == "fixed"); font->setFamily(attr(el, "fo:font-family", font->family())); font->setKerning(attr(el, "style:letter-kerning", font->kerning())); // underline const QByteArray underlineType(attr(el, "style:text-underline-type", QByteArray())); font->setUnderline(!underlineType.isEmpty() && underlineType != "none"); // double or single (we don't recognize them) // stricken-out const QByteArray strikeOutType(attr(el, "style:text-line-through-type", QByteArray())); font->setStrikeOut(!strikeOutType.isEmpty() && strikeOutType != "none"); // double or single (we don't recognize them) //! @todo support fo:font-size-rel? //! @todo support fo:font-size in px font->setPointSizeF(KReportUtils::attr(el, "fo:font-size", font->pointSizeF())); // letter spacing // §7.16.2 of [XSL] http://www.w3.org/TR/xsl11/#letter-spacing font->setLetterSpacing(QFont::PercentageSpacing, 100.0 * KReportUtils::attrPercent(el, "fo:letter-spacing", font->letterSpacing())); } void KReportUtils::writeFontAttributes(QDomElement *el, const QFont &font) { Q_ASSERT(el); switch (font.capitalization()) { case QFont::SmallCaps: el->setAttribute(QLatin1String("fo:font-variant"), QLatin1String("small-caps")); break; case QFont::MixedCase: // default: "normal", do not save break; case QFont::AllUppercase: el->setAttribute(QLatin1String("fo:text-transform"), QLatin1String("uppercase")); break; case QFont::AllLowercase: el->setAttribute(QLatin1String("fo:text-transform"), QLatin1String("lowercase")); break; case QFont::Capitalize: el->setAttribute(QLatin1String("fo:text-transform"), QLatin1String("capitalize")); break; } // Remember : Qt and CSS/XSL doesn't have the same scale. It's 100-900 instead of Qt's 0-100 // See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#font-weight // and http://www.w3.org/TR/CSS2/fonts.html#font-boldness if (font.weight() == QFont::Light) { el->setAttribute(QLatin1String("fo:font-weight"), 200); } else if (font.weight() == QFont::Normal) { // Default //el->setAttribute("fo:font-weight", "normal"); // 400 } else if (font.weight() == QFont::DemiBold) { el->setAttribute(QLatin1String("fo:font-weight"), 600); } else if (font.weight() == QFont::Bold) { el->setAttribute(QLatin1String("fo:font-weight"), QLatin1String("bold")); // 700 } else if (font.weight() == QFont::Black) { el->setAttribute(QLatin1String("fo:font-weight"), 900); } else { el->setAttribute(QLatin1String("fo:font-weight"), qBound(10, font.weight(), 90) * 10); } // italic, default is "normal" if (font.italic()) { el->setAttribute(QLatin1String("fo:font-style"), QLatin1String("italic")); } // pitch, default is "variable" if (font.fixedPitch()) { el->setAttribute(QLatin1String("style:font-pitch"), QLatin1String("fixed")); } if (!font.family().isEmpty()) { el->setAttribute(QLatin1String("fo:font-family"), font.family()); } // kerning, default is "true" el->setAttribute(QLatin1String("style:letter-kerning"), QLatin1String(font.kerning() ? "true" : "false")); // underline, default is "none" if (font.underline()) { el->setAttribute(QLatin1String("style:text-underline-type"), QLatin1String("single")); } // stricken-out, default is "none" if (font.strikeOut()) { el->setAttribute(QLatin1String("style:text-line-through-type"), QLatin1String("single")); } el->setAttribute(QLatin1String("fo:font-size"), font.pointSize()); // letter spacing, default is "normal" // §7.16.2 of [XSL] http://www.w3.org/TR/xsl11/#letter-spacing if (font.letterSpacingType() == QFont::PercentageSpacing) { // A value of 100 will keep the spacing unchanged; a value of 200 will enlarge // the spacing after a character by the width of the character itself. if (font.letterSpacing() != 100.0) { el->setAttribute(QLatin1String("fo:letter-spacing"), roundValueToString(font.letterSpacing()) + QLatin1Char('%')); } } else { // QFont::AbsoluteSpacing // A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing. el->setAttribute(QLatin1String("fo:letter-spacing"), roundValueToString(font.letterSpacing())); } } void KReportUtils::buildXMLRect(QDomElement *entity, const QPointF &pos, const QSizeF &size) { Q_ASSERT(entity); KReportUtils::setAttribute(entity, pos); KReportUtils::setAttribute(entity, size ); } void KReportUtils::buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts) { Q_ASSERT(doc); Q_ASSERT(entity); QDomElement element = doc->createElement(QLatin1String("report:text-style")); element.setAttribute(QLatin1String("fo:background-color"), ts.backgroundColor.name()); element.setAttribute(QLatin1String("fo:foreground-color"), ts.foregroundColor.name()); element.setAttribute(QLatin1String("fo:background-opacity"), QString::number(ts.backgroundOpacity) + QLatin1Char('%')); KReportUtils::writeFontAttributes(&element, ts.font); entity->appendChild(element); } void KReportUtils::buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls) { Q_ASSERT(doc); Q_ASSERT(entity); QDomElement element = doc->createElement(QLatin1String("report:line-style")); element.setAttribute(QLatin1String("report:line-color"), ls.color().name()); - element.setAttribute(QLatin1String("report:line-weight"), ls.width()); + element.setAttribute(QLatin1String("report:line-weight"), ls.weight()); QString l; switch (ls.penStyle()) { case Qt::NoPen: l = QLatin1String("nopen"); break; case Qt::SolidLine: l = QLatin1String("solid"); break; case Qt::DashLine: l = QLatin1String("dash"); break; case Qt::DotLine: l = QLatin1String("dot"); break; case Qt::DashDotLine: l = QLatin1String("dashdot"); break; case Qt::DashDotDotLine: l = QLatin1String("dashdotdot"); break; default: l = QLatin1String("solid"); } element.setAttribute(QLatin1String("report:line-style"), l); entity->appendChild(element); } void KReportUtils::addPropertyAsAttribute(QDomElement* e, KProperty* p) { Q_ASSERT(e); Q_ASSERT(p); const QString name = QLatin1String("report:") + QLatin1String(p->name().toLower()); switch (p->value().type()) { case QVariant::Int : e->setAttribute(name, p->value().toInt()); break; case QVariant::Double: e->setAttribute(name, p->value().toDouble()); break; case QVariant::Bool: e->setAttribute(name, p->value().toInt()); break; default: e->setAttribute(name, p->value().toString()); break; } } void KReportUtils::setAttribute(QDomElement *e, const QString &attribute, double value) { Q_ASSERT(e); QString s; s.setNum(value, 'f', DBL_DIG); e->setAttribute(attribute, s + QLatin1String("pt")); } void KReportUtils::setAttribute(QDomElement *e, const QPointF &value) { Q_ASSERT(e); KReportUtils::setAttribute(e, QLatin1String("svg:x"), value.x()); KReportUtils::setAttribute(e, QLatin1String("svg:y"), value.y()); } void KReportUtils::setAttribute(QDomElement *e, const QSizeF &value) { Q_ASSERT(e); KReportUtils::setAttribute(e, QLatin1String("svg:width"), value.width()); KReportUtils::setAttribute(e, QLatin1String("svg:height"), value.height()); } bool KReportUtils::parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts) { Q_ASSERT(ts); if (elemSource.tagName() != QLatin1String("report:text-style")) return false; ts->backgroundColor = QColor(elemSource.attribute(QLatin1String("fo:background-color"), QLatin1String("#ffffff"))); ts->foregroundColor = QColor(elemSource.attribute(QLatin1String("fo:foreground-color"), QLatin1String("#000000"))); bool ok; ts->backgroundOpacity = KReportUtils::readPercent(elemSource, "fo:background-opacity", 100, &ok); if (!ok) { return false; } KReportUtils::readFontAttributes(elemSource, &ts->font); return true; } bool KReportUtils::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) { Q_ASSERT(ls); if (elemSource.tagName() == QLatin1String("report:line-style")) { ls->setColor(QColor(elemSource.attribute(QLatin1String("report:line-color"), QLatin1String("#ffffff")))); - ls->setWidth(elemSource.attribute(QLatin1String("report:line-weight"), QLatin1String("0.0")).toDouble()); + ls->setWeight(elemSource.attribute(QLatin1String("report:line-weight"), QLatin1String("0.0")).toDouble()); QString l = elemSource.attribute(QLatin1String("report:line-style"), QLatin1String("nopen")); if (l == QLatin1String("nopen")) { ls->setPenStyle(Qt::NoPen); } else if (l == QLatin1String("solid")) { ls->setPenStyle(Qt::SolidLine); } else if (l == QLatin1String("dash")) { ls->setPenStyle(Qt::DashLine); } else if (l == QLatin1String("dot")) { ls->setPenStyle(Qt::DotLine); } else if (l == QLatin1String("dashdot")) { ls->setPenStyle(Qt::DashDotLine); } else if (l == QLatin1String("dashdotdot")) { ls->setPenStyle(Qt::DashDotDotLine); } return true; } return false; } #if 0 bool KReportUtils::parseReportRect(const QDomElement & elemSource, KReportPosition *pos, KReportSize *size) { Q_ASSERT(pos); Q_ASSERT(size); // QStringList sl; // QDomNamedNodeMap map = elemSource.attributes(); // for (int i=0; i < map.count(); ++i ) { // sl << map.item(i).nodeName(); // } QPointF _pos; QSizeF _siz; _pos.setX(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:x"), QLatin1String("1cm")))); _pos.setY(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:y"), QLatin1String("1cm")))); _siz.setWidth(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:width"), QLatin1String("1cm")))); _siz.setHeight(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("1cm")))); pos->setPointPos(_pos); size->setPointSize(_siz); return true; } #endif class PageIds : private QHash { public: PageIds() {} QPageSize::PageSizeId id(const QString &key) { if (isEmpty()) { for (int i = 0; i < QPageSize::LastPageSize; ++i) { QString key(QPageSize::key(static_cast(i))); if (key.isEmpty()) { break; } insert(key, static_cast(i)); } } return value(key); } }; Q_GLOBAL_STATIC(PageIds, s_pageIds) QPageSize::PageSizeId KReportUtils::pageSizeId(const QString &key) { return s_pageIds->id(key); } QPageSize KReportUtils::pageSize(const QString &key) { return QPageSize(s_pageIds->id(key)); } diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp index 95ad2499..496b31b9 100644 --- a/src/items/check/KReportItemCheck.cpp +++ b/src/items/check/KReportItemCheck.cpp @@ -1,195 +1,195 @@ /* 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_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing check element encountered unknown 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.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", static_cast(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().toReal()); + ls.setWeight(m_lineWeight->value().toReal()); 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) { OROCheckBox *chk = new OROCheckBox(); chk->setPosition(scenePosition(position()) + offset); chk->setSize(sceneSize(size())); chk->setLineStyle(lineStyle()); chk->setForegroundColor(m_foregroundColor->value().value()); 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->insertPrimitive(chk); } if (section) { OROCheckBox *chk2 = dynamic_cast(chk->clone()); if (chk2) { 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 12013a56..823beb4b 100644 --- a/src/items/field/KReportItemField.cpp +++ b/src/items/field/KReportItemField.cpp @@ -1,288 +1,288 @@ /* 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_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknown 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.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", static_cast(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().toReal()); + ls.setWeight(m_lineWeight->value().toReal()); 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(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->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/label/KReportItemLabel.cpp b/src/items/label/KReportItemLabel.cpp index 1a8c49a7..2cf47cf4 100644 --- a/src/items/label/KReportItemLabel.cpp +++ b/src/items/label/KReportItemLabel.cpp @@ -1,209 +1,209 @@ /* 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_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing label element encountered unknown 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.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", static_cast(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().toReal()); + ls.setWeight(m_lineWeight->value().toReal()); 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->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/label/KReportLabelPlugin.cpp b/src/items/label/KReportLabelPlugin.cpp index 94383a12..9af63234 100644 --- a/src/items/label/KReportLabelPlugin.cpp +++ b/src/items/label/KReportLabelPlugin.cpp @@ -1,107 +1,107 @@ /* This file is part of the KDE project Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KReportLabelPlugin.h" #include "KReportItemLabel.h" #include "KReportDesignerItemLabel.h" #include "KReportDesigner.h" #include "KReportPluginMetaData.h" #include "KReportLabelElement.h" #include "KReportLineStyle.h" #include "KReportUtils.h" #ifdef KREPORT_SCRIPTING #include "KReportScriptLabel.h" #endif #include KREPORT_PLUGIN_FACTORY(KReportLabelPlugin, "label.json") KReportLabelPlugin::KReportLabelPlugin(QObject *parent, const QVariantList &args) : KReportPluginInterface(parent, args) { } KReportLabelPlugin::~KReportLabelPlugin() { } QObject* KReportLabelPlugin::createRendererInstance(const QDomNode &elem) { return new KReportItemLabel(elem); } QObject* KReportLabelPlugin::createDesignerInstance(KReportDesigner* designer, QGraphicsScene* scene, const QPointF &pos) { return new KReportDesignerItemLabel(designer, scene, pos); } QObject* KReportLabelPlugin::createDesignerInstance(const QDomNode & element, KReportDesigner *designer, QGraphicsScene * scene) { return new KReportDesignerItemLabel(element, designer, scene); } KReportElement KReportLabelPlugin::createElement() { return KReportLabelElement(); } bool KReportLabelPlugin::loadElement(KReportElement *el, const QDomElement &dom, KReportDesignReadingStatus *status) { if (!KReportPluginInterface::loadElement(el, dom, status)) { return false; } KReportLabelElement label(*el); label.setText(KReportUtils::attr(dom, "report:caption", QString())); QString s = KReportUtils::attr(dom, "report:horizontal-align", QString()); Qt::Alignment alignment = KReportUtils::horizontalAlignment(s, label.alignment() & Qt::AlignHorizontal_Mask); s = KReportUtils::attr(dom, "report:vertical-align", QString()); alignment |= KReportUtils::verticalAlignment(s, label.alignment() & Qt::AlignVertical_Mask); label.setAlignment(alignment); const QDomElement textStyleDom = dom.firstChildElement(QLatin1String("report:text-style")); QFont font(label.font()); KReportUtils::readFontAttributes(textStyleDom, &font); label.setFont(font); const QDomElement lineStyleDom = dom.firstChildElement(QLatin1String("report:line-style")); KReportLineStyle borderStyle(label.borderStyle()); s = KReportUtils::attr(lineStyleDom, "report:line-style", QString()); borderStyle.setPenStyle(KReportUtils::penStyle(s, borderStyle.penStyle())); borderStyle.setColor(KReportUtils::attr(lineStyleDom, "report:line-color", borderStyle.color())); // border-line-width could be better name but it's too late... - borderStyle.setWidth(KReportUtils::attr(lineStyleDom, "report:line-weight", borderStyle.width())); + borderStyle.setWeight(KReportUtils::attr(lineStyleDom, "report:line-weight", borderStyle.weight())); label.setBorderStyle(borderStyle); return true; } #ifdef KREPORT_SCRIPTING QObject* KReportLabelPlugin::createScriptInstance(KReportItemBase *item) { KReportItemLabel *label = dynamic_cast(item); if (label) { return new Scripting::Label(label); } return 0; } #endif #include "KReportLabelPlugin.moc" diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp index 0afde971..327279e9 100644 --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -1,320 +1,320 @@ /* 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 #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_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknown 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.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", static_cast(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().toReal()); + ls.setWeight(m_lineWeight->value().toReal()); 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; QRegularExpression 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()) { QRegularExpressionMatch match = re.match(qstrValue); int idx = match.capturedStart(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->insertPrimitive(tb); } if (section) { OROTextBox *tb2 = dynamic_cast(tb->clone()); if (tb2) { 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->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/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp index bfc8db20..7f4325e0 100644 --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -1,247 +1,247 @@ /* 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 "KReportUtils_p.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 { + } 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->pageCount()) toPage = document->pageCount(); qreal scaleX = context.printer()->resolution() / qreal(KReportPrivate::dpiX()); qreal scaleY = context.printer()->resolution() / qreal(KReportPrivate::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->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 (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()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().weight() * scaleX, tb->lineStyle().penStyle())); context.painter()->drawRect(rc); //Reset back to defaults for next element context.painter()->restore(); } else if (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()); + QPen pen(ln->lineStyle().color(), ln->lineStyle().weight() * 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 (OROImage *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); QImage img = im->image(); if (im->isScaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); context.painter()->drawImage(rc.topLeft(), img, sr); } else if (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 (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 (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 (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) { + if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().weight() <= 0) { context.painter()->setPen(QPen(Qt::lightGray)); } else { - context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); + context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().weight() * scaleX, chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == OROCheckBox::Cross) { context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); 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() == 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 b53f0d1f..51c82bc6 100644 --- a/src/renderer/KReportScreenRenderer_p.cpp +++ b/src/renderer/KReportScreenRenderer_p.cpp @@ -1,209 +1,209 @@ /* 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() { } 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->primitiveCount(); i++) { OROPrimitive *prim = p->primitive(i); if (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()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().weight(), tb->lineStyle().penStyle())); context.painter()->drawRect(rc); //Reset back to defaults for next element context.painter()->restore(); } else if (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()); + QPen pen(ln->lineStyle().color(), ln->lineStyle().weight(), 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 (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 (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 ( OROImage *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); QImage img = im->image(); if (im->isScaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); context.painter()->drawImage(rc.topLeft(), img, sr); } else if (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 (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) { + if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().weight() <= 0) { context.painter()->setPen(QPen(Qt::lightGray)); } else { - context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width(), chk->lineStyle().penStyle())); + context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().weight(), chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == OROCheckBox::Cross) { context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); 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() == 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/scripting/KReportScriptDraw.cpp b/src/renderer/scripting/KReportScriptDraw.cpp index 070c2e1f..d78edbb1 100644 --- a/src/renderer/scripting/KReportScriptDraw.cpp +++ b/src/renderer/scripting/KReportScriptDraw.cpp @@ -1,132 +1,132 @@ /* 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 #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(); r->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h)))); QPen pen(QColor(lc), lw); QColor c(fc); c.setAlpha(a); QBrush bru(c); r->setBrush(bru); r->setPen(pen); 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(); e->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h)))); QPen pen(QColor(lc), lw); QColor c(fc); c.setAlpha(a); QBrush bru(c); e->setBrush(bru); e->setPen(pen); 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(); ln->setStartPoint(KReportItemBase::scenePosition(QPointF(x1, y1) + m_curOffset)); ln->setEndPoint(KReportItemBase::scenePosition(QPointF(x2, y2) + m_curOffset)); KReportLineStyle ls; ls.setColor(QColor(lc)); - ls.setWidth(1); + ls.setWeight(1); ls.setPenStyle(Qt::SolidLine); ln->setLineStyle(ls); 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); + ls.setWeight(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->insertPrimitive(tb); } }