~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to libs/koreport/renderer/odtframe/KoOdtFrameReportCheckBox.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Calligra Report Engine
 
3
   Copyright (C) 2011, 2012 by Dag Andersen (danders@get2net.dk)
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library 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
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
   Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "KoOdtFrameReportCheckBox.h"
 
22
#include <KoXmlWriter.h>
 
23
#include <KoDpi.h>
 
24
#include <KoOdfGraphicStyles.h>
 
25
#include <KoGenStyle.h>
 
26
#include <KoGenStyles.h>
 
27
#include <KoUnit.h>
 
28
#include <KoStore.h>
 
29
#include <KoStoreDevice.h>
 
30
 
 
31
#include "renderobjects.h"
 
32
 
 
33
#include <QColor>
 
34
#include <QPainter>
 
35
#include <QPen>
 
36
#include <QImage>
 
37
 
 
38
#include <kmimetype.h>
 
39
 
 
40
#include <kdebug.h>
 
41
 
 
42
KoOdtFrameReportCheckBox::KoOdtFrameReportCheckBox(OROCheck *primitive)
 
43
    : KoOdtFrameReportPrimitive(primitive)
 
44
{
 
45
}
 
46
 
 
47
KoOdtFrameReportCheckBox::~KoOdtFrameReportCheckBox()
 
48
{
 
49
}
 
50
 
 
51
OROCheck *KoOdtFrameReportCheckBox::checkBox() const
 
52
{
 
53
    return static_cast<OROCheck*>(m_primitive);
 
54
}
 
55
 
 
56
void KoOdtFrameReportCheckBox::createStyle(KoGenStyles &coll)
 
57
{
 
58
    KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic");
 
59
    gs.addProperty("draw:fill", "none");
 
60
    gs.addPropertyPt("fo:margin", 0);
 
61
    gs.addProperty("style:horizontal-pos", "from-left");
 
62
    gs.addProperty("style:horizontal-rel", "page");
 
63
    gs.addProperty("style:vertical-pos", "from-top");
 
64
    gs.addProperty("style:vertical-rel", "page");
 
65
    gs.addProperty("style:wrap", "dynamic");
 
66
    gs.addPropertyPt("style:wrap-dynamic-threshold", 0);
 
67
 
 
68
    QPen pen;
 
69
    qreal weight = checkBox()->lineStyle().weight;
 
70
    if (weight < 1.0) {
 
71
        weight = 1.0;
 
72
    }
 
73
    pen.setWidthF(weight);
 
74
    pen.setColor(checkBox()->lineStyle().lineColor);
 
75
    pen.setStyle(checkBox()->lineStyle().style);
 
76
    KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen);
 
77
 
 
78
    m_frameStyleName = coll.insert(gs, "F");
 
79
}
 
80
 
 
81
void KoOdtFrameReportCheckBox::createBody(KoXmlWriter *bodyWriter) const
 
82
{
 
83
    bodyWriter->startElement("draw:frame");
 
84
    bodyWriter->addAttribute("draw:id", itemName());
 
85
    bodyWriter->addAttribute("xml:id", itemName());
 
86
    bodyWriter->addAttribute("draw:name", itemName());
 
87
    bodyWriter->addAttribute("text:anchor-type", "page");
 
88
    bodyWriter->addAttribute("text:anchor-page-number", pageNumber());
 
89
    bodyWriter->addAttribute("draw:style-name", m_frameStyleName);
 
90
 
 
91
    commonAttributes(bodyWriter);
 
92
 
 
93
    bodyWriter->startElement("draw:image");
 
94
    bodyWriter->addAttribute("xlink:href", "Pictures/" + imageName());
 
95
    bodyWriter->addAttribute("xlink:type", "simple");
 
96
    bodyWriter->addAttribute("xlink:show", "embed");
 
97
    bodyWriter->addAttribute("xlink:actuate", "onLoad");
 
98
    bodyWriter->endElement(); // draw:image
 
99
 
 
100
    bodyWriter->endElement(); // draw:frame
 
101
}
 
102
 
 
103
QString KoOdtFrameReportCheckBox::imageName() const
 
104
{
 
105
    return QString("Checkbox_%1.png").arg(m_uid);
 
106
}
 
107
 
 
108
bool KoOdtFrameReportCheckBox::saveData(KoStore* store, KoXmlWriter* manifestWriter) const
 
109
{
 
110
    QString name = "Pictures/" + imageName();
 
111
    if (!store->open(name)) {
 
112
        return false;
 
113
    }
 
114
    OROCheck * chk = checkBox();
 
115
    QSizeF sz = chk->size();
 
116
    QPen fpen; // frame pen
 
117
    if (chk->lineStyle().style == Qt::NoPen || chk->lineStyle().weight <= 0) {
 
118
        fpen = QPen(QColor(224, 224, 224));
 
119
    } else {
 
120
        fpen = QPen(chk->lineStyle().lineColor, chk->lineStyle().weight, chk->lineStyle().style);
 
121
    }
 
122
    QPointF ps(fpen.widthF(), fpen.widthF());
 
123
    QRectF rc = QRectF(0, 0, sz.width() + (ps.x()*2), sz.height() + (ps.y()*2));
 
124
 
 
125
    QPainter painter;
 
126
    QImage image(rc.size().toSize(), QImage::Format_ARGB32);
 
127
    image.fill(0);
 
128
    painter.begin(&image);
 
129
    painter.setBackgroundMode(Qt::OpaqueMode);
 
130
    painter.setRenderHint(QPainter::Antialiasing);
 
131
 
 
132
    qreal ox = sz.width() / 5;
 
133
    qreal oy = sz.height() / 5;
 
134
 
 
135
    //Checkbox Style
 
136
    if (chk->checkType() == "Cross") {
 
137
        painter.drawRoundedRect(rc.adjusted(ps.x(), ps.y(), -ps.x(), -ps.y()), sz.width() / 10 , sz.height() / 10);
 
138
 
 
139
        if (chk->value()) {
 
140
            QPen lp;
 
141
            lp.setColor(chk->foregroundColor());
 
142
            lp.setWidth(ox > oy ? oy : ox);
 
143
            painter.setPen(lp);
 
144
            QRectF r = rc.adjusted(ox + ps.x(), oy + ps.y(), -(ox + ps.x()), -(oy + ps.y()));
 
145
            painter.drawLine(r.topLeft(), r.bottomRight());
 
146
            painter.drawLine(r.bottomLeft(), r.topRight());
 
147
        }
 
148
    } else if (chk->checkType() == "Dot") {
 
149
        //Radio Style
 
150
        painter.drawEllipse(rc);
 
151
 
 
152
        if (chk->value()) {
 
153
            QBrush lb(chk->foregroundColor());
 
154
            painter.setBrush(lb);
 
155
            painter.setPen(Qt::NoPen);
 
156
            painter.drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy);
 
157
        }
 
158
    } else {
 
159
        //Tickbox Style
 
160
        painter.drawRoundedRect(rc.adjusted(ps.x(), ps.y(), -ps.x(), -ps.y()), sz.width() / 10 , sz.height() / 10);
 
161
 
 
162
        if (chk->value()) {
 
163
            QPen lp;
 
164
            lp.setColor(chk->foregroundColor());
 
165
            lp.setWidth(ox > oy ? oy : ox);
 
166
            painter.setPen(lp);
 
167
            painter.drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps);
 
168
            painter.drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps);
 
169
        }
 
170
    }
 
171
    painter.end();
 
172
 
 
173
    KoStoreDevice device(store);
 
174
    bool ok = image.save(&device, "PNG");
 
175
    if (ok) {
 
176
        const QString mimetype(KMimeType::findByPath(name, 0 , true)->name());
 
177
        manifestWriter->addManifestEntry(name,  mimetype);
 
178
        kDebug()<<"manifest:"<<mimetype;
 
179
    }
 
180
    bool cl = store->close();
 
181
    kDebug()<<ok<<cl;
 
182
    return ok && cl;
 
183
}