2
* OpenRPT report writer and rendering engine
3
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
4
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
#include "reportentitylabel.h"
21
#include "reportentities.h"
22
#include "KoReportDesigner.h"
27
#include <klocalizedstring.h>
28
#include <koproperty/EditorView.h>
29
#include <QGraphicsScene>
30
#include <QGraphicsSceneMouseEvent>
33
// class ReportEntityLabel
36
void ReportEntityLabel::init(QGraphicsScene * scene)
41
ReportRectEntity::init(&m_pos, &m_size, m_set);
43
connect(properties(), SIGNAL(propertyChanged(KoProperty::Set&, KoProperty::Property&)),
44
this, SLOT(slotPropertyChanged(KoProperty::Set&, KoProperty::Property&)));
49
// methods (constructors)
50
ReportEntityLabel::ReportEntityLabel(KoReportDesigner* d, QGraphicsScene * scene, const QPointF &pos)
54
setSceneRect(getTextRect());
55
m_pos.setScenePos(pos);
56
m_name->setValue(m_reportDesigner->suggestEntityName("label"));
59
ReportEntityLabel::ReportEntityLabel(QDomNode & element, KoReportDesigner * d, QGraphicsScene * s)
60
: ReportRectEntity(d), KRLabelData(element)
63
setSceneRect(m_pos.toScene(), m_size.toScene());
66
ReportEntityLabel* ReportEntityLabel::clone()
69
QDomElement e = d.createElement("clone");
73
return new ReportEntityLabel(n, designer(), 0);
76
// methods (deconstructor)
77
ReportEntityLabel::~ReportEntityLabel()
80
QRectF ReportEntityLabel::getTextRect()
82
return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), m_text->value().toString());
85
void ReportEntityLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
90
// store any values we plan on changing so we can restore them
91
QFont f = painter->font();
92
QPen p = painter->pen();
94
painter->setFont(font());
96
QColor bg = m_backgroundColor->value().value<QColor>();
97
bg.setAlpha((m_backgroundOpacity->value().toInt() / 100) * 255);
99
painter->setBackground(bg);
100
painter->setPen(m_foregroundColor->value().value<QColor>());
102
painter->fillRect(QGraphicsRectItem::rect(), bg);
103
painter->drawText(rect(), textFlags(), text());
105
if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
106
painter->setPen(QPen(QColor(224, 224, 224)));
108
painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt()));
111
painter->drawRect(QGraphicsRectItem::rect());
113
painter->setBackgroundMode(Qt::TransparentMode);
114
painter->setPen(m_foregroundColor->value().value<QColor>());
116
drawHandles(painter);
118
// restore an values before we started just in case
123
void ReportEntityLabel::buildXML(QDomDocument & doc, QDomElement & parent)
127
QDomElement entity = doc.createElement("report:label");
130
addPropertyAsAttribute(&entity, m_name);
131
addPropertyAsAttribute(&entity, m_text);
132
addPropertyAsAttribute(&entity, m_verticalAlignment);
133
addPropertyAsAttribute(&entity, m_horizontalAlignment);
134
entity.setAttribute("report:z-index", zValue());
137
buildXMLRect(doc, entity, &m_pos, &m_size);
140
buildXMLTextStyle(doc, entity, textStyle());
143
buildXMLLineStyle(doc, entity, lineStyle());
145
parent.appendChild(entity);
148
void ReportEntityLabel::slotPropertyChanged(KoProperty::Set &s, KoProperty::Property &p)
152
if (p.name() == "Name") {
153
//For some reason p.oldValue returns an empty string
154
if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) {
155
p.setValue(m_oldName);
157
m_oldName = p.value().toString();
161
ReportRectEntity::propertyChanged(s, p);
162
if (m_reportDesigner) m_reportDesigner->setModified(true);