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

« back to all changes in this revision

Viewing changes to libs/koreport/wrtembed/KoReportDesignerItemBase.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 "KoReportDesignerItemBase.h"
 
21
 
 
22
// qt
 
23
#include <qpainter.h>
 
24
#include <qstring.h>
 
25
#include <qlabel.h>
 
26
#include <qlineedit.h>
 
27
#include <qdom.h>
 
28
#include <qinputdialog.h>
 
29
#include <qslider.h>
 
30
#include <qdatastream.h>
 
31
#include <qcheckbox.h>
 
32
#include <qradiobutton.h>
 
33
#include <qsettings.h>
 
34
#include <kdebug.h>
 
35
 
 
36
#include <koproperty/Property.h>
 
37
#include <koproperty/Set.h>
 
38
#include <koproperty/EditorView.h>
 
39
#include <KoGlobal.h>
 
40
#include "KoReportItemBase.h"
 
41
#include <krutils.h>
 
42
#include <klocalizedstring.h>
 
43
 
 
44
//
 
45
// ReportEntity
 
46
//
 
47
KoReportDesignerItemBase::KoReportDesignerItemBase(KoReportDesigner* r)
 
48
{
 
49
    m_reportDesigner = r;
 
50
}
 
51
 
 
52
void KoReportDesignerItemBase::buildXML(QGraphicsItem * item, QDomDocument & doc, QDomElement & parent)
 
53
{
 
54
    KoReportDesignerItemBase *re = 0;
 
55
    re = dynamic_cast<KoReportDesignerItemBase*>(item);
 
56
 
 
57
    if (re) {
 
58
        re->buildXML(doc, parent);
 
59
    }
 
60
 
 
61
}
 
62
 
 
63
void KoReportDesignerItemBase::buildXMLRect(QDomDocument & doc, QDomElement & entity, KRPos *pos, KRSize *siz)
 
64
{
 
65
    Q_UNUSED(doc)
 
66
    KoUnit unit = pos->unit();
 
67
    
 
68
    entity.setAttribute("svg:x", QString::number(pos->toUnit().x()) + KoUnit::unitName(unit));
 
69
    entity.setAttribute("svg:y", QString::number(pos->toUnit().y()) + KoUnit::unitName(unit));
 
70
    entity.setAttribute("svg:width", QString::number(siz->toUnit().width()) + KoUnit::unitName(unit));
 
71
    entity.setAttribute("svg:height", QString::number(siz->toUnit().height()) + KoUnit::unitName(unit));
 
72
}
 
73
 
 
74
void KoReportDesignerItemBase::buildXMLTextStyle(QDomDocument & doc, QDomElement & entity, KRTextStyleData ts)
 
75
{
 
76
    QDomElement element = doc.createElement("report:text-style");
 
77
 
 
78
    element.setAttribute("fo:background-color", ts.backgroundColor.name());
 
79
    element.setAttribute("fo:foreground-color", ts.foregroundColor.name());
 
80
    element.setAttribute("fo:background-opacity", QString::number(ts.backgroundOpacity) + '%');
 
81
    KRUtils::writeFontAttributes(element, ts.font);
 
82
 
 
83
    entity.appendChild(element);
 
84
}
 
85
 
 
86
void KoReportDesignerItemBase::buildXMLLineStyle(QDomDocument & doc, QDomElement & entity, KRLineStyleData ls)
 
87
{
 
88
    QDomElement element = doc.createElement("report:line-style");
 
89
 
 
90
    element.setAttribute("report:line-color", ls.lineColor.name());
 
91
    element.setAttribute("report:line-weight", QString::number(ls.weight));
 
92
 
 
93
    QString l;
 
94
    switch (ls.style) {
 
95
    case Qt::NoPen:
 
96
        l = "nopen";
 
97
        break;
 
98
    case Qt::SolidLine:
 
99
        l = "solid";
 
100
        break;
 
101
    case Qt::DashLine:
 
102
        l = "dash";
 
103
        break;
 
104
    case Qt::DotLine:
 
105
        l = "dot";
 
106
        break;
 
107
    case Qt::DashDotLine:
 
108
        l = "dashdot";
 
109
        break;
 
110
    case Qt::DashDotDotLine:
 
111
        l = "dashdotdot";
 
112
        break;
 
113
    default:
 
114
        l = "solid";
 
115
 
 
116
    }
 
117
    element.setAttribute("report:line-style", l);
 
118
 
 
119
    entity.appendChild(element);
 
120
}
 
121
 
 
122
QString KoReportDesignerItemBase::dataSourceAndObjectTypeName(const QString& dataSource, const QString& objectTypeName)
 
123
{
 
124
    return i18nc("<data-source>: <object>", "%1: %2", dataSource, objectTypeName);
 
125
}
 
126
 
 
127
// static
 
128
void KoReportDesignerItemBase::addPropertyAsAttribute(QDomElement* e, KoProperty::Property* p)
 
129
{
 
130
    switch (p->value().type()) {
 
131
    case QVariant::Int :
 
132
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toInt());
 
133
        break;
 
134
    case QVariant::Double:
 
135
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toDouble());
 
136
        break;
 
137
    case QVariant::Bool:
 
138
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toInt());
 
139
        break;
 
140
    default:
 
141
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toString());
 
142
        break;
 
143
    }
 
144
}