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

« back to all changes in this revision

Viewing changes to libs/koreport/common/krfielddata.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
 
 * Kexi Report Plugin
3
 
 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2.1 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 
 * Lesser General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
#include "krfielddata.h"
19
 
#include <KoGlobal.h>
20
 
#include <kdebug.h>
21
 
#include <klocalizedstring.h>
22
 
#include <kglobalsettings.h>
23
 
#include <koproperty/Set.h>
24
 
 
25
 
KRFieldData::~KRFieldData()
26
 
{
27
 
}
28
 
 
29
 
KRFieldData::KRFieldData(QDomNode & element)
30
 
{
31
 
    createProperties();
32
 
    QDomNodeList nl = element.childNodes();
33
 
    QString n;
34
 
    QDomNode node;
35
 
 
36
 
    m_name->setValue(element.toElement().attribute("report:name"));
37
 
    m_controlSource->setValue(element.toElement().attribute("report:item-data-source"));
38
 
    Z = element.toElement().attribute("report:z-index").toDouble();
39
 
    m_horizontalAlignment->setValue(element.toElement().attribute("report:horizontal-align"));
40
 
    m_verticalAlignment->setValue(element.toElement().attribute("report:vertical-align"));
41
 
 
42
 
    parseReportRect(element.toElement(), &m_pos, &m_size);
43
 
    
44
 
    for (int i = 0; i < nl.count(); i++) {
45
 
        node = nl.item(i);
46
 
        n = node.nodeName();
47
 
 
48
 
        if (n == "report:text-style") {
49
 
            KRTextStyleData ts;
50
 
            if (parseReportTextStyleData(node.toElement(), ts)) {
51
 
                m_backgroundColor->setValue(ts.backgroundColor);
52
 
                m_foregroundColor->setValue(ts.foregroundColor);
53
 
                m_backgroundOpacity->setValue(ts.backgroundOpacity);
54
 
                m_font->setValue(ts.font);
55
 
 
56
 
            }
57
 
        } else if (n == "report:line-style") {
58
 
            KRLineStyleData ls;
59
 
            if (parseReportLineStyleData(node.toElement(), ls)) {
60
 
                m_lineWeight->setValue(ls.weight);
61
 
                m_lineColor->setValue(ls.lineColor);
62
 
                m_lineStyle->setValue(ls.style);
63
 
            }
64
 
        } else {
65
 
            kDebug() << "while parsing field element encountered unknow element: " << n;
66
 
        }
67
 
    }
68
 
}
69
 
 
70
 
void KRFieldData::createProperties()
71
 
{
72
 
    m_set = new KoProperty::Set(0, "Field");
73
 
 
74
 
    QStringList keys, strings;
75
 
 
76
 
    m_controlSource = new KoProperty::Property("item-data-source", QStringList(), QStringList(), QString(), i18n("Data Source"));
77
 
 
78
 
    m_controlSource->setOption("extraValueAllowed", "true");
79
 
 
80
 
    keys << "left" << "center" << "right";
81
 
    strings << i18n("Left") << i18n("Center") << i18n("Right");
82
 
    m_horizontalAlignment = new KoProperty::Property("horizontal-align", keys, strings, "left", i18n("Horizontal Alignment"));
83
 
 
84
 
    keys.clear();
85
 
    strings.clear();
86
 
    keys << "top" << "center" << "bottom";
87
 
    strings << i18n("Top") << i18n("Center") << i18n("Bottom");
88
 
    m_verticalAlignment = new KoProperty::Property("vertical-align", keys, strings, "center", i18n("Vertical Alignment"));
89
 
 
90
 
    m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), "Font", i18n("Font"));
91
 
 
92
 
    m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
93
 
    m_foregroundColor = new KoProperty::Property("foregroud-color", Qt::black, i18n("Foreground Color"));
94
 
 
95
 
    m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Opacity"));
96
 
    m_backgroundOpacity->setOption("max", 100);
97
 
    m_backgroundOpacity->setOption("min", 0);
98
 
    m_backgroundOpacity->setOption("unit", "%");
99
 
 
100
 
    m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
101
 
    m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
102
 
    m_lineStyle = new KoProperty::Property("line-style", Qt::NoPen, i18n("Line Style"), i18n("Line Style"), KoProperty::LineStyle);
103
 
 
104
 
#if 0
105
 
    //TODO I do not think we need these
106
 
    m_trackTotal = new KoProperty::Property("TrackTotal", QVariant(false), i18n("Track Total"));
107
 
    m_trackBuiltinFormat = new KoProperty::Property("TrackBuiltinFormat", QVariant(false), i18n("Track Builtin Format"));
108
 
    _useSubTotal = new KoProperty::Property("UseSubTotal", QVariant(false), i18n("Use Sub Total"_);
109
 
    _trackTotalFormat = new KoProperty::Property("TrackTotalFormat", QString(), i18n("Track Total Format"));
110
 
#endif
111
 
    addDefaultProperties();
112
 
    m_set->addProperty(m_controlSource);
113
 
    m_set->addProperty(m_horizontalAlignment);
114
 
    m_set->addProperty(m_verticalAlignment);
115
 
    m_set->addProperty(m_font);
116
 
    m_set->addProperty(m_backgroundColor);
117
 
    m_set->addProperty(m_foregroundColor);
118
 
    m_set->addProperty(m_backgroundOpacity);
119
 
    m_set->addProperty(m_lineWeight);
120
 
    m_set->addProperty(m_lineColor);
121
 
    m_set->addProperty(m_lineStyle);
122
 
    //_set->addProperty ( _trackTotal );
123
 
    //_set->addProperty ( _trackBuiltinFormat );
124
 
    //_set->addProperty ( _useSubTotal );
125
 
    //_set->addProperty ( _trackTotalFormat );
126
 
}
127
 
 
128
 
Qt::Alignment KRFieldData::textFlags() const
129
 
{
130
 
    Qt::Alignment align;
131
 
    QString t;
132
 
    t = m_horizontalAlignment->value().toString();
133
 
    if (t == "center")
134
 
        align = Qt::AlignHCenter;
135
 
    else if (t == "right")
136
 
        align = Qt::AlignRight;
137
 
    else
138
 
        align = Qt::AlignLeft;
139
 
 
140
 
    t = m_verticalAlignment->value().toString();
141
 
    if (t == "center")
142
 
        align |= Qt::AlignVCenter;
143
 
    else if (t == "bottom")
144
 
        align |= Qt::AlignBottom;
145
 
    else
146
 
        align |= Qt::AlignTop;
147
 
 
148
 
    return align;
149
 
}
150
 
 
151
 
KRTextStyleData KRFieldData::textStyle()
152
 
{
153
 
    KRTextStyleData d;
154
 
    d.backgroundColor = m_backgroundColor->value().value<QColor>();
155
 
    d.foregroundColor = m_foregroundColor->value().value<QColor>();
156
 
    d.font = m_font->value().value<QFont>();
157
 
    d.backgroundOpacity = m_backgroundOpacity->value().toInt();
158
 
 
159
 
    return d;
160
 
}
161
 
 
162
 
QString KRFieldData::controlSource() const
163
 
{
164
 
    return m_controlSource->value().toString();
165
 
}
166
 
 
167
 
void KRFieldData::setControlSource(const QString& t)
168
 
{
169
 
    if (m_controlSource->value() != t) {
170
 
        m_controlSource->setValue(t);
171
 
    }
172
 
 
173
 
    kDebug() << "Field: " << entityName() << "is" << controlSource();
174
 
}
175
 
 
176
 
KRLineStyleData KRFieldData::lineStyle()
177
 
{
178
 
    KRLineStyleData ls;
179
 
    ls.weight = m_lineWeight->value().toInt();
180
 
    ls.lineColor = m_lineColor->value().value<QColor>();
181
 
    ls.style = (Qt::PenStyle)m_lineStyle->value().toInt();
182
 
    return ls;
183
 
}
184
 
// RTTI
185
 
int KRFieldData::type() const
186
 
{
187
 
    return RTTI;
188
 
}
189
 
int KRFieldData::RTTI = KRObjectData::EntityField;
190
 
KRFieldData * KRFieldData::toField()
191
 
{
192
 
    return this;
193
 
}