18#include "KReportItemField.h"
19#include "KReportRenderObjects.h"
20#include "KReportUtils.h"
21#include "kreportplugin_debug.h"
22#ifdef KREPORT_SCRIPTING
23#include "KReportScriptHandler.h"
26#include <KPropertyListData>
27#include <KPropertySet>
30#include <QDomNodeList>
31#include <QFontMetrics>
32#include <QApplication>
34KReportItemField::KReportItemField()
39KReportItemField::KReportItemField(
const QDomNode & element)
42 nameProperty()->setValue(KReportUtils::readNameAttribute(element.
toElement()));
48 KReportUtils::setPropertyValue(m_canGrow, element.
toElement());
49 KReportUtils::setPropertyValue(m_wordWrap, element.
toElement());
56 for (
int i = 0; i < nl.
count(); i++) {
61 KReportTextStyleData ts;
62 if (parseReportTextStyleData(node.
toElement(), &ts)) {
63 m_backgroundColor->setValue(ts.backgroundColor);
64 m_foregroundColor->setValue(ts.foregroundColor);
65 m_backgroundOpacity->setValue(ts.backgroundOpacity);
66 m_font->setValue(ts.font);
71 if (parseReportLineStyleData(node.
toElement(), &ls)) {
72 m_lineWeight->setValue(ls.
weight());
73 m_lineColor->setValue(ls.
color());
74 m_lineStyle->setValue(
static_cast<int>(ls.
penStyle()));
77 kreportpluginWarning() <<
"while parsing field element encountered unknown element: " << n;
82KReportItemField::~KReportItemField()
86void KReportItemField::createProperties()
88 createDataSourceProperty();
90 m_itemValue =
new KProperty(
"value", QString(),
tr(
"Value"),
tr(
"Value used if not bound to a field"));
92 KPropertyListData *listData =
new KPropertyListData(
93 { QLatin1String(
"left"), QLatin1String(
"center"), QLatin1String(
"right") },
94 QVariantList{
tr(
"Left"),
tr(
"Center"),
tr(
"Right") });
95 m_horizontalAlignment =
new KProperty(
"horizontal-align", listData, QLatin1String(
"left"),
96 tr(
"Horizontal Alignment"));
98 listData =
new KPropertyListData(
99 { QLatin1String(
"top"), QLatin1String(
"center"), QLatin1String(
"bottom") },
100 QVariantList{
tr(
"Top"),
tr(
"Center"),
tr(
"Bottom") });
101 m_verticalAlignment =
new KProperty(
"vertical-align", listData, QLatin1String(
"center"),
102 tr(
"Vertical Alignment"));
106 m_backgroundColor =
new KProperty(
"background-color", QColor(
Qt::white),
tr(
"Background Color"));
107 m_foregroundColor =
new KProperty(
"foreground-color", QColor(
Qt::black),
tr(
"Foreground Color"));
109 m_backgroundOpacity =
new KProperty(
"background-opacity", QVariant(0),
tr(
"Background Opacity"));
110 m_backgroundOpacity->setOption(
"max", 100);
111 m_backgroundOpacity->setOption(
"min", 0);
112 m_backgroundOpacity->setOption(
"suffix", QLatin1String(
"%"));
114 m_lineWeight =
new KProperty(
"line-weight", 1.0,
tr(
"Line Weight"));
115 m_lineWeight->setOption(
"step", 1.0);
116 m_lineColor =
new KProperty(
"line-color", QColor(
Qt::black),
tr(
"Line Color"));
119 m_wordWrap =
new KProperty(
"word-wrap", QVariant(
false),
tr(
"Word Wrap"));
120 m_canGrow =
new KProperty(
"can-grow", QVariant(
false),
tr(
"Can Grow"));
124 m_trackTotal =
new KProperty(
"trackTotal", QVariant(
false), futureI18n(
"Track Total"));
125 m_trackBuiltinFormat =
new KProperty(
"trackBuiltinFormat", QVariant(
false), futureI18n(
"Track Builtin Format"));
126 _useSubTotal =
new KProperty(
"useSubTotal", QVariant(
false), futureI18n(
"Use Sub Total"_));
127 _trackTotalFormat =
new KProperty(
"trackTotalFormat", QString(), futureI18n(
"Track Total Format"));
130 propertySet()->addProperty(m_itemValue);
131 propertySet()->addProperty(m_horizontalAlignment);
132 propertySet()->addProperty(m_verticalAlignment);
133 propertySet()->addProperty(m_font);
134 propertySet()->addProperty(m_backgroundColor);
135 propertySet()->addProperty(m_foregroundColor);
136 propertySet()->addProperty(m_backgroundOpacity);
137 propertySet()->addProperty(m_lineWeight);
138 propertySet()->addProperty(m_lineColor);
139 propertySet()->addProperty(m_lineStyle);
140 propertySet()->addProperty(m_wordWrap);
141 propertySet()->addProperty(m_canGrow);
149int KReportItemField::textFlags()
const
153 t = m_horizontalAlignment->value().toString();
154 if (t == QLatin1String(
"center"))
156 else if (t == QLatin1String(
"right"))
161 t = m_verticalAlignment->value().toString();
162 if (t == QLatin1String(
"center"))
164 else if (t == QLatin1String(
"bottom"))
169 if (m_wordWrap->value().toBool() ==
true) {
175KReportTextStyleData KReportItemField::textStyle()
const
177 KReportTextStyleData d;
178 d.backgroundColor = m_backgroundColor->value().value<QColor>();
179 d.foregroundColor = m_foregroundColor->value().value<QColor>();
180 d.font = m_font->value().value<QFont>();
181 d.backgroundOpacity = m_backgroundOpacity->value().toInt();
189 ls.setWeight(m_lineWeight->value().toReal());
190 ls.setColor(m_lineColor->value().value<QColor>());
191 ls.setPenStyle((
Qt::PenStyle)m_lineStyle->value().toInt());
195QString KReportItemField::typeName()
const
197 return QLatin1String(
"field");
201 const QVariant &data, KReportScriptHandler *script)
203 OROTextBox * tb =
new OROTextBox();
207 tb->setFlags(textFlags());
208 tb->setTextStyle(textStyle());
209 tb->setLineStyle(lineStyle());
210 tb->setCanGrow(m_canGrow->value().toBool());
211 tb->setWordWrap(m_wordWrap->value().toBool());
217#ifdef KREPORT_SCRIPTING
218 if (ids.
left(1) == QLatin1String(
"=") && script) {
219 if (!ids.
contains(QLatin1String(
"PageTotal()"))) {
220 QVariant v = script->evaluate(ids.
mid(1));
224 tb->setRequiresPostProcessing(
true);
232 str = m_itemValue->value().toString();
240 if (tb->wordWrap()) {
242 QFontMetricsF metrics(font());
243 QRectF temp(tb->position().
x(), tb->position().
y(), tb->size().
width(), 5000);
244 r = metrics.boundingRect(temp, tb->flags(), str);
247 QFontMetricsF metrics(font());
248 QRectF temp(tb->position().
x(), tb->position().
y(), 5000, tb->size().
height());
249 r = metrics.boundingRect(temp, tb->flags(), str);
251 tb->setSize(r.
size() + QSize(4,4));
255 page->insertPrimitive(tb);
259 OROPrimitive *clone = tb->clone();
261 section->addPrimitive(clone);
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
QPointF position() const
Return the position in points.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
QSizeF size() const
Return the size in points.
QString itemDataSource() const
The KReportLineStyle class represents line style.
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Represents a single a single row in a document and may contain zero or more OROPrimitives.
QString attribute(const QString &name, const QString &defValue) const const
QDomNodeList childNodes() const const
QString nodeName() const const
QDomElement toElement() const const
QDomNode item(int index) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QSizeF size() const const
qreal height() const const
qreal width() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString left(qsizetype n) const const
QString mid(qsizetype position, qsizetype n) const const
QString toString() const const