~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to libs/koreport/wrtembed/reportentitylabel.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 "reportentitylabel.h"
21
 
#include "reportentities.h"
22
 
#include "KoReportDesigner.h"
23
 
 
24
 
#include <qdom.h>
25
 
#include <qpainter.h>
26
 
#include <kdebug.h>
27
 
#include <klocalizedstring.h>
28
 
#include <koproperty/EditorView.h>
29
 
#include <QGraphicsScene>
30
 
#include <QGraphicsSceneMouseEvent>
31
 
 
32
 
//
33
 
// class ReportEntityLabel
34
 
//
35
 
 
36
 
void ReportEntityLabel::init(QGraphicsScene * scene)
37
 
{
38
 
    if (scene)
39
 
        scene->addItem(this);
40
 
 
41
 
    ReportRectEntity::init(&m_pos, &m_size, m_set);
42
 
 
43
 
    connect(properties(), SIGNAL(propertyChanged(KoProperty::Set&, KoProperty::Property&)),
44
 
            this, SLOT(slotPropertyChanged(KoProperty::Set&, KoProperty::Property&)));
45
 
 
46
 
    setZValue(Z);
47
 
}
48
 
 
49
 
// methods (constructors)
50
 
ReportEntityLabel::ReportEntityLabel(KoReportDesigner* d, QGraphicsScene * scene, const QPointF &pos)
51
 
        : ReportRectEntity(d)
52
 
{
53
 
    init(scene);
54
 
    setSceneRect(getTextRect());
55
 
    m_pos.setScenePos(pos);
56
 
    m_name->setValue(m_reportDesigner->suggestEntityName("label"));
57
 
}
58
 
 
59
 
ReportEntityLabel::ReportEntityLabel(QDomNode & element, KoReportDesigner * d, QGraphicsScene * s)
60
 
        : ReportRectEntity(d), KRLabelData(element)
61
 
{
62
 
    init(s);
63
 
    setSceneRect(m_pos.toScene(), m_size.toScene());
64
 
}
65
 
 
66
 
ReportEntityLabel* ReportEntityLabel::clone()
67
 
{
68
 
    QDomDocument d;
69
 
    QDomElement e = d.createElement("clone");
70
 
    QDomNode n;
71
 
    buildXML(d, e);
72
 
    n = e.firstChild();
73
 
    return new ReportEntityLabel(n, designer(), 0);
74
 
}
75
 
 
76
 
// methods (deconstructor)
77
 
ReportEntityLabel::~ReportEntityLabel()
78
 
{}
79
 
 
80
 
QRectF ReportEntityLabel::getTextRect()
81
 
{
82
 
    return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), m_text->value().toString());
83
 
}
84
 
 
85
 
void ReportEntityLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
86
 
{
87
 
    Q_UNUSED(option);
88
 
    Q_UNUSED(widget);
89
 
 
90
 
    // store any values we plan on changing so we can restore them
91
 
    QFont f = painter->font();
92
 
    QPen  p = painter->pen();
93
 
 
94
 
    painter->setFont(font());
95
 
 
96
 
    QColor bg = m_backgroundColor->value().value<QColor>();
97
 
    bg.setAlpha((m_backgroundOpacity->value().toInt() / 100) * 255);
98
 
 
99
 
    painter->setBackground(bg);
100
 
    painter->setPen(m_foregroundColor->value().value<QColor>());
101
 
 
102
 
    painter->fillRect(QGraphicsRectItem::rect(), bg);
103
 
    painter->drawText(rect(), textFlags(), text());
104
 
 
105
 
    if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
106
 
        painter->setPen(QPen(QColor(224, 224, 224)));
107
 
    } else {
108
 
        painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt()));
109
 
    }
110
 
 
111
 
    painter->drawRect(QGraphicsRectItem::rect());
112
 
 
113
 
    painter->setBackgroundMode(Qt::TransparentMode);
114
 
    painter->setPen(m_foregroundColor->value().value<QColor>());
115
 
 
116
 
    drawHandles(painter);
117
 
 
118
 
    // restore an values before we started just in case
119
 
    painter->setFont(f);
120
 
    painter->setPen(p);
121
 
}
122
 
 
123
 
void ReportEntityLabel::buildXML(QDomDocument & doc, QDomElement & parent)
124
 
{
125
 
    kDebug();
126
 
 
127
 
    QDomElement entity = doc.createElement("report:label");
128
 
 
129
 
    // properties
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());
135
 
 
136
 
    // bounding rect
137
 
    buildXMLRect(doc, entity, &m_pos, &m_size);
138
 
 
139
 
    //text style info
140
 
    buildXMLTextStyle(doc, entity, textStyle());
141
 
 
142
 
    //Line Style
143
 
    buildXMLLineStyle(doc, entity, lineStyle());
144
 
 
145
 
    parent.appendChild(entity);
146
 
}
147
 
 
148
 
void ReportEntityLabel::slotPropertyChanged(KoProperty::Set &s, KoProperty::Property &p)
149
 
{
150
 
    Q_UNUSED(s);
151
 
 
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);
156
 
        } else {
157
 
            m_oldName = p.value().toString();
158
 
        }
159
 
    }
160
 
 
161
 
    ReportRectEntity::propertyChanged(s, p);
162
 
    if (m_reportDesigner) m_reportDesigner->setModified(true);
163
 
 
164
 
}
165
 
 
166
 
 
167
 
 
168