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 "krtextdata.h"
19
#include <koproperty/Property.h>
20
#include <koproperty/Set.h>
24
#include <klocalizedstring.h>
25
#include <kglobalsettings.h>
27
KRTextData::KRTextData(QDomNode & element) : m_bottomPadding(0.0)
29
QDomNodeList nl = element.childNodes();
34
m_name->setValue(element.toElement().attribute("report:name"));
35
m_controlSource->setValue(element.toElement().attribute("report:item-data-source"));
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"));
39
m_bottomPadding = element.toElement().attribute("report:bottom-padding").toDouble();
41
parseReportRect(element.toElement(), &m_pos, &m_size);
43
for (int i = 0; i < nl.count(); i++) {
47
if (n == "report:text-style") {
49
if (parseReportTextStyleData(node.toElement(), ts)) {
50
m_backgroundColor->setValue(ts.backgroundColor);
51
m_foregroundColor->setValue(ts.foregroundColor);
52
m_backgroundOpacity->setValue(ts.backgroundOpacity);
53
m_font->setValue(ts.font);
56
} else if (n == "report:line-style") {
58
if (parseReportLineStyleData(node.toElement(), ls)) {
59
m_lineWeight->setValue(ls.weight);
60
m_lineColor->setValue(ls.lineColor);
61
m_lineStyle->setValue(ls.style);
64
kDebug() << "while parsing field element encountered unknow element: " << n;
70
KRTextData::~KRTextData()
74
Qt::Alignment KRTextData::textFlags() const
78
t = m_horizontalAlignment->value().toString();
80
align = Qt::AlignHCenter;
81
else if (t == "right")
82
align = Qt::AlignRight;
84
align = Qt::AlignLeft;
86
t = m_verticalAlignment->value().toString();
88
align |= Qt::AlignVCenter;
89
else if (t == "bottom")
90
align |= Qt::AlignBottom;
92
align |= Qt::AlignTop;
97
void KRTextData::createProperties()
99
m_set = new KoProperty::Set(0, "Text");
101
//connect ( set, SIGNAL ( propertyChanged ( KoProperty::Set &, KoProperty::Property & ) ), this, SLOT ( propertyChanged ( KoProperty::Set &, KoProperty::Property & ) ) );
103
QStringList keys, strings;
105
//_query = new KoProperty::Property ( "Query", QStringList(), QStringList(), "Data Source", "Query" );
106
m_controlSource = new KoProperty::Property("item-data-source", QStringList(), QStringList(), QString(), i18n("Data Source"));
108
keys << "left" << "center" << "right";
109
strings << i18n("Left") << i18n("Center") << i18n("Right");
110
m_horizontalAlignment = new KoProperty::Property("horizontal-align", keys, strings, "left", i18n("Horizontal Alignment"));
114
keys << "top" << "center" << "bottom";
115
strings << i18n("Top") << i18n("Center") << i18n("Bottom");
116
m_verticalAlignment = new KoProperty::Property("vertical-align", keys, strings, "center", i18n("Vertical Alignment"));
118
m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), "Font", i18n("Font"));
120
m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
121
m_foregroundColor = new KoProperty::Property("foreground-color", Qt::black, i18n("Foreground Color"));
123
m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
124
m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
125
m_lineStyle = new KoProperty::Property("line-style", Qt::NoPen, i18n("Line Style"), i18n("Line Style"), KoProperty::LineStyle);
126
m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Opacity"));
127
m_backgroundOpacity->setOption("max", 100);
128
m_backgroundOpacity->setOption("min", 0);
129
m_backgroundOpacity->setOption("unit", "%");
131
addDefaultProperties();
132
m_set->addProperty(m_controlSource);
133
m_set->addProperty(m_horizontalAlignment);
134
m_set->addProperty(m_verticalAlignment);
135
m_set->addProperty(m_font);
136
m_set->addProperty(m_backgroundColor);
137
m_set->addProperty(m_foregroundColor);
138
m_set->addProperty(m_backgroundOpacity);
139
m_set->addProperty(m_lineWeight);
140
m_set->addProperty(m_lineColor);
141
m_set->addProperty(m_lineStyle);
145
QString KRTextData::controlSource() const
147
return m_controlSource->value().toString();
150
qreal KRTextData::bottomPadding() const
152
return m_bottomPadding;
155
void KRTextData::setBottomPadding(qreal bp)
157
if (m_bottomPadding != bp) {
158
m_bottomPadding = bp;
162
KRTextStyleData KRTextData::textStyle()
165
d.backgroundColor = m_backgroundColor->value().value<QColor>();
166
d.foregroundColor = m_foregroundColor->value().value<QColor>();
167
d.font = m_font->value().value<QFont>();
168
d.backgroundOpacity = m_backgroundOpacity->value().toInt();
172
KRLineStyleData KRTextData::lineStyle()
175
ls.weight = m_lineWeight->value().toInt();
176
ls.lineColor = m_lineColor->value().value<QColor>();
177
ls.style = (Qt::PenStyle)m_lineStyle->value().toInt();
182
int KRTextData::type() const
186
int KRTextData::RTTI = KRObjectData::EntityText;
187
KRTextData* KRTextData::toText()