KReport

KoOdtFrameReportPicture.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2011, 2012 by Dag Andersen (danders@get2net.dk)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "KoOdtFrameReportPicture.h"
21#include "KReportRenderObjects.h"
22
23#include <KoXmlWriter.h>
24#include <KoOdfGraphicStyles.h>
25#include <KoGenStyle.h>
26#include <KoGenStyles.h>
27#include <KReportUnit.h>
28#include <KoStore.h>
29#include <KoStoreDevice.h>
30
31#include <QPainter>
32#include "kreport_debug.h"
33#include <QMimeDatabase>
34#include <QMimeType>
35
36KoOdtFrameReportPicture::KoOdtFrameReportPicture(OROPrimitive *primitive)
37 : KoOdtFrameReportPrimitive(primitive)
38{
39}
40
41KoOdtFrameReportPicture::~KoOdtFrameReportPicture()
42{
43}
44
45OROPicture *KoOdtFrameReportPicture::picture() const
46{
47 return dynamic_cast<OROPicture*>(m_primitive);
48}
49
50void KoOdtFrameReportPicture::createBody(KoXmlWriter *bodyWriter) const
51{
52 bodyWriter->startElement("draw:frame");
53 bodyWriter->addAttribute("draw:id", itemName());
54 bodyWriter->addAttribute("xml:id", itemName());
55 bodyWriter->addAttribute("draw:name", itemName());
56 bodyWriter->addAttribute("text:anchor-type", "page");
57 bodyWriter->addAttribute("text:anchor-page-number", pageNumber());
58 bodyWriter->addAttribute("draw:style-name", m_frameStyleName);
59
60 commonAttributes(bodyWriter);
61
62 bodyWriter->startElement("draw:image");
63 bodyWriter->addAttribute("xlink:href", "Pictures/" + pictureName());
64 bodyWriter->addAttribute("xlink:type", "simple");
65 bodyWriter->addAttribute("xlink:show", "embed");
66 bodyWriter->addAttribute("xlink:actuate", "onLoad");
67 bodyWriter->endElement();
68
69 bodyWriter->endElement(); // draw:frame
70}
71
72bool KoOdtFrameReportPicture::saveData(KoStore* store, KoXmlWriter* manifestWriter) const
73{
74 QString name = "Pictures/" + pictureName();
75 if (!store->open(name)) {
76 return false;
77 }
78 KoStoreDevice device(store);
79 QImage image(m_primitive->size().toSize(), QImage::Format_ARGB32);
80 image.fill(0);
81 QPainter painter;
82 painter.begin(&image);
84 painter.drawPicture(0, 0, *(picture()->picture()));
85 painter.end();
86 //kreportDebug()<<image.format();
87 bool ok = image.save(&device, "PNG");
88 if (ok) {
91 manifestWriter->addManifestEntry(name, mimetype);
92 }
93 ok = store->close() && ok;
94 return ok;
95}
Defines a picture. A picture is different to an image, in that it is drawn using commands.
Represents the basic primitive with a position and type. Other primitives are subclasses with a defin...
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
QString name(StandardAction id)
QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const const
bool begin(QPaintDevice *device)
void drawPicture(const QPoint &point, const QPicture &picture)
bool end()
void setRenderHint(RenderHint hint, bool on)
QSize toSize() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.