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 "reportentityimage.h"
21
#include "reportentities.h"
22
#include "KoReportDesigner.h"
24
#include <QImageWriter>
25
#include <QGraphicsScene>
26
#include <QGraphicsSceneMouseEvent>
32
#include <klocalizedstring.h>
34
#include <koproperty/Property.h>
35
#include <koproperty/Set.h>
36
#include <koproperty/EditorView.h>
39
// ReportEntitiesImage
41
// contructors/deconstructors
43
void ReportEntityImage::init(QGraphicsScene * scene)
48
connect(m_set, SIGNAL(propertyChanged(KoProperty::Set&, KoProperty::Property&)),
49
this, SLOT(slotPropertyChanged(KoProperty::Set&, KoProperty::Property&)));
51
ReportRectEntity::init(&m_pos, &m_size, m_set);
53
m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames());
57
ReportEntityImage::ReportEntityImage(KoReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos)
58
: ReportRectEntity(rw)
61
m_size.setSceneSize(QSizeF(100, 100));
62
m_pos.setScenePos(pos);
63
m_name->setValue(m_reportDesigner->suggestEntityName("image"));
66
ReportEntityImage::ReportEntityImage(QDomNode & element, KoReportDesigner * rw, QGraphicsScene* scene)
67
: KRImageData(element), ReportRectEntity(rw)
70
setSceneRect(m_pos.toScene(), m_size.toScene());
73
ReportEntityImage* ReportEntityImage::clone()
76
QDomElement e = d.createElement("clone");
80
return new ReportEntityImage(n, designer(), 0);
83
ReportEntityImage::~ReportEntityImage()
85
// do we need to clean anything up?
88
void ReportEntityImage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
93
// store any values we plan on changing so we can restore them
94
QPen p = painter->pen();
97
//QImage t_img = _image;
98
QImage t_img = m_staticImage->value().value<QPixmap>().toImage();
99
if (mode() == "stretch") {
100
t_img = t_img.scaled(rect().width(), rect().height(), Qt::KeepAspectRatio);
102
painter->drawImage(rect().left(), rect().top(), t_img, 0, 0, rect().width(), rect().height());
104
painter->drawText(rect(), 0, dataSourceAndObjectTypeName(controlSource(), "image"));
107
//Draw a border so user knows the object edge
108
painter->setPen(QPen(QColor(224, 224, 224)));
109
painter->drawRect(rect());
112
drawHandles(painter);
114
// restore an values before we started just in case
118
void ReportEntityImage::buildXML(QDomDocument & doc, QDomElement & parent)
120
QDomElement entity = doc.createElement("report:image");
123
addPropertyAsAttribute(&entity, m_name);
124
addPropertyAsAttribute(&entity, m_resizeMode);
125
entity.setAttribute("report:z-index", zValue());
126
buildXMLRect(doc, entity, &m_pos, &m_size);
130
QDomElement map = doc.createElement("report:inline-image-data");
131
map.appendChild(doc.createTextNode(inlineImageData()));
132
entity.appendChild(map);
134
addPropertyAsAttribute(&entity, m_controlSource);
137
parent.appendChild(entity);
140
void ReportEntityImage::slotPropertyChanged(KoProperty::Set &s, KoProperty::Property &p)
142
if (p.name() == "Name") {
143
//For some reason p.oldValue returns an empty string
144
if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) {
145
p.setValue(m_oldName);
147
m_oldName = p.value().toString();
151
ReportRectEntity::propertyChanged(s, p);
152
if (m_reportDesigner) m_reportDesigner->setModified(true);
155
void ReportEntityImage::mousePressEvent(QGraphicsSceneMouseEvent * event)
157
m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames());
158
ReportRectEntity::mousePressEvent(event);