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

« back to all changes in this revision

Viewing changes to libs/koreport/common/krtextdata.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

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 "krtextdata.h"
 
19
#include <koproperty/Property.h>
 
20
#include <koproperty/Set.h>
 
21
#include <KoGlobal.h>
 
22
#include <KLocale>
 
23
#include <KDebug>
 
24
#include <klocalizedstring.h>
 
25
#include <kglobalsettings.h>
 
26
 
 
27
KRTextData::KRTextData(QDomNode & element) : m_bottomPadding(0.0)
 
28
{
 
29
    QDomNodeList nl = element.childNodes();
 
30
    QString n;
 
31
    QDomNode node;
 
32
 
 
33
    createProperties();
 
34
    m_name->setValue(element.toElement().attribute("report:name"));
 
35
    m_controlSource->setValue(element.toElement().attribute("report:item-data-source"));
 
36
    Z = element.toElement().attribute("report:z-index").toDouble();
 
37
    m_horizontalAlignment->setValue(element.toElement().attribute("report:horizontal-align"));
 
38
    m_verticalAlignment->setValue(element.toElement().attribute("report:vertical-align"));
 
39
    m_bottomPadding = element.toElement().attribute("report:bottom-padding").toDouble();
 
40
 
 
41
    parseReportRect(element.toElement(), &m_pos, &m_size);
 
42
    
 
43
    for (int i = 0; i < nl.count(); i++) {
 
44
        node = nl.item(i);
 
45
        n = node.nodeName();
 
46
 
 
47
        if (n == "report:text-style") {
 
48
            KRTextStyleData ts;
 
49
            if (parseReportTextStyleData(node.toElement(), ts)) {
 
50
                m_backgroundColor->setValue(ts.backgroundColor);
 
51
                m_foregroundColor->setValue(ts.foregroundColor);
 
52
                m_backgroundOpacity->setValue(ts.backgroundOpacity);
 
53
                m_font->setValue(ts.font);
 
54
 
 
55
            }
 
56
        } else if (n == "report:line-style") {
 
57
            KRLineStyleData ls;
 
58
            if (parseReportLineStyleData(node.toElement(), ls)) {
 
59
                m_lineWeight->setValue(ls.weight);
 
60
                m_lineColor->setValue(ls.lineColor);
 
61
                m_lineStyle->setValue(ls.style);
 
62
            }
 
63
        } else {
 
64
            kDebug() << "while parsing field element encountered unknow element: " << n;
 
65
        }
 
66
    }
 
67
 
 
68
}
 
69
 
 
70
KRTextData::~KRTextData()
 
71
{
 
72
}
 
73
 
 
74
Qt::Alignment KRTextData::textFlags() const
 
75
{
 
76
    Qt::Alignment align;
 
77
    QString t;
 
78
    t = m_horizontalAlignment->value().toString();
 
79
    if (t == "center")
 
80
        align = Qt::AlignHCenter;
 
81
    else if (t == "right")
 
82
        align = Qt::AlignRight;
 
83
    else
 
84
        align = Qt::AlignLeft;
 
85
 
 
86
    t = m_verticalAlignment->value().toString();
 
87
    if (t == "center")
 
88
        align |= Qt::AlignVCenter;
 
89
    else if (t == "bottom")
 
90
        align |= Qt::AlignBottom;
 
91
    else
 
92
        align |= Qt::AlignTop;
 
93
 
 
94
    return align;
 
95
}
 
96
 
 
97
void KRTextData::createProperties()
 
98
{
 
99
    m_set = new KoProperty::Set(0, "Text");
 
100
 
 
101
    //connect ( set, SIGNAL ( propertyChanged ( KoProperty::Set &, KoProperty::Property & ) ), this, SLOT ( propertyChanged ( KoProperty::Set &, KoProperty::Property & ) ) );
 
102
 
 
103
    QStringList keys, strings;
 
104
 
 
105
    //_query = new KoProperty::Property ( "Query", QStringList(), QStringList(), "Data Source", "Query" );
 
106
    m_controlSource = new KoProperty::Property("item-data-source", QStringList(), QStringList(), QString(), i18n("Data Source"));
 
107
 
 
108
    keys << "left" << "center" << "right";
 
109
    strings << i18n("Left") << i18n("Center") << i18n("Right");
 
110
    m_horizontalAlignment = new KoProperty::Property("horizontal-align", keys, strings, "left", i18n("Horizontal Alignment"));
 
111
 
 
112
    keys.clear();
 
113
    strings.clear();
 
114
    keys << "top" << "center" << "bottom";
 
115
    strings << i18n("Top") << i18n("Center") << i18n("Bottom");
 
116
    m_verticalAlignment = new KoProperty::Property("vertical-align", keys, strings, "center", i18n("Vertical Alignment"));
 
117
 
 
118
    m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), "Font", i18n("Font"));
 
119
 
 
120
    m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
 
121
    m_foregroundColor = new KoProperty::Property("foreground-color", Qt::black, i18n("Foreground Color"));
 
122
 
 
123
    m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
 
124
    m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
 
125
    m_lineStyle = new KoProperty::Property("line-style", Qt::NoPen, i18n("Line Style"), i18n("Line Style"), KoProperty::LineStyle);
 
126
    m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Opacity"));
 
127
    m_backgroundOpacity->setOption("max", 100);
 
128
    m_backgroundOpacity->setOption("min", 0);
 
129
    m_backgroundOpacity->setOption("unit", "%");
 
130
 
 
131
    addDefaultProperties();
 
132
    m_set->addProperty(m_controlSource);
 
133
    m_set->addProperty(m_horizontalAlignment);
 
134
    m_set->addProperty(m_verticalAlignment);
 
135
    m_set->addProperty(m_font);
 
136
    m_set->addProperty(m_backgroundColor);
 
137
    m_set->addProperty(m_foregroundColor);
 
138
    m_set->addProperty(m_backgroundOpacity);
 
139
    m_set->addProperty(m_lineWeight);
 
140
    m_set->addProperty(m_lineColor);
 
141
    m_set->addProperty(m_lineStyle);
 
142
 
 
143
}
 
144
 
 
145
QString KRTextData::controlSource() const
 
146
{
 
147
    return m_controlSource->value().toString();
 
148
}
 
149
 
 
150
qreal KRTextData::bottomPadding() const
 
151
{
 
152
    return m_bottomPadding;
 
153
}
 
154
 
 
155
void KRTextData::setBottomPadding(qreal bp)
 
156
{
 
157
    if (m_bottomPadding != bp) {
 
158
        m_bottomPadding = bp;
 
159
    }
 
160
}
 
161
 
 
162
KRTextStyleData KRTextData::textStyle()
 
163
{
 
164
    KRTextStyleData d;
 
165
    d.backgroundColor = m_backgroundColor->value().value<QColor>();
 
166
    d.foregroundColor = m_foregroundColor->value().value<QColor>();
 
167
    d.font = m_font->value().value<QFont>();
 
168
    d.backgroundOpacity = m_backgroundOpacity->value().toInt();
 
169
    return d;
 
170
}
 
171
 
 
172
KRLineStyleData KRTextData::lineStyle()
 
173
{
 
174
    KRLineStyleData ls;
 
175
    ls.weight = m_lineWeight->value().toInt();
 
176
    ls.lineColor = m_lineColor->value().value<QColor>();
 
177
    ls.style = (Qt::PenStyle)m_lineStyle->value().toInt();
 
178
    return ls;
 
179
}
 
180
 
 
181
// RTTI
 
182
int KRTextData::type() const
 
183
{
 
184
    return RTTI;
 
185
}
 
186
int KRTextData::RTTI = KRObjectData::EntityText;
 
187
KRTextData* KRTextData::toText()
 
188
{
 
189
    return this;
 
190
}