diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp index 2cfdc275..504d43b5 100644 --- a/src/common/KReportItemBase.cpp +++ b/src/common/KReportItemBase.cpp @@ -1,119 +1,237 @@ /* 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 "KReportItemBase.h" -#include "KReportPosition.h" -#include "KReportSize.h" #include "KReportUtils.h" #include +#include +#include -KReportItemBase::KReportItemBase() +class Q_DECL_HIDDEN KReportItemBase::Private { - Z = 0; - m_name = new KProperty("name", QString(), tr("Name"), tr("Object Name")); - m_name->setAutoSync(0); +public: + Private(); + ~Private(); + + KPropertySet *set; + KProperty *nameProperty; + KProperty *sizeProperty; + KProperty *positionProperty; + QString oldName; + qreal z; +}; + +KReportItemBase::Private::Private() +{ + set = new KPropertySet(); + nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name")); + nameProperty->setAutoSync(0); + + positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position")); + sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size")); + + set->addProperty(nameProperty); + set->addProperty(positionProperty); + set->addProperty(sizeProperty); +} + +KReportItemBase::Private::~Private() +{ + delete set; } -KReportItemBase::~KReportItemBase() { } -void KReportItemBase::addDefaultProperties() +KReportItemBase::KReportItemBase() : d(new Private()) { - m_set->addProperty(m_name); - m_set->addProperty(m_pos.property()); - m_set->addProperty(m_size.property()); + d->z = 0; + + connect(propertySet(), &KPropertySet::propertyChanged, + this, &KReportItemBase::propertyChanged); +} + +KReportItemBase::~KReportItemBase() +{ + delete d; } bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts) { return KReportUtils::parseReportTextStyleData(elemSource, ts); } bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) { return KReportUtils::parseReportLineStyleData(elemSource, ls); } -bool KReportItemBase::parseReportRect(const QDomElement & elemSource, KReportPosition *pos, KReportSize *size) +bool KReportItemBase::parseReportRect(const QDomElement & elemSource) { - return KReportUtils::parseReportRect(elemSource, pos, size); + QPointF pos; + QSizeF size; + + pos.setX(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:x"), QLatin1String("1cm")))); + pos.setY(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:y"), QLatin1String("1cm")))); + size.setWidth(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:width"), QLatin1String("1cm")))); + size.setHeight(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("1cm")))); + + setPosition(pos); + setSize(size); + + return true; + } void KReportItemBase::setUnit(const KReportUnit& u) { - m_pos.setUnit(u); - m_size.setUnit(u); + qDebug() << "Setting page unit to: " << u.symbol(); + d->positionProperty->setOption("unit", u.symbol()); + d->sizeProperty->setOption("unit", u.symbol()); } int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler* script) { Q_UNUSED(page) Q_UNUSED(section) Q_UNUSED(offset) Q_UNUSED(data) Q_UNUSED(script) return 0; } int KReportItemBase::renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportData *data, KReportScriptHandler* script) { Q_UNUSED(page) Q_UNUSED(section) Q_UNUSED(offset) Q_UNUSED(data) Q_UNUSED(script) return 0; } QString KReportItemBase::itemDataSource() const { return QString(); } -KPropertySet* KReportItemBase::propertySet() const +KPropertySet* KReportItemBase::propertySet() { - return m_set; + return d->set; } bool KReportItemBase::supportsSubQuery() const { return false; } QString KReportItemBase::entityName() const { - return m_name->value().toString(); + return d->nameProperty->value().toString(); } void KReportItemBase::setEntityName(const QString& n) { - m_name->setValue(n); + d->nameProperty->setValue(n); +} + +KProperty* KReportItemBase::nameProperty() +{ + return d->nameProperty; +} + +QString KReportItemBase::oldName() const +{ + return d->oldName; +} + +void KReportItemBase::setOldName(const QString& old) +{ + d->oldName = old; +} + +QPointF KReportItemBase::position() const +{ + return d->positionProperty->value().toPointF(); +} + +QSizeF KReportItemBase::size() const +{ + return d->sizeProperty->value().toSizeF(); +} + +const KPropertySet * KReportItemBase::propertySet() const +{ + return propertySet(); } -KReportPosition KReportItemBase::position() const +QPointF KReportItemBase::scenePosition(const QPointF &pos) { - return m_pos; + const qreal x = POINT_TO_INCH(pos.x()) * KReportDpi::dpiX(); + const qreal y = POINT_TO_INCH(pos.y()) * KReportDpi::dpiY(); + return QPointF(x, y); } -KReportSize KReportItemBase::size() const +QSizeF KReportItemBase::sceneSize(const QSizeF &size) { - return m_size; + const qreal w = POINT_TO_INCH(size.width()) * KReportDpi::dpiX(); + const qreal h = POINT_TO_INCH(size.height()) * KReportDpi::dpiY(); + return QSizeF(w, h); } +qreal KReportItemBase::z() const +{ + return d->z; +} + +void KReportItemBase::setZ(qreal z) +{ + d->z = z; +} + +void KReportItemBase::setPosition(const QPointF& pos) +{ + d->positionProperty->setValue(pos); +} + +void KReportItemBase::setSize(const QSizeF& size) +{ + d->sizeProperty->setValue(size); +} + +QPointF KReportItemBase::positionFromScene(const QPointF& pos) +{ + const qreal x = INCH_TO_POINT(pos.x() / KReportDpi::dpiX()); + const qreal y = INCH_TO_POINT(pos.y() / KReportDpi::dpiY()); + return QPointF(x, y); +} + +QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) +{ + qreal w = INCH_TO_POINT(size.width() / KReportDpi::dpiX()); + qreal h = INCH_TO_POINT(size.height() / KReportDpi::dpiY()); + return QSizeF(w, h); +} + +void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p) +{ +} + + + diff --git a/src/common/KReportItemBase.h b/src/common/KReportItemBase.h index 1fc4c3e2..5a6a4b78 100644 --- a/src/common/KReportItemBase.h +++ b/src/common/KReportItemBase.h @@ -1,138 +1,156 @@ /* This file is part of the KDE project * Copyright (C) 2007-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 . */ #ifndef KREPORTITEMBASE_H #define KREPORTITEMBASE_H #include "config-kreport.h" #include "kreport_export.h" #include "KReportPosition.h" #include "KReportSize.h" +#include "KReportDpi.h" #include #include #include class OROPage; class OROSection; class KReportSize; class KReportData; class KReportLineStyle; #ifdef KREPORT_SCRIPTING class KReportScriptHandler; #else #define KReportScriptHandler void #endif class KProperty; class KPropertySet; class QDomElement; class KRTextStyleData { public: QFont font; Qt::Alignment alignment; QColor backgroundColor; QColor foregroundColor; int backgroundOpacity; }; /* class KReportLineStyle { public: int weight; QColor lineColor; Qt::PenStyle style; }; */ /** */ class KREPORT_EXPORT KReportItemBase : public QObject { Q_OBJECT public: KReportItemBase(); virtual ~KReportItemBase(); /** @brief Return the item type as a string. Required by all items @return Item type */ virtual QString typeName() const = 0; /** @brief Render the item into a primitive which is used by the second stage renderer @return the height required by the object */ virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script); /** @brief Render a complex item that uses a sub query as a data source @return the height required by the object */ virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportData *data, KReportScriptHandler *script); /** @brief Override if the item supports a simple data source, such as a field @return The field name or expression for the data source */ virtual QString itemDataSource() const; /** @brief Override if the item uses a sub query and linked fields, such as a chart or sub-report @return True if uses a sub query */ virtual bool supportsSubQuery() const; - - KPropertySet* propertySet() const; - + + KPropertySet* propertySet(); + const KPropertySet* propertySet() const; + void setEntityName(const QString& n); QString entityName() const; virtual void setUnit(const KReportUnit& u); - KReportPosition position() const; - KReportSize size() const; + /** + * @brief Return the size in points + */ + QSizeF size() const; + + /** + * @brief Return the position in points + */ + QPointF position() const; + + void setPosition(const QPointF &pos); + void setSize(const QSizeF &siz); + + qreal z() const; + void setZ(qreal z); + + //Helper function to map between size/position units + static QPointF scenePosition(const QPointF &pos); + static QSizeF sceneSize(const QSizeF &size); + static QPointF positionFromScene(const QPointF &pos); + static QSizeF sizeFromScene(const QSizeF &size); - qreal Z; protected: - KPropertySet *m_set; - KProperty *m_name; - KReportPosition m_pos; - KReportSize m_size; - - QString m_oldName; - - void addDefaultProperties(); - virtual void createProperties() = 0; - - static bool parseReportRect(const QDomElement &, KReportPosition *pos, KReportSize *size); + bool parseReportRect(const QDomElement &elem); static bool parseReportTextStyleData(const QDomElement &, KRTextStyleData*); static bool parseReportLineStyleData(const QDomElement &, KReportLineStyle*); - - + + KProperty *nameProperty(); + QString oldName() const; + void setOldName(const QString &old); + + Q_SLOT virtual void propertyChanged(KPropertySet &s, KProperty &p); + +private: + class Private; + Private * const d; }; #endif diff --git a/src/common/KReportItemLine.cpp b/src/common/KReportItemLine.cpp index 47a7871a..84469276 100644 --- a/src/common/KReportItemLine.cpp +++ b/src/common/KReportItemLine.cpp @@ -1,154 +1,150 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemLine.h" #include "KReportRenderObjects.h" #include "kreport_debug.h" #include #include KReportItemLine::KReportItemLine() { createProperties(); } KReportItemLine::KReportItemLine(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; QPointF _s, _e; - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); + setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); _s.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x1"), QLatin1String("1cm")))); _s.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y1"), QLatin1String("1cm")))); _e.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x2"), QLatin1String("1cm")))); _e.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y2"), QLatin1String("2cm")))); m_start.setPointPos(_s); m_end.setPointPos(_e); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(int(ls.penStyle())); } } else { kreportWarning() << "while parsing line element encountered unknow element: " << n; } } } KReportItemLine::~KReportItemLine() { - delete m_set; } void KReportItemLine::createProperties() { - m_set = new KPropertySet; - m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", (int)Qt::SolidLine, tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_start.setName(QLatin1String("Start")); m_end.setName(QLatin1String("End")); - m_set->addProperty(m_name); - m_set->addProperty(m_start.property()); - m_set->addProperty(m_end.property()); - m_set->addProperty(m_lineWeight); - m_set->addProperty(m_lineColor); - m_set->addProperty(m_lineStyle); + propertySet()->addProperty(m_start.property()); + propertySet()->addProperty(m_end.property()); + propertySet()->addProperty(m_lineWeight); + propertySet()->addProperty(m_lineColor); + propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemLine::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } int KReportItemLine::weight() const { return m_lineWeight->value().toInt(); } void KReportItemLine::setWeight(int w) { m_lineWeight->setValue(w); } QString KReportItemLine::typeName() const { return QLatin1String("line"); } int KReportItemLine::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) Q_UNUSED(data) OROLine * ln = new OROLine(); QPointF s = m_start.toScene(); QPointF e = m_end.toScene(); s += offset; e += offset; ln->setStartPoint(s); ln->setEndPoint(e); ln->setLineStyle(lineStyle()); if (page) page->addPrimitive(ln); OROLine *l2 = dynamic_cast(ln->clone()); l2->setStartPoint(m_start.toPoint()); l2->setEndPoint(m_end.toPoint()); if (section) section->addPrimitive(l2); return 0; } void KReportItemLine::setUnit(const KReportUnit &u) { m_start.setUnit(u); m_end.setUnit(u); } KReportPosition KReportItemLine::startPosition() const { return m_start; } KReportPosition KReportItemLine::endPosition() const { return m_end; } diff --git a/src/common/KReportItemLine.h b/src/common/KReportItemLine.h index 7a3c7363..a9c9349f 100644 --- a/src/common/KReportItemLine.h +++ b/src/common/KReportItemLine.h @@ -1,67 +1,67 @@ /* 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 . */ #ifndef KREPORTITEMLINE_H #define KREPORTITEMLINE_H #include "KReportItemBase.h" #include "KReportPosition.h" #include "kreport_export.h" class QDomNode; namespace Scripting { class Line; } /** */ -class KREPORT_EXPORT KReportItemLine : public KReportItemBase +class KReportItemLine : public KReportItemBase { Q_OBJECT public: KReportItemLine(); explicit KReportItemLine(const QDomNode & element); ~KReportItemLine(); virtual QString typeName() const; virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script); virtual void setUnit(const KReportUnit&); KReportPosition startPosition() const; KReportPosition endPosition() const; protected: KReportPosition m_start; KReportPosition m_end; KProperty *m_lineColor; KProperty *m_lineWeight; KProperty *m_lineStyle; KReportLineStyle lineStyle() const; int weight() const; void setWeight(int w); private: virtual void createProperties(); friend class Scripting::Line; }; #endif diff --git a/src/common/KReportSectionData.cpp b/src/common/KReportSectionData.cpp index 1861ac39..67393878 100644 --- a/src/common/KReportSectionData.cpp +++ b/src/common/KReportSectionData.cpp @@ -1,216 +1,216 @@ /* 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) * Copyright (C) 2010 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 "KReportSectionData.h" #include "KReportDocument.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportItemLine.h" #include "KReportDesigner.h" #include "kreport_debug.h" #include #include KReportSectionData::KReportSectionData(QObject* parent) : QObject(parent) { createProperties(QDomElement()); } KReportSectionData::KReportSectionData(const QDomElement & elemSource, KReportDocument* report) : QObject(report) { setObjectName(elemSource.tagName()); m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type"))); createProperties(elemSource); if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::None) { m_valid = false; return; } m_backgroundColor->setValue(QColor(elemSource.attribute(QLatin1String("fo:background-color")))); KReportPluginManager* manager = KReportPluginManager::self(); QDomNodeList section = elemSource.childNodes(); for (int nodeCounter = 0; nodeCounter < section.count(); nodeCounter++) { QDomElement elemThis = section.item(nodeCounter).toElement(); QString n = elemThis.tagName(); if (n.startsWith(QLatin1String("report:"))) { QString reportItemName = n.mid(qstrlen("report:")); if (reportItemName == QLatin1String("line")) { KReportItemLine * line = new KReportItemLine(elemThis); m_objects.append(line); continue; } KReportPluginInterface *plugin = manager->plugin(reportItemName); if (plugin) { QObject *obj = plugin->createRendererInstance(elemThis); if (obj) { KReportItemBase *krobj = dynamic_cast(obj); if (krobj) { m_objects.append(krobj); } continue; } } } kreportWarning() << "While parsing section encountered an unknown element: " << n; } qSort(m_objects.begin(), m_objects.end(), zLessThan); m_valid = true; } KReportSectionData::~KReportSectionData() { delete m_set; qDeleteAll(m_objects); } bool KReportSectionData::zLessThan(KReportItemBase* s1, KReportItemBase* s2) { - return s1->Z < s2->Z; + return s1->z() < s2->z(); } bool KReportSectionData::xLessThan(KReportItemBase* s1, KReportItemBase* s2) { return s1->position().toPoint().x() < s2->position().toPoint().x(); } void KReportSectionData::createProperties(const QDomElement & elemSource) { m_set = new KPropertySet(this); KReportDesigner::addMetaProperties(m_set, tr("Section", "Report section"), QLatin1String("kreport-section-element")); m_height = new KProperty("height", KReportUnit(KReportUnit::Centimeter).fromUserValue(2.0), tr("Height")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_height->setOption("unit", QLatin1String("cm")); if (!elemSource.isNull()) m_height->setValue(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("2.0cm")))); m_set->addProperty(m_height); m_set->addProperty(m_backgroundColor); } QString KReportSectionData::name() const { return (objectName() + QLatin1Char('-') + sectionTypeString(m_type)); } QString KReportSectionData::sectionTypeString(KReportSectionData::Section s) { //! @todo use QMap QString sectiontype; switch (s) { case KReportSectionData::PageHeaderAny: sectiontype = QLatin1String("header-page-any"); break; case KReportSectionData::PageHeaderEven: sectiontype = QLatin1String("header-page-even"); break; case KReportSectionData::PageHeaderOdd: sectiontype = QLatin1String("header-page-odd"); break; case KReportSectionData::PageHeaderFirst: sectiontype = QLatin1String("header-page-first"); break; case KReportSectionData::PageHeaderLast: sectiontype = QLatin1String("header-page-last"); break; case KReportSectionData::PageFooterAny: sectiontype = QLatin1String("footer-page-any"); break; case KReportSectionData::PageFooterEven: sectiontype = QLatin1String("footer-page-even"); break; case KReportSectionData::PageFooterOdd: sectiontype = QLatin1String("footer-page-odd"); break; case KReportSectionData::PageFooterFirst: sectiontype = QLatin1String("footer-page-first"); break; case KReportSectionData::PageFooterLast: sectiontype = QLatin1String("footer-page-last"); break; case KReportSectionData::ReportHeader: sectiontype = QLatin1String("header-report"); break; case KReportSectionData::ReportFooter: sectiontype = QLatin1String("footer-report"); break; case KReportSectionData::GroupHeader: sectiontype = QLatin1String("group-header"); break; case KReportSectionData::GroupFooter: sectiontype = QLatin1String("group-footer"); break; case KReportSectionData::Detail: sectiontype = QLatin1String("detail"); break; default: ; } return sectiontype; } KReportSectionData::Section KReportSectionData::sectionTypeFromString(const QString& s) { //! @todo use QMap KReportSectionData::Section sec; //kreportDebug() << "Determining section type for " << s; if (s == QLatin1String("header-page-any")) sec = KReportSectionData::PageHeaderAny; else if (s == QLatin1String("header-page-even")) sec = KReportSectionData::PageHeaderEven; else if (s == QLatin1String("header-page-odd")) sec = KReportSectionData::PageHeaderOdd; else if (s == QLatin1String("header-page-first")) sec = KReportSectionData::PageHeaderFirst; else if (s == QLatin1String("header-page-last")) sec = KReportSectionData::PageHeaderLast; else if (s == QLatin1String("header-report")) sec = KReportSectionData::ReportHeader; else if (s == QLatin1String("footer-page-any")) sec = KReportSectionData::PageFooterAny; else if (s == QLatin1String("footer-page-even")) sec = KReportSectionData::PageFooterEven; else if (s == QLatin1String("footer-page-odd")) sec = KReportSectionData::PageFooterOdd; else if (s == QLatin1String("footer-page-first")) sec = KReportSectionData::PageFooterFirst; else if (s == QLatin1String("footer-page-last")) sec = KReportSectionData::PageFooterLast; else if (s == QLatin1String("footer-report")) sec = KReportSectionData::ReportFooter; else if (s == QLatin1String("group-header")) sec = KReportSectionData::GroupHeader; else if (s == QLatin1String("group-footer")) sec = KReportSectionData::GroupFooter; else if (s == QLatin1String("detail")) sec = KReportSectionData::Detail; else sec = KReportSectionData::None; return sec; } diff --git a/src/common/KReportUtils.cpp b/src/common/KReportUtils.cpp index 027912a7..04f88024 100644 --- a/src/common/KReportUtils.cpp +++ b/src/common/KReportUtils.cpp @@ -1,556 +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 "KReportPosition.h" #include "KReportSize.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, KReportPosition *pos, KReportSize *size) +void KReportUtils::buildXMLRect(QDomElement *entity, const QPointF &pos, const QSizeF &size) { Q_ASSERT(entity); - Q_ASSERT(pos); - Q_ASSERT(size); - KReportUtils::setAttribute(entity, pos->toPoint() ); - KReportUtils::setAttribute(entity, size->toPoint() ); + + 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()); 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")).toInt()); 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; } 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; } 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/common/KReportUtils.h b/src/common/KReportUtils.h index 430f9375..49e0d301 100644 --- a/src/common/KReportUtils.h +++ b/src/common/KReportUtils.h @@ -1,131 +1,131 @@ /* 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. */ #ifndef KREPORTUTILS_H #define KREPORTUTILS_H #include "kreport_export.h" #include #include #include #include class QDomDocument; class QDomElement; class QFont; class QPointF; class KProperty; class KReportPosition; class KReportSize; class KRTextStyleData; class KReportLineStyle; namespace KReportUtils { KREPORT_EXPORT QString attr(const QDomElement &el, const char *attrName, const QString &defaultValue = QString()); KREPORT_EXPORT QByteArray attr(const QDomElement &el, const char *attrName, const QByteArray &defaultValue = QByteArray()); KREPORT_EXPORT bool attr(const QDomElement &el, const char *attrName, bool defaultValue = false); KREPORT_EXPORT int attr(const QDomElement &el, const char *attrName, int defaultValue = 0); KREPORT_EXPORT qreal attr(const QDomElement &el, const char *attrName, qreal defaultValue = 0.0); KREPORT_EXPORT QColor attr(const QDomElement &el, const char *attrName, const QColor &defaultValue = QColor()); //! @return percent value converted to qreal, e.g. 1.0 for "100%", 0.505 for "50.5%". //! @a defaultValue is returned if there is not "%" suffix or no proper number. KREPORT_EXPORT qreal attrPercent(const QDomElement& el, const char* attrName, qreal defaultValue = 0.0); //! @return pen style from @a str or @a defaultValue //! Values from ODF 1.2 19.493 style:line-style are also recognized. KREPORT_EXPORT Qt::PenStyle penStyle(const QString &str, Qt::PenStyle defaultValue); //! @return vertical alignment flag from @a str or @a defaultValue KREPORT_EXPORT Qt::Alignment verticalAlignment(const QString &str, Qt::Alignment defaultValue); //! @return horizontal alignment flag from @a str or @a defaultValue KREPORT_EXPORT Qt::Alignment horizontalAlignment(const QString &str, Qt::Alignment defaultValue); //! @return vertical alignment flag name from @a alignment KREPORT_EXPORT QString verticalToString(Qt::Alignment alignment); //! @return horizontal alignment flag from @a alignment KREPORT_EXPORT QString horizontalToString(Qt::Alignment alignment); //! @return rectangle value read from svg:x, svg:y, svg:width, svg:height attributes of @a el. //! If any of the arguments are missing, @a defaultValue is returned. KREPORT_EXPORT QRectF readRectAttributes(const QDomElement &el, const QRectF &defaultValue = QRectF()); //! @return percent value for element @a name. If the element is missing, returns @a defaultPercentValue. //! If @a ok is not 0, *ok is set to the result. KREPORT_EXPORT int readPercent(const QDomElement & el, const char* name, int defaultPercentValue, bool *ok); //! Reads all font attributes for element @a el into @a font. //! @todo add unit tests KREPORT_EXPORT void readFontAttributes(const QDomElement& el, QFont* font); //! Writes all attributes of font @a font into element @a el. //! @todo add unit tests KREPORT_EXPORT void writeFontAttributes(QDomElement *el, const QFont &font); //! Writes attributes for the rect position @p pos, @p siz - KREPORT_EXPORT void buildXMLRect(QDomElement *entity, KReportPosition *pos, KReportSize *size); + KREPORT_EXPORT void buildXMLRect(QDomElement *entity, const QPointF &pos, const QSizeF &size); //! Writes attributes for text style @p ts KREPORT_EXPORT void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts); //! Writes attributes for line style @p ls KREPORT_EXPORT void buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls); //! Writes attributes for the property @p p KREPORT_EXPORT void addPropertyAsAttribute(QDomElement* e, KProperty* p); //! Writes @p attribute to element @p e, @p value is stored in points with unit 'pt' KREPORT_EXPORT void setAttribute(QDomElement *e, const QString &attribute, double value); //! Writes point @p value as attributes to element @p e KREPORT_EXPORT void setAttribute(QDomElement *e, const QPointF &value); //! Writes size @p value as attributes to element @p e KREPORT_EXPORT void setAttribute(QDomElement *e, const QSizeF &value); //! Reads attributes from @p elemSource into text style @p ts KREPORT_EXPORT bool parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts); //! Reads attributes from @p elemSource into line style @p ls KREPORT_EXPORT bool parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls); //! Reads attributes from @p elemSource into rect @p pos, @p siz KREPORT_EXPORT bool parseReportRect(const QDomElement & elemSource, KReportPosition *pos, KReportSize *size); //! @return page size ID for page key (the PPD standard mediaOption keyword, e.g. "A4") //! @note It's an efficient workaround because QPageSize misses this function. KREPORT_EXPORT QPageSize::PageSizeId pageSizeId(const QString &key); //! Like QPageSize::PageSizeId pageSizeId(const QString &key) but returns entire QPageSize object. KREPORT_EXPORT QPageSize pageSize(const QString &key); } // KReportUtils #endif diff --git a/src/items/check/KReportDesignerItemCheckBox.cpp b/src/items/check/KReportDesignerItemCheckBox.cpp index 62208e61..64bf63ae 100644 --- a/src/items/check/KReportDesignerItemCheckBox.cpp +++ b/src/items/check/KReportDesignerItemCheckBox.cpp @@ -1,184 +1,183 @@ /* 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 "KReportDesignerItemCheckBox.h" #include "KReportDesignerItemRectBase.h" #include "KReportDesigner.h" #include "KReportLineStyle.h" #include #include #include #include // // class ReportEntityCheck // void KReportDesignerItemCheckBox::init(QGraphicsScene *scene, KReportDesigner *d) { if (scene) scene->addItem(this); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); - connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - setZValue(Z); + setZValue(z()); } // methods (constructors) KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos) - : KReportDesignerItemRectBase(d) + : KReportDesignerItemRectBase(d, this) { Q_UNUSED(pos); init(scene, d); setSceneRect(properRect(*d, KREPORT_ITEM_CHECK_DEFAULT_WIDTH, KREPORT_ITEM_CHECK_DEFAULT_HEIGHT)); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) - : KReportItemCheckBox(element), KReportDesignerItemRectBase(d) + : KReportItemCheckBox(element), KReportDesignerItemRectBase(d, this) { init(s, d); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemCheckBox* KReportDesignerItemCheckBox::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemCheckBox(n, designer(), 0); } // methods (deconstructor) KReportDesignerItemCheckBox::~KReportDesignerItemCheckBox() {} void KReportDesignerItemCheckBox::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); // store any values we plan on changing so we can restore them QFont f = painter->font(); QPen p = painter->pen(); QBrush b = painter->brush(); painter->setBackgroundMode(Qt::OpaqueMode); painter->setRenderHint(QPainter::Antialiasing); painter->setPen(m_foregroundColor->value().value()); if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { painter->setPen(QPen(Qt::lightGray)); } else { painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); } - qreal ox = m_size.toScene().width() / 5; - qreal oy = m_size.toScene().height() / 5; + QSizeF sceneSize = this->sceneSize(size()); + qreal ox = sceneSize.width() / 5; + qreal oy = sceneSize.height() / 5; //Checkbox Style if (m_checkStyle->value().toString() == QLatin1String("Cross")) { - painter->drawRoundedRect(QGraphicsRectItem::rect(), m_size.toScene().width() / 10 , m_size.toScene().height() / 10); + painter->drawRoundedRect(QGraphicsRectItem::rect(), sceneSize.width() / 10 , sceneSize.height() / 10); QPen lp; lp.setColor(m_foregroundColor->value().value()); lp.setWidth(ox > oy ? oy : ox); painter->setPen(lp); - painter->drawLine(ox, oy, m_size.toScene().width() - ox, m_size.toScene().height() - oy); - painter->drawLine(ox, m_size.toScene().height() - oy, m_size.toScene().width() - ox, oy); + painter->drawLine(ox, oy, sceneSize.width() - ox, sceneSize.height() - oy); + painter->drawLine(ox, sceneSize.height() - oy, sceneSize.width() - ox, oy); } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) { //Radio Style painter->drawEllipse(QGraphicsRectItem::rect()); QBrush lb(m_foregroundColor->value().value()); painter->setBrush(lb); painter->setPen(Qt::NoPen); - painter->drawEllipse(rect().center(), m_size.toScene().width() / 2 - ox, m_size.toScene().height() / 2 - oy); + painter->drawEllipse(rect().center(), sceneSize.width() / 2 - ox, sceneSize.height() / 2 - oy); } else { //Tickbox Style - painter->drawRoundedRect(QGraphicsRectItem::rect(), m_size.toScene().width() / 10 , m_size.toScene().height() / 10); + painter->drawRoundedRect(QGraphicsRectItem::rect(), sceneSize.width() / 10 , sceneSize.height() / 10); QPen lp; lp.setColor(m_foregroundColor->value().value()); lp.setWidth(ox > oy ? oy : ox); painter->setPen(lp); - painter->drawLine(ox, m_size.toScene().height() / 2, m_size.toScene().width() / 2, m_size.toScene().height() - oy); - painter->drawLine(m_size.toScene().width() / 2, m_size.toScene().height() - oy, m_size.toScene().width() - ox, oy); + painter->drawLine(ox, sceneSize.height() / 2, sceneSize.width() / 2, sceneSize.height() - oy); + painter->drawLine(sceneSize.width() / 2, sceneSize.height() - oy, sceneSize.width() - ox, oy); } painter->setBackgroundMode(Qt::TransparentMode); painter->setPen(m_foregroundColor->value().value()); // restore an values before we started just in case painter->setFont(f); painter->setPen(p); painter->setBrush(b); drawHandles(painter); } void KReportDesignerItemCheckBox::buildXML(QDomDocument *doc, QDomElement *parent) { //kreportpluginDebug(); QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); //properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_controlSource); entity.setAttribute(QLatin1String("fo:foreground-color"), m_foregroundColor->value().toString()); addPropertyAsAttribute(&entity, m_checkStyle); addPropertyAsAttribute(&entity, m_staticValue); // bounding rect - buildXMLRect(doc, &entity, &m_pos, &m_size); + buildXMLRect(doc, &entity, this); //Line Style buildXMLLineStyle(doc, &entity, lineStyle()); parent->appendChild(entity); } void KReportDesignerItemCheckBox::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s) if (p.name() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } KReportDesignerItemRectBase::propertyChanged(s, p); - if (m_reportDesigner) m_reportDesigner->setModified(true); + if (designer()) designer()->setModified(true); } void KReportDesignerItemCheckBox::mousePressEvent(QGraphicsSceneMouseEvent * event) { - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp index f2e74f33..c9b2232e 100644 --- a/src/items/check/KReportItemCheck.cpp +++ b/src/items/check/KReportItemCheck.cpp @@ -1,190 +1,186 @@ /* 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; - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); + nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + 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(), &m_pos, &m_size); + parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing check element encountered unknow element: " << n; } } } KReportItemCheckBox::~KReportItemCheckBox() { - delete m_set; } void KReportItemCheckBox::createProperties() { - m_set = new KPropertySet; - QStringList keys, strings; keys << QLatin1String("Cross") << QLatin1String("Tick") << QLatin1String("Dot"); strings << tr("Cross") << tr("Tick") << tr("Dot"); m_checkStyle = new KProperty("check-style", keys, strings, QLatin1String("Cross"), tr("Style")); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::SolidLine), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_staticValue = new KProperty("value", QVariant(false), tr("Value"), tr("Value used if not bound to a field")); - addDefaultProperties(); - m_set->addProperty(m_controlSource); - m_set->addProperty(m_staticValue); - m_set->addProperty(m_checkStyle); - m_set->addProperty(m_foregroundColor); - m_set->addProperty(m_lineWeight); - m_set->addProperty(m_lineColor); - m_set->addProperty(m_lineStyle); + propertySet()->addProperty(m_controlSource); + propertySet()->addProperty(m_staticValue); + propertySet()->addProperty(m_checkStyle); + propertySet()->addProperty(m_foregroundColor); + propertySet()->addProperty(m_lineWeight); + propertySet()->addProperty(m_lineColor); + propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemCheckBox::lineStyle() { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } QString KReportItemCheckBox::itemDataSource() const { return m_controlSource->value().toString(); } // RTTI QString KReportItemCheckBox::typeName() const { return QLatin1String("check"); } int KReportItemCheckBox::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROCheck *chk = new OROCheck(); - chk->setPosition(m_pos.toScene() + offset); - chk->setSize(m_size.toScene()); + chk->setPosition(scenePosition(position()) + offset); + chk->setSize(sceneSize(size())); chk->setLineStyle(lineStyle()); chk->setForegroundColor(m_foregroundColor->value().value()); chk->setCheckType(m_checkStyle->value().toString()); QString str; bool v = false; QString cs = itemDataSource(); //kreportpluginDebug() << "ControlSource:" << cs; if (!cs.isEmpty()) { #ifdef KREPORT_SCRIPTING if (cs.left(1) == QLatin1String("=") && script) { str = script->evaluate(cs.mid(1)).toString(); } else #else Q_UNUSED(script); #endif { str = data.toString(); } str = str.toLower(); //kreportpluginDebug() << "Check Value:" << str; if (str == QLatin1String("t") || str == QLatin1String("y") || str == QLatin1String("true") || str == QLatin1String("1")) v = true; } else { v = value(); } chk->setValue(v); if (page) { page->addPrimitive(chk); } if (section) { OROCheck *chk2 = dynamic_cast(chk->clone()); - chk2->setPosition(m_pos.toPoint()); + 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/check/KReportScriptCheck.cpp b/src/items/check/KReportScriptCheck.cpp index 5437d7fe..3abb7333 100644 --- a/src/items/check/KReportScriptCheck.cpp +++ b/src/items/check/KReportScriptCheck.cpp @@ -1,111 +1,111 @@ /* 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 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 "KReportScriptCheck.h" #include namespace Scripting { CheckBox::CheckBox(KReportItemCheckBox *c) { m_check = c; } CheckBox::~CheckBox() { } bool CheckBox::value() const { return m_check->value(); } void CheckBox::setValue(bool v) { m_check->setValue(v); } QString CheckBox::checkStyle() const { return m_check->m_checkStyle->value().toString(); } void CheckBox::setCheckStyle(const QString &style) { m_check->m_checkStyle->setValue(style); } QColor CheckBox::foregroundColor() const { return m_check->m_foregroundColor->value().value(); } void CheckBox::setForegroundColor(const QColor& c) { m_check->m_foregroundColor->setValue(c); } QColor CheckBox::lineColor() const { return m_check->m_lineColor->value().value(); } void CheckBox::setLineColor(const QColor& c) { m_check->m_lineColor->setValue(c); } int CheckBox::lineWeight() const { return m_check->m_lineWeight->value().toInt(); } void CheckBox::setLineWeight(int w) { m_check->m_lineWeight->setValue(w); } int CheckBox::lineStyle() const { return m_check->m_lineStyle->value().toInt(); } void CheckBox::setLineStyle(int s) { if (s < 0 || s > 5) { s = 1; } m_check->m_lineStyle->setValue(s); } QPointF CheckBox::position() const { - return m_check->m_pos.toPoint(); + return m_check->position(); } void CheckBox::setPosition(const QPointF &p) { - m_check->m_pos.setPointPos(p); + m_check->setPosition(p); } QSizeF CheckBox::size() const { - return m_check->m_size.toPoint(); + return m_check->size(); } void CheckBox::setSize(const QSizeF &s) { - m_check->m_size.setPointSize(s); + m_check->setSize(s); } } diff --git a/src/items/field/KReportDesignerItemField.cpp b/src/items/field/KReportDesignerItemField.cpp index 3c568f62..65400bd3 100644 --- a/src/items/field/KReportDesignerItemField.cpp +++ b/src/items/field/KReportDesignerItemField.cpp @@ -1,191 +1,186 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerItemField.h" #include "KReportItemField.h" #include "KReportDesigner.h" #include "kreportplugin_debug.h" #include "KReportLineStyle.h" #include #include #include #include // // class ReportEntityField // void KReportDesignerItemField::init(QGraphicsScene * scene, KReportDesigner * d) { if (scene) scene->addItem(this); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); - - connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), - this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - - setZValue(Z); + setZValue(z()); updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); } // methods (constructors) KReportDesignerItemField::KReportDesignerItemField(KReportDesigner * rw, QGraphicsScene * scene, const QPointF &pos) - : KReportDesignerItemRectBase(rw) + : KReportDesignerItemRectBase(rw, this) { Q_UNUSED(pos); init(scene, rw); setSceneRect(properRect(*rw, getTextRect().width(), getTextRect().height())); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemField::KReportDesignerItemField(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) - : KReportItemField(element), KReportDesignerItemRectBase(d) + : KReportItemField(element), KReportDesignerItemRectBase(d, this) { init(s, d); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemField* KReportDesignerItemField::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemField(n, designer(), 0); } // methods (deconstructor) KReportDesignerItemField::~KReportDesignerItemField() {} QRect KReportDesignerItemField::getTextRect() const { - return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), m_renderText); + return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), renderText()); } void KReportDesignerItemField::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); // store any values we plan on changing so we can restore them QFont f = painter->font(); QPen p = painter->pen(); painter->setFont(font()); painter->setBackgroundMode(Qt::TransparentMode); QColor bg = m_backgroundColor->value().value(); bg.setAlphaF(m_backgroundOpacity->value().toReal() *0.01); painter->setPen(m_foregroundColor->value().value()); painter->fillRect(QGraphicsRectItem::rect(), bg); - painter->drawText(rect(), textFlags(), m_renderText); + painter->drawText(rect(), textFlags(), renderText()); if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { painter->setPen(QPen(Qt::lightGray)); } else { painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); } painter->drawRect(rect()); drawHandles(painter); // restore an values before we started just in case painter->setFont(f); painter->setPen(p); } void KReportDesignerItemField::buildXML(QDomDocument *doc, QDomElement *parent) { QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_controlSource); addPropertyAsAttribute(&entity, m_verticalAlignment); addPropertyAsAttribute(&entity, m_horizontalAlignment); addPropertyAsAttribute(&entity, m_wordWrap); addPropertyAsAttribute(&entity, m_canGrow); addPropertyAsAttribute(&entity, m_itemValue); entity.setAttribute(QLatin1String("report:z-index"), zValue()); // bounding rect - buildXMLRect(doc, &entity, &m_pos, &m_size); + buildXMLRect(doc, &entity, this); //text style info buildXMLTextStyle(doc, &entity, textStyle()); //Line Style buildXMLLineStyle(doc, &entity, lineStyle()); #if 0 //Field Totals if (m_trackTotal) { QDomElement tracktotal = doc->createElement("tracktotal"); if (m_trackBuiltinFormat) tracktotal.setAttribute("builtin", "true"); if (_useSubTotal) tracktotal.setAttribute("subtotal", "true"); tracktotal.appendChild(doc.createTextNode(_trackTotalFormat->value().toString())); entity.appendChild(tracktotal); } #endif parent->appendChild(entity); } void KReportDesignerItemField::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s); if (p.name() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); KReportDesignerItemRectBase::propertyChanged(s, p); - if (m_reportDesigner)m_reportDesigner->setModified(true); + if (designer())designer()->setModified(true); } void KReportDesignerItemField::mousePressEvent(QGraphicsSceneMouseEvent * event) { //kreportpluginDebug() << m_reportDesigner->fieldKeys() << m_reportDesigner->fieldNames(); - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/items/field/KReportItemField.cpp b/src/items/field/KReportItemField.cpp index 699613e6..4034fe7b 100644 --- a/src/items/field/KReportItemField.cpp +++ b/src/items/field/KReportItemField.cpp @@ -1,291 +1,287 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemField.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #ifdef KREPORT_SCRIPTING #include "renderer/scripting/KReportScriptHandler.h" #endif #include #include #include #include #include KReportItemField::KReportItemField() { createProperties(); } KReportItemField::KReportItemField(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); + 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"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + 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(), &m_pos, &m_size); + parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; } } } KReportItemField::~KReportItemField() { - delete m_set; } void KReportItemField::createProperties() { - m_set = new KPropertySet; - QStringList keys, strings; m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_wordWrap = new KProperty("word-wrap", QVariant(false), tr("Word Wrap")); m_canGrow = new KProperty("can-grow", QVariant(false), tr("Can Grow")); //! @todo I do not think we need these #if 0 //Field Totals m_trackTotal = new KProperty("trackTotal", QVariant(false), futureI18n("Track Total")); m_trackBuiltinFormat = new KProperty("trackBuiltinFormat", QVariant(false), futureI18n("Track Builtin Format")); _useSubTotal = new KProperty("useSubTotal", QVariant(false), futureI18n("Use Sub Total"_)); _trackTotalFormat = new KProperty("trackTotalFormat", QString(), futureI18n("Track Total Format")); #endif - addDefaultProperties(); - m_set->addProperty(m_controlSource); - m_set->addProperty(m_itemValue); - m_set->addProperty(m_horizontalAlignment); - m_set->addProperty(m_verticalAlignment); - m_set->addProperty(m_font); - m_set->addProperty(m_backgroundColor); - m_set->addProperty(m_foregroundColor); - m_set->addProperty(m_backgroundOpacity); - m_set->addProperty(m_lineWeight); - m_set->addProperty(m_lineColor); - m_set->addProperty(m_lineStyle); - m_set->addProperty(m_wordWrap); - m_set->addProperty(m_canGrow); + propertySet()->addProperty(m_controlSource); + propertySet()->addProperty(m_itemValue); + propertySet()->addProperty(m_horizontalAlignment); + propertySet()->addProperty(m_verticalAlignment); + propertySet()->addProperty(m_font); + propertySet()->addProperty(m_backgroundColor); + propertySet()->addProperty(m_foregroundColor); + propertySet()->addProperty(m_backgroundOpacity); + propertySet()->addProperty(m_lineWeight); + propertySet()->addProperty(m_lineColor); + propertySet()->addProperty(m_lineStyle); + propertySet()->addProperty(m_wordWrap); + propertySet()->addProperty(m_canGrow); //_set->addProperty ( _trackTotal ); //_set->addProperty ( _trackBuiltinFormat ); //_set->addProperty ( _useSubTotal ); //_set->addProperty ( _trackTotalFormat ); } int KReportItemField::textFlags() const { int flags; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) flags = Qt::AlignHCenter; else if (t == QLatin1String("right")) flags = Qt::AlignRight; else flags = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) flags |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) flags |= Qt::AlignBottom; else flags |= Qt::AlignTop; if (m_wordWrap->value().toBool() == true) { flags |= Qt::TextWordWrap; } return flags; } KRTextStyleData KReportItemField::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } QString KReportItemField::itemDataSource() const { return m_controlSource->value().toString(); } void KReportItemField::setItemDataSource(const QString& t) { if (m_controlSource->value() != t) { m_controlSource->setValue(t); } //kreportpluginDebug() << "Field: " << entityName() << "is" << itemDataSource(); } KReportLineStyle KReportItemField::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemField::typeName() const { return QLatin1String("field"); } int KReportItemField::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROTextBox * tb = new OROTextBox(); - tb->setPosition(m_pos.toScene() + offset); - tb->setSize(m_size.toScene()); + 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(); } } else #else Q_UNUSED(script); #endif if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string str = ids.mid(1); } else { str = data.toString(); } } else { str = m_itemValue->value().toString(); } tb->setText(str); //Work out the size of the text if (tb->canGrow()) { QRect r; if (tb->wordWrap()) { //Grow vertically QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), tb->size().width(), 5000); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } else { //Grow Horizontally QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), 5000, tb->size().height()); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } tb->setSize(r.size() + QSize(4,4)); } if (page) { page->addPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); - clone->setPosition(m_pos.toScene()); + clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } - int height = m_pos.toScene().y() + tb->size().height(); + 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/field/KReportScriptField.cpp b/src/items/field/KReportScriptField.cpp index 1e1e4eb2..be18d8f2 100644 --- a/src/items/field/KReportScriptField.cpp +++ b/src/items/field/KReportScriptField.cpp @@ -1,183 +1,183 @@ /* 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 "KReportScriptField.h" namespace Scripting { Field::Field(KReportItemField *f) { m_field = f; } Field::~Field() { } QString Field::source() const { return m_field->itemDataSource(); } void Field::setSource(const QString& s) { m_field->setItemDataSource(s); } int Field::horizontalAlignment() const { const QString a = m_field->m_horizontalAlignment->value().toString().toLower(); if (a == QLatin1String("left")) { return -1; } if (a == QLatin1String("center")) { return 0; } if (a == QLatin1String("right")) { return 1; } return -1; } void Field::setHorizonalAlignment(int a) { switch (a) { case -1: m_field->m_horizontalAlignment->setValue(QLatin1String("left")); break; case 0: m_field->m_horizontalAlignment->setValue(QLatin1String("center")); break; case 1: m_field->m_horizontalAlignment->setValue(QLatin1String("right")); break; default: m_field->m_horizontalAlignment->setValue(QLatin1String("left")); break; } } int Field::verticalAlignment() const { const QString a = m_field->m_horizontalAlignment->value().toString().toLower(); if (a == QLatin1String("top")) { return -1; } if (a == QLatin1String("middle")) { return 0; } if (a == QLatin1String("bottom")) { return 1; } return -1; } void Field::setVerticalAlignment(int a) { switch (a) { case -1: m_field->m_verticalAlignment->setValue(QLatin1String("top")); break; case 0: m_field->m_verticalAlignment->setValue(QLatin1String("middle")); break; case 1: m_field->m_verticalAlignment->setValue(QLatin1String("bottom")); break; default: m_field->m_verticalAlignment->setValue(QLatin1String("middle")); break; } } QColor Field::backgroundColor() const { return m_field->m_backgroundColor->value().value(); } void Field::setBackgroundColor(const QColor& c) { m_field->m_backgroundColor->setValue(c); } QColor Field::foregroundColor() const { return m_field->m_foregroundColor->value().value(); } void Field::setForegroundColor(const QColor& c) { m_field->m_foregroundColor->setValue(c); } int Field::backgroundOpacity() const { return m_field->m_backgroundOpacity->value().toInt(); } void Field::setBackgroundOpacity(int o) { m_field->m_backgroundOpacity->setValue(o); } QColor Field::lineColor() const { return m_field->m_lineColor->value().value(); } void Field::setLineColor(const QColor& c) { m_field->m_lineColor->setValue(c); } int Field::lineWeight() const { return m_field->m_lineWeight->value().toInt(); } void Field::setLineWeight(int w) { m_field->m_lineWeight->setValue(w); } int Field::lineStyle() const { return m_field->m_lineStyle->value().toInt(); } void Field::setLineStyle(int s) { if (s < 0 || s > 5) { s = 1; } m_field->m_lineStyle->setValue(s); } QPointF Field::position() const { - return m_field->m_pos.toPoint(); + return m_field->position(); } void Field::setPosition(const QPointF &p) { - m_field->m_pos.setPointPos(p); + m_field->setPosition(p); } QSizeF Field::size() const { - return m_field->m_size.toPoint(); + return m_field->size(); } void Field::setSize(const QSizeF &s) { - m_field->m_size.setPointSize(s); + m_field->setSize(s); } } diff --git a/src/items/image/KReportDesignerItemImage.cpp b/src/items/image/KReportDesignerItemImage.cpp index 40163b3a..3c958d77 100644 --- a/src/items/image/KReportDesignerItemImage.cpp +++ b/src/items/image/KReportDesignerItemImage.cpp @@ -1,152 +1,150 @@ /* 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 "KReportDesignerItemImage.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include #include #include #include #include // // ReportEntitiesImage // // contructors/deconstructors void KReportDesignerItemImage::init(QGraphicsScene *scene, KReportDesigner *d) { //kreportpluginDebug(); if (scene) scene->addItem(this); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); - - connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), + connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); - setZValue(Z); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); + setZValue(z()); } KReportDesignerItemImage::KReportDesignerItemImage(KReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos) - : KReportDesignerItemRectBase(rw) + : KReportDesignerItemRectBase(rw, this) { Q_UNUSED(pos); //kreportpluginDebug(); init(scene, rw); setSceneRect(properRect(*rw, KREPORT_ITEM_RECT_DEFAULT_WIDTH, KREPORT_ITEM_RECT_DEFAULT_WIDTH)); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemImage::KReportDesignerItemImage(const QDomNode & element, KReportDesigner * rw, QGraphicsScene* scene) - : KReportItemImage(element), KReportDesignerItemRectBase(rw) + : KReportItemImage(element), KReportDesignerItemRectBase(rw, this) { init(scene, rw); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemImage* KReportDesignerItemImage::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemImage(n, designer(), 0); } KReportDesignerItemImage::~KReportDesignerItemImage() { // do we need to clean anything up? } void KReportDesignerItemImage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); // store any values we plan on changing so we can restore them QPen p = painter->pen(); if (isInline()) { //QImage t_img = _image; QImage t_img = m_staticImage->value().value().toImage(); if (mode() == QLatin1String("stretch")) { t_img = t_img.scaled(rect().width(), rect().height(), Qt::KeepAspectRatio); } painter->drawImage(rect().left(), rect().top(), t_img, 0, 0, rect().width(), rect().height()); } else { painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("image"))); } //Draw a border so user knows the object edge painter->setPen(QPen(Qt::lightGray)); painter->drawRect(rect()); drawHandles(painter); // restore an values before we started just in case painter->setPen(p); } void KReportDesignerItemImage::buildXML(QDomDocument *doc, QDomElement *parent) { QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_resizeMode); - entity.setAttribute(QLatin1String("report:z-index"), zValue()); - buildXMLRect(doc, &entity, &m_pos, &m_size); + entity.setAttribute(QLatin1String("report:z-index"), z()); + buildXMLRect(doc, &entity, this); if (isInline()) { QDomElement map = doc->createElement(QLatin1String("report:inline-image-data")); map.appendChild(doc->createTextNode(QLatin1String(inlineImageData()))); entity.appendChild(map); } else { addPropertyAsAttribute(&entity, m_controlSource); } parent->appendChild(entity); } void KReportDesignerItemImage::slotPropertyChanged(KPropertySet &s, KProperty &p) { if (p.name() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } KReportDesignerItemRectBase::propertyChanged(s, p); - if (m_reportDesigner) m_reportDesigner->setModified(true); + if (designer()) designer()->setModified(true); } void KReportDesignerItemImage::mousePressEvent(QGraphicsSceneMouseEvent * event) { - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/items/image/KReportItemImage.cpp b/src/items/image/KReportItemImage.cpp index f764fe37..69bb2302 100644 --- a/src/items/image/KReportItemImage.cpp +++ b/src/items/image/KReportItemImage.cpp @@ -1,192 +1,188 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemImage.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include KReportItemImage::KReportItemImage() { createProperties(); } KReportItemImage::KReportItemImage(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); + nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_resizeMode->setValue(element.toElement().attribute(QLatin1String("report:resize-mode"), QLatin1String("stretch"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); - parseReportRect(element.toElement(), &m_pos, &m_size); + parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:inline-image-data")) { setInlineImageData(node.firstChild().nodeValue().toLatin1()); } else { kreportpluginWarning() << "while parsing image element encountered unknow element: " << n; } } } KReportItemImage::~KReportItemImage() { - delete m_set; } bool KReportItemImage::isInline() const { return !(inlineImageData().isEmpty()); } QByteArray KReportItemImage::inlineImageData() const { QPixmap pixmap = m_staticImage->value().value(); QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::ReadWrite); pixmap.save(&buffer, "PNG"); // writes pixmap into ba in PNG format, //! @todo should I remember the format used, or save as PNG as its lossless? return buffer.buffer().toBase64(); } void KReportItemImage::setInlineImageData(const QByteArray &dat, const QString &fn) { if (!fn.isEmpty()) { QPixmap pix(fn); if (!pix.isNull()) m_staticImage->setValue(pix); else { QPixmap blank(1, 1); blank.fill(); m_staticImage->setValue(blank); } } else { const QByteArray binaryStream(QByteArray::fromBase64(dat)); const QPixmap pix(QPixmap::fromImage(QImage::fromData(binaryStream), Qt::ColorOnly)); m_staticImage->setValue(pix); } } QString KReportItemImage::mode() const { return m_resizeMode->value().toString(); } void KReportItemImage::setMode(const QString &m) { if (mode() != m) { m_resizeMode->setValue(m); } } void KReportItemImage::createProperties() { - m_set = new KPropertySet; - m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); QStringList keys, strings; keys << QLatin1String("clip") << QLatin1String("stretch"); strings << tr("Clip") << tr("Stretch"); m_resizeMode = new KProperty("resize-mode", keys, strings, QLatin1String("clip"), tr("Resize Mode")); m_staticImage = new KProperty("static-image", QPixmap(), tr("Value"), tr("Value used if not bound to a field")); - addDefaultProperties(); - m_set->addProperty(m_controlSource); - m_set->addProperty(m_resizeMode); - m_set->addProperty(m_staticImage); + propertySet()->addProperty(m_controlSource); + propertySet()->addProperty(m_resizeMode); + propertySet()->addProperty(m_staticImage); } void KReportItemImage::setColumn(const QString &c) { m_controlSource->setValue(c); } QString KReportItemImage::itemDataSource() const { return m_controlSource->value().toString(); } QString KReportItemImage::typeName() const { return QLatin1String("image"); } int KReportItemImage::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) QByteArray uudata; QByteArray imgdata; if (!isInline()) { imgdata = data.toByteArray(); } else { uudata = inlineImageData(); imgdata = QByteArray::fromBase64(uudata); } QImage img; img.loadFromData(imgdata); OROImage * id = new OROImage(); id->setImage(img); if (mode().toLower() == QLatin1String("stretch")) { id->setScaled(true); id->setAspectRatioMode(Qt::KeepAspectRatio); id->setTransformationMode(Qt::SmoothTransformation); } - id->setPosition(m_pos.toScene() + offset); - id->setSize(m_size.toScene()); + id->setPosition(scenePosition(position()) + offset); + id->setSize(sceneSize(size())); if (page) { page->addPrimitive(id); } if (section) { OROImage *i2 = dynamic_cast(id->clone()); - i2->setPosition(m_pos.toPoint()); + i2->setPosition(scenePosition(position())); section->addPrimitive(i2); } if (!page) { delete id; } return 0; //Item doesn't stretch the section height } diff --git a/src/items/image/KReportScriptImage.cpp b/src/items/image/KReportScriptImage.cpp index 214a7756..ce13fbe4 100644 --- a/src/items/image/KReportScriptImage.cpp +++ b/src/items/image/KReportScriptImage.cpp @@ -1,78 +1,78 @@ /* 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 "KReportScriptImage.h" #include "KReportItemImage.h" #include namespace Scripting { Image::Image(KReportItemImage *i) { m_image = i; } Image::~Image() { } QPointF Image::position() const { - return m_image->m_pos.toPoint(); + return m_image->position(); } void Image::setPosition(const QPointF& p) { - m_image->m_pos.setPointPos(p); + m_image->setPosition(p); } QSizeF Image::size() const { - return m_image->m_size.toPoint(); + return m_image->size(); } void Image::setSize(const QSizeF& s) { - m_image->m_size.setPointSize(s); + m_image->setSize(s); } QString Image::resizeMode() const { return m_image->m_resizeMode->value().toString(); } void Image::setResizeMode(const QString &rm) { if (rm == QLatin1String("Stretch")) { m_image->m_resizeMode->setValue(QLatin1String("Stretch")); } else { m_image->m_resizeMode->setValue(QLatin1String("Clip")); } } void Image::setInlineImage(const QByteArray &ba) { m_image->setInlineImageData(ba); } void Image::loadFromFile(const QVariant &pth) { QString str = pth.toString(); m_image->setInlineImageData(QByteArray(), str); } } diff --git a/src/items/label/KReportDesignerItemLabel.cpp b/src/items/label/KReportDesignerItemLabel.cpp index 8584dace..69db4f59 100644 --- a/src/items/label/KReportDesignerItemLabel.cpp +++ b/src/items/label/KReportDesignerItemLabel.cpp @@ -1,223 +1,221 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerItemLabel.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include "KReportDesignerSectionScene.h" #include "KReportLineStyle.h" #include #include #include #include #include #include #include void KReportDesignerItemLabel::init(QGraphicsScene *scene, KReportDesigner *d) { if (scene) scene->addItem(this); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); - connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - setZValue(Z); + setZValue(z()); setFlag(ItemIsFocusable); m_inlineEdit = new BoundedTextItem(this); m_inlineEdit->setVisible(false); m_inlineEdit->setFlag(ItemIsFocusable); m_inlineEdit->setFlag(ItemIsSelectable, false); QTextDocument *doc = new QTextDocument; doc->setDocumentMargin(0); doc->setPlainText(text()); m_inlineEdit->setDocument(doc); connect(m_inlineEdit, SIGNAL(exitEditMode()), this, SLOT(exitInlineEditingMode())); } // methods (constructors) KReportDesignerItemLabel::KReportDesignerItemLabel(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos) - : KReportDesignerItemRectBase(d) + : KReportDesignerItemRectBase(d, this) { Q_UNUSED(pos); init(scene, d); setSceneRect(properRect(*d, getTextRect().width(), getTextRect().height())); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); enterInlineEditingMode(); } KReportDesignerItemLabel::KReportDesignerItemLabel(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) - : KReportItemLabel(element), KReportDesignerItemRectBase(d), m_inlineEdit(0) + : KReportItemLabel(element), KReportDesignerItemRectBase(d, this), m_inlineEdit(0) { init(s, d); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemLabel* KReportDesignerItemLabel::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemLabel(n, designer(), 0); } // methods (deconstructor) KReportDesignerItemLabel::~KReportDesignerItemLabel() {} QRectF KReportDesignerItemLabel::getTextRect() const { return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), m_text->value().toString()); } void KReportDesignerItemLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); if (m_inlineEdit->isVisible()) { return; } // store any values we plan on changing so we can restore them QFont f = painter->font(); QPen p = painter->pen(); painter->setFont(font()); painter->setBackgroundMode(Qt::TransparentMode); QColor bg = m_backgroundColor->value().value(); bg.setAlphaF(m_backgroundOpacity->value().toReal() * 0.01); painter->setPen(m_foregroundColor->value().value()); painter->fillRect(QGraphicsRectItem::rect(), bg); painter->drawText(rect(), textFlags(), text()); if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { painter->setPen(QPen(QColor(224, 224, 224))); } else { painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); } painter->drawRect(QGraphicsRectItem::rect()); painter->setPen(m_foregroundColor->value().value()); drawHandles(painter); // restore an values before we started just in case painter->setFont(f); painter->setPen(p); } void KReportDesignerItemLabel::buildXML(QDomDocument *doc, QDomElement *parent) { //kreportpluginDebug(); QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_text); addPropertyAsAttribute(&entity, m_verticalAlignment); addPropertyAsAttribute(&entity, m_horizontalAlignment); - entity.setAttribute(QLatin1String("report:z-index"), zValue()); + entity.setAttribute(QLatin1String("report:z-index"), z()); // bounding rect - buildXMLRect(doc, &entity, &m_pos, &m_size); + buildXMLRect(doc, &entity, this); //text style info buildXMLTextStyle(doc, &entity, textStyle()); //Line Style buildXMLLineStyle(doc, &entity, lineStyle()); parent->appendChild(entity); } void KReportDesignerItemLabel::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s); if (p.name() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } else if (p.name() == "caption") { m_inlineEdit->setPlainText(p.value().toString()); } KReportDesignerItemRectBase::propertyChanged(s, p); - if (m_reportDesigner) m_reportDesigner->setModified(true); + if (designer()) designer()->setModified(true); } void KReportDesignerItemLabel::enterInlineEditingMode() { if (!m_inlineEdit->isVisible()) { m_inlineEdit->setVisible(true); m_inlineEdit->setPlainText(text()); m_inlineEdit->setFocus(); QTextCursor c = m_inlineEdit->textCursor(); c.select(QTextCursor::Document); m_inlineEdit->setTextCursor(c); m_inlineEdit->setFont(m_font->value().value()); m_inlineEdit->setDefaultTextColor(m_foregroundColor->value().value()); m_inlineEdit->setBackgroudColor(m_backgroundColor->value().value()); m_inlineEdit->setBackgroudOpacity(m_backgroundOpacity->value().toDouble() / 100.0); m_inlineEdit->setForegroundColor(m_foregroundColor->value().value()); m_inlineEdit->setFont(m_font->value().value()); update(); } } void KReportDesignerItemLabel::exitInlineEditingMode() { if (m_inlineEdit->isVisible()) { m_inlineEdit->setVisible(false); setText(m_inlineEdit->toPlainText()); } } void KReportDesignerItemLabel::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { Q_UNUSED(event); enterInlineEditingMode(); } void KReportDesignerItemLabel::keyReleaseEvent(QKeyEvent* event) { if (event->key() == Qt::Key_F2) { enterInlineEditingMode(); } else { QGraphicsRectItem::keyReleaseEvent(event); } } diff --git a/src/items/label/KReportItemLabel.cpp b/src/items/label/KReportItemLabel.cpp index ea85e3cd..335e2867 100644 --- a/src/items/label/KReportItemLabel.cpp +++ b/src/items/label/KReportItemLabel.cpp @@ -1,212 +1,208 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemLabel.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include KReportItemLabel::KReportItemLabel() { createProperties(); } KReportItemLabel::KReportItemLabel(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); + nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_text->setValue(element.toElement().attribute(QLatin1String("report:caption"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + 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(), &m_pos, &m_size); + parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing label element encountered unknow element: " << n; } } } KReportItemLabel::~KReportItemLabel() { - delete m_set; } QString KReportItemLabel::text() const { return m_text->value().toString(); } void KReportItemLabel::setText(const QString& t) { m_text->setValue(t); } void KReportItemLabel::createProperties() { - m_set = new KPropertySet; - m_text = new KProperty("caption", QLatin1String("Label"), tr("Caption")); QStringList keys, strings; keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); - addDefaultProperties(); - m_set->addProperty(m_text); - m_set->addProperty(m_horizontalAlignment); - m_set->addProperty(m_verticalAlignment); - m_set->addProperty(m_font); - m_set->addProperty(m_backgroundColor); - m_set->addProperty(m_foregroundColor); - m_set->addProperty(m_backgroundOpacity); - m_set->addProperty(m_lineWeight); - m_set->addProperty(m_lineColor); - m_set->addProperty(m_lineStyle); + propertySet()->addProperty(m_text); + propertySet()->addProperty(m_horizontalAlignment); + propertySet()->addProperty(m_verticalAlignment); + propertySet()->addProperty(m_font); + propertySet()->addProperty(m_backgroundColor); + propertySet()->addProperty(m_foregroundColor); + propertySet()->addProperty(m_backgroundOpacity); + propertySet()->addProperty(m_lineWeight); + propertySet()->addProperty(m_lineColor); + propertySet()->addProperty(m_lineStyle); } Qt::Alignment KReportItemLabel::textFlags() const { Qt::Alignment align; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) align = Qt::AlignHCenter; else if (t == QLatin1String("right")) align = Qt::AlignRight; else align = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) align |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) align |= Qt::AlignBottom; else align |= Qt::AlignTop; return align; } KRTextStyleData KReportItemLabel::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemLabel::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemLabel::typeName() const { return QLatin1String("label"); } int KReportItemLabel::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(data) Q_UNUSED(script) OROTextBox * tb = new OROTextBox(); - tb->setPosition(m_pos.toScene() + offset); - tb->setSize(m_size.toScene()); + tb->setPosition(scenePosition(position()) + offset); + tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setText(text()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->addPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); - clone->setPosition(m_pos.toScene()); + 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/KReportScriptLabel.cpp b/src/items/label/KReportScriptLabel.cpp index ecb6dc42..a7304344 100644 --- a/src/items/label/KReportScriptLabel.cpp +++ b/src/items/label/KReportScriptLabel.cpp @@ -1,183 +1,183 @@ /* 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 "KReportScriptLabel.h" namespace Scripting { Label::Label(KReportItemLabel *l) { m_label = l; } Label::~Label() { } QString Label::caption() const { return m_label->text(); } void Label::setCaption(const QString& c) { m_label->setText(c); } int Label::horizontalAlignment() const { const QString a = m_label->m_horizontalAlignment->value().toString().toLower(); if (a == QLatin1String("left")) { return -1; } if (a == QLatin1String("center")) { return 0; } if (a == QLatin1String("right")) { return 1; } return -1; } void Label::setHorizonalAlignment(int a) { switch (a) { case -1: m_label->m_horizontalAlignment->setValue(QLatin1String("left")); break; case 0: m_label->m_horizontalAlignment->setValue(QLatin1String("center")); break; case 1: m_label->m_horizontalAlignment->setValue(QLatin1String("right")); break; default: m_label->m_horizontalAlignment->setValue(QLatin1String("left")); break; } } int Label::verticalAlignment() const { const QString a = m_label->m_horizontalAlignment->value().toString().toLower(); if (a == QLatin1String("top")) { return -1; } if (a == QLatin1String("middle")) { return 0; } if (a == QLatin1String("bottom")) { return 1; } return -1; } void Label::setVerticalAlignment(int a) { switch (a) { case -1: m_label->m_verticalAlignment->setValue(QLatin1String("top")); break; case 0: m_label->m_verticalAlignment->setValue(QLatin1String("middle")); break; case 1: m_label->m_verticalAlignment->setValue(QLatin1String("bottom")); break; default: m_label->m_verticalAlignment->setValue(QLatin1String("middle")); break; } } QColor Label::backgroundColor() const { return m_label->m_backgroundColor->value().value(); } void Label::setBackgroundColor(const QColor& c) { m_label->m_backgroundColor->setValue(c); } QColor Label::foregroundColor() const { return m_label->m_foregroundColor->value().value(); } void Label::setForegroundColor(const QColor& c) { m_label->m_foregroundColor->setValue(c); } int Label::backgroundOpacity() const { return m_label->m_backgroundOpacity->value().toInt(); } void Label::setBackgroundOpacity(int o) { m_label->m_backgroundOpacity->setValue(o); } QColor Label::lineColor() const { return m_label->m_lineColor->value().value(); } void Label::setLineColor(const QColor& c) { m_label->m_lineColor->setValue(c); } int Label::lineWeight() const { return m_label->m_lineWeight->value().toInt(); } void Label::setLineWeight(int w) { m_label->m_lineWeight->setValue(w); } int Label::lineStyle() const { return m_label->m_lineStyle->value().toInt(); } void Label::setLineStyle(int s) { if (s < 0 || s > 5) { s = 1; } m_label->m_lineStyle->setValue(s); } QPointF Label::position() const { - return m_label->m_pos.toPoint(); + return m_label->position(); } void Label::setPosition(const QPointF &p) { - m_label->m_pos.setPointPos(p); + m_label->setPosition(p); } QSizeF Label::size() const { - return m_label->m_size.toPoint(); + return m_label->size(); } void Label::setSize(const QSizeF &s) { - m_label->m_size.setPointSize(s); + m_label->setSize(s); } } diff --git a/src/items/text/KReportDesignerItemText.cpp b/src/items/text/KReportDesignerItemText.cpp index c4b7ea0b..bad5e5af 100644 --- a/src/items/text/KReportDesignerItemText.cpp +++ b/src/items/text/KReportDesignerItemText.cpp @@ -1,184 +1,175 @@ /* 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 "KReportDesignerItemText.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include "KReportLineStyle.h" #include #include #include #include #include #include "kreportplugin_debug.h" // // class ReportEntityText // // methods (constructors) void KReportDesignerItemText::init(QGraphicsScene *scene, KReportDesigner *d) { //setFlags(ItemIsSelectable | ItemIsMovable); if (scene) scene->addItem(this); connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); - - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); - setZValue(Z); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); + setZValue(z()); updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("textarea")); } KReportDesignerItemText::KReportDesignerItemText(KReportDesigner * rw, QGraphicsScene * scene, const QPointF &pos) - : KReportDesignerItemRectBase(rw) + : KReportDesignerItemRectBase(rw, this) { Q_UNUSED(pos); init(scene, rw); setSceneRect(properRect(*rw, getTextRect().width(), getTextRect().height())); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemText::KReportDesignerItemText(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) - : KReportItemText(element), KReportDesignerItemRectBase(d) + : KReportItemText(element), KReportDesignerItemRectBase(d, this) { init(s, d); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemText* KReportDesignerItemText::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemText(n, designer(), 0); } KReportDesignerItemText::~KReportDesignerItemText () {} QRect KReportDesignerItemText::getTextRect() const { - return QFontMetrics(font()).boundingRect(int (x()), int (y()), 0, 0, textFlags(), m_renderText); + return QFontMetrics(font()).boundingRect(int (x()), int (y()), 0, 0, textFlags(), renderText()); } void KReportDesignerItemText::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget) // store any values we plan on changing so we can restore them QFont f = painter->font(); QPen p = painter->pen(); painter->setFont(font()); painter->setBackgroundMode(Qt::TransparentMode); QColor bg = m_backgroundColor->value().value(); bg.setAlphaF(m_backgroundOpacity->value().toReal()*0.01); painter->setPen(m_foregroundColor->value().value()); painter->fillRect(rect(), bg); - painter->drawText(rect(), textFlags(), m_renderText); + painter->drawText(rect(), textFlags(), renderText()); if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { painter->setPen(QPen(Qt::lightGray)); } else { painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); } painter->drawRect(rect()); painter->setPen(m_foregroundColor->value().value()); drawHandles(painter); // restore an values before we started just in case painter->setFont(f); painter->setPen(p); } void KReportDesignerItemText::buildXML(QDomDocument *doc, QDomElement *parent) { //kreportpluginDebug(); QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_controlSource); addPropertyAsAttribute(&entity, m_verticalAlignment); addPropertyAsAttribute(&entity, m_horizontalAlignment); entity.setAttribute(QLatin1String("report:bottom-padding"), m_bottomPadding); - entity.setAttribute(QLatin1String("report:z-index"), zValue()); + entity.setAttribute(QLatin1String("report:z-index"), z()); addPropertyAsAttribute(&entity, m_itemValue); // bounding rect - buildXMLRect(doc, &entity, &m_pos, &m_size); + buildXMLRect(doc, &entity, this); //text style info buildXMLTextStyle(doc, &entity, textStyle()); //Line Style buildXMLLineStyle(doc, &entity, lineStyle()); parent->appendChild(entity); } void KReportDesignerItemText::mousePressEvent(QGraphicsSceneMouseEvent * event) { - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } void KReportDesignerItemText::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s); - if (p.name() == "position") { - m_pos.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); - } else if (p.name() == "size") { - m_size.setUnitSize(p.value().toSizeF(), KReportSize::DontUpdateProperty); - } else if (p.name() == "name") { + if (p.name() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } - setSceneRect(m_pos.toScene(), m_size.toScene(), DontUpdateProperty); - if (m_reportDesigner) - m_reportDesigner->setModified(true); - if (scene()) - scene()->update(); + KReportDesignerItemRectBase::propertyChanged(s, p); + if (designer()) designer()->setModified(true); updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("textarea")); } diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp index 8fb04726..64836116 100644 --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -1,319 +1,315 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemText.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include #include #include KReportItemText::KReportItemText() : KReportItemText(QDomNode()) { } KReportItemText::KReportItemText(const QDomNode & element) : m_bottomPadding(0.0) { QDomNodeList nl = element.childNodes(); QString n; QDomNode node; createProperties(); - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); + 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"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + 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(), &m_pos, &m_size); + parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; } } } KReportItemText::~KReportItemText() { - delete m_set; } 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() { - m_set = new KPropertySet; - //connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) ); QStringList keys, strings; //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" ); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); - addDefaultProperties(); - m_set->addProperty(m_controlSource); - m_set->addProperty(m_itemValue); - m_set->addProperty(m_horizontalAlignment); - m_set->addProperty(m_verticalAlignment); - m_set->addProperty(m_font); - m_set->addProperty(m_backgroundColor); - m_set->addProperty(m_foregroundColor); - m_set->addProperty(m_backgroundOpacity); - m_set->addProperty(m_lineWeight); - m_set->addProperty(m_lineColor); - m_set->addProperty(m_lineStyle); + propertySet()->addProperty(m_controlSource); + propertySet()->addProperty(m_itemValue); + propertySet()->addProperty(m_horizontalAlignment); + propertySet()->addProperty(m_verticalAlignment); + propertySet()->addProperty(m_font); + propertySet()->addProperty(m_backgroundColor); + propertySet()->addProperty(m_foregroundColor); + propertySet()->addProperty(m_backgroundOpacity); + propertySet()->addProperty(m_lineWeight); + propertySet()->addProperty(m_lineColor); + propertySet()->addProperty(m_lineStyle); } QString KReportItemText::itemDataSource() const { return m_controlSource->value().toString(); } qreal KReportItemText::bottomPadding() const { return m_bottomPadding; } void KReportItemText::setBottomPadding(qreal bp) { if (m_bottomPadding != bp) { m_bottomPadding = bp; } } KRTextStyleData KReportItemText::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemText::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemText::typeName() const { return QLatin1String("text"); } int KReportItemText::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script); QString qstrValue; QString cs = itemDataSource(); if (!cs.isEmpty()) { if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string qstrValue = cs.mid(1); } else { qstrValue = data.toString(); } } else { qstrValue = m_itemValue->value().toString(); } - - QPointF pos = m_pos.toScene(); - QSizeF size = m_size.toScene(); + + QPointF pos = scenePosition(position()); + QSizeF siz = sceneSize(size()); pos += offset; - QRectF trf(pos, size); + QRectF trf(pos, siz); qreal intStretch = trf.top() - offset.y(); if (qstrValue.length()) { QRectF rect = trf; int pos = 0; QChar separator; QRegExp re(QLatin1String("\\s")); QPrinter prnt(QPrinter::HighResolution); QFontMetrics fm(font(), &prnt); // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; - int intRectWidth = (int)((m_size.toPoint().width() / 72) * prnt.resolution()); + int intRectWidth = (int)((size().width() / 72) * prnt.resolution()); int intLineCounter = 0; qreal intBaseTop = trf.top(); qreal intRectHeight = trf.height(); while (qstrValue.length()) { int idx = re.indexIn(qstrValue, pos); if (idx == -1) { idx = qstrValue.length(); separator = QLatin1Char('\n'); } else separator = qstrValue.at(idx); if (fm.boundingRect(qstrValue.left(idx)).width() < intRectWidth || pos == 0) { pos = idx + 1; if (separator == QLatin1Char('\n')) { QString line = qstrValue.left(idx); qstrValue.remove(0, idx + 1); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->addPrimitive(tb); } if (section) { OROTextBox *tb2 = dynamic_cast(tb->clone()); - tb2->setPosition(m_pos.toPoint()); + tb2->setPosition(scenePosition(position())); section->addPrimitive(tb2); } if (!page) { delete tb; } intStretch += intRectHeight; intLineCounter++; } } else { QString line = qstrValue.left(pos - 1); qstrValue.remove(0, pos); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->addPrimitive(tb); } else { delete tb; } intStretch += intRectHeight; intLineCounter++; } } intStretch += (m_bottomPadding / 100.0); } return intStretch; //Item returns its required section height } diff --git a/src/items/text/KReportScriptText.cpp b/src/items/text/KReportScriptText.cpp index a37f6860..f3a2672b 100644 --- a/src/items/text/KReportScriptText.cpp +++ b/src/items/text/KReportScriptText.cpp @@ -1,205 +1,205 @@ /* 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 "KReportScriptText.h" #include #include #include "kreportplugin_debug.h" namespace Scripting { Text::Text(KReportItemText* t) { m_text = t; } Text::~Text() { } QString Text::source() const { return m_text->itemDataSource(); } void Text::setSource(const QString& s) { m_text->m_controlSource->setValue(s); } int Text::horizontalAlignment() const { const QString a = m_text->m_horizontalAlignment->value().toString().toLower(); if (a == QLatin1String("left")) { return -1; } if (a == QLatin1String("center")) { return 0; } if (a == QLatin1String("right")) { return 1; } return -1; } void Text::setHorizonalAlignment(int a) { switch (a) { case -1: m_text->m_horizontalAlignment->setValue(QLatin1String("left")); break; case 0: m_text->m_horizontalAlignment->setValue(QLatin1String("center")); break; case 1: m_text->m_horizontalAlignment->setValue(QLatin1String("right")); break; default: m_text->m_horizontalAlignment->setValue(QLatin1String("left")); break; } } int Text::verticalAlignment() const { const QString a = m_text->m_horizontalAlignment->value().toString().toLower(); if (a == QLatin1String("top")) { return -1; } if (a == QLatin1String("middle")) { return 0; } if (a == QLatin1String("bottom")) { return 1; } return -1; } void Text::setVerticalAlignment(int a) { switch (a) { case -1: m_text->m_verticalAlignment->setValue(QLatin1String("top")); break; case 0: m_text->m_verticalAlignment->setValue(QLatin1String("middle")); break; case 1: m_text->m_verticalAlignment->setValue(QLatin1String("bottom")); break; default: m_text->m_verticalAlignment->setValue(QLatin1String("middle")); break; } } QColor Text::backgroundColor() const { return m_text->m_backgroundColor->value().value(); } void Text::setBackgroundColor(const QColor& c) { m_text->m_backgroundColor->setValue(QColor(c)); } QColor Text::foregroundColor() const { return m_text->m_foregroundColor->value().value(); } void Text::setForegroundColor(const QColor& c) { m_text->m_foregroundColor->setValue(QColor(c)); } int Text::backgroundOpacity() const { return m_text->m_backgroundOpacity->value().toInt(); } void Text::setBackgroundOpacity(int o) { m_text->m_backgroundOpacity->setValue(o); } QColor Text::lineColor() const { return m_text->m_lineColor->value().value(); } void Text::setLineColor(const QColor& c) { m_text->m_lineColor->setValue(QColor(c)); } int Text::lineWeight() const { return m_text->m_lineWeight->value().toInt(); } void Text::setLineWeight(int w) { m_text->m_lineWeight->setValue(w); } int Text::lineStyle() const { return m_text->m_lineStyle->value().toInt(); } void Text::setLineStyle(int s) { if (s < 0 || s > 5) { s = 1; } m_text->m_lineStyle->setValue(s); } QPointF Text::position() const { - return m_text->m_pos.toPoint(); + return m_text->position(); } void Text::setPosition(const QPointF& p) { - m_text->m_pos.setPointPos(p); + m_text->setPosition(p); } QSizeF Text::size() const { - return m_text->m_size.toPoint(); + return m_text->size(); } void Text::setSize(const QSizeF& s) { - m_text->m_size.setPointSize(s); + m_text->setSize(s); } void Text::loadFromFile(const QString &fn) { QFile file(fn); //kreportpluginDebug() << "Loading from" << fn; if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { m_text->m_controlSource->setValue(tr("$Unable to read %1").arg(fn)); return; } QTextStream in(&file); QString data = in.readAll(); /* while (!in.atEnd()) { QString line = in.readLine(); process_line(line); }*/ m_text->m_controlSource->setValue(QVariant(QLatin1String("$") + data)); } } diff --git a/src/plugins/barcode/KReportDesignerItemBarcode.cpp b/src/plugins/barcode/KReportDesignerItemBarcode.cpp index b91b79b7..5eb25631 100644 --- a/src/plugins/barcode/KReportDesignerItemBarcode.cpp +++ b/src/plugins/barcode/KReportDesignerItemBarcode.cpp @@ -1,174 +1,173 @@ /* 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 "KReportDesignerItemBarcode.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include "barcodepaint.h" #include #include #include #include #include #include #include "kreportplugin_debug.h" void KReportDesignerItemBarcode::init(QGraphicsScene *scene, KReportDesigner *d) { if (scene) scene->addItem(this); - connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), + connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); setMaxLength(5); - setZValue(Z); + setZ(z()); updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString()); } // methods (constructors) KReportDesignerItemBarcode::KReportDesignerItemBarcode(KReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos) - : KReportDesignerItemRectBase(rw) + : KReportDesignerItemRectBase(rw, this) { Q_UNUSED(pos); init(scene, rw); setSceneRect(properRect(*rw, m_minWidthTotal*m_dpiX, m_minHeight*m_dpiY)); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemBarcode::KReportDesignerItemBarcode(const QDomNode & element, KReportDesigner * rw, QGraphicsScene* scene) - : KReportItemBarcode(element), KReportDesignerItemRectBase(rw) + : KReportItemBarcode(element), KReportDesignerItemRectBase(rw, this) { init(scene, rw); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemBarcode* KReportDesignerItemBarcode::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemBarcode(n, designer(), 0); } // methods (deconstructor) KReportDesignerItemBarcode::~KReportDesignerItemBarcode() {} QRect KReportDesignerItemBarcode::getTextRect() { QFont fnt = QFont(); return QFontMetrics(fnt) .boundingRect(int (x()), int (y()), 0, 0, 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("barcode"))); } void KReportDesignerItemBarcode::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); // store any values we plan on changing so we can restore them QPen p = painter->pen(); painter->setBackground(Qt::white); //Draw a border so user knows the object edge painter->setPen(QPen(QColor(224, 224, 224))); painter->drawRect(rect()); drawHandles(painter); QByteArray fmt = m_format->value().toByteArray(); if (fmt == "i2of5") { - renderI2of5(rect().toRect(), m_renderText, alignment(), painter); + renderI2of5(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "3of9") { - render3of9(rect().toRect(), m_renderText, alignment(), painter); + render3of9(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "3of9+") { - renderExtended3of9(rect().toRect(), m_renderText, alignment(), painter); + renderExtended3of9(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "128") { - renderCode128(rect().toRect(), m_renderText, alignment(), painter); + renderCode128(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "upc-a") { - renderCodeUPCA(rect().toRect(), m_renderText, alignment(), painter); + renderCodeUPCA(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "upc-e") { - renderCodeUPCE(rect().toRect(), m_renderText, alignment(), painter); + renderCodeUPCE(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "ean13") { - renderCodeEAN13(rect().toRect(), m_renderText, alignment(), painter); + renderCodeEAN13(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "ean8") { - renderCodeEAN8(rect().toRect(), m_renderText, alignment(), painter); + renderCodeEAN8(rect().toRect(), renderText(), alignment(), painter); } painter->setPen(Qt::black); painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("barcode"))); // restore an values before we started just in case painter->setPen(p); } void KReportDesignerItemBarcode::buildXML(QDomDocument *doc, QDomElement *parent) { //kreportpluginDebug(); QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_controlSource); addPropertyAsAttribute(&entity, m_horizontalAlignment); addPropertyAsAttribute(&entity, m_format); addPropertyAsAttribute(&entity, m_maxLength); entity.setAttribute(QLatin1String("report:z-index"), zValue()); addPropertyAsAttribute(&entity, m_itemValue); // bounding rect - buildXMLRect(doc, &entity, &m_pos, &m_size); + buildXMLRect(doc, &entity, this); parent->appendChild(entity); } void KReportDesignerItemBarcode::slotPropertyChanged(KPropertySet &s, KProperty &p) { if (p.name() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString()); KReportDesignerItemRectBase::propertyChanged(s, p); - if (m_reportDesigner) m_reportDesigner->setModified(true); + if (designer()) designer()->setModified(true); } void KReportDesignerItemBarcode::mousePressEvent(QGraphicsSceneMouseEvent * event) { - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/plugins/barcode/KReportItemBarcode.cpp b/src/plugins/barcode/KReportItemBarcode.cpp index b78390c5..95713a4e 100644 --- a/src/plugins/barcode/KReportItemBarcode.cpp +++ b/src/plugins/barcode/KReportItemBarcode.cpp @@ -1,257 +1,253 @@ /* 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 "KReportItemBarcode.h" #include #include #include #include "kreportplugin_debug.h" #include "barcodes.h" KReportItemBarcode::KReportItemBarcode() : KReportItemBarcode(QDomNode()) { } KReportItemBarcode::KReportItemBarcode(const QDomNode & element) : m_minWidthData(0), m_minWidthTotal(0), m_minHeight(0) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); + 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"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_maxLength->setValue(element.toElement().attribute(QLatin1String("report:barcode-max-length"))); m_format->setValue(element.toElement().attribute(QLatin1String("report:barcode-format"))); - parseReportRect(element.toElement(), &m_pos, &m_size); + parseReportRect(element.toElement()); } void KReportItemBarcode::setMaxLength(int i) { if (i > 0) { if (m_maxLength->value().toInt() != i) { m_maxLength->setValue(i); } if (m_format->value().toString() == QLatin1String("3of9")) { int C = i; // number of characters int N = 2; // narrow mult for wide line int X = 1; // narrow line width int I = 1; // interchange line width m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0; //m_minHeight = m_minWidthData * 0.15; /*if(min_height < 0.25)*/ m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any // of our required quiet zone in conversions } else if (m_format->value().toString() == QLatin1String("3of9+")) { int C = i * 2; // number of characters int N = 2; // narrow mult for wide line int X = 1; // 1px narrow line int I = 1; // 1px narrow line interchange m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0; //m_minHeight = m_minWidthData * 0.15; /*if(min_height < 0.25)*/ m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any // of our required quiet zone in conversions } else if (m_format->value().toString() == QLatin1String("i2of5")) { int C = i * 2; // number of characters int N = 2; // narrow mult for wide line int X = 1; // 1px narrow line m_minWidthTotal = ((C * (2.0*N + 3.0) + 6.0 + N) * X); m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; } else if (m_format->value().toString() == QLatin1String("128")) { int C = i; // assuming 1:1 ratio of data passed in to data actually used in encoding int X = 1; // 1px wide m_minWidthData = (((11 * C) + 35) * X) / 100.0; // assuming CODE A or CODE B //m_minHeight = m_minWidthData * 0.15; /*if(min_height < 0.25)*/ m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; // added a little bugger to make sure we don't loose any // of our required quiet zone in conversions } else if (m_format->value().toString() == QLatin1String("upc-a")) { m_minWidthData = 0.95; m_minWidthTotal = 1.15; m_minHeight = 0.25; } else if (m_format->value().toString() == QLatin1String("upc-e")) { m_minWidthData = 0.52; m_minWidthTotal = 0.70; m_minHeight = 0.25; } else if (m_format->value().toString() == QLatin1String("ean13")) { m_minWidthData = 0.95; m_minWidthTotal = 1.15; m_minHeight = 0.25; } else if (m_format->value().toString() == QLatin1String("ean8")) { m_minWidthData = 0.67; m_minWidthTotal = 0.90; m_minHeight = 0.25; } else { kreportpluginWarning() << "Unknown format encountered: " << m_format->value().toString(); } } } void KReportItemBarcode::createProperties() { - m_set = new KPropertySet; - QStringList keys, strings; 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("3of9") << QLatin1String("3of9+") << QLatin1String("128") << QLatin1String("ean8") << QLatin1String("ean13") << QLatin1String("i2of5") << QLatin1String("upc-a") << QLatin1String("upc-e"); strings << tr("Code 3 of 9", "Barcode symbology, keep short") << tr("Code 3 of 9 Ext.", "3 of 3 Extended: Barcode symbology, keep short") << tr("Code 128", "Barcode symbology, keep short") << tr("EAN-8", "Barcode symbology, keep short") << tr("EAN-13", "Barcode symbology, keep short") << tr("Interleaved 2 of 5", "Interleaved barcode 2 of 5: barcode symbology, keep short") << tr("UPC-A", "Barcode symbology, keep short") << tr("UPC-E", "Barcode symbology, keep short"); m_format = new KProperty("barcode-format", keys, strings, QLatin1String("3of9"), tr("Barcode Format")); m_maxLength = new KProperty("barcode-max-length", 5, tr("Max Length"), tr("Maximum Barcode Length")); - addDefaultProperties(); - m_set->addProperty(m_controlSource); - m_set->addProperty(m_itemValue); - m_set->addProperty(m_format); - m_set->addProperty(m_horizontalAlignment); - m_set->addProperty(m_maxLength); + propertySet()->addProperty(m_controlSource); + propertySet()->addProperty(m_itemValue); + propertySet()->addProperty(m_format); + propertySet()->addProperty(m_horizontalAlignment); + propertySet()->addProperty(m_maxLength); } KReportItemBarcode::~KReportItemBarcode() { - delete m_set; } int KReportItemBarcode::alignment() { QByteArray a = m_horizontalAlignment->value().toByteArray(); if (a == "left") return 0; else if (a == "center") return 1; else if (a == "right") return 2; else return 0; } QString KReportItemBarcode::itemDataSource() const { return m_controlSource->value().toString(); } QString KReportItemBarcode::format() { return m_format->value().toString(); } int KReportItemBarcode::maxLength() { return m_maxLength->value().toInt(); } void KReportItemBarcode::setFormat(const QString& f) { m_format->setValue(f); } void KReportItemBarcode::setAlignment(int) { //! @todo Barcode alignment } //RTTI QString KReportItemBarcode::typeName() const { return QLatin1String("barcode"); } int KReportItemBarcode::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(section); Q_UNUSED(script); - QPointF pos = m_pos.toScene(); - QSizeF size = m_size.toScene(); + QPointF pos = scenePosition(position()); + QSizeF siz = sceneSize(size()); pos += offset; - QRectF rect = QRectF(pos, size); + QRectF rect = QRectF(pos, siz); QString val; if (m_controlSource->value().toString().isEmpty()) { val = m_itemValue->value().toString(); } else { val = data.toString(); } if (page) { QByteArray fmt = m_format->value().toByteArray(); int align = alignment(); if (fmt == "3of9") render3of9(page, rect, val, align); else if (fmt == "3of9+") renderExtended3of9(page, rect, val, align); else if (fmt == "i2of5") renderI2of5(page, rect, val, align); else if (fmt == "128") renderCode128(page, rect, val, align); else if (fmt == "ean13") renderCodeEAN13(page, rect, val, align); else if (fmt == "ean8") renderCodeEAN8(page, rect, val, align); else if (fmt == "upc-a") renderCodeUPCA(page, rect, val, align); else if (fmt == "upc-e") renderCodeUPCE(page, rect, val, align); else { kreportpluginWarning() << "Unknown barcode format:" << fmt; } } return 0; } diff --git a/src/plugins/barcode/KReportScriptBarcode.cpp b/src/plugins/barcode/KReportScriptBarcode.cpp index 4cd93120..2fad24ba 100644 --- a/src/plugins/barcode/KReportScriptBarcode.cpp +++ b/src/plugins/barcode/KReportScriptBarcode.cpp @@ -1,105 +1,105 @@ /* 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 "KReportScriptBarcode.h" #include namespace Scripting { Barcode::Barcode(KReportItemBarcode *b) { m_barcode = b; } Barcode::~Barcode() { } QPointF Barcode::position() { - return m_barcode->m_pos.toPoint(); + return m_barcode->position(); } void Barcode::setPosition(const QPointF& p) { - m_barcode->m_pos.setPointPos(p); + m_barcode->setPosition(p); } QSizeF Barcode::size() { - return m_barcode->m_size.toPoint(); + return m_barcode->size(); } void Barcode::setSize(const QSizeF& s) { - m_barcode->m_size.setPointSize(s); + m_barcode->setSize(s); } int Barcode::horizontalAlignment() { const QString a = m_barcode->m_horizontalAlignment->value().toString().toLower(); if (a == QLatin1String("left")) { return -1; } if (a == QLatin1String("center")) { return 0; } if (a == QLatin1String("right")) { return 1; } return -1; } void Barcode::setHorizonalAlignment(int a) { switch (a) { case -1: m_barcode->m_horizontalAlignment->setValue(QLatin1String("left")); break; case 0: m_barcode->m_horizontalAlignment->setValue(QLatin1String("center")); break; case 1: m_barcode->m_horizontalAlignment->setValue(QLatin1String("right")); break; default: m_barcode->m_horizontalAlignment->setValue(QLatin1String("left")); break; } } QString Barcode::source() { return m_barcode->m_controlSource->value().toString(); } void Barcode::setSource(const QString& s) { m_barcode->m_controlSource->setValue(s); } QString Barcode::format() { return m_barcode->m_format->value().toString(); } void Barcode::setFormat(const QString& s) { m_barcode->m_format->setValue(s); } } diff --git a/src/plugins/maps/KReportDesignerItemMaps.cpp b/src/plugins/maps/KReportDesignerItemMaps.cpp index 3c80e091..f516f844 100644 --- a/src/plugins/maps/KReportDesignerItemMaps.cpp +++ b/src/plugins/maps/KReportDesignerItemMaps.cpp @@ -1,135 +1,133 @@ /* * Copyright (C) 2007-2016 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 2011-2015 by Radoslaw Wicik (radoslaw@wicik.pl) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerItemMaps.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include #include #include #include #include #include #include "kreportplugin_debug.h" void KReportDesignerItemMaps::init(QGraphicsScene *scene, KReportDesigner *d) { if (scene) scene->addItem(this); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); - - connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), + connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); - setZValue(Z); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); + setZValue(z()); } KReportDesignerItemMaps::KReportDesignerItemMaps(KReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos) - : KReportDesignerItemRectBase(rw) + : KReportDesignerItemRectBase(rw, this) { Q_UNUSED(pos); init(scene, rw); setSceneRect(properRect(*rw, KREPORT_ITEM_RECT_DEFAULT_WIDTH, KREPORT_ITEM_RECT_DEFAULT_WIDTH)); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemMaps::KReportDesignerItemMaps(const QDomNode &element, KReportDesigner * rw, QGraphicsScene* scene) - : KReportItemMaps(element), KReportDesignerItemRectBase(rw) + : KReportItemMaps(element), KReportDesignerItemRectBase(rw, this) { init(scene, rw); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemMaps* KReportDesignerItemMaps::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemMaps(n, designer(), 0); } KReportDesignerItemMaps::~KReportDesignerItemMaps() { // do we need to clean anything up? } void KReportDesignerItemMaps::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); // store any values we plan on changing so we can restore them QPen p = painter->pen(); painter->fillRect(rect(), QColor(0xc2, 0xfc, 0xc7));//C2FCC7 //Draw a border so user knows the object edge painter->setPen(QPen(QColor(224, 224, 224))); painter->drawRect(rect()); painter->setPen(Qt::black); painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("map"))); drawHandles(painter); // restore an values before we started just in case painter->setPen(p); } void KReportDesignerItemMaps::buildXML(QDomDocument *doc, QDomElement *parent) { QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_controlSource); addPropertyAsAttribute(&entity, m_latitudeProperty); addPropertyAsAttribute(&entity, m_longitudeProperty); addPropertyAsAttribute(&entity, m_zoomProperty); addPropertyAsAttribute(&entity, m_themeProperty); //addPropertyAsAttribute(&entity, m_resizeMode); - entity.setAttribute(QLatin1String("report:z-index"), zValue()); - buildXMLRect(doc, &entity, &m_pos, &m_size); + entity.setAttribute(QLatin1String("report:z-index"), z()); + buildXMLRect(doc, &entity, this); parent->appendChild(entity); } void KReportDesignerItemMaps::slotPropertyChanged(KPropertySet &s, KProperty &p) { //kreportpluginDebug() << p.name() << ":" << p.value(); if (p.name().toLower() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } KReportDesignerItemRectBase::propertyChanged(s, p); - if (m_reportDesigner) m_reportDesigner->setModified(true); + if (designer()) designer()->setModified(true); } void KReportDesignerItemMaps::mousePressEvent(QGraphicsSceneMouseEvent * event) { - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/plugins/maps/KReportItemMaps.cpp b/src/plugins/maps/KReportItemMaps.cpp index b39ce4a9..6c540a3a 100644 --- a/src/plugins/maps/KReportItemMaps.cpp +++ b/src/plugins/maps/KReportItemMaps.cpp @@ -1,237 +1,228 @@ /* * Copyright (C) 2007-2016 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 2011-2015 by Radoslaw Wicik (radoslaw@wicik.pl) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemMaps.h" #include #include #include #include #define myDebug() if (0) kDebug(44021) //! @todo replace with ReportItemMaps(const QDomNode &element = QDomNode()) KReportItemMaps::KReportItemMaps() : KReportItemMaps(QDomNode()) { } KReportItemMaps::KReportItemMaps(const QDomNode &element) : m_longtitude(0) , m_latitude(0) , m_zoom(1200) , m_pageId(0) , m_sectionId(0) , m_oroPicture(0) , m_longDataSetFromScript(false) , m_latDataSetFromScript(false) , m_zoomDataSetFromScript(false) { createProperties(); - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); + nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); + setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_latitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:latitude")).toDouble()); m_longitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:longitude")).toDouble()); m_zoomProperty->setValue(element.toElement().attribute(QLatin1String("report:zoom")).toInt()); QString themeId(element.toElement().attribute(QLatin1String("report:theme"))); themeId = themeId.isEmpty() ? m_themeManager.mapThemeIds()[0] : themeId; m_themeProperty->setValue(themeId); - parseReportRect(element.toElement(), &m_pos, &m_size); + parseReportRect(element.toElement()); } KReportItemMaps::~KReportItemMaps() { - delete m_set; } void KReportItemMaps::createProperties() { - m_set = new KPropertySet; - m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_latitudeProperty = new KProperty("latitude", 0.0, tr("Latitude"), tr("Latitude"), KProperty::Double); m_latitudeProperty->setOption("min", -90); m_latitudeProperty->setOption("max", 90); m_latitudeProperty->setOption("unit", QString::fromUtf8("°")); m_latitudeProperty->setOption("precision", 7); m_longitudeProperty = new KProperty("longitude", 0.0, tr("Longitude"), tr("Longitude"), KProperty::Double); m_longitudeProperty->setOption("min", -180); m_longitudeProperty->setOption("max", 180); m_longitudeProperty->setOption("unit", QString::fromUtf8("°")); m_longitudeProperty->setOption("precision", 7); m_zoomProperty = new KProperty("zoom", 1000, tr("Zoom"), tr("Zoom") ); m_zoomProperty->setOption("min", 0); m_zoomProperty->setOption("max", 4000); m_zoomProperty->setOption("step", 100); m_zoomProperty->setOption("slider", true); QStringList mapThemIds(m_themeManager.mapThemeIds()); m_themeProperty = new KProperty("theme", mapThemIds, mapThemIds, mapThemIds[1]); if (mapThemIds.contains(QLatin1String("earth/srtm/srtm.dgml"))) { m_themeProperty->setValue(QLatin1String("earth/srtm/srtm.dgml"), false); } - addDefaultProperties(); - m_set->addProperty(m_controlSource); - m_set->addProperty(m_latitudeProperty); - m_set->addProperty(m_longitudeProperty); - m_set->addProperty(m_zoomProperty); - m_set->addProperty(m_themeProperty); + propertySet()->addProperty(m_controlSource); + propertySet()->addProperty(m_latitudeProperty); + propertySet()->addProperty(m_longitudeProperty); + propertySet()->addProperty(m_zoomProperty); + propertySet()->addProperty(m_themeProperty); } void KReportItemMaps::setColumn(const QString &c) { m_controlSource->setValue(c); } QString KReportItemMaps::itemDataSource() const { return m_controlSource->value().toString(); } QString KReportItemMaps::typeName() const { return QLatin1String("maps"); } int KReportItemMaps::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) deserializeData(data); m_pageId = page; m_sectionId = section; m_offset = offset; m_oroPicture = new OROPicture(); - m_oroPicture->setPosition(m_pos.toScene() + m_offset); - m_oroPicture->setSize(m_size.toScene()); + m_oroPicture->setPosition(scenePosition(position()) + m_offset); + m_oroPicture->setSize(sceneSize(size())); if (m_pageId) { m_pageId->addPrimitive(m_oroPicture); } if (m_sectionId) { OROPicture *i2 = dynamic_cast(m_oroPicture->clone()); if (i2) { - i2->setPosition(m_pos.toPoint()); + i2->setPosition(scenePosition(position())); } } m_mapRenderer.renderJob(this); return 0; //Item doesn't stretch the section height } void KReportItemMaps::deserializeData(const QVariant& serialized) { //kreportpluginDebug() << "Map data for this record is" << serialized; QStringList dataList = serialized.toString().split(QLatin1Char(';')); if (dataList.size() == 3) { m_latitude = dataList[0].toDouble(); m_longtitude = dataList[1].toDouble(); m_zoom = dataList[2].toInt(); } else { m_latitude = m_latitudeProperty->value().toReal(); m_longtitude = m_longitudeProperty->value().toReal(); m_zoom = m_zoomProperty->value().toInt(); } } void KReportItemMaps::renderFinished() { emit finishedRendering(); } OROPicture* KReportItemMaps::oroImage() { return m_oroPicture; } qreal KReportItemMaps::longtitude() const { return m_longtitude; } qreal KReportItemMaps::latitude() const { return m_latitude; } int KReportItemMaps::zoom() const { return m_zoom; } -QSize KReportItemMaps::size() const -{ - return m_size.toScene().toSize(); -} - QString KReportItemMaps::themeId() const { return m_themeProperty->value().toString(); } QVariant KReportItemMaps::realItemData(const QVariant& itemData) const { double lat, lon; int zoom; QStringList dataList = itemData.toString().split(QLatin1Char(';')); if (dataList.size() == 3) { lat = dataList[0].toDouble(); lon = dataList[1].toDouble(); zoom = dataList[2].toInt(); } else if (dataList.size() == 2) { lat = dataList[0].toDouble(); lon = dataList[1].toDouble(); zoom = m_zoomProperty->value().toInt(); } else { lat = m_latitudeProperty->value().toReal(); lon = m_longitudeProperty->value().toReal(); zoom = m_zoomProperty->value().toInt(); } if (m_longDataSetFromScript) { lon = m_longtitude; } if (m_latDataSetFromScript) { lat = m_latitude; } if (m_zoomDataSetFromScript) { zoom = m_zoom; } return QString(QLatin1String("%1;%2;%3")).arg(lat).arg(lon).arg(zoom); } diff --git a/src/plugins/maps/KReportItemMaps.h b/src/plugins/maps/KReportItemMaps.h index 7aa831fc..bf303a2a 100644 --- a/src/plugins/maps/KReportItemMaps.h +++ b/src/plugins/maps/KReportItemMaps.h @@ -1,99 +1,98 @@ /* * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 2011-2015 by Radoslaw Wicik (radoslaw@wicik.pl) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTITEMMAPS_H #define KREPORTITEMMAPS_H #include "KReportAsyncItemBase.h" #include #include #include #include "KReportPosition.h" #include "KReportSize.h" #include "KReportMapRenderer.h" #include class OROImage; class OROPicture; class OROPage; class OROSection; namespace Scripting { class Maps; } class KReportItemMaps : public KReportAsyncItemBase { Q_OBJECT public: KReportItemMaps(); explicit KReportItemMaps(const QDomNode &element); virtual ~KReportItemMaps(); virtual QString typeName() const; virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script); virtual QString itemDataSource() const; virtual QVariant realItemData(const QVariant &itemData) const; void renderFinished(); qreal longtitude() const; qreal latitude() const; int zoom() const; QString themeId() const; - QSize size() const; OROPicture* oroImage(); protected: KProperty* m_controlSource; KProperty* m_latitudeProperty; KProperty* m_longitudeProperty; KProperty* m_zoomProperty; KProperty* m_themeProperty; void setColumn(const QString&); qreal m_longtitude; qreal m_latitude; int m_zoom; OROPage *m_pageId; OROSection *m_sectionId; QPointF m_offset; OROPicture * m_oroPicture; KReportMapRenderer m_mapRenderer; Marble::MapThemeManager m_themeManager; private: virtual void createProperties(); void deserializeData(const QVariant& serialized); bool m_longDataSetFromScript; bool m_latDataSetFromScript; bool m_zoomDataSetFromScript; friend class Scripting::Maps; }; #endif diff --git a/src/plugins/maps/KReportMapRenderer.cpp b/src/plugins/maps/KReportMapRenderer.cpp index 15cfc028..10b75a18 100644 --- a/src/plugins/maps/KReportMapRenderer.cpp +++ b/src/plugins/maps/KReportMapRenderer.cpp @@ -1,125 +1,125 @@ /* * Copyright (C) 2015 Radosław Wicik * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "KReportMapRenderer.h" #include "KReportItemMaps.h" #include #include #include #include #include #include #include #include "kreportplugin_debug.h" KReportMapRenderer::KReportMapRenderer(QObject* parent) : QObject(parent) , m_currentJob(0) { m_marble.setMapThemeId(QLatin1String("earth/openstreetmap/openstreetmap.dgml")); m_marble.setShowOverviewMap(false); m_marble.setMapQualityForViewContext(Marble::PrintQuality, Marble::Still); m_marble.setShowCrosshairs(true); foreach(Marble::AbstractFloatItem* floatItem, m_marble.floatItems()){ if(floatItem->nameId() == QString(QLatin1String("navigation"))){ floatItem->setVisible(false); } } connect(m_marble.model()->downloadManager(), &Marble::HttpDownloadManager::progressChanged, this, &KReportMapRenderer::downloadProgres); connect(&m_marble, &Marble::MarbleMap::renderStatusChanged, this, &KReportMapRenderer::onRenderStatusChange); connect(&m_retryTimer, &QTimer::timeout, this, &KReportMapRenderer::retryRender); } KReportMapRenderer::~KReportMapRenderer() { } void KReportMapRenderer::renderJob(KReportItemMaps* reportItemMaps) { m_currentJob = reportItemMaps; int zoom = m_currentJob->zoom(); //kreportpluginDebug() << "Map Renderer rendering" << m_currentJob->longtitude() << m_currentJob->latitude(); m_marble.setMapThemeId(m_currentJob->themeId()); //some themes enable overview map, and this must be disabled after theme switch. m_marble.setShowOverviewMap(false); - m_marble.setSize(m_currentJob->size()); + m_marble.setSize(KReportItemBase::sceneSize(m_currentJob->size()).toSize()); m_marble.centerOn(m_currentJob->longtitude(), m_currentJob->latitude()); m_marble.setRadius(pow(M_E, (zoom / 200.0))); // Create a painter that will do the painting. Marble::GeoPainter geoPainter( m_currentJob->oroImage()->picture(), m_marble.viewport(), m_marble.mapQuality() ); m_marble.paint( geoPainter, QRect() ); if (m_marble.renderStatus() == Marble::Complete) { m_currentJob->renderFinished(); } else { m_retryTimer.start(1000); } } void KReportMapRenderer::onRenderStatusChange(Marble::RenderStatus renderStatus) { //kreportpluginDebug() << m_marble.renderStatus() << "|" << renderStatus; if(m_currentJob){ /*kreportpluginDebug() << this << m_currentJob << m_currentJob->longtitude() << m_currentJob->latitude() << m_currentJob->zoom() << " | status: " << renderStatus;*/ if(renderStatus == Marble::Complete){ m_currentJob->renderFinished(); } } } void KReportMapRenderer::downloadProgres(int active, int queued) { Q_UNUSED(active) Q_UNUSED(queued) //if(m_currentJob){ // kreportpluginDebug() << "job:" << m_currentJob // << "(" << m_currentJob->latitude() << "," << m_currentJob->longtitude() << ")" // << "active/queued:" << active << "/" << queued; //} } void KReportMapRenderer::retryRender() { //kreportpluginDebug() << "Retrying map render"; // Create a painter that will do the painting. Marble::GeoPainter geoPainter( m_currentJob->oroImage()->picture(), m_marble.viewport(), m_marble.mapQuality() ); m_marble.paint( geoPainter, QRect() ); if (m_marble.renderStatus() == Marble::Complete) { m_retryTimer.stop(); m_currentJob->renderFinished(); } } diff --git a/src/plugins/maps/KReportScriptMaps.cpp b/src/plugins/maps/KReportScriptMaps.cpp index b5873b70..2391a314 100644 --- a/src/plugins/maps/KReportScriptMaps.cpp +++ b/src/plugins/maps/KReportScriptMaps.cpp @@ -1,74 +1,74 @@ /* * Copyright (C) 2007-2016 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 "KReportScriptMaps.h" #include "KReportItemMaps.h" namespace Scripting { Maps::Maps(KReportItemMaps *i) { m_map = i; m_map->m_latDataSetFromScript = false; m_map->m_longDataSetFromScript = false; m_map->m_zoomDataSetFromScript = false; } Maps::~Maps() { } QPointF Maps::position() const { - return m_map->m_pos.toPoint(); + return m_map->position(); } void Maps::setPosition(const QPointF& p) { - m_map->m_pos.setPointPos(p); + m_map->setPosition(p); } QSizeF Maps::size() const { - return m_map->m_size.toPoint(); + return m_map->size(); } void Maps::setSize(const QSizeF& s) { - m_map->m_size.setPointSize(s); + m_map->setSize(s); } void Maps::setLatitude(qreal latitude) { m_map->m_latitude = latitude; m_map->m_latDataSetFromScript = true; } void Maps::setLongitude(qreal longitude) { m_map->m_longtitude = longitude; m_map->m_longDataSetFromScript = true; } void Maps::setZoom(int zoom) { m_map->m_zoom = zoom; m_map->m_zoomDataSetFromScript = true; } } diff --git a/src/plugins/web/KReportDesignerItemWeb.cpp b/src/plugins/web/KReportDesignerItemWeb.cpp index 31d3c2d7..9c668f7e 100644 --- a/src/plugins/web/KReportDesignerItemWeb.cpp +++ b/src/plugins/web/KReportDesignerItemWeb.cpp @@ -1,125 +1,124 @@ /* This file is part of the KDE project Copyright Shreya Pandit Copyright 2011 Adam Pigg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KReportDesignerItemWeb.h" #include #include #include #include #include #include #include #include #include "kreportplugin_debug.h" -void KReportDesignerItemWeb::init(QGraphicsScene *scene, KReportDesigner *d) //done,compared,add function if necessary +void KReportDesignerItemWeb::init(QGraphicsScene *scene, KReportDesigner *d) { if (scene) scene->addItem(this); - connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); - setZValue(Z); + connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); + + setZValue(z()); } KReportDesignerItemWeb::KReportDesignerItemWeb(KReportDesigner *rw, QGraphicsScene *scene, - const QPointF &pos) //done,compared - : KReportDesignerItemRectBase(rw) + const QPointF &pos) : KReportDesignerItemRectBase(rw, this) { Q_UNUSED(pos); init(scene, rw); setSceneRect(properRect(*rw, KREPORT_ITEM_RECT_DEFAULT_WIDTH, KREPORT_ITEM_RECT_DEFAULT_WIDTH)); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemWeb::KReportDesignerItemWeb(const QDomNode &element, KReportDesigner *rw, - QGraphicsScene *scene) //done,compared - : KReportItemWeb(element), KReportDesignerItemRectBase(rw) + QGraphicsScene *scene) + : KReportItemWeb(element), KReportDesignerItemRectBase(rw, this) { init(scene, rw); - setSceneRect(m_pos.toScene(), m_size.toScene()); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } -KReportDesignerItemWeb *KReportDesignerItemWeb::clone() //done,compared +KReportDesignerItemWeb *KReportDesignerItemWeb::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemWeb(n, designer(), 0); } KReportDesignerItemWeb::~KReportDesignerItemWeb() //done,compared { // do we need to clean anything up? } void KReportDesignerItemWeb::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->drawRect(QGraphicsRectItem::rect()); painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("web-view"))); painter->setBackgroundMode(Qt::TransparentMode); drawHandles(painter); } void KReportDesignerItemWeb::buildXML(QDomDocument *doc, QDomElement *parent) { Q_UNUSED(doc); Q_UNUSED(parent); QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties addPropertyAsAttribute(&entity, m_controlSource); - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); entity.setAttribute(QLatin1String("report:z-index"), zValue()); - buildXMLRect(doc, &entity, &m_pos, &m_size); + buildXMLRect(doc, &entity, this); parent->appendChild(entity); } void KReportDesignerItemWeb::slotPropertyChanged(KPropertySet &s, KProperty &p) { if (p.name() == "name") { - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } KReportDesignerItemRectBase::propertyChanged(s, p); - if (m_reportDesigner) { - m_reportDesigner->setModified(true); + if (designer()) { + designer()->setModified(true); } } void KReportDesignerItemWeb::mousePressEvent(QGraphicsSceneMouseEvent *event) { - m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); + m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/plugins/web/KReportItemWeb.cpp b/src/plugins/web/KReportItemWeb.cpp index a6e20892..8264d5ef 100644 --- a/src/plugins/web/KReportItemWeb.cpp +++ b/src/plugins/web/KReportItemWeb.cpp @@ -1,146 +1,144 @@ /* This file is part of the KDE project Copyright Shreya Pandit Copyright 2011 Adam Pigg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KReportItemWeb.h" #include #include #include #include #include #include #include #include #include "kreportplugin_debug.h" KReportItemWeb::KReportItemWeb(): m_rendering(false) { createProperties(); init(); } KReportItemWeb::KReportItemWeb(const QDomNode &element) { createProperties(); init(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; QDomElement e = element.toElement(); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); - m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); - Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); - parseReportRect(element.toElement(), &m_pos, &m_size); + nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); + setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); + parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); } } void KReportItemWeb::init() { m_webPage = new QWebPage(); connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); } void KReportItemWeb::createProperties() { - m_set = new KPropertySet; - m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); - m_set->addProperty(m_controlSource); - addDefaultProperties(); + propertySet()->addProperty(m_controlSource); } KReportItemWeb::~KReportItemWeb() { - delete m_set; } + QString KReportItemWeb::typeName() const { return QLatin1String("web"); } void KReportItemWeb::loadFinished(bool) { //kreportpluginDebug() << m_rendering; if (m_rendering) { OROPicture * pic = new OROPicture(); - m_webPage->setViewportSize(m_size.toScene().toSize()); + m_webPage->setViewportSize(sceneSize(size()).toSize()); m_webPage->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); m_webPage->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); QPainter p(pic->picture()); m_webPage->mainFrame()->render(&p); - QPointF pos = m_pos.toScene(); - QSizeF size = m_size.toScene(); + QPointF pos = scenePosition(position()); + QSizeF siz = sceneSize(size()); pos += m_targetOffset; pic->setPosition(pos); - pic->setSize(size); + pic->setSize(siz); if (m_targetPage) m_targetPage->addPrimitive(pic, false, true); OROPicture *p2 = dynamic_cast(pic->clone()); if (p2) { - p2->setPosition(m_pos.toPoint()); + p2->setPosition(scenePosition(position())); if (m_targetSection) { m_targetSection->addPrimitive(p2); } } + m_rendering = false; emit(finishedRendering()); } } int KReportItemWeb::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script); m_rendering = true; //kreportpluginDebug() << data; m_targetPage = page; m_targetSection = section; m_targetOffset = offset; QUrl url = QUrl::fromUserInput(data.toString()); if (url.isValid()) { m_webPage->mainFrame()->load(url); } else { m_webPage->mainFrame()->setHtml(data.toString()); } return 0; //Item doesn't stretch the section height } QString KReportItemWeb::itemDataSource() const { return m_controlSource->value().toString(); } diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp index d469656f..5885e8a3 100644 --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -1,1552 +1,1553 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC * Copyright (C) 2007-2010 by Adam Pigg * Copyright (C) 2011 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 "KReportDesigner.h" #include "KReportDesignerSection.h" #include "KReportDesignerSectionScene.h" #include "KReportDesignerSectionView.h" #include "KReportDesignerSectionDetailGroup.h" #include "KReportPropertiesButton.h" #include "KReportSectionEditor.h" #include "KReportDesignerSectionDetail.h" #include "KReportDesignerItemLine.h" #include "KReportRuler_p.h" #include "KReportZoomHandler.h" #include "KReportPageSize.h" #include "KReportDpi.h" #include "KReportUtils.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportSection.h" #include "KReportPluginMetaData.h" #include "kreport_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include //! Also add public method for runtime? const char ns[] = "http://kexi-project.org/report/2.0"; static QDomElement propertyToElement(QDomDocument* d, KProperty* p) { QDomElement e = d->createElement(QLatin1String("report:" + p->name().toLower())); e.appendChild(d->createTextNode(p->value().toString())); return e; } // // define and implement the ReportWriterSectionData class // a simple class to hold/hide data in the ReportHandler class // class ReportWriterSectionData { public: ReportWriterSectionData() { selected_x_offset = 0; selected_y_offset = 0; mouseAction = ReportWriterSectionData::MA_None; } virtual ~ReportWriterSectionData() { } enum MouseAction { MA_None = 0, MA_Insert = 1, MA_Grab = 2, MA_MoveStartPoint, MA_MoveEndPoint, MA_ResizeNW = 8, MA_ResizeN, MA_ResizeNE, MA_ResizeE, MA_ResizeSE, MA_ResizeS, MA_ResizeSW, MA_ResizeW }; int selected_x_offset; int selected_y_offset; MouseAction mouseAction; QString insertItem; QList copy_list; QList cut_list; }; //! @internal class Q_DECL_HIDDEN KReportDesigner::Private { public: Private() : activeScene(0) , reportHeader(0) , pageHeaderFirst(0) , pageHeaderOdd(0) , pageHeaderEven(0) , pageHeaderLast(0) , pageHeaderAny(0) , pageFooterFirst(0) , pageFooterOdd(0) , pageFooterEven(0) , pageFooterLast(0) , pageFooterAny(0) , reportFooter(0) , detail(0) , pressX(-1) , pressY(-1) , releaseX(-1) , releaseY(-1) , modified(false) , kordata(0) {} ~Private() { delete zoom; delete sectionData; delete set; delete kordata; } QGridLayout *grid; KReportRuler *hruler; KReportZoomHandler *zoom; QVBoxLayout *vboxlayout; KReportPropertiesButton *pageButton; QGraphicsScene *activeScene; ReportWriterSectionData *sectionData; KReportDesignerSection *reportHeader; KReportDesignerSection *pageHeaderFirst; KReportDesignerSection *pageHeaderOdd; KReportDesignerSection *pageHeaderEven; KReportDesignerSection *pageHeaderLast; KReportDesignerSection *pageHeaderAny; KReportDesignerSection *pageFooterFirst; KReportDesignerSection *pageFooterOdd; KReportDesignerSection *pageFooterEven; KReportDesignerSection *pageFooterLast; KReportDesignerSection *pageFooterAny; KReportDesignerSection *reportFooter; KReportDesignerSectionDetail *detail; //Properties KPropertySet *set; KPropertySet *itmset; KProperty *title; KProperty *pageSize; KProperty *orientation; KProperty *unit; KProperty *customHeight; KProperty *customWidth; KProperty *leftMargin; KProperty *rightMargin; KProperty *topMargin; KProperty *bottomMargin; KProperty *showGrid; KProperty *gridDivisions; KProperty *gridSnap; KProperty *labelType; #ifdef KREPORT_SCRIPTING KProperty *script; #endif //Actions QAction *editCutAction; QAction *editCopyAction; QAction *editPasteAction; QAction *editDeleteAction; QAction *sectionEdit; QAction *parameterEdit; QAction *itemRaiseAction; QAction *itemLowerAction; qreal pressX; qreal pressY; qreal releaseX; qreal releaseY; bool modified; // true if this document has been modified, false otherwise QString originalInterpreter; //Value of the script interpreter at load time QString originalScript; //Value of the script at load time KReportData *kordata; }; KReportDesigner::KReportDesigner(QWidget * parent) : QWidget(parent), d(new Private()) { init(); } void KReportDesigner::init() { KReportPluginManager::self(); // this loads icons early enough d->sectionData = new ReportWriterSectionData(); createProperties(); createActions(); d->grid = new QGridLayout(this); d->grid->setSpacing(0); d->grid->setMargin(0); d->grid->setColumnStretch(1, 1); d->grid->setRowStretch(1, 1); d->grid->setSizeConstraint(QLayout::SetFixedSize); d->vboxlayout = new QVBoxLayout(); d->vboxlayout->setSpacing(0); d->vboxlayout->setMargin(0); d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); //Create nice rulers d->zoom = new KReportZoomHandler(); d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoom); d->pageButton = new KReportPropertiesButton(this); d->hruler->setUnit(KReportUnit(KReportUnit::Centimeter)); d->grid->addWidget(d->pageButton, 0, 0); d->grid->addWidget(d->hruler, 0, 1); d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); d->pageButton->setMaximumSize(QSize(19, 22)); d->pageButton->setMinimumSize(QSize(19, 22)); d->detail = new KReportDesignerSectionDetail(this); d->vboxlayout->insertWidget(0, d->detail); setLayout(d->grid); connect(d->pageButton, SIGNAL(released()), this, SLOT(slotPageButton_Pressed())); emit pagePropertyChanged(*d->set); connect(d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); changeSet(d->set); } KReportDesigner::~KReportDesigner() { delete d; } ///The loading Code KReportDesigner::KReportDesigner(QWidget *parent, const QDomElement &data) : QWidget(parent), d(new Private()) { init(); if (data.tagName() != QLatin1String("report:content")) { // arg we got an xml file but not one i know of kreportWarning() << "root element was not "; } //kreportDebug() << data.text(); deleteDetail(); QDomNodeList nlist = data.childNodes(); QDomNode it; for (int i = 0; i < nlist.count(); ++i) { it = nlist.item(i); // at this level all the children we get should be Elements if (it.isElement()) { QString n = it.nodeName().toLower(); //kreportDebug() << n; if (n == QLatin1String("report:title")) { setReportTitle(it.firstChild().nodeValue()); #ifdef KREPORT_SCRIPTING } else if (n == QLatin1String("report:script")) { d->originalInterpreter = it.toElement().attribute(QLatin1String("report:script-interpreter")); d->originalScript = it.firstChild().nodeValue(); d->script->setValue(d->originalScript); if (d->originalInterpreter != QLatin1String("javascript") && d->originalInterpreter != QLatin1String("qtscript")) { QString msg = tr("This report contains scripts of type \"%1\". " "Only scripts written in JavaScript language are " "supported. To prevent losing the scripts, their type " "and content will not be changed unless you change these scripts." ).arg(d->originalInterpreter); QMessageBox::warning(this, tr("Unsupported Script Type"), msg); } #endif } else if (n == QLatin1String("report:grid")) { d->showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); d->gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); d->gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); d->unit->setValue(it.toElement().attribute(QLatin1String("report:page-unit"), QLatin1String("cm"))); } //! @todo Load page options else if (n == QLatin1String("report:page-style")) { QString pagetype = it.firstChild().nodeValue(); if (pagetype == QLatin1String("predefined")) { d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); } else if (pagetype == QLatin1String("custom")) { d->pageSize->setValue(QLatin1String("custom")); d->customHeight->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String("")))); d->customWidth->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-widtht"), QLatin1String("")))); } else if (pagetype == QLatin1String("label")) { //! @todo } d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); d->orientation->setValue(it.toElement().attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait"))); } else if (n == QLatin1String("report:body")) { QDomNodeList sectionlist = it.childNodes(); QDomNode sec; for (int s = 0; s < sectionlist.count(); ++s) { sec = sectionlist.item(s); if (sec.isElement()) { QString sn = sec.nodeName().toLower(); //kreportDebug() << sn; if (sn == QLatin1String("report:section")) { QString sectiontype = sec.toElement().attribute(QLatin1String("report:section-type")); if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == 0) { insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); } } else if (sn == QLatin1String("report:detail")) { KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); rsd->initFromXML(&sec); setDetail(rsd); } } else { kreportWarning() << "Encountered an unknown Element: " << n; } } } } else { kreportWarning() << "Encountered a child node of root that is not an Element"; } } this->slotPageButton_Pressed(); emit reportDataChanged(); slotPropertyChanged(*d->set, *d->unit); // set unit for all items setModified(false); } ///The saving code QDomElement KReportDesigner::document() const { QDomDocument doc; QString saveInterpreter; QDomElement content = doc.createElement(QLatin1String("report:content")); content.setAttribute(QLatin1String("xmlns:report"), QLatin1String(ns)); content.setAttribute(QLatin1String("xmlns:fo"), QLatin1String("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")); content.setAttribute(QLatin1String("xmlns:svg"), QLatin1String("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")); doc.appendChild(content); //title content.appendChild(propertyToElement(&doc, d->title)); #ifdef KREPORT_SCRIPTING if (!d->script->value().toString().isEmpty()) { if (d->script->value().toString() != d->originalScript || d->originalInterpreter == QLatin1String("qtscript")) { //The script has changed so force interpreter to 'javascript'. Also set if was using qtscript saveInterpreter = QLatin1String("javascript"); } else { saveInterpreter = d->originalInterpreter; } QDomElement scr = propertyToElement(&doc, d->script); scr.setAttribute(QLatin1String("report:script-interpreter"), saveInterpreter); content.appendChild(scr); } #endif QDomElement grd = doc.createElement(QLatin1String("report:grid")); KReportUtils::addPropertyAsAttribute(&grd, d->showGrid); KReportUtils::addPropertyAsAttribute(&grd, d->gridDivisions); KReportUtils::addPropertyAsAttribute(&grd, d->gridSnap); KReportUtils::addPropertyAsAttribute(&grd, d->unit); content.appendChild(grd); // pageOptions // -- size QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); if (d->pageSize->value().toString() == QLatin1String("Custom")) { pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customWidth->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customHeight->value().toDouble()); } else if (d->pageSize->value().toString() == QLatin1String("Label")) { pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); } else { pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); } // -- orientation KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation); // -- margins: save as points, and not localized KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-top"), d->topMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-bottom"), d->bottomMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-right"), d->rightMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-left"), d->leftMargin->value().toDouble()); content.appendChild(pagestyle); QDomElement body = doc.createElement(QLatin1String("report:body")); QDomElement domsection; for (int i = KReportSectionData::PageHeaderFirst; i <= KReportSectionData::PageFooterAny; ++i) { KReportDesignerSection *sec = section((KReportSectionData::Section)i); if (sec) { domsection = doc.createElement(QLatin1String("report:section")); domsection.setAttribute(QLatin1String("report:section-type"), KReportSectionData::sectionTypeString(KReportSectionData::Section(i))); sec->buildXML(&doc, &domsection); body.appendChild(domsection); } } QDomElement detail = doc.createElement(QLatin1String("report:detail")); d->detail->buildXML(&doc, &detail); body.appendChild(detail); content.appendChild(body); return content; } void KReportDesigner::slotSectionEditor() { KReportSectionEditor se(this); (void)se.exec(); } void KReportDesigner::setReportData(KReportData* kodata) { if (d->kordata == kodata) { return; } delete d->kordata; d->kordata = kodata; slotPageButton_Pressed(); setModified(true); emit reportDataChanged(); } KReportDesignerSection * KReportDesigner::section(KReportSectionData::Section s) const { KReportDesignerSection *sec; switch (s) { case KReportSectionData::PageHeaderAny: sec = d->pageHeaderAny; break; case KReportSectionData::PageHeaderEven: sec = d->pageHeaderEven; break; case KReportSectionData::PageHeaderOdd: sec = d->pageHeaderOdd; break; case KReportSectionData::PageHeaderFirst: sec = d->pageHeaderFirst; break; case KReportSectionData::PageHeaderLast: sec = d->pageHeaderLast; break; case KReportSectionData::PageFooterAny: sec = d->pageFooterAny; break; case KReportSectionData::PageFooterEven: sec = d->pageFooterEven; break; case KReportSectionData::PageFooterOdd: sec = d->pageFooterOdd; break; case KReportSectionData::PageFooterFirst: sec = d->pageFooterFirst; break; case KReportSectionData::PageFooterLast: sec = d->pageFooterLast; break; case KReportSectionData::ReportHeader: sec = d->reportHeader; break; case KReportSectionData::ReportFooter: sec = d->reportFooter; break; default: sec = 0; } return sec; } void KReportDesigner::removeSection(KReportSectionData::Section s) { KReportDesignerSection* sec = section(s); if (sec) { delete sec; switch (s) { case KReportSectionData::PageHeaderAny: d->pageHeaderAny = 0; break; case KReportSectionData::PageHeaderEven: sec = d->pageHeaderEven = 0; break; case KReportSectionData::PageHeaderOdd: d->pageHeaderOdd = 0; break; case KReportSectionData::PageHeaderFirst: d->pageHeaderFirst = 0; break; case KReportSectionData::PageHeaderLast: d->pageHeaderLast = 0; break; case KReportSectionData::PageFooterAny: d->pageFooterAny = 0; break; case KReportSectionData::PageFooterEven: d->pageFooterEven = 0; break; case KReportSectionData::PageFooterOdd: d->pageFooterOdd = 0; break; case KReportSectionData::PageFooterFirst: d->pageFooterFirst = 0; break; case KReportSectionData::PageFooterLast: d->pageFooterLast = 0; break; case KReportSectionData::ReportHeader: d->reportHeader = 0; break; case KReportSectionData::ReportFooter: d->reportFooter = 0; break; default: sec = 0; } setModified(true); adjustSize(); } } void KReportDesigner::insertSection(KReportSectionData::Section s) { KReportDesignerSection* sec = section(s); if (!sec) { int idx = 0; for (int i = 1; i <= s; ++i) { if (section((KReportSectionData::Section)i)) idx++; } if (s > KReportSectionData::ReportHeader) idx++; //kreportDebug() << idx; KReportDesignerSection *rs = new KReportDesignerSection(this); d->vboxlayout->insertWidget(idx, rs); switch (s) { case KReportSectionData::PageHeaderAny: rs->setTitle(tr("Page Header (Any)")); d->pageHeaderAny = rs; break; case KReportSectionData::PageHeaderEven: rs->setTitle(tr("Page Header (Even)")); d->pageHeaderEven = rs; break; case KReportSectionData::PageHeaderOdd: rs->setTitle(tr("Page Header (Odd)")); d->pageHeaderOdd = rs; break; case KReportSectionData::PageHeaderFirst: rs->setTitle(tr("Page Header (First)")); d->pageHeaderFirst = rs; break; case KReportSectionData::PageHeaderLast: rs->setTitle(tr("Page Header (Last)")); d->pageHeaderLast = rs; break; case KReportSectionData::PageFooterAny: rs->setTitle(tr("Page Footer (Any)")); d->pageFooterAny = rs; break; case KReportSectionData::PageFooterEven: rs->setTitle(tr("Page Footer (Even)")); d->pageFooterEven = rs; break; case KReportSectionData::PageFooterOdd: rs->setTitle(tr("Page Footer (Odd)")); d->pageFooterOdd = rs; break; case KReportSectionData::PageFooterFirst: rs->setTitle(tr("Page Footer (First)")); d->pageFooterFirst = rs; break; case KReportSectionData::PageFooterLast: rs->setTitle(tr("Page Footer (Last)")); d->pageFooterLast = rs; break; case KReportSectionData::ReportHeader: rs->setTitle(tr("Report Header")); d->reportHeader = rs; break; case KReportSectionData::ReportFooter: rs->setTitle(tr("Report Footer")); d->reportFooter = rs; break; //These sections cannot be inserted this way case KReportSectionData::None: case KReportSectionData::GroupHeader: case KReportSectionData::GroupFooter: case KReportSectionData::Detail: break; } rs->show(); setModified(true); adjustSize(); emit pagePropertyChanged(*d->set); } } void KReportDesigner::setReportTitle(const QString & str) { if (reportTitle() != str) { d->title->setValue(str); setModified(true); } } KPropertySet * KReportDesigner::propertySet() const { return d->set; } KPropertySet* KReportDesigner::itemPropertySet() const { return d->itmset; } KReportData *KReportDesigner::reportData() const { return d->kordata; } KReportDesignerSectionDetail * KReportDesigner::detailSection() const { return d->detail; } QString KReportDesigner::reportTitle() const { return d->title->value().toString(); } bool KReportDesigner::isModified() const { return d->modified; } void KReportDesigner::setModified(bool mod) { d->modified = mod; if (d->modified) { emit dirty(); } } QStringList KReportDesigner::fieldNames() const { QStringList qs; qs << QString(); if (d->kordata) qs << d->kordata->fieldNames(); return qs; } QStringList KReportDesigner::fieldKeys() const { QStringList qs; qs << QString(); if (d->kordata) qs << d->kordata->fieldKeys(); return qs; } void KReportDesigner::createProperties() { QStringList keys, strings; d->set = new KPropertySet; KReportDesigner::addMetaProperties(d->set, tr("Report", "Main report element"), QLatin1String("kreport-report-element")); connect(d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); keys.clear(); keys = KReportPageSize::pageFormatKeys(); strings = KReportPageSize::pageFormatNames(); QString defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); d->pageSize = new KProperty("page-size", keys, strings, defaultKey, tr("Page Size")); keys.clear(); strings.clear(); keys << QLatin1String("portrait") << QLatin1String("landscape"); strings << tr("Portrait") << tr("Landscape"); d->orientation = new KProperty("print-orientation", keys, strings, QLatin1String("portrait"), tr("Page Orientation")); keys.clear(); strings.clear(); strings = KReportUnit::listOfUnitNameForUi(KReportUnit::HidePixel); QString unit; foreach(const QString &un, strings) { unit = un.mid(un.indexOf(QLatin1String("(")) + 1, 2); keys << unit; } d->unit = new KProperty("page-unit", keys, strings, QLatin1String("cm"), tr("Page Unit")); d->showGrid = new KProperty("grid-visible", true, tr("Show Grid")); d->gridSnap = new KProperty("grid-snap", true, tr("Snap to Grid")); d->gridDivisions = new KProperty("grid-divisions", 4, tr("Grid Divisions")); d->leftMargin = new KProperty("margin-left", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Left Margin"), tr("Left Margin"), KProperty::Double); d->rightMargin = new KProperty("margin-right", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Right Margin"), tr("Right Margin"), KProperty::Double); d->topMargin = new KProperty("margin-top", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Top Margin"), tr("Top Margin"), KProperty::Double); d->bottomMargin = new KProperty("margin-bottom", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); d->leftMargin->setOption("unit", QLatin1String("cm")); d->rightMargin->setOption("unit", QLatin1String("cm")); d->topMargin->setOption("unit", QLatin1String("cm")); d->bottomMargin->setOption("unit", QLatin1String("cm")); d->set->addProperty(d->title); d->set->addProperty(d->pageSize); d->set->addProperty(d->orientation); d->set->addProperty(d->unit); d->set->addProperty(d->gridSnap); d->set->addProperty(d->showGrid); d->set->addProperty(d->gridDivisions); d->set->addProperty(d->leftMargin); d->set->addProperty(d->rightMargin); d->set->addProperty(d->topMargin); d->set->addProperty(d->bottomMargin); #ifdef KREPORT_SCRIPTING d->script = new KProperty("script", QStringList(), QStringList(), QString(), tr("Object Script")); d->set->addProperty(d->script); #endif // KProperty* _customHeight; // KProperty* _customWidth; } /** @brief Handle property changes */ void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) { setModified(true); emit pagePropertyChanged(s); if (p.name() == "page-unit") { d->hruler->setUnit(pageUnit()); QString newstr = d->set->property("page-unit").value().toString(); d->set->property("margin-left").setOption("unit", newstr); d->set->property("margin-right").setOption("unit", newstr); d->set->property("margin-top").setOption("unit", newstr); d->set->property("margin-bottom").setOption("unit", newstr); } } void KReportDesigner::slotPageButton_Pressed() { #ifdef KREPORT_SCRIPTING if (d->kordata) { QStringList sl = d->kordata->scriptList(); sl.prepend(QLatin1String("")); d->script->setListData(sl, sl); } changeSet(d->set); #endif } QSize KReportDesigner::sizeHint() const { int w = 0; int h = 0; if (d->pageFooterAny) h += d->pageFooterAny->sizeHint().height(); if (d->pageFooterEven) h += d->pageFooterEven->sizeHint().height(); if (d->pageFooterFirst) h += d->pageFooterFirst->sizeHint().height(); if (d->pageFooterLast) h += d->pageFooterLast->sizeHint().height(); if (d->pageFooterOdd) h += d->pageFooterOdd->sizeHint().height(); if (d->pageHeaderAny) h += d->pageHeaderAny->sizeHint().height(); if (d->pageHeaderEven) h += d->pageHeaderEven->sizeHint().height(); if (d->pageHeaderFirst) h += d->pageHeaderFirst->sizeHint().height(); if (d->pageHeaderLast) h += d->pageHeaderLast->sizeHint().height(); if (d->pageHeaderOdd) h += d->pageHeaderOdd->sizeHint().height(); if (d->reportHeader) h += d->reportHeader->sizeHint().height(); if (d->reportFooter) { h += d->reportFooter->sizeHint().height(); } if (d->detail) { h += d->detail->sizeHint().height(); w += d->detail->sizeHint().width(); } h += d->hruler->height(); return QSize(w, h); } int KReportDesigner::pageWidthPx() const { KReportPageOptions po; po.setPageSize(d->set->property("page-size").value().toString()); po.setPortrait(d->set->property("print-orientation").value().toString() == QLatin1String("portrait")); QSizeF pageSizePx = po.pixelSize(); int width = pageSizePx.width(); width = width - POINT_TO_INCH(d->set->property("margin-left").value().toDouble()) * KReportDpi::dpiX(); width = width - POINT_TO_INCH(d->set->property("margin-right").value().toDouble()) * KReportDpi::dpiX(); return width; } void KReportDesigner::resizeEvent(QResizeEvent * event) { Q_UNUSED(event); d->hruler->setRulerLength(pageWidthPx()); } void KReportDesigner::setDetail(KReportDesignerSectionDetail *rsd) { if (!d->detail) { int idx = 0; if (d->pageHeaderFirst) idx++; if (d->pageHeaderOdd) idx++; if (d->pageHeaderEven) idx++; if (d->pageHeaderLast) idx++; if (d->pageHeaderAny) idx++; if (d->reportHeader) idx++; d->detail = rsd; d->vboxlayout->insertWidget(idx, d->detail); } } void KReportDesigner::deleteDetail() { delete d->detail; d->detail = 0; } KReportUnit KReportDesigner::pageUnit() const { QString u; bool found; u = d->unit->value().toString(); KReportUnit unit = KReportUnit::fromSymbol(u, &found); if (!found) { unit = KReportUnit(KReportUnit::Centimeter); } return unit; } void KReportDesigner::setGridOptions(bool vis, int div) { d->showGrid->setValue(QVariant(vis)); d->gridDivisions->setValue(div); } // // methods for the sectionMouse*Event() // void KReportDesigner::sectionContextMenuEvent(KReportDesignerSectionScene * s, QGraphicsSceneContextMenuEvent * e) { Q_UNUSED(s); QMenu pop; bool itemsSelected = selectionCount() > 0; if (itemsSelected) { //! @todo KF5 use KStandardAction QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-cut")), tr("Cut"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditCut())); pop.addAction(a); //! @todo KF5 use KStandardAction a = new QAction(QIcon::fromTheme(QLatin1String("edit-copy")), tr("Copy"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditCopy())); pop.addAction(a); } if (!d->sectionData->copy_list.isEmpty()) { QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-paste")), tr("Paste"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditPaste())); pop.addAction(a); } if (itemsSelected) { pop.addSeparator(); //! @todo KF5 use KStandard* //const KGuiItem del = KStandardGuiItem::del(); //a->setToolTip(del.toolTip()); //a->setShortcut(QKeySequence(QKeySequence::Delete)); QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), tr("Delete"), this); connect(a, SIGNAL(triggered()), SLOT(slotEditDelete())); pop.addAction(a); } if (!pop.actions().isEmpty()) { pop.exec(e->screenPos()); } } void KReportDesigner::sectionMousePressEvent(KReportDesignerSectionView * v, QMouseEvent * e) { Q_UNUSED(v); d->pressX = e->pos().x(); d->pressY = e->pos().y(); } void KReportDesigner::sectionMouseReleaseEvent(KReportDesignerSectionView * v, QMouseEvent * e) { e->accept(); d->releaseX = e->pos().x(); d->releaseY = e->pos().y(); if (e->button() == Qt::LeftButton) { QPointF pos(d->pressX, d->pressY); QPointF end(d->releaseX, d->releaseY); if (d->releaseY >= v->scene()->height()) { d->releaseY = v->scene()->height(); end.setY(v->scene()->height()); } if (d->releaseX >= v->scene()->width()) { d->releaseX = v->scene()->width(); end.setX(v->scene()->width()); } if (d->sectionData->mouseAction == ReportWriterSectionData::MA_Insert) { QGraphicsItem * item = 0; QString classString; QString iconName; if (d->sectionData->insertItem == QLatin1String("org.kde.kreport.line")) { item = new KReportDesignerItemLine(v->designer(), v->scene(), pos, end); classString = tr("Line", "Report line element"); iconName = QLatin1String("kreport-line-element"); } else { KReportPluginManager* pluginManager = KReportPluginManager::self(); KReportPluginInterface *plug = pluginManager->plugin(d->sectionData->insertItem); if (plug) { QObject *obj = plug->createDesignerInstance(v->designer(), v->scene(), pos); if (obj) { item = dynamic_cast(obj); classString = plug->metaData()->name(); iconName = plug->metaData()->iconName(); } } else { kreportWarning() << "attempted to insert an unknown item"; } } if (item) { item->setVisible(true); item->setSelected(true); KReportItemBase* baseReportItem = dynamic_cast(item); if (baseReportItem) { + baseReportItem->setUnit(pageUnit()); KPropertySet *set = baseReportItem->propertySet(); KReportDesigner::addMetaProperties(set, classString, iconName); changeSet(set); if (v && v->designer()) { v->designer()->setModified(true); } emit itemInserted(d->sectionData->insertItem); } } d->sectionData->mouseAction = ReportWriterSectionData::MA_None; d->sectionData->insertItem.clear(); unsetSectionCursor(); } } } unsigned int KReportDesigner::selectionCount() const { if (activeScene()) return activeScene()->selectedItems().count(); else return 0; } void KReportDesigner::changeSet(KPropertySet *s) { //Set the checked state of the report properties button if (s == d->set) d->pageButton->setCheckState(Qt::Checked); else d->pageButton->setCheckState(Qt::Unchecked); d->itmset = s; emit propertySetChanged(); } // // Actions // void KReportDesigner::slotItem(const QString &entity) { //kreportDebug() << entity; d->sectionData->mouseAction = ReportWriterSectionData::MA_Insert; d->sectionData->insertItem = entity; setSectionCursor(QCursor(Qt::CrossCursor)); } void KReportDesigner::slotEditDelete() { QGraphicsItem * item = 0; bool modified = false; while (selectionCount() > 0) { item = activeScene()->selectedItems().value(0); if (item) { QGraphicsScene * scene = item->scene(); delete item; scene->update(); d->sectionData->mouseAction = ReportWriterSectionData::MA_None; modified = true; } } activeScene()->selectedItems().clear(); /*! @todo temporary: clears cut and copy lists to make sure we do not crash if weve deleted something in the list should really check if an item is in the list first and remove it. */ d->sectionData->cut_list.clear(); d->sectionData->copy_list.clear(); if (modified) { setModified(true); } } void KReportDesigner::slotEditCut() { if (selectionCount() > 0) { //First delete any items that are curerntly in the list //so as not to leak memory qDeleteAll(d->sectionData->cut_list); d->sectionData->cut_list.clear(); QGraphicsItem * item = activeScene()->selectedItems().first(); bool modified = false; if (item) { d->sectionData->copy_list.clear(); foreach(QGraphicsItem *item, activeScene()->selectedItems()) { d->sectionData->cut_list.append(dynamic_cast(item)); d->sectionData->copy_list.append(dynamic_cast(item)); } foreach(QGraphicsItem *item, activeScene()->selectedItems()) { activeScene()->removeItem(item); activeScene()->update(); modified = true; } d->sectionData->selected_x_offset = 10; d->sectionData->selected_y_offset = 10; } if (modified) { setModified(true); } } } void KReportDesigner::slotEditCopy() { if (selectionCount() < 1) return; QGraphicsItem * item = activeScene()->selectedItems().first(); if (item) { d->sectionData->copy_list.clear(); foreach(QGraphicsItem *item, activeScene()->selectedItems()) { d->sectionData->copy_list.append(dynamic_cast(item)); } d->sectionData->selected_x_offset = 10; d->sectionData->selected_y_offset = 10; } } void KReportDesigner::slotEditPaste() { // call the editPaste function passing it a reportsection slotEditPaste(activeScene()); } void KReportDesigner::slotEditPaste(QGraphicsScene * canvas) { // paste a new item of the copy we have in the specified location if (!d->sectionData->copy_list.isEmpty()) { QList activeItems = canvas->selectedItems(); QGraphicsItem *activeItem = 0; if (activeItems.count() == 1) { activeItem = activeItems.first(); } canvas->clearSelection(); d->sectionData->mouseAction = ReportWriterSectionData::MA_None; //! @todo this code sucks :) //! The setPos calls only work AFTER the name has been set ?!?!? foreach(KReportDesignerItemBase *item, d->sectionData->copy_list) { KReportItemBase *obj = dynamic_cast(item); const QString type = obj ? obj->typeName() : QLatin1String("object"); //kreportDebug() << type; KReportDesignerItemBase *ent = item->clone(); KReportItemBase *new_obj = dynamic_cast(ent); new_obj->setEntityName(suggestEntityName(type)); if (activeItem) { - new_obj->position().setScenePos(QPointF(activeItem->x() + 10, activeItem->y() + 10)); + new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(activeItem->x() + 10, activeItem->y() + 10))); } else { - new_obj->position().setScenePos(QPointF(0, 0)); + new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(0, 0))); } changeSet(new_obj->propertySet()); QGraphicsItem *pasted_ent = dynamic_cast(ent); if (pasted_ent) { pasted_ent->setSelected(true); canvas->addItem(pasted_ent); pasted_ent->show(); d->sectionData->mouseAction = ReportWriterSectionData::MA_Grab; setModified(true); } } } } void KReportDesigner::slotRaiseSelected() { dynamic_cast(activeScene())->raiseSelected(); } void KReportDesigner::slotLowerSelected() { dynamic_cast(activeScene())->lowerSelected(); } QGraphicsScene* KReportDesigner::activeScene() const { return d->activeScene; } void KReportDesigner::setActiveScene(QGraphicsScene* a) { if (d->activeScene && d->activeScene != a) d->activeScene->clearSelection(); d->activeScene = a; //Trigger an update so that the last scene redraws its title; update(); } KReportZoomHandler* KReportDesigner::zoomHandler() const { return d->zoom; } QString KReportDesigner::suggestEntityName(const QString &n) const { KReportDesignerSection *sec; int itemCount = 0; //Count items in the main sections for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) { sec = section((KReportSectionData::Section) i); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } if (d->detail) { //Count items in the group headers/footers for (int i = 0; i < d->detail->groupSectionCount(); i++) { sec = d->detail->groupSection(i)->groupHeader(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } sec = d->detail->groupSection(i)->groupFooter(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } sec = d->detail->detailSection(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } while (!isEntityNameUnique(n + QString::number(itemCount))) { itemCount++; } return n + QString::number(itemCount); } bool KReportDesigner::isEntityNameUnique(const QString &n, KReportItemBase* ignore) const { KReportDesignerSection *sec; bool unique = true; //Check items in the main sections for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) { sec = section((KReportSectionData::Section)i); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } if (!unique) break; } } //Count items in the group headers/footers if (unique && d->detail) { for (int i = 0; i < d->detail->groupSectionCount(); ++i) { sec = d->detail->groupSection(i)->groupHeader(); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } } sec = d->detail->groupSection(i)->groupFooter(); if (unique && sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } } } } if (unique && d->detail) { sec = d->detail->detailSection(); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } } } return unique; } static bool actionPriortyLessThan(QAction* act1, QAction* act2) { if (act1->data().toInt() > 0 && act2->data().toInt() > 0) { return act1->data().toInt() < act2->data().toInt(); } return false; } QList KReportDesigner::itemActions(QActionGroup* group) { KReportPluginManager* manager = KReportPluginManager::self(); QList actList = manager->createActions(group); //! @todo make line a real plugin so this isn't needed: QAction *act = new QAction(QIcon::fromTheme(QLatin1String("kreport-line-element")), tr("Line"), group); act->setObjectName(QLatin1String("org.kde.kreport.line")); act->setData(9); act->setCheckable(true); actList << act; qSort(actList.begin(), actList.end(), actionPriortyLessThan); int i = 0; /*! @todo maybe this is a bit hackish It finds the first plugin based on the priority in userdata The lowest oriority a plugin can have is 10 And inserts a separator before it. */ bool sepInserted = false; foreach(QAction *a, actList) { ++i; if (!sepInserted && a->data().toInt() >= 10) { QAction *sep = new QAction(QLatin1String("separator"), group); sep->setSeparator(true); actList.insert(i-1, sep); sepInserted = true; } if (group) { group->addAction(a); } } return actList; } QList< QAction* > KReportDesigner::designerActions() { QList al; QAction *sep = new QAction(QString(), this); sep->setSeparator(true); al << d->editCutAction << d->editCopyAction << d->editPasteAction << d->editDeleteAction << sep << d->sectionEdit << sep << d->itemLowerAction << d->itemRaiseAction; return al; } void KReportDesigner::createActions() { d->editCutAction = new QAction(QIcon::fromTheme(QLatin1String("edit-cut")), tr("Cu&t"), this); d->editCutAction->setObjectName(QLatin1String("edit_cut")); d->editCutAction->setToolTip(tr("Cut selection to clipboard")); d->editCutAction->setShortcuts(KStandardShortcut::cut()); d->editCutAction->setProperty("iconOnly", true); d->editCopyAction = new QAction(QIcon::fromTheme(QLatin1String("edit-copy")), tr("&Copy"), this); d->editCopyAction->setObjectName(QLatin1String("edit_copy")); d->editCopyAction->setToolTip(tr("Copy selection to clipboard")); d->editCopyAction->setShortcuts(KStandardShortcut::copy()); d->editCopyAction->setProperty("iconOnly", true); d->editPasteAction = new QAction(QIcon::fromTheme(QLatin1String("edit-paste")), tr("&Paste"), this); d->editPasteAction->setObjectName(QLatin1String("edit_paste")); d->editPasteAction->setToolTip(tr("Paste clipboard content")); d->editPasteAction->setShortcuts(KStandardShortcut::paste()); d->editPasteAction->setProperty("iconOnly", true); const KGuiItem del = KStandardGuiItem::del(); d->editDeleteAction = new QAction(del.icon(), del.text(), this); d->editDeleteAction->setObjectName(QLatin1String("edit_delete")); d->editDeleteAction->setToolTip(del.toolTip()); d->editDeleteAction->setWhatsThis(del.whatsThis()); d->editDeleteAction->setProperty("iconOnly", true); d->sectionEdit = new QAction(tr("Edit Sections"), this); d->sectionEdit->setObjectName(QLatin1String("section_edit")); d->itemRaiseAction = new QAction(QIcon::fromTheme(QLatin1String("arrow-up")), tr("Raise"), this); d->itemRaiseAction->setObjectName(QLatin1String("item_raise")); d->itemLowerAction = new QAction(QIcon::fromTheme(QLatin1String("arrow-down")), tr("Lower"), this); d->itemLowerAction->setObjectName(QLatin1String("item_lower")); //Edit Actions connect(d->editCutAction, SIGNAL(triggered(bool)), this, SLOT(slotEditCut())); connect(d->editCopyAction, SIGNAL(triggered(bool)), this, SLOT(slotEditCopy())); connect(d->editPasteAction, SIGNAL(triggered(bool)), this, SLOT(slotEditPaste())); connect(d->editDeleteAction, SIGNAL(triggered(bool)), this, SLOT(slotEditDelete())); connect(d->sectionEdit, SIGNAL(triggered(bool)), this, SLOT(slotSectionEditor())); //Raise/Lower connect(d->itemRaiseAction, SIGNAL(triggered(bool)), this, SLOT(slotRaiseSelected())); connect(d->itemLowerAction, SIGNAL(triggered(bool)), this, SLOT(slotLowerSelected())); } void KReportDesigner::setSectionCursor(const QCursor& c) { if (d->pageFooterAny) d->pageFooterAny->setSectionCursor(c); if (d->pageFooterEven) d->pageFooterEven->setSectionCursor(c); if (d->pageFooterFirst) d->pageFooterFirst->setSectionCursor(c); if (d->pageFooterLast) d->pageFooterLast->setSectionCursor(c); if (d->pageFooterOdd) d->pageFooterOdd->setSectionCursor(c); if (d->pageHeaderAny) d->pageHeaderAny->setSectionCursor(c); if (d->pageHeaderEven) d->pageHeaderEven->setSectionCursor(c); if (d->pageHeaderFirst) d->pageHeaderFirst->setSectionCursor(c); if (d->pageHeaderLast) d->pageHeaderLast->setSectionCursor(c); if (d->pageHeaderOdd) d->pageHeaderOdd->setSectionCursor(c); if (d->detail) d->detail->setSectionCursor(c); } void KReportDesigner::unsetSectionCursor() { if (d->pageFooterAny) d->pageFooterAny->unsetSectionCursor(); if (d->pageFooterEven) d->pageFooterEven->unsetSectionCursor(); if (d->pageFooterFirst) d->pageFooterFirst->unsetSectionCursor(); if (d->pageFooterLast) d->pageFooterLast->unsetSectionCursor(); if (d->pageFooterOdd) d->pageFooterOdd->unsetSectionCursor(); if (d->pageHeaderAny) d->pageHeaderAny->unsetSectionCursor(); if (d->pageHeaderEven) d->pageHeaderEven->unsetSectionCursor(); if (d->pageHeaderFirst) d->pageHeaderFirst->unsetSectionCursor(); if (d->pageHeaderLast) d->pageHeaderLast->unsetSectionCursor(); if (d->pageHeaderOdd) d->pageHeaderOdd->unsetSectionCursor(); if (d->detail) d->detail->unsetSectionCursor(); } qreal KReportDesigner::countSelectionHeight() const { if (d->releaseY == -1 || d->pressY == -1) { return -1; } return qAbs(d->releaseY - d->pressY); } qreal KReportDesigner::countSelectionWidth() const { if (d->releaseX == -1 || d->pressX == -1) { return -1; } return qAbs(d->releaseX - d->pressX); } qreal KReportDesigner::getSelectionPressX() const { return d->pressX; } qreal KReportDesigner::getSelectionPressY() const { return d->pressY; } QPointF KReportDesigner::getPressPoint() const { return QPointF(d->pressX, d->pressY); } QPointF KReportDesigner::getReleasePoint() const { return QPointF(d->releaseX, d->releaseY); } void KReportDesigner::plugItemActions(const QList &actList) { foreach(QAction *a, actList) { connect(a, SIGNAL(triggered(bool)), this, SLOT(slotItemTriggered(bool))); } } void KReportDesigner::slotItemTriggered(bool checked) { if (!checked) { return; } QObject *theSender = sender(); if (!theSender) { return; } slotItem(theSender->objectName()); } void KReportDesigner::addMetaProperties(KPropertySet* set, const QString &classString, const QString &iconName) { Q_ASSERT(set); KProperty *prop; set->addProperty(prop = new KProperty("this:classString", classString)); prop->setVisible(false); set->addProperty(prop = new KProperty("this:iconName", iconName)); prop->setVisible(false); } diff --git a/src/wrtembed/KReportDesignerItemBase.cpp b/src/wrtembed/KReportDesignerItemBase.cpp index 9e310cc2..53f4a13e 100644 --- a/src/wrtembed/KReportDesignerItemBase.cpp +++ b/src/wrtembed/KReportDesignerItemBase.cpp @@ -1,75 +1,118 @@ /* 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 "KReportDesignerItemBase.h" #include "KReportItemBase.h" #include "KReportUtils.h" #include #include #include -// -// ReportEntity -// +class Q_DECL_HIDDEN KReportDesignerItemBase::Private +{ +public: + Private(); + ~Private(); + + KReportDesigner *reportDesigner; + KReportItemBase *item; + QString renderText; +}; + +KReportDesignerItemBase::Private::Private() +{ +} + +KReportDesignerItemBase::Private::~Private() +{ +} + KReportDesignerItemBase::~KReportDesignerItemBase() { + delete d; } -KReportDesignerItemBase::KReportDesignerItemBase(KReportDesigner* r) +KReportDesignerItemBase::KReportDesignerItemBase(KReportDesigner *r, KReportItemBase *b) : d(new Private()) { - m_reportDesigner = r; + d->reportDesigner = r; + d->item = b; } void KReportDesignerItemBase::buildXML(QGraphicsItem * item, QDomDocument *doc, QDomElement *parent) { KReportDesignerItemBase *re = 0; re = dynamic_cast(item); if (re) { re->buildXML(doc, parent); } } -void KReportDesignerItemBase::buildXMLRect(QDomDocument *doc, QDomElement *entity, KReportPosition *pos, KReportSize *size) +void KReportDesignerItemBase::buildXMLRect(QDomDocument *doc, QDomElement *entity, KReportItemBase *i) { Q_UNUSED(doc); - KReportUtils::buildXMLRect(entity, pos, size); + KReportUtils::buildXMLRect(entity, i->position(), i->size()); } void KReportDesignerItemBase::buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts) { KReportUtils::buildXMLTextStyle(doc, entity, ts); } void KReportDesignerItemBase::buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls) { KReportUtils::buildXMLLineStyle(doc, entity, ls); } QString KReportDesignerItemBase::dataSourceAndObjectTypeName(const QString& dataSource, const QString& objectTypeName) const { return QString::fromLatin1("%1: %2").arg(dataSource).arg(objectTypeName); } // static void KReportDesignerItemBase::addPropertyAsAttribute(QDomElement* e, KProperty* p) { KReportUtils::addPropertyAsAttribute(e, p); } + +KReportDesigner * KReportDesignerItemBase::designer() const +{ + return d->reportDesigner; +} + +void KReportDesignerItemBase::setDesigner(KReportDesigner* rd) +{ + d->reportDesigner = rd; +} + +KReportItemBase *KReportDesignerItemBase::item() const +{ + return d->item; +} + +QString KReportDesignerItemBase::renderText() const +{ + return d->renderText; +} + +void KReportDesignerItemBase::setRenderText(const QString& text) +{ + d->renderText = text; +} diff --git a/src/wrtembed/KReportDesignerItemBase.h b/src/wrtembed/KReportDesignerItemBase.h index 5ab4af8b..bdd1ea58 100644 --- a/src/wrtembed/KReportDesignerItemBase.h +++ b/src/wrtembed/KReportDesignerItemBase.h @@ -1,92 +1,87 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ /* * This file contains all the Report Entity classes. Each one is a * derivative of ReportEntity, which in turn is derived from QCanvasItem. */ #ifndef KREPORTDESIGNERITEMBASE_H #define KREPORTDESIGNERITEMBASE_H #include #include "KReportItemBase.h" class QDomDocument; class QDomElement; class KReportDesigner; class KReportPosition; class KReportSize; // // ReportEntity // class KREPORT_EXPORT KReportDesignerItemBase { public: virtual ~KReportDesignerItemBase(); static void buildXML(QGraphicsItem * item, QDomDocument *doc, QDomElement *parent); virtual void buildXML(QDomDocument *doc, QDomElement *parent) = 0; - static void buildXMLRect(QDomDocument *doc, QDomElement *entity, KReportPosition *pos, KReportSize *size); + static void buildXMLRect(QDomDocument *doc, QDomElement *entity, KReportItemBase *i); static void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts); static void buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls); - static QFont getDefaultEntityFont(); - static void setDefaultEntityFont(const QFont &); - virtual KReportDesignerItemBase* clone() = 0; virtual void move(const QPointF&) = 0; - KReportDesigner* designer() const { - return m_reportDesigner; - } - void setDesigner(KReportDesigner* rd) { - m_reportDesigner = rd; - } + KReportDesigner* designer() const; + void setDesigner(KReportDesigner* rd); static void addPropertyAsAttribute(QDomElement* e, KProperty* p); protected: - explicit KReportDesignerItemBase(KReportDesigner*); - KReportDesigner* m_reportDesigner; + explicit KReportDesignerItemBase(KReportDesigner*, KReportItemBase*); QString dataSourceAndObjectTypeName(const QString& dataSource, const QString& objectTypeName) const; /** * @brief Updates the text that is shown for the item in the report designer * If itemDataSource is set then it is preferred over itemStaticValue * itemType is appended to the end of the text * * @param itemDataSource source field property * @param itemStaticValue value property * @param itemType type of item * @return void */ - void updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType); - QString m_renderText; + void updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType); + KReportItemBase *item() const; + + void setRenderText(const QString &text); + QString renderText() const; private: - static bool m_readDefaultFont; - static QFont m_defaultFont; + class Private; + Private * const d; }; #endif diff --git a/src/wrtembed/KReportDesignerItemLine.cpp b/src/wrtembed/KReportDesignerItemLine.cpp index eaf99f02..c431bad6 100644 --- a/src/wrtembed/KReportDesignerItemLine.cpp +++ b/src/wrtembed/KReportDesignerItemLine.cpp @@ -1,251 +1,248 @@ /* 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 "KReportDesignerItemLine.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include "KReportDesignerSectionScene.h" #include "KReportUtils.h" #include "KReportLineStyle.h" #include #include #include #include // // class ReportEntityLine // void KReportDesignerItemLine::init(QGraphicsScene* s, KReportDesigner *r) { - m_reportDesigner = r; setPos(0, 0); setUnit(r->pageUnit()); + nameProperty()->setValue(r->suggestEntityName(typeName())); + setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); setPen(QPen(Qt::black, 5)); setAcceptHoverEvents(true); if (s) s->addItem(this); - connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), - this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - - setZValue(Z); + setZValue(z()); } KReportDesignerItemLine::KReportDesignerItemLine(KReportDesigner * d, QGraphicsScene * scene, const QPointF &pos) - : KReportDesignerItemBase(d) + : KReportDesignerItemBase(d, this) { init(scene, d); setLineScene(QLineF(pos, QPointF(20,20)+pos)); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); + } KReportDesignerItemLine::KReportDesignerItemLine(KReportDesigner * d, QGraphicsScene * scene, const QPointF &startPos, const QPointF &endPos) - : KReportDesignerItemBase(d) + : KReportDesignerItemBase(d, this) { init(scene, d); setLineScene(QLineF(startPos, endPos)); - m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); - } KReportDesignerItemLine::KReportDesignerItemLine(const QDomNode & entity, KReportDesigner * d, QGraphicsScene * scene) - : KReportItemLine(entity), KReportDesignerItemBase(d) + : KReportItemLine(entity), KReportDesignerItemBase(d, this) { init(scene, d); setLine ( m_start.toScene().x(), m_start.toScene().y(), m_end.toScene().x(), m_end.toScene().y() ); } KReportDesignerItemLine* KReportDesignerItemLine::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemLine(n, designer(), 0); } void KReportDesignerItemLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->setRenderHint(QPainter::Antialiasing, true); QPen p = painter->pen(); painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); painter->drawLine(line()); if (isSelected()) { // draw a selected border for visual purposes painter->setPen(QPen(QColor(128, 128, 255), 0, Qt::DotLine)); QPointF pt = line().p1(); painter->fillRect(pt.x(), pt.y() - 2, 5, 5, QColor(128, 128, 255)); pt = line().p2(); painter->fillRect(pt.x() - 4, pt.y() - 2, 5, 5, QColor(128, 128, 255)); painter->setPen(p); } } void KReportDesignerItemLine::buildXML(QDomDocument *doc, QDomElement *parent) { QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); + addPropertyAsAttribute(&entity, nameProperty()); entity.setAttribute(QLatin1String("report:z-index"), zValue()); KReportUtils::setAttribute(&entity, QLatin1String("svg:x1"), m_start.toPoint().x()); KReportUtils::setAttribute(&entity, QLatin1String("svg:y1"), m_start.toPoint().y()); KReportUtils::setAttribute(&entity, QLatin1String("svg:x2"), m_end.toPoint().x()); KReportUtils::setAttribute(&entity, QLatin1String("svg:y2"), m_end.toPoint().y()); buildXMLLineStyle(doc, &entity, lineStyle()); parent->appendChild(entity); } -void KReportDesignerItemLine::slotPropertyChanged(KPropertySet &s, KProperty &p) +void KReportDesignerItemLine::propertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s); if (p.name() == "Start" || p.name() == "End") { if (p.name() == "Start") m_start.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); if (p.name() == "End") m_end.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); setLine(m_start.toScene().x(), m_start.toScene().y(), m_end.toScene().x(), m_end.toScene().y()); } else if (p.name() == "name") { //For some reason p.oldValue returns an empty string - if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { - p.setValue(m_oldName); + if (!designer()->isEntityNameUnique(p.value().toString(), this)) { + p.setValue(oldName()); } else { - m_oldName = p.value().toString(); + setOldName(p.value().toString()); } } - if (m_reportDesigner) - m_reportDesigner->setModified(true); + if (designer()) + designer()->setModified(true); update(); } void KReportDesignerItemLine::mousePressEvent(QGraphicsSceneMouseEvent * event) { - m_reportDesigner->changeSet(m_set); + designer()->changeSet(propertySet()); setSelected(true); QGraphicsLineItem::mousePressEvent(event); } QVariant KReportDesignerItemLine::itemChange(GraphicsItemChange change, const QVariant &value) { return QGraphicsItem::itemChange(change, value); } void KReportDesignerItemLine::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { QGraphicsLineItem::mouseReleaseEvent(event); } void KReportDesignerItemLine::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { int x; int y; QPointF p = dynamic_cast(scene())->gridPoint(event->scenePos()); //kreportDebug() << p; x = p.x(); y = p.y(); if (x < 0) x = 0; if (y < 0) y = 0; if (x > scene()->width()) x = scene()->width(); if (y > scene()->height()) y = scene()->height(); switch (m_grabAction) { case 1: m_start.setScenePos(QPointF(x,y)); break; case 2: m_end.setScenePos(QPointF(x,y)); break; default: QPointF d = mapToItem(this, dynamic_cast(scene())->gridPoint(event->scenePos())) - mapToItem(this, dynamic_cast(scene())->gridPoint(event->lastScenePos())); if (((line().p1() + d).x() >= 0) && ((line().p2() + d).x() >= 0) && ((line().p1() + d).y() >= 0) && ((line().p2() + d).y() >= 0) && ((line().p1() + d).x() <= scene()->width()) && ((line().p2() + d).x() <= scene()->width()) && ((line().p1() + d).y() <= scene()->height()) && ((line().p2() + d).y() <= scene()->height())) setLineScene(QLineF(line().p1() + d, line().p2() + d)); break; } } int KReportDesignerItemLine::grabHandle(QPointF pos) { if (QRectF(line().p1().x(), line().p1().y() - 2, 5, 5).contains(pos)) { // we are over point 1 return 1; } else if (QRectF(line().p2().x() - 4, line().p2().y() - 2, 5, 5).contains(pos)) { // we are over point 2 return 2; } else { return 0; } } void KReportDesignerItemLine::hoverMoveEvent(QGraphicsSceneHoverEvent * event) { if (isSelected()) { m_grabAction = grabHandle(event->pos()); switch (m_grabAction) { case 1: //Point 1 setCursor(Qt::SizeAllCursor); break; case 2: //Point 2 setCursor(Qt::SizeAllCursor); break; default: unsetCursor(); } } } void KReportDesignerItemLine::setLineScene(QLineF l) { m_start.setScenePos(l.p1(), KReportPosition::DontUpdateProperty); m_end.setScenePos(l.p2()); } void KReportDesignerItemLine::move(const QPointF& m) { - QPointF original = m_pos.toScene(); + QPointF original = scenePosition(position()); original += m; - m_pos.setScenePos(original); + + setPosition(positionFromScene(original)); } diff --git a/src/wrtembed/KReportDesignerItemLine.h b/src/wrtembed/KReportDesignerItemLine.h index 8ba86d2a..03910881 100644 --- a/src/wrtembed/KReportDesignerItemLine.h +++ b/src/wrtembed/KReportDesignerItemLine.h @@ -1,64 +1,62 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTDESIGNERITEMLINE_H #define KREPORTDESIGNERITEMLINE_H #include "KReportDesignerItemBase.h" #include "KReportItemLine.h" #include class KReportDesigner; class KPropertySet; class KReportDesignerItemLine : public KReportItemLine, public QGraphicsLineItem, public KReportDesignerItemBase { Q_OBJECT public: KReportDesignerItemLine(KReportDesigner *, QGraphicsScene * scene, const QPointF &pos); KReportDesignerItemLine(KReportDesigner * d, QGraphicsScene * scene, const QPointF &startPos, const QPointF &endPos); KReportDesignerItemLine(const QDomNode & element, KReportDesigner *, QGraphicsScene * scene); virtual void buildXML(QDomDocument *doc, QDomElement *parent); virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget = 0); virtual KReportDesignerItemLine* clone(); void setLineScene(QLineF); virtual void move(const QPointF&); private: KReportDesigner* m_rd; void init(QGraphicsScene*, KReportDesigner *); int grabHandle(QPointF pos); int m_grabAction; protected: virtual void hoverMoveEvent(QGraphicsSceneHoverEvent * event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - -private Q_SLOTS: - void slotPropertyChanged(KPropertySet &, KProperty &); + virtual void propertyChanged(KPropertySet &s, KProperty &p); }; #endif diff --git a/src/wrtembed/KReportDesignerItemRectBase.cpp b/src/wrtembed/KReportDesignerItemRectBase.cpp index 9633de0e..1d8e9157 100644 --- a/src/wrtembed/KReportDesignerItemRectBase.cpp +++ b/src/wrtembed/KReportDesignerItemRectBase.cpp @@ -1,386 +1,389 @@ /* 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 "KReportDesignerItemRectBase.h" #include "KReportDesignerSectionView.h" #include "KReportDesigner.h" #include "KReportPosition.h" #include "KReportSize.h" #include "KReportDesignerSectionScene.h" #include "KReportDpi.h" #include #include #include -KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r) - : QGraphicsRectItem(), KReportDesignerItemBase(r) +class Q_DECL_HIDDEN KReportDesignerItemRectBase::Private +{ +public: + Private(); + ~Private(); + + int grabAction; +}; + +KReportDesignerItemRectBase::Private::Private() +{ +} + +KReportDesignerItemRectBase::Private::~Private() +{ +} + +KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b) + : QGraphicsRectItem(), KReportDesignerItemBase(r, b), d(new KReportDesignerItemRectBase::Private) { m_dpiX = KReportDpi::dpiX(); m_dpiY = KReportDpi::dpiY(); - m_ppos = 0; - m_psize = 0; - m_grabAction = 0; + d->grabAction = 0; setAcceptHoverEvents(true); -#if QT_VERSION >= 0x040600 setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); -#else - setFlags(ItemIsSelectable | ItemIsMovable); -#endif -} - -void KReportDesignerItemRectBase::init(KReportPosition* p, KReportSize* s, KPropertySet* se, KReportDesigner *d) -{ - Q_UNUSED(d); - m_ppos = p; - m_psize = s; - m_pset = se; } KReportDesignerItemRectBase::~KReportDesignerItemRectBase() { + delete d; } QRectF KReportDesignerItemRectBase::sceneRect() { - return QRectF(m_ppos->toScene(), m_psize->toScene()); + return QRectF(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } QRectF KReportDesignerItemRectBase::pointRect() const { - if (m_ppos && m_psize) - return QRectF(m_ppos->toPoint(), m_psize->toPoint()); - else - return QRectF(0, 0, 0, 0); + return QRectF(item()->position(), item()->size()); } void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update) { setSceneRect(QRectF(topLeft, size), update); } void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, UpdatePropertyFlag update) { QGraphicsRectItem::setPos(rect.x(), rect.y()); setRect(0, 0, rect.width(), rect.height()); if (update == UpdateProperty) { - m_ppos->setScenePos(QPointF(rect.x(), rect.y())); - m_psize->setSceneSize(QSizeF(rect.width(), rect.height())); + item()->setPosition(KReportItemBase::positionFromScene(QPointF(rect.x(), rect.y()))); + item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect.width(), rect.height()))); } this->update(); } void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) { //Update and show properties - m_ppos->setScenePos(QPointF(sceneRect().x(), sceneRect().y())); - m_reportDesigner->changeSet(m_pset); + item()->setPosition(KReportItemBase::positionFromScene(QPointF(sceneRect().x(), sceneRect().y()))); + designer()->changeSet(item()->propertySet()); setSelected(true); scene()->update(); QGraphicsItem::mousePressEvent(event); } void KReportDesignerItemRectBase::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { //Keep the size and position in sync - m_ppos->setScenePos(pos()); - m_psize->setSceneSize(QSizeF(rect().width(), rect().height())); + item()->setPosition(KReportItemBase::positionFromScene(pos())); + item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect().width(), rect().height()))); QGraphicsItem::mouseReleaseEvent(event); } void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { //kreportDebug() << m_grabAction; qreal w, h; QPointF p = dynamic_cast(scene())->gridPoint(event->scenePos()); w = p.x() - scenePos().x(); h = p.y() - scenePos().y(); //! @todo use an enum for the directions - switch (m_grabAction) { + switch (d->grabAction) { case 1: if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() >= 0) setSceneRect(QPointF(p.x(), p.y()), QSizeF(sceneRect().x() - p.x() + rect().width(), sceneRect().y() - p.y() + rect().height())); break; case 2: if (sceneRect().y() - p.y() + rect().height() >= 0) setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(rect().width(), sceneRect().y() - p.y() + rect().height())); break; case 3: if (sceneRect().y() - p.y() + rect().height() >= 0 && w >= 0) setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(w, sceneRect().y() - p.y() + rect().height())); break; case 4: if (w >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, (rect().height()))); break; case 5: if (h >= 0 && w >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, h)); break; case 6: if (h >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF((rect().width()), h)); break; case 7: if (sceneRect().x() - p.x() + rect().width() >= 0 && h >= 0) setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), h)); break; case 8: if (sceneRect().x() - p.x() + rect().width() >= 0) setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), rect().height())); break; default: QGraphicsItem::mouseMoveEvent(event); } } void KReportDesignerItemRectBase::hoverMoveEvent(QGraphicsSceneHoverEvent * event) { //m_grabAction = 0; if (isSelected()) { - m_grabAction = grabHandle(event->pos()); - switch (m_grabAction) { + d->grabAction = grabHandle(event->pos()); + switch (d->grabAction) { case 1: setCursor(Qt::SizeFDiagCursor); break; case 2: setCursor(Qt::SizeVerCursor); break; case 3: setCursor(Qt::SizeBDiagCursor); break; case 4: setCursor(Qt::SizeHorCursor); break; case 5: setCursor(Qt::SizeFDiagCursor); break; case 6: setCursor(Qt::SizeVerCursor); break; case 7: setCursor(Qt::SizeBDiagCursor); break; case 8: setCursor(Qt::SizeHorCursor); break; default: unsetCursor(); } } //kreportDebug() << m_grabAction; } void KReportDesignerItemRectBase::drawHandles(QPainter *painter) { if (isSelected()) { // draw a selected border for visual purposes painter->setPen(QPen(QColor(128, 128, 255), 0, Qt::DotLine)); painter->drawRect(rect()); const QRectF r = rect(); double halfW = (r.width() / 2); double halfH = (r.height() / 2); QPointF center = r.center(); center += QPointF(0.75,0.75); painter->fillRect(center.x() - halfW, center.y() - halfH , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - 2, center.y() - halfH , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + halfW - 4, center.y() - halfH, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + (halfW - 4), center.y() - 2, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + halfW - 4 , center.y() + halfH - 4 , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - 2, center.y() + halfH - 4, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - halfW, center.y() + halfH - 4 , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - halfW, center.y() - 2, 5, 5, QColor(128, 128, 255)); } } /** @return 1 2 3 8 0 4 7 6 5 */ int KReportDesignerItemRectBase::grabHandle(QPointF pos) { QRectF r = boundingRect(); int halfW = (int)(r.width() / 2); int halfH = (int)(r.height() / 2); QPointF center = r.center(); if (QRectF(center.x() - (halfW), center.y() - (halfH), 5, 5).contains(pos)) { // we are over the top-left handle return 1; } else if (QRectF(center.x() - 2, center.y() - (halfH), 5, 5).contains(pos)) { // top-middle handle return 2; } else if (QRectF(center.x() + (halfW - 4), center.y() - (halfH), 5, 5).contains(pos)) { // top-right return 3; } else if (QRectF(center.x() + (halfW - 4), center.y() - 2, 5, 5).contains(pos)) { // middle-right return 4; } else if (QRectF(center.x() + (halfW - 4), center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-left return 5; } else if (QRectF(center.x() - 2, center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-middle return 6; } else if (QRectF(center.x() - (halfW), center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-right return 7; } else if (QRectF(center.x() - (halfW), center.y() - 2, 5, 5).contains(pos)) { // middle-right return 8; } return 0; } QVariant KReportDesignerItemRectBase::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange && scene()) { QPointF newPos = value.toPointF(); newPos = dynamic_cast(scene())->gridPoint(newPos); if (newPos.x() < 0) newPos.setX(0); else if (newPos.x() > (scene()->width() - rect().width())) newPos.setX(scene()->width() - rect().width()); if (newPos.y() < 0) newPos.setY(0); else if (newPos.y() > (scene()->height() - rect().height())) newPos.setY(scene()->height() - rect().height()); return newPos; } else if (change == ItemPositionHasChanged && scene()) { - m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); - } else if (change == ItemSceneHasChanged && scene() && m_psize) { + item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); + //TODO dont update property + //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); + } else if (change == ItemSceneHasChanged && scene() && item()) { QPointF newPos = pos(); newPos = dynamic_cast(scene())->gridPoint(newPos); if (newPos.x() < 0) newPos.setX(0); else if (newPos.x() > (scene()->width() - rect().width())) newPos.setX(scene()->width() - rect().width()); if (newPos.y() < 0) newPos.setY(0); else if (newPos.y() > (scene()->height() - rect().height())) newPos.setY(scene()->height() - rect().height()); - setSceneRect(newPos, m_psize->toScene(), KReportDesignerItemRectBase::DontUpdateProperty); + setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); } return QGraphicsItem::itemChange(change, value); } void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) { Q_UNUSED(s) if (p.name() == "position") { - m_ppos->setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); + item()->setPosition(p.value().toPointF()); //TODO dont update property } else if (p.name() == "size") { - m_psize->setUnitSize(p.value().toSizeF(), KReportSize::DontUpdateProperty); + item()->setSize(p.value().toSizeF()); //TODO dont update property } - setSceneRect(m_ppos->toScene(), m_psize->toScene(), DontUpdateProperty); + setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()), DontUpdateProperty); } void KReportDesignerItemRectBase::move(const QPointF& /*m*/) { //! @todo } QPointF KReportDesignerItemRectBase::properPressPoint(const KReportDesigner &d) const { const QPointF pressPoint = d.getPressPoint(); const QPointF releasePoint = d.getReleasePoint(); if (releasePoint.x() < pressPoint.x() && releasePoint.y() < pressPoint.y()) { return releasePoint; } if (releasePoint.x() < pressPoint.x() && releasePoint.y() > pressPoint.y()) { return QPointF(releasePoint.x(), pressPoint.y()); } if (releasePoint.x() > pressPoint.x() && releasePoint.y() < pressPoint.y()) { return QPointF(pressPoint.x(), releasePoint.y()); } return QPointF(pressPoint); } QRectF KReportDesignerItemRectBase::properRect(const KReportDesigner &d, qreal minWidth, qreal minHeight) const { QPointF tempPressPoint = properPressPoint(d); qreal currentPressX = tempPressPoint.x(); qreal currentPressY = tempPressPoint.y(); const qreal width = qMax(d.countSelectionWidth(), minWidth); const qreal height = qMax(d.countSelectionHeight(), minHeight); qreal tempReleasePointX = tempPressPoint.x() + width; qreal tempReleasePointY = tempPressPoint.y() + height; if (tempReleasePointX > scene()->width()) { int offsetWidth = tempReleasePointX - scene()->width(); currentPressX = tempPressPoint.x() - offsetWidth; } if (tempReleasePointY > scene()->height()) { int offsetHeight = tempReleasePointY - scene()->height(); currentPressY = tempPressPoint.y() - offsetHeight; } return (QRectF(QPointF(currentPressX, currentPressY), QSizeF(width, height))); } void KReportDesignerItemRectBase::enterInlineEditingMode() { } void KReportDesignerItemRectBase::exitInlineEditingMode() { } void KReportDesignerItemBase::updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType) { if (itemDataSource.isEmpty()) { if (itemType.isEmpty()) { - m_renderText = itemStaticValue; + setRenderText(itemStaticValue); } else { - m_renderText = dataSourceAndObjectTypeName(itemStaticValue, itemType); + setRenderText(dataSourceAndObjectTypeName(itemStaticValue, itemType)); } } else { if (itemType.isEmpty()) { - m_renderText = itemDataSource; + setRenderText(itemDataSource); } else { - m_renderText = dataSourceAndObjectTypeName(itemDataSource, itemType); + setRenderText(dataSourceAndObjectTypeName(itemDataSource, itemType)); } } } diff --git a/src/wrtembed/KReportDesignerItemRectBase.h b/src/wrtembed/KReportDesignerItemRectBase.h index 69df0118..52eb029a 100644 --- a/src/wrtembed/KReportDesignerItemRectBase.h +++ b/src/wrtembed/KReportDesignerItemRectBase.h @@ -1,92 +1,87 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTDESIGNERITEMRECTBASE_H #define KREPORTDESIGNERITEMRECTBASE_H #include #include "KReportDesignerItemBase.h" #include "kreport_export.h" class KReportDesigner; class KReportPosition; class KReportSize; class KPropertySet; const int KREPORT_ITEM_RECT_DEFAULT_WIDTH = 100; const int KREPORT_ITEM_RECT_DEFAULT_HEIGHT = 100; /** */ class KREPORT_EXPORT KReportDesignerItemRectBase : public QGraphicsRectItem, public KReportDesignerItemBase { public: - explicit KReportDesignerItemRectBase(KReportDesigner*); + explicit KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b); virtual ~KReportDesignerItemRectBase(); QRectF pointRect() const; virtual void enterInlineEditingMode(); virtual void exitInlineEditingMode(); protected: - void init(KReportPosition*, KReportSize*, KPropertySet*, KReportDesigner *r); - int m_dpiX; int m_dpiY; qreal m_userHeight; qreal m_userWidth; qreal m_pressX; qreal m_pressY; enum UpdatePropertyFlag { UpdateProperty, DontUpdateProperty }; void setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update = UpdateProperty); void setSceneRect(const QRectF& rect, UpdatePropertyFlag update = UpdateProperty); void drawHandles(QPainter*); QRectF sceneRect(); virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent * event); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); void propertyChanged(const KPropertySet &s, const KProperty &p); virtual void move(const QPointF&); QRectF properRect(const KReportDesigner &d, qreal minWidth, qreal minHeight) const; private: int grabHandle(QPointF); QPointF properPressPoint(const KReportDesigner &d) const; - int m_grabAction; - - KReportPosition* m_ppos; - KReportSize* m_psize; - KPropertySet* m_pset; + class Private; + Private * const d; }; #endif diff --git a/src/wrtembed/KReportDesignerSection.cpp b/src/wrtembed/KReportDesignerSection.cpp index 9f5cc9c6..aa897f47 100644 --- a/src/wrtembed/KReportDesignerSection.cpp +++ b/src/wrtembed/KReportDesignerSection.cpp @@ -1,426 +1,427 @@ /* 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) * Copyright (C) 2014 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 "KReportDesignerSection.h" #include "KReportDesignerSectionScene.h" #include "KReportDesignerSectionView.h" #include "KReportDesigner.h" #include "KReportDesignerItemBase.h" #include "KReportUtils.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportDesignerItemRectBase.h" #include "KReportDesignerItemLine.h" #include "KReportRuler_p.h" #include "KReportZoomHandler.h" #include "KReportDpi.h" #include "KReportPluginMetaData.h" #include "kreport_debug.h" #include #include #include #include #include #include #include #include #include //! @internal class ReportResizeBar : public QFrame { Q_OBJECT public: explicit ReportResizeBar(QWidget * parent = 0, Qt::WindowFlags f = 0); Q_SIGNALS: void barDragged(int delta); protected: void mouseMoveEvent(QMouseEvent * e); }; //! @internal class KReportDesignerSectionTitle : public QLabel { Q_OBJECT public: explicit KReportDesignerSectionTitle(QWidget *parent = 0); ~KReportDesignerSectionTitle(); Q_SIGNALS: void clicked(); protected: virtual void paintEvent(QPaintEvent* event); virtual void mousePressEvent(QMouseEvent *event); }; //! @internal class Q_DECL_HIDDEN KReportDesignerSection::Private { public: explicit Private() {} ~Private() {} KReportDesignerSectionTitle *title; KReportDesignerSectionScene *scene; ReportResizeBar *resizeBar; KReportDesignerSectionView *sceneView; KReportDesigner*reportDesigner; KReportRuler *sectionRuler; KReportSectionData *sectionData; int dpiY; }; KReportDesignerSection::KReportDesignerSection(KReportDesigner * rptdes) : QWidget(rptdes) , d(new Private()) { Q_ASSERT(rptdes); d->sectionData = new KReportSectionData(this); connect(d->sectionData->propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); d->dpiY = KReportDpi::dpiY(); d->reportDesigner = rptdes; setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QGridLayout * glayout = new QGridLayout(this); glayout->setSpacing(0); glayout->setMargin(0); glayout->setColumnStretch(1, 1); glayout->setRowStretch(1, 1); glayout->setSizeConstraint(QLayout::SetFixedSize); // ok create the base interface d->title = new KReportDesignerSectionTitle(this); d->title->setObjectName(QLatin1String("detail")); d->title->setText(tr("Detail")); d->sectionRuler = new KReportRuler(this, Qt::Vertical, d->reportDesigner->zoomHandler()); d->sectionRuler->setUnit(d->reportDesigner->pageUnit()); d->scene = new KReportDesignerSectionScene(d->reportDesigner->pageWidthPx(), d->dpiY, rptdes); d->scene->setBackgroundBrush(d->sectionData->backgroundColor()); d->sceneView = new KReportDesignerSectionView(rptdes, d->scene, this); d->sceneView->setObjectName(QLatin1String("scene view")); d->sceneView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); d->resizeBar = new ReportResizeBar(this); connect(d->resizeBar, SIGNAL(barDragged(int)), this, SLOT(slotResizeBarDragged(int))); connect(d->reportDesigner, SIGNAL(pagePropertyChanged(KPropertySet&)), this, SLOT(slotPageOptionsChanged(KPropertySet&))); connect(d->scene, SIGNAL(clicked()), this, (SLOT(slotSceneClicked()))); connect(d->scene, SIGNAL(lostFocus()), d->title, SLOT(update())); connect(d->title, SIGNAL(clicked()), this, (SLOT(slotSceneClicked()))); glayout->addWidget(d->title, 0, 0, 1, 2); glayout->addWidget(d->sectionRuler, 1, 0); glayout->addWidget(d->sceneView , 1, 1); glayout->addWidget(d->resizeBar, 2, 0, 1, 2); d->sectionRuler->setFixedWidth(d->sectionRuler->sizeHint().width()); setLayout(glayout); slotResizeBarDragged(0); } KReportDesignerSection::~KReportDesignerSection() { delete d; } void KReportDesignerSection::setTitle(const QString & s) { d->title->setText(s); } void KReportDesignerSection::slotResizeBarDragged(int delta) { if (d->sceneView->designer() && d->sceneView->designer()->propertySet()->property("page-size").value().toString() == QLatin1String("Labels")) { return; // we don't want to allow this on reports that are for labels } slotSceneClicked(); // switches property set to this section qreal h = d->scene->height() + delta; if (h < 1) h = 1; h = d->scene->gridPoint(QPointF(0, h)).y(); d->sectionData->m_height->setValue(INCH_TO_POINT(h/d->dpiY)); d->sectionRuler->setRulerLength(h); d->scene->setSceneRect(0, 0, d->scene->width(), h); d->sceneView->resizeContents(QSize(d->scene->width(), h)); d->reportDesigner->setModified(true); } void KReportDesignerSection::buildXML(QDomDocument *doc, QDomElement *section) { KReportUtils::setAttribute(section, QLatin1String("svg:height"), d->sectionData->m_height->value().toDouble()); section->setAttribute(QLatin1String("fo:background-color"), d->sectionData->backgroundColor().name()); // now get a list of all the QGraphicsItems on this scene and output them. QGraphicsItemList list = d->scene->items(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); ++it) { KReportDesignerItemBase::buildXML((*it), doc, section); } } void KReportDesignerSection::initFromXML(const QDomNode & section) { QDomNodeList nl = section.childNodes(); QDomNode node; QString n; qreal h = KReportUnit::parseValue(section.toElement().attribute(QLatin1String("svg:height"), QLatin1String("2.0cm"))); d->sectionData->m_height->setValue(h); h = POINT_TO_INCH(h) * d->dpiY; //kreportDebug() << "Section Height: " << h; d->scene->setSceneRect(0, 0, d->scene->width(), h); slotResizeBarDragged(0); d->sectionData->m_backgroundColor->setValue(QColor(section.toElement().attribute(QLatin1String("fo:background-color"), QLatin1String("#ffffff")))); for (int i = 0; i < nl.count(); ++i) { node = nl.item(i); n = node.nodeName(); if (n.startsWith(QLatin1String("report:"))) { //Load objects //report:line is a special case as it is not a plugin QString reportItemName = n.mid(qstrlen("report:")); if (reportItemName == QLatin1String("line")) { (new KReportDesignerItemLine(node, d->sceneView->designer(), d->scene))->setVisible(true); continue; } KReportPluginManager* manager = KReportPluginManager::self(); KReportPluginInterface *plugin = manager->plugin(reportItemName); if (plugin) { QObject *obj = plugin->createDesignerInstance(node, d->reportDesigner, d->scene); if (obj) { KReportDesignerItemRectBase *entity = dynamic_cast(obj); if (entity) { entity->setVisible(true); } KReportItemBase *item = dynamic_cast(obj); if (item) { + item->setUnit(d->reportDesigner->pageUnit()); KReportDesigner::addMetaProperties(item->propertySet(), plugin->metaData()->name(), plugin->metaData()->iconName()); } continue; } } } kreportWarning() << "Encountered unknown node while parsing section: " << n; } } QSize KReportDesignerSection::sizeHint() const { return QSize(d->scene->width() + d->sectionRuler->frameSize().width(), d->title->frameSize().height() + d->sceneView->sizeHint().height() + d->resizeBar->frameSize().height()); } void KReportDesignerSection::slotPageOptionsChanged(KPropertySet &set) { Q_UNUSED(set) KReportUnit unit = d->reportDesigner->pageUnit(); d->sectionData->m_height->setOption("unit", unit.symbol()); //update items position with unit QList itms = d->scene->items(); for (int i = 0; i < itms.size(); ++i) { KReportItemBase *obj = dynamic_cast(itms[i]); if (obj) { obj->setUnit(unit); } } d->scene->setSceneRect(0, 0, d->reportDesigner->pageWidthPx(), d->scene->height()); d->title->setMinimumWidth(d->reportDesigner->pageWidthPx() + d->sectionRuler->frameSize().width()); d->sectionRuler->setUnit(d->reportDesigner->pageUnit()); //Trigger a redraw of the background d->sceneView->resetCachedContent(); d->reportDesigner->adjustSize(); d->reportDesigner->repaint(); slotResizeBarDragged(0); } void KReportDesignerSection::slotSceneClicked() { d->reportDesigner->setActiveScene(d->scene); d->reportDesigner->changeSet(d->sectionData->propertySet()); } void KReportDesignerSection::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s) //kreportDebug() << p.name(); //Handle Background Color if (p.name() == "background-color") { d->scene->setBackgroundBrush(p.value().value()); } if (p.name() == "height") { d->scene->setSceneRect(0, 0, d->scene->width(), POINT_TO_INCH(p.value().toDouble()) * d->dpiY); slotResizeBarDragged(0); } if (d->reportDesigner) d->reportDesigner->setModified(true); d->sceneView->resetCachedContent(); d->scene->update(); } void KReportDesignerSection::setSectionCursor(const QCursor& c) { if (d->sceneView) d->sceneView->setCursor(c); } void KReportDesignerSection::unsetSectionCursor() { if (d->sceneView) d->sceneView->unsetCursor(); } QGraphicsItemList KReportDesignerSection::items() const { QGraphicsItemList items; if (d->scene) { foreach (QGraphicsItem *itm, d->scene->items()) { if (itm->parentItem() == 0) { items << itm; } } } return items; } // // class ReportResizeBar // ReportResizeBar::ReportResizeBar(QWidget * parent, Qt::WindowFlags f) : QFrame(parent, f) { setCursor(QCursor(Qt::SizeVerCursor)); setFrameStyle(QFrame::HLine); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); } void ReportResizeBar::mouseMoveEvent(QMouseEvent * e) { e->accept(); emit barDragged(e->y()); } //============================================================================= KReportDesignerSectionTitle::KReportDesignerSectionTitle(QWidget*parent) : QLabel(parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setAlignment(Qt::AlignLeft | Qt::AlignTop); setMinimumHeight(qMax(fontMetrics().lineSpacing(),16 + 2)); //16 = Small icon size } KReportDesignerSectionTitle::~KReportDesignerSectionTitle() { } //! \return true if \a o has parent \a par. static bool hasParent(QObject* par, QObject* o) { if (!o || !par) return false; while (o && o != par) o = o->parent(); return o == par; } static void replaceColors(QPixmap* original, const QColor& color) { QImage dest(original->toImage()); QPainter p(&dest); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(dest.rect(), color); *original = QPixmap::fromImage(dest); } void KReportDesignerSectionTitle::paintEvent(QPaintEvent * event) { QPainter painter(this); KReportDesignerSection* _section = dynamic_cast(parent()); const bool current = _section->d->scene == _section->d->reportDesigner->activeScene(); QPalette::ColorGroup cg = QPalette::Inactive; QWidget *activeWindow = QApplication::activeWindow(); if (activeWindow) { QWidget *par = activeWindow->focusWidget(); if (qobject_cast(par)) { par = par->parentWidget(); // we're close, pick common parent } if (hasParent(par, this)) { cg = QPalette::Active; } } if (current) { painter.fillRect(rect(), palette().brush(cg, QPalette::Highlight)); } painter.setPen(palette().color(cg, current ? QPalette::HighlightedText : QPalette::WindowText)); QPixmap pixmap(QIcon::fromTheme(QLatin1String("arrow-down")).pixmap(16,16)); replaceColors(&pixmap, painter.pen().color()); const int left = 25; painter.drawPixmap(QPoint(left, (height() - pixmap.height()) / 2), pixmap); painter.drawText(rect().adjusted(left + pixmap.width() + 4, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, text()); QFrame::paintEvent(event); } void KReportDesignerSectionTitle::mousePressEvent(QMouseEvent *event) { QLabel::mousePressEvent(event); if (event->button() == Qt::LeftButton) { emit clicked(); } } #include "KReportDesignerSection.moc"