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

« back to all changes in this revision

Viewing changes to libs/koreport/items/label/KoReportItemLabel.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 "KoReportItemLabel.h"
 
19
#include <koproperty/Property.h>
 
20
#include <koproperty/Set.h>
 
21
#include <KoGlobal.h>
 
22
#include <kdebug.h>
 
23
#include <klocalizedstring.h>
 
24
#include <kglobalsettings.h>
 
25
#include "renderobjects.h"
 
26
 
 
27
KoReportItemLabel::KoReportItemLabel(QDomNode & element)
 
28
{
 
29
    createProperties();
 
30
    QDomNodeList nl = element.childNodes();
 
31
    QString n;
 
32
    QDomNode node;
 
33
 
 
34
    m_name->setValue(element.toElement().attribute("report:name"));
 
35
    m_text->setValue(element.toElement().attribute("report:caption"));
 
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
 
 
40
    parseReportRect(element.toElement(), &m_pos, &m_size);
 
41
    
 
42
    for (int i = 0; i < nl.count(); i++) {
 
43
        node = nl.item(i);
 
44
        n = node.nodeName();
 
45
 
 
46
        if (n == "report:text-style") {
 
47
            KRTextStyleData ts;
 
48
            if (parseReportTextStyleData(node.toElement(), ts)) {
 
49
                m_backgroundColor->setValue(ts.backgroundColor);
 
50
                m_foregroundColor->setValue(ts.foregroundColor);
 
51
                m_backgroundOpacity->setValue(ts.backgroundOpacity);
 
52
                m_font->setValue(ts.font);
 
53
 
 
54
            }
 
55
        } else if (n == "report:line-style") {
 
56
            KRLineStyleData ls;
 
57
            if (parseReportLineStyleData(node.toElement(), ls)) {
 
58
                m_lineWeight->setValue(ls.weight);
 
59
                m_lineColor->setValue(ls.lineColor);
 
60
                m_lineStyle->setValue(ls.style);
 
61
            }
 
62
        } else {
 
63
            kDebug() << "while parsing label element encountered unknow element: " << n;
 
64
        }
 
65
    }
 
66
}
 
67
 
 
68
QString KoReportItemLabel::text() const
 
69
{
 
70
    return m_text->value().toString();
 
71
}
 
72
 
 
73
void KoReportItemLabel::setText(const QString& t)
 
74
{
 
75
    m_text->setValue(t);
 
76
}
 
77
 
 
78
void KoReportItemLabel::createProperties()
 
79
{
 
80
    m_set = new KoProperty::Set(0, "Label");
 
81
 
 
82
    m_text = new KoProperty::Property("caption", "Label", i18n("Caption"));
 
83
    QStringList keys, strings;
 
84
 
 
85
    keys << "left" << "center" << "right";
 
86
    strings << i18n("Left") << i18n("Center") << i18n("Right");
 
87
    m_horizontalAlignment = new KoProperty::Property("horizontal-align", keys, strings, "left", i18n("Horizontal Alignment"));
 
88
 
 
89
    keys.clear();
 
90
    strings.clear();
 
91
    keys << "top" << "center" << "bottom";
 
92
    strings << i18n("Top") << i18n("Center") << i18n("Bottom");
 
93
    m_verticalAlignment = new KoProperty::Property("vertical-align", keys, strings, "center", i18n("Vertical Alignment"));
 
94
 
 
95
    m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), i18n("Font"), i18n("Font"));
 
96
 
 
97
    m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
 
98
    m_foregroundColor = new KoProperty::Property("foreground-color", Qt::black, i18n("Foreground Color"));
 
99
    m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Opacity"));
 
100
    m_backgroundOpacity->setOption("max", 100);
 
101
    m_backgroundOpacity->setOption("min", 0);
 
102
    m_backgroundOpacity->setOption("unit", "%");
 
103
 
 
104
    m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
 
105
    m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
 
106
    m_lineStyle = new KoProperty::Property("line-style", Qt::NoPen, i18n("Line Style"), i18n("Line Style"), KoProperty::LineStyle);
 
107
 
 
108
    addDefaultProperties();
 
109
    m_set->addProperty(m_text);
 
110
    m_set->addProperty(m_horizontalAlignment);
 
111
    m_set->addProperty(m_verticalAlignment);
 
112
    m_set->addProperty(m_font);
 
113
    m_set->addProperty(m_backgroundColor);
 
114
    m_set->addProperty(m_foregroundColor);
 
115
    m_set->addProperty(m_backgroundOpacity);
 
116
    m_set->addProperty(m_lineWeight);
 
117
    m_set->addProperty(m_lineColor);
 
118
    m_set->addProperty(m_lineStyle);
 
119
}
 
120
 
 
121
Qt::Alignment KoReportItemLabel::textFlags() const
 
122
{
 
123
    Qt::Alignment align;
 
124
    QString t;
 
125
    t = m_horizontalAlignment->value().toString();
 
126
    if (t == "center")
 
127
        align = Qt::AlignHCenter;
 
128
    else if (t == "right")
 
129
        align = Qt::AlignRight;
 
130
    else
 
131
        align = Qt::AlignLeft;
 
132
 
 
133
    t = m_verticalAlignment->value().toString();
 
134
    if (t == "center")
 
135
        align |= Qt::AlignVCenter;
 
136
    else if (t == "bottom")
 
137
        align |= Qt::AlignBottom;
 
138
    else
 
139
        align |= Qt::AlignTop;
 
140
 
 
141
    return align;
 
142
}
 
143
 
 
144
KRTextStyleData KoReportItemLabel::textStyle()
 
145
{
 
146
    KRTextStyleData d;
 
147
    d.backgroundColor = m_backgroundColor->value().value<QColor>();
 
148
    d.foregroundColor = m_foregroundColor->value().value<QColor>();
 
149
    d.font = m_font->value().value<QFont>();
 
150
    d.backgroundOpacity = m_backgroundOpacity->value().toInt();
 
151
    return d;
 
152
}
 
153
 
 
154
KRLineStyleData KoReportItemLabel::lineStyle()
 
155
{
 
156
    KRLineStyleData ls;
 
157
    ls.weight = m_lineWeight->value().toInt();
 
158
    ls.lineColor = m_lineColor->value().value<QColor>();
 
159
    ls.style = (Qt::PenStyle)m_lineStyle->value().toInt();
 
160
    return ls;
 
161
}
 
162
 
 
163
// RTTI
 
164
QString KoReportItemLabel::typeName() const
 
165
{
 
166
    return "report:label";
 
167
}
 
168
 
 
169
int KoReportItemLabel::render(OROPage* page, OROSection* section,  QPointF offset, QVariant data, KRScriptHandler *script)
 
170
{
 
171
    Q_UNUSED(data)
 
172
    Q_UNUSED(script)
 
173
    
 
174
    OROTextBox * tb = new OROTextBox();
 
175
    tb->setPosition(m_pos.toScene() + offset);
 
176
    tb->setSize(m_size.toScene());
 
177
    tb->setFont(font());
 
178
    tb->setText(text());
 
179
    tb->setFlags(textFlags());
 
180
    tb->setTextStyle(textStyle());
 
181
    tb->setLineStyle(lineStyle());
 
182
    if (page) page->addPrimitive(tb);
 
183
 
 
184
    OROPrimitive *clone = tb->clone();
 
185
    clone->setPosition(m_pos.toScene());
 
186
    if (section) section->addPrimitive(clone);
 
187
 
 
188
    return 0; //Item doesnt stretch the section height
 
189
}
 
190