~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/koreport/wrtembed/reportentityimage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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)
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include "reportentityimage.h"
21
 
#include "reportentities.h"
22
 
#include "KoReportDesigner.h"
23
 
 
24
 
#include <QImageWriter>
25
 
#include <QGraphicsScene>
26
 
#include <QGraphicsSceneMouseEvent>
27
 
#include <QBuffer>
28
 
#include <kcodecs.h>
29
 
#include <qdom.h>
30
 
#include <QPainter>
31
 
#include <kdebug.h>
32
 
#include <klocalizedstring.h>
33
 
 
34
 
#include <koproperty/Property.h>
35
 
#include <koproperty/Set.h>
36
 
#include <koproperty/EditorView.h>
37
 
 
38
 
//
39
 
// ReportEntitiesImage
40
 
//
41
 
// contructors/deconstructors
42
 
 
43
 
void ReportEntityImage::init(QGraphicsScene * scene)
44
 
{
45
 
    if (scene)
46
 
        scene->addItem(this);
47
 
 
48
 
    connect(m_set, SIGNAL(propertyChanged(KoProperty::Set&, KoProperty::Property&)),
49
 
            this, SLOT(slotPropertyChanged(KoProperty::Set&, KoProperty::Property&)));
50
 
 
51
 
    ReportRectEntity::init(&m_pos, &m_size, m_set);
52
 
 
53
 
    m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames());
54
 
    setZValue(Z);
55
 
}
56
 
 
57
 
ReportEntityImage::ReportEntityImage(KoReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos)
58
 
        : ReportRectEntity(rw)
59
 
{
60
 
    init(scene);
61
 
    m_size.setSceneSize(QSizeF(100, 100));
62
 
    m_pos.setScenePos(pos);
63
 
    m_name->setValue(m_reportDesigner->suggestEntityName("image"));
64
 
}
65
 
 
66
 
ReportEntityImage::ReportEntityImage(QDomNode & element, KoReportDesigner * rw, QGraphicsScene* scene)
67
 
        : KRImageData(element), ReportRectEntity(rw)
68
 
{
69
 
    init(scene);
70
 
    setSceneRect(m_pos.toScene(), m_size.toScene());
71
 
}
72
 
 
73
 
ReportEntityImage* ReportEntityImage::clone()
74
 
{
75
 
    QDomDocument d;
76
 
    QDomElement e = d.createElement("clone");
77
 
    QDomNode n;
78
 
    buildXML(d, e);
79
 
    n = e.firstChild();
80
 
    return new ReportEntityImage(n, designer(), 0);
81
 
}
82
 
 
83
 
ReportEntityImage::~ReportEntityImage()
84
 
{
85
 
    // do we need to clean anything up?
86
 
}
87
 
 
88
 
void ReportEntityImage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
89
 
{
90
 
    Q_UNUSED(option);
91
 
    Q_UNUSED(widget);
92
 
 
93
 
    // store any values we plan on changing so we can restore them
94
 
    QPen  p = painter->pen();
95
 
 
96
 
    if (isInline()) {
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);
101
 
        }
102
 
        painter->drawImage(rect().left(), rect().top(), t_img, 0, 0, rect().width(), rect().height());
103
 
    } else {
104
 
        painter->drawText(rect(), 0, dataSourceAndObjectTypeName(controlSource(), "image"));
105
 
    }
106
 
 
107
 
    //Draw a border so user knows the object edge
108
 
    painter->setPen(QPen(QColor(224, 224, 224)));
109
 
    painter->drawRect(rect());
110
 
 
111
 
 
112
 
    drawHandles(painter);
113
 
 
114
 
    // restore an values before we started just in case
115
 
    painter->setPen(p);
116
 
}
117
 
 
118
 
void ReportEntityImage::buildXML(QDomDocument & doc, QDomElement & parent)
119
 
{
120
 
    QDomElement entity = doc.createElement("report:image");
121
 
 
122
 
    // properties
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);
127
 
 
128
 
 
129
 
    if (isInline()) {
130
 
        QDomElement map = doc.createElement("report:inline-image-data");
131
 
        map.appendChild(doc.createTextNode(inlineImageData()));
132
 
        entity.appendChild(map);
133
 
    } else {
134
 
        addPropertyAsAttribute(&entity, m_controlSource);
135
 
    }
136
 
 
137
 
    parent.appendChild(entity);
138
 
}
139
 
 
140
 
void ReportEntityImage::slotPropertyChanged(KoProperty::Set &s, KoProperty::Property &p)
141
 
{
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);
146
 
        } else {
147
 
            m_oldName = p.value().toString();
148
 
        }
149
 
    }
150
 
 
151
 
    ReportRectEntity::propertyChanged(s, p);
152
 
    if (m_reportDesigner) m_reportDesigner->setModified(true);
153
 
}
154
 
 
155
 
void ReportEntityImage::mousePressEvent(QGraphicsSceneMouseEvent * event)
156
 
{
157
 
    m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames());
158
 
    ReportRectEntity::mousePressEvent(event);
159
 
}