diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp index 385f7ce2..f11b0f43 100644 --- a/src/items/check/KReportItemCheck.cpp +++ b/src/items/check/KReportItemCheck.cpp @@ -1,192 +1,192 @@ /* This file is part of the KDE project * Copyright (C) 2009-2010 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemCheck.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #ifdef KREPORT_SCRIPTING #include "renderer/scripting/KReportScriptHandler.h" #endif #include #include #include KReportItemCheckBox::KReportItemCheckBox() { createProperties(); } KReportItemCheckBox::KReportItemCheckBox(const QDomNode &element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_foregroundColor->setValue(QColor(element.toElement().attribute(QLatin1String("fo:foreground-color")))); m_checkStyle->setValue(element.toElement().attribute(QLatin1String("report:check-style"))); m_staticValue->setValue(QVariant(element.toElement().attribute(QLatin1String("report:value"))).toBool()); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing check element encountered unknow element: " << n; } } } KReportItemCheckBox::~KReportItemCheckBox() { } void KReportItemCheckBox::createProperties() { QStringList keys, strings; keys << QLatin1String("Cross") << QLatin1String("Tick") << QLatin1String("Dot"); strings << tr("Cross") << tr("Tick") << tr("Dot"); m_checkStyle = new KProperty("check-style", keys, strings, QLatin1String("Cross"), tr("Style")); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); - m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); + m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::SolidLine), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_staticValue = new KProperty("value", QVariant(false), tr("Value"), tr("Value used if not bound to a field")); propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_staticValue); propertySet()->addProperty(m_checkStyle); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemCheckBox::lineStyle() { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } QString KReportItemCheckBox::itemDataSource() const { return m_controlSource->value().toString(); } // RTTI QString KReportItemCheckBox::typeName() const { return QLatin1String("check"); } int KReportItemCheckBox::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROCheckBox *chk = new OROCheckBox(); chk->setPosition(scenePosition(position()) + offset); chk->setSize(sceneSize(size())); chk->setLineStyle(lineStyle()); chk->setForegroundColor(m_foregroundColor->value().value()); if (m_checkStyle->value().toString() == QLatin1String("Cross")) { chk->setCheckType(OROCheckBox::Cross); } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) { chk->setCheckType(OROCheckBox::Dot); } else { chk->setCheckType(OROCheckBox::Tick); } QString str; bool v = false; QString cs = itemDataSource(); //kreportpluginDebug() << "ControlSource:" << cs; if (!cs.isEmpty()) { #ifdef KREPORT_SCRIPTING if (cs.left(1) == QLatin1String("=") && script) { str = script->evaluate(cs.mid(1)).toString(); } else #else Q_UNUSED(script); #endif { str = data.toString(); } str = str.toLower(); //kreportpluginDebug() << "Check Value:" << str; if (str == QLatin1String("t") || str == QLatin1String("y") || str == QLatin1String("true") || str == QLatin1String("1")) v = true; } else { v = value(); } chk->setValue(v); if (page) { page->insertPrimitive(chk); } if (section) { OROCheckBox *chk2 = dynamic_cast(chk->clone()); chk2->setPosition(scenePosition(position())); section->addPrimitive(chk2); } if (!page) { delete chk; } return 0; //Item doesn't stretch the section height } bool KReportItemCheckBox::value() const { return m_staticValue->value().toBool(); } void KReportItemCheckBox::setValue(bool v) { m_staticValue->setValue(v); } diff --git a/src/items/field/KReportItemField.cpp b/src/items/field/KReportItemField.cpp index 0f737d5e..054815d5 100644 --- a/src/items/field/KReportItemField.cpp +++ b/src/items/field/KReportItemField.cpp @@ -1,287 +1,287 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemField.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #ifdef KREPORT_SCRIPTING #include "renderer/scripting/KReportScriptHandler.h" #endif #include #include #include #include #include KReportItemField::KReportItemField() { createProperties(); } KReportItemField::KReportItemField(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); m_canGrow->setValue(element.toElement().attribute(QLatin1String("report:can-grow"))); m_wordWrap->setValue(element.toElement().attribute(QLatin1String("report:word-wrap"))); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; } } } KReportItemField::~KReportItemField() { } void KReportItemField::createProperties() { QStringList keys, strings; m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); - m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); + m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_wordWrap = new KProperty("word-wrap", QVariant(false), tr("Word Wrap")); m_canGrow = new KProperty("can-grow", QVariant(false), tr("Can Grow")); //! @todo I do not think we need these #if 0 //Field Totals m_trackTotal = new KProperty("trackTotal", QVariant(false), futureI18n("Track Total")); m_trackBuiltinFormat = new KProperty("trackBuiltinFormat", QVariant(false), futureI18n("Track Builtin Format")); _useSubTotal = new KProperty("useSubTotal", QVariant(false), futureI18n("Use Sub Total"_)); _trackTotalFormat = new KProperty("trackTotalFormat", QString(), futureI18n("Track Total Format")); #endif propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); propertySet()->addProperty(m_wordWrap); propertySet()->addProperty(m_canGrow); //_set->addProperty ( _trackTotal ); //_set->addProperty ( _trackBuiltinFormat ); //_set->addProperty ( _useSubTotal ); //_set->addProperty ( _trackTotalFormat ); } int KReportItemField::textFlags() const { int flags; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) flags = Qt::AlignHCenter; else if (t == QLatin1String("right")) flags = Qt::AlignRight; else flags = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) flags |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) flags |= Qt::AlignBottom; else flags |= Qt::AlignTop; if (m_wordWrap->value().toBool() == true) { flags |= Qt::TextWordWrap; } return flags; } KRTextStyleData KReportItemField::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } QString KReportItemField::itemDataSource() const { return m_controlSource->value().toString(); } void KReportItemField::setItemDataSource(const QString& t) { if (m_controlSource->value() != t) { m_controlSource->setValue(t); } //kreportpluginDebug() << "Field: " << entityName() << "is" << itemDataSource(); } KReportLineStyle KReportItemField::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemField::typeName() const { return QLatin1String("field"); } int KReportItemField::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); tb->setCanGrow(m_canGrow->value().toBool()); tb->setWordWrap(m_wordWrap->value().toBool()); QString str; QString ids = itemDataSource(); if (!ids.isEmpty()) { #ifdef KREPORT_SCRIPTING if (ids.left(1) == QLatin1String("=") && script) { //Everything after = is treated as code if (!ids.contains(QLatin1String("PageTotal()"))) { QVariant v = script->evaluate(ids.mid(1)); str = v.toString(); } else { str = ids.mid(1); tb->setRequiresPostProcessing(true); } } else #else Q_UNUSED(script); #endif if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string str = ids.mid(1); } else { str = data.toString(); } } else { str = m_itemValue->value().toString(); } tb->setText(str); //Work out the size of the text if (tb->canGrow()) { QRect r; if (tb->wordWrap()) { //Grow vertically QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), tb->size().width(), 5000); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } else { //Grow Horizontally QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), 5000, tb->size().height()); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } tb->setSize(r.size() + QSize(4,4)); } if (page) { page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } int height = scenePosition(position()).y() + tb->size().height(); //If there is no page to add the item to, delete it now because it wont be deleted later if (!page) { delete tb; } return height; } diff --git a/src/items/label/KReportItemLabel.cpp b/src/items/label/KReportItemLabel.cpp index 68f1a561..99dc2885 100644 --- a/src/items/label/KReportItemLabel.cpp +++ b/src/items/label/KReportItemLabel.cpp @@ -1,208 +1,208 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemLabel.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include KReportItemLabel::KReportItemLabel() { createProperties(); } KReportItemLabel::KReportItemLabel(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_text->setValue(element.toElement().attribute(QLatin1String("report:caption"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing label element encountered unknow element: " << n; } } } KReportItemLabel::~KReportItemLabel() { } QString KReportItemLabel::text() const { return m_text->value().toString(); } void KReportItemLabel::setText(const QString& t) { m_text->setValue(t); } void KReportItemLabel::createProperties() { m_text = new KProperty("caption", QLatin1String("Label"), tr("Caption")); QStringList keys, strings; keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); - m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); + m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); propertySet()->addProperty(m_text); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } Qt::Alignment KReportItemLabel::textFlags() const { Qt::Alignment align; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) align = Qt::AlignHCenter; else if (t == QLatin1String("right")) align = Qt::AlignRight; else align = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) align |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) align |= Qt::AlignBottom; else align |= Qt::AlignTop; return align; } KRTextStyleData KReportItemLabel::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemLabel::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemLabel::typeName() const { return QLatin1String("label"); } int KReportItemLabel::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(data) Q_UNUSED(script) OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setText(text()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } if (!page) { delete tb; } return 0; //Item doesn't stretch the section height } diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp index bcbdb294..48ba4202 100644 --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -1,315 +1,315 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemText.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include #include #include KReportItemText::KReportItemText() : KReportItemText(QDomNode()) { } KReportItemText::KReportItemText(const QDomNode & element) : m_bottomPadding(0.0) { QDomNodeList nl = element.childNodes(); QString n; QDomNode node; createProperties(); nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); m_bottomPadding = element.toElement().attribute(QLatin1String("report:bottom-padding")).toDouble(); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; } } } KReportItemText::~KReportItemText() { } Qt::Alignment KReportItemText::textFlags() const { Qt::Alignment align; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) align = Qt::AlignHCenter; else if (t == QLatin1String("right")) align = Qt::AlignRight; else align = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) align |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) align |= Qt::AlignBottom; else align |= Qt::AlignTop; return align; } void KReportItemText::createProperties() { //connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) ); QStringList keys, strings; //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" ); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); - m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); + m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } QString KReportItemText::itemDataSource() const { return m_controlSource->value().toString(); } qreal KReportItemText::bottomPadding() const { return m_bottomPadding; } void KReportItemText::setBottomPadding(qreal bp) { if (m_bottomPadding != bp) { m_bottomPadding = bp; } } KRTextStyleData KReportItemText::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemText::lineStyle() const { KReportLineStyle ls; ls.setWidth(m_lineWeight->value().toInt()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemText::typeName() const { return QLatin1String("text"); } int KReportItemText::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script); QString qstrValue; QString cs = itemDataSource(); if (!cs.isEmpty()) { if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string qstrValue = cs.mid(1); } else { qstrValue = data.toString(); } } else { qstrValue = m_itemValue->value().toString(); } QPointF pos = scenePosition(position()); QSizeF siz = sceneSize(size()); pos += offset; QRectF trf(pos, siz); qreal intStretch = trf.top() - offset.y(); if (qstrValue.length()) { QRectF rect = trf; int pos = 0; QChar separator; QRegExp re(QLatin1String("\\s")); QPrinter prnt(QPrinter::HighResolution); QFontMetrics fm(font(), &prnt); // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; int intRectWidth = (int)((size().width() / 72) * prnt.resolution()); int intLineCounter = 0; qreal intBaseTop = trf.top(); qreal intRectHeight = trf.height(); while (qstrValue.length()) { int idx = re.indexIn(qstrValue, pos); if (idx == -1) { idx = qstrValue.length(); separator = QLatin1Char('\n'); } else separator = qstrValue.at(idx); if (fm.boundingRect(qstrValue.left(idx)).width() < intRectWidth || pos == 0) { pos = idx + 1; if (separator == QLatin1Char('\n')) { QString line = qstrValue.left(idx); qstrValue.remove(0, idx + 1); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->insertPrimitive(tb); } if (section) { OROTextBox *tb2 = dynamic_cast(tb->clone()); tb2->setPosition(scenePosition(position())); section->addPrimitive(tb2); } if (!page) { delete tb; } intStretch += intRectHeight; intLineCounter++; } } else { QString line = qstrValue.left(pos - 1); qstrValue.remove(0, pos); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->insertPrimitive(tb); } else { delete tb; } intStretch += intRectHeight; intLineCounter++; } } intStretch += (m_bottomPadding / 100.0); } return intStretch; //Item returns its required section height }