KReport

KoOdtFrameReportImage.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 "KoOdtFrameReportImage.h"
21#include <KoXmlWriter.h>
22#include <KoStore.h>
23#include <KoStoreDevice.h>
24
25#include <QMimeDatabase>
26#include <QMimeType>
27
28#include "KReportRenderObjects.h"
29
30KoOdtFrameReportImage::KoOdtFrameReportImage(OROImage *primitive)
31 : KoOdtFrameReportPrimitive(primitive)
32{
33}
34
35KoOdtFrameReportImage::~KoOdtFrameReportImage()
36{
37}
38
39OROImage *KoOdtFrameReportImage::image() const
40{
41 return static_cast<OROImage*>(m_primitive);
42}
43
44void KoOdtFrameReportImage::setImageName(const QString &name)
45{
46 m_name = name;
47}
48
49void KoOdtFrameReportImage::createBody(KoXmlWriter *bodyWriter) const
50{
51 bodyWriter->startElement("draw:frame");
52 bodyWriter->addAttribute("draw:style-name", "picture");
53 bodyWriter->addAttribute("draw:id", itemName());
54 bodyWriter->addAttribute("draw:name", itemName());
55 bodyWriter->addAttribute("text:anchor-type", "page");
56 bodyWriter->addAttribute("text:anchor-page-number", pageNumber());
57 bodyWriter->addAttribute("draw:style-name", m_frameStyleName);
58
59 commonAttributes(bodyWriter);
60
61 bodyWriter->startElement("draw:image");
62 bodyWriter->addAttribute("xlink:href", "Pictures/" + imageName());
63 bodyWriter->addAttribute("xlink:type", "simple");
64 bodyWriter->addAttribute("xlink:show", "embed");
65 bodyWriter->addAttribute("xlink:actuate", "onLoad");
66 bodyWriter->endElement();
67
68 bodyWriter->endElement(); // draw:frame
69}
70
71bool KoOdtFrameReportImage::saveData(KoStore* store, KoXmlWriter* manifestWriter) const
72{
73 QString name = "Pictures/" + imageName();
74 if (!store->open(name)) {
75 return false;
76 }
77 KoStoreDevice device(store);
78 bool ok = image()->image().save(&device, "PNG");
79 if (ok) {
82 manifestWriter->addManifestEntry(name, mimetype);
83 }
84 ok = store->close() && ok;
85 return ok;
86}
Defines an image. An image is a bitmap.
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
QString name(StandardAction id)
bool save(QIODevice *device, const char *format, int quality) const const
QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.