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 "KoReportItemLabel.h"
19
#include <koproperty/Property.h>
20
#include <koproperty/Set.h>
23
#include <klocalizedstring.h>
24
#include <kglobalsettings.h>
25
#include "renderobjects.h"
27
KoReportItemLabel::KoReportItemLabel(QDomNode & element)
30
QDomNodeList nl = element.childNodes();
34
m_name->setValue(element.toElement().attribute("report:name"));
35
m_text->setValue(element.toElement().attribute("report:caption"));
36
Z = element.toElement().attribute("report:z-index").toDouble();
37
m_horizontalAlignment->setValue(element.toElement().attribute("report:horizontal-align"));
38
m_verticalAlignment->setValue(element.toElement().attribute("report:vertical-align"));
40
parseReportRect(element.toElement(), &m_pos, &m_size);
42
for (int i = 0; i < nl.count(); i++) {
46
if (n == "report:text-style") {
48
if (parseReportTextStyleData(node.toElement(), ts)) {
49
m_backgroundColor->setValue(ts.backgroundColor);
50
m_foregroundColor->setValue(ts.foregroundColor);
51
m_backgroundOpacity->setValue(ts.backgroundOpacity);
52
m_font->setValue(ts.font);
55
} else if (n == "report:line-style") {
57
if (parseReportLineStyleData(node.toElement(), ls)) {
58
m_lineWeight->setValue(ls.weight);
59
m_lineColor->setValue(ls.lineColor);
60
m_lineStyle->setValue(ls.style);
63
kDebug() << "while parsing label element encountered unknow element: " << n;
68
QString KoReportItemLabel::text() const
70
return m_text->value().toString();
73
void KoReportItemLabel::setText(const QString& t)
78
void KoReportItemLabel::createProperties()
80
m_set = new KoProperty::Set(0, "Label");
82
m_text = new KoProperty::Property("caption", "Label", i18n("Caption"));
83
QStringList keys, strings;
85
keys << "left" << "center" << "right";
86
strings << i18n("Left") << i18n("Center") << i18n("Right");
87
m_horizontalAlignment = new KoProperty::Property("horizontal-align", keys, strings, "left", i18n("Horizontal Alignment"));
91
keys << "top" << "center" << "bottom";
92
strings << i18n("Top") << i18n("Center") << i18n("Bottom");
93
m_verticalAlignment = new KoProperty::Property("vertical-align", keys, strings, "center", i18n("Vertical Alignment"));
95
m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), i18n("Font"), i18n("Font"));
97
m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
98
m_foregroundColor = new KoProperty::Property("foreground-color", Qt::black, i18n("Foreground Color"));
99
m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Opacity"));
100
m_backgroundOpacity->setOption("max", 100);
101
m_backgroundOpacity->setOption("min", 0);
102
m_backgroundOpacity->setOption("unit", "%");
104
m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
105
m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
106
m_lineStyle = new KoProperty::Property("line-style", Qt::NoPen, i18n("Line Style"), i18n("Line Style"), KoProperty::LineStyle);
108
addDefaultProperties();
109
m_set->addProperty(m_text);
110
m_set->addProperty(m_horizontalAlignment);
111
m_set->addProperty(m_verticalAlignment);
112
m_set->addProperty(m_font);
113
m_set->addProperty(m_backgroundColor);
114
m_set->addProperty(m_foregroundColor);
115
m_set->addProperty(m_backgroundOpacity);
116
m_set->addProperty(m_lineWeight);
117
m_set->addProperty(m_lineColor);
118
m_set->addProperty(m_lineStyle);
121
Qt::Alignment KoReportItemLabel::textFlags() const
125
t = m_horizontalAlignment->value().toString();
127
align = Qt::AlignHCenter;
128
else if (t == "right")
129
align = Qt::AlignRight;
131
align = Qt::AlignLeft;
133
t = m_verticalAlignment->value().toString();
135
align |= Qt::AlignVCenter;
136
else if (t == "bottom")
137
align |= Qt::AlignBottom;
139
align |= Qt::AlignTop;
144
KRTextStyleData KoReportItemLabel::textStyle()
147
d.backgroundColor = m_backgroundColor->value().value<QColor>();
148
d.foregroundColor = m_foregroundColor->value().value<QColor>();
149
d.font = m_font->value().value<QFont>();
150
d.backgroundOpacity = m_backgroundOpacity->value().toInt();
154
KRLineStyleData KoReportItemLabel::lineStyle()
157
ls.weight = m_lineWeight->value().toInt();
158
ls.lineColor = m_lineColor->value().value<QColor>();
159
ls.style = (Qt::PenStyle)m_lineStyle->value().toInt();
164
QString KoReportItemLabel::typeName() const
166
return "report:label";
169
int KoReportItemLabel::render(OROPage* page, OROSection* section, QPointF offset, QVariant data, KRScriptHandler *script)
174
OROTextBox * tb = new OROTextBox();
175
tb->setPosition(m_pos.toScene() + offset);
176
tb->setSize(m_size.toScene());
179
tb->setFlags(textFlags());
180
tb->setTextStyle(textStyle());
181
tb->setLineStyle(lineStyle());
182
if (page) page->addPrimitive(tb);
184
OROPrimitive *clone = tb->clone();
185
clone->setPosition(m_pos.toScene());
186
if (section) section->addPrimitive(clone);
188
return 0; //Item doesnt stretch the section height