3
Copyright (C) 2011, 2012 by Dag Andersen (danders@get2net.dk)
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.
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.
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.
21
#include "KoOdtFrameReportCheckBox.h"
22
#include <KoXmlWriter.h>
24
#include <KoOdfGraphicStyles.h>
25
#include <KoGenStyle.h>
26
#include <KoGenStyles.h>
29
#include <KoStoreDevice.h>
31
#include "renderobjects.h"
38
#include <kmimetype.h>
42
KoOdtFrameReportCheckBox::KoOdtFrameReportCheckBox(OROCheck *primitive)
43
: KoOdtFrameReportPrimitive(primitive)
47
KoOdtFrameReportCheckBox::~KoOdtFrameReportCheckBox()
51
OROCheck *KoOdtFrameReportCheckBox::checkBox() const
53
return static_cast<OROCheck*>(m_primitive);
56
void KoOdtFrameReportCheckBox::createStyle(KoGenStyles &coll)
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);
69
qreal weight = checkBox()->lineStyle().weight;
73
pen.setWidthF(weight);
74
pen.setColor(checkBox()->lineStyle().lineColor);
75
pen.setStyle(checkBox()->lineStyle().style);
76
KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen);
78
m_frameStyleName = coll.insert(gs, "F");
81
void KoOdtFrameReportCheckBox::createBody(KoXmlWriter *bodyWriter) const
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);
91
commonAttributes(bodyWriter);
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
100
bodyWriter->endElement(); // draw:frame
103
QString KoOdtFrameReportCheckBox::imageName() const
105
return QString("Checkbox_%1.png").arg(m_uid);
108
bool KoOdtFrameReportCheckBox::saveData(KoStore* store, KoXmlWriter* manifestWriter) const
110
QString name = "Pictures/" + imageName();
111
if (!store->open(name)) {
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));
120
fpen = QPen(chk->lineStyle().lineColor, chk->lineStyle().weight, chk->lineStyle().style);
122
QPointF ps(fpen.widthF(), fpen.widthF());
123
QRectF rc = QRectF(0, 0, sz.width() + (ps.x()*2), sz.height() + (ps.y()*2));
126
QImage image(rc.size().toSize(), QImage::Format_ARGB32);
128
painter.begin(&image);
129
painter.setBackgroundMode(Qt::OpaqueMode);
130
painter.setRenderHint(QPainter::Antialiasing);
132
qreal ox = sz.width() / 5;
133
qreal oy = sz.height() / 5;
136
if (chk->checkType() == "Cross") {
137
painter.drawRoundedRect(rc.adjusted(ps.x(), ps.y(), -ps.x(), -ps.y()), sz.width() / 10 , sz.height() / 10);
141
lp.setColor(chk->foregroundColor());
142
lp.setWidth(ox > oy ? oy : ox);
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());
148
} else if (chk->checkType() == "Dot") {
150
painter.drawEllipse(rc);
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);
160
painter.drawRoundedRect(rc.adjusted(ps.x(), ps.y(), -ps.x(), -ps.y()), sz.width() / 10 , sz.height() / 10);
164
lp.setColor(chk->foregroundColor());
165
lp.setWidth(ox > oy ? oy : ox);
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);
173
KoStoreDevice device(store);
174
bool ok = image.save(&device, "PNG");
176
const QString mimetype(KMimeType::findByPath(name, 0 , true)->name());
177
manifestWriter->addManifestEntry(name, mimetype);
178
kDebug()<<"manifest:"<<mimetype;
180
bool cl = store->close();