1
/* This file is part of the KDE project
2
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
3
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
4
* Copyright (C) 2016 by Dag Andersen <danders@get2net.dk>
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 "PlanReportDesignerItemText.h"
22
#include "KReportDesignerItemBase.h"
23
#include "KReportDesigner.h"
24
#include "KReportLineStyle.h"
26
#include <KPropertySet>
27
#include <QDomDocument>
29
#include <QGraphicsScene>
30
#include <QGraphicsSceneMouseEvent>
33
void PlanReportDesignerItemText::init(QGraphicsScene *scene, KReportDesigner *d)
35
//setFlags(ItemIsSelectable | ItemIsMovable);
39
connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
40
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
42
KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d);
44
m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames());
47
updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(),
48
QLatin1String("textarea"));
51
PlanReportDesignerItemText::PlanReportDesignerItemText(KReportDesigner * rw, QGraphicsScene * scene, const QPointF &pos)
52
: KReportDesignerItemRectBase(rw)
56
setSceneRect(properRect(*rw, getTextRect().width(), getTextRect().height()));
57
m_name->setValue(m_reportDesigner->suggestEntityName(typeName()));
60
PlanReportDesignerItemText::PlanReportDesignerItemText(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s)
61
: PlanReportItemText(element), KReportDesignerItemRectBase(d)
64
setSceneRect(m_pos.toScene(), m_size.toScene());
67
PlanReportDesignerItemText* PlanReportDesignerItemText::clone()
70
QDomElement e = d.createElement(QLatin1String("clone"));
74
return new PlanReportDesignerItemText(n, designer(), 0);
77
PlanReportDesignerItemText::~PlanReportDesignerItemText()
80
QRect PlanReportDesignerItemText::getTextRect() const
82
return QFontMetrics(font()).boundingRect(int (x()), int (y()), 0, 0, textFlags(), m_renderText);
85
void PlanReportDesignerItemText::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());
95
painter->setBackgroundMode(Qt::TransparentMode);
97
QColor bg = m_backgroundColor->value().value<QColor>();
98
bg.setAlphaF(m_backgroundOpacity->value().toReal()*0.01);
100
painter->setPen(m_foregroundColor->value().value<QColor>());
102
painter->fillRect(rect(), bg);
103
painter->drawText(rect(), textFlags(), m_renderText);
105
if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
106
painter->setPen(QPen(Qt::lightGray));
108
painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt()));
110
painter->drawRect(rect());
112
painter->setPen(m_foregroundColor->value().value<QColor>());
114
drawHandles(painter);
116
// restore an values before we started just in case
121
void PlanReportDesignerItemText::buildXML(QDomDocument *doc, QDomElement *parent)
123
//kreportpluginDebug();
124
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
127
addPropertyAsAttribute(&entity, m_name);
128
addPropertyAsAttribute(&entity, m_controlSource);
129
addPropertyAsAttribute(&entity, m_verticalAlignment);
130
addPropertyAsAttribute(&entity, m_horizontalAlignment);
131
entity.setAttribute(QLatin1String("report:bottom-padding"), m_bottomPadding);
132
entity.setAttribute(QLatin1String("report:z-index"), zValue());
133
addPropertyAsAttribute(&entity, m_itemValue);
136
buildXMLRect(doc, &entity, &m_pos, &m_size);
139
buildXMLTextStyle(doc, &entity, textStyle());
142
buildXMLLineStyle(doc, &entity, lineStyle());
144
parent->appendChild(entity);
147
void PlanReportDesignerItemText::mousePressEvent(QGraphicsSceneMouseEvent * event)
149
m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames());
150
KReportDesignerItemRectBase::mousePressEvent(event);
154
void PlanReportDesignerItemText::slotPropertyChanged(KPropertySet &s, KProperty &p)
158
if (p.name() == "position") {
159
m_pos.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty);
160
} else if (p.name() == "size") {
161
m_size.setUnitSize(p.value().toSizeF(), KReportSize::DontUpdateProperty);
162
} else if (p.name() == "name") {
163
//For some reason p.oldValue returns an empty string
164
if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) {
165
p.setValue(m_oldName);
167
m_oldName = p.value().toString();
171
setSceneRect(m_pos.toScene(), m_size.toScene(), DontUpdateProperty);
172
if (m_reportDesigner)
173
m_reportDesigner->setModified(true);
177
updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(),
178
QLatin1String("textarea"));