3
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
#include "krfielddata.h"
21
#include <klocalizedstring.h>
22
#include <kglobalsettings.h>
23
#include <koproperty/Set.h>
25
KRFieldData::~KRFieldData()
29
KRFieldData::KRFieldData(QDomNode & element)
32
QDomNodeList nl = element.childNodes();
36
m_name->setValue(element.toElement().attribute("report:name"));
37
m_controlSource->setValue(element.toElement().attribute("report:item-data-source"));
38
Z = element.toElement().attribute("report:z-index").toDouble();
39
m_horizontalAlignment->setValue(element.toElement().attribute("report:horizontal-align"));
40
m_verticalAlignment->setValue(element.toElement().attribute("report:vertical-align"));
42
parseReportRect(element.toElement(), &m_pos, &m_size);
44
for (int i = 0; i < nl.count(); i++) {
48
if (n == "report:text-style") {
50
if (parseReportTextStyleData(node.toElement(), ts)) {
51
m_backgroundColor->setValue(ts.backgroundColor);
52
m_foregroundColor->setValue(ts.foregroundColor);
53
m_backgroundOpacity->setValue(ts.backgroundOpacity);
54
m_font->setValue(ts.font);
57
} else if (n == "report:line-style") {
59
if (parseReportLineStyleData(node.toElement(), ls)) {
60
m_lineWeight->setValue(ls.weight);
61
m_lineColor->setValue(ls.lineColor);
62
m_lineStyle->setValue(ls.style);
65
kDebug() << "while parsing field element encountered unknow element: " << n;
70
void KRFieldData::createProperties()
72
m_set = new KoProperty::Set(0, "Field");
74
QStringList keys, strings;
76
m_controlSource = new KoProperty::Property("item-data-source", QStringList(), QStringList(), QString(), i18n("Data Source"));
78
m_controlSource->setOption("extraValueAllowed", "true");
80
keys << "left" << "center" << "right";
81
strings << i18n("Left") << i18n("Center") << i18n("Right");
82
m_horizontalAlignment = new KoProperty::Property("horizontal-align", keys, strings, "left", i18n("Horizontal Alignment"));
86
keys << "top" << "center" << "bottom";
87
strings << i18n("Top") << i18n("Center") << i18n("Bottom");
88
m_verticalAlignment = new KoProperty::Property("vertical-align", keys, strings, "center", i18n("Vertical Alignment"));
90
m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), "Font", i18n("Font"));
92
m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
93
m_foregroundColor = new KoProperty::Property("foregroud-color", Qt::black, i18n("Foreground Color"));
95
m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Opacity"));
96
m_backgroundOpacity->setOption("max", 100);
97
m_backgroundOpacity->setOption("min", 0);
98
m_backgroundOpacity->setOption("unit", "%");
100
m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
101
m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
102
m_lineStyle = new KoProperty::Property("line-style", Qt::NoPen, i18n("Line Style"), i18n("Line Style"), KoProperty::LineStyle);
105
//TODO I do not think we need these
106
m_trackTotal = new KoProperty::Property("TrackTotal", QVariant(false), i18n("Track Total"));
107
m_trackBuiltinFormat = new KoProperty::Property("TrackBuiltinFormat", QVariant(false), i18n("Track Builtin Format"));
108
_useSubTotal = new KoProperty::Property("UseSubTotal", QVariant(false), i18n("Use Sub Total"_);
109
_trackTotalFormat = new KoProperty::Property("TrackTotalFormat", QString(), i18n("Track Total Format"));
111
addDefaultProperties();
112
m_set->addProperty(m_controlSource);
113
m_set->addProperty(m_horizontalAlignment);
114
m_set->addProperty(m_verticalAlignment);
115
m_set->addProperty(m_font);
116
m_set->addProperty(m_backgroundColor);
117
m_set->addProperty(m_foregroundColor);
118
m_set->addProperty(m_backgroundOpacity);
119
m_set->addProperty(m_lineWeight);
120
m_set->addProperty(m_lineColor);
121
m_set->addProperty(m_lineStyle);
122
//_set->addProperty ( _trackTotal );
123
//_set->addProperty ( _trackBuiltinFormat );
124
//_set->addProperty ( _useSubTotal );
125
//_set->addProperty ( _trackTotalFormat );
128
Qt::Alignment KRFieldData::textFlags() const
132
t = m_horizontalAlignment->value().toString();
134
align = Qt::AlignHCenter;
135
else if (t == "right")
136
align = Qt::AlignRight;
138
align = Qt::AlignLeft;
140
t = m_verticalAlignment->value().toString();
142
align |= Qt::AlignVCenter;
143
else if (t == "bottom")
144
align |= Qt::AlignBottom;
146
align |= Qt::AlignTop;
151
KRTextStyleData KRFieldData::textStyle()
154
d.backgroundColor = m_backgroundColor->value().value<QColor>();
155
d.foregroundColor = m_foregroundColor->value().value<QColor>();
156
d.font = m_font->value().value<QFont>();
157
d.backgroundOpacity = m_backgroundOpacity->value().toInt();
162
QString KRFieldData::controlSource() const
164
return m_controlSource->value().toString();
167
void KRFieldData::setControlSource(const QString& t)
169
if (m_controlSource->value() != t) {
170
m_controlSource->setValue(t);
173
kDebug() << "Field: " << entityName() << "is" << controlSource();
176
KRLineStyleData KRFieldData::lineStyle()
179
ls.weight = m_lineWeight->value().toInt();
180
ls.lineColor = m_lineColor->value().value<QColor>();
181
ls.style = (Qt::PenStyle)m_lineStyle->value().toInt();
185
int KRFieldData::type() const
189
int KRFieldData::RTTI = KRObjectData::EntityField;
190
KRFieldData * KRFieldData::toField()