File indexing completed on 2024-05-12 04:43:22
0001 /* This file is part of the KDE project 0002 Copyright (C) 2011, 2012 by Dag Andersen (danders@get2net.dk) 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoOdtFrameReportImage.h" 0021 #include <KoXmlWriter.h> 0022 #include <KoStore.h> 0023 #include <KoStoreDevice.h> 0024 0025 #include <QMimeDatabase> 0026 #include <QMimeType> 0027 0028 #include "KReportRenderObjects.h" 0029 0030 KoOdtFrameReportImage::KoOdtFrameReportImage(OROImage *primitive) 0031 : KoOdtFrameReportPrimitive(primitive) 0032 { 0033 } 0034 0035 KoOdtFrameReportImage::~KoOdtFrameReportImage() 0036 { 0037 } 0038 0039 OROImage *KoOdtFrameReportImage::image() const 0040 { 0041 return static_cast<OROImage*>(m_primitive); 0042 } 0043 0044 void KoOdtFrameReportImage::setImageName(const QString &name) 0045 { 0046 m_name = name; 0047 } 0048 0049 void KoOdtFrameReportImage::createBody(KoXmlWriter *bodyWriter) const 0050 { 0051 bodyWriter->startElement("draw:frame"); 0052 bodyWriter->addAttribute("draw:style-name", "picture"); 0053 bodyWriter->addAttribute("draw:id", itemName()); 0054 bodyWriter->addAttribute("draw:name", itemName()); 0055 bodyWriter->addAttribute("text:anchor-type", "page"); 0056 bodyWriter->addAttribute("text:anchor-page-number", pageNumber()); 0057 bodyWriter->addAttribute("draw:style-name", m_frameStyleName); 0058 0059 commonAttributes(bodyWriter); 0060 0061 bodyWriter->startElement("draw:image"); 0062 bodyWriter->addAttribute("xlink:href", "Pictures/" + imageName()); 0063 bodyWriter->addAttribute("xlink:type", "simple"); 0064 bodyWriter->addAttribute("xlink:show", "embed"); 0065 bodyWriter->addAttribute("xlink:actuate", "onLoad"); 0066 bodyWriter->endElement(); 0067 0068 bodyWriter->endElement(); // draw:frame 0069 } 0070 0071 bool KoOdtFrameReportImage::saveData(KoStore* store, KoXmlWriter* manifestWriter) const 0072 { 0073 QString name = "Pictures/" + imageName(); 0074 if (!store->open(name)) { 0075 return false; 0076 } 0077 KoStoreDevice device(store); 0078 bool ok = image()->image().save(&device, "PNG"); 0079 if (ok) { 0080 QMimeDatabase db; 0081 const QString mimetype(db.mimeTypeForFile(name, QMimeDatabase::MatchExtension).name()); 0082 manifestWriter->addManifestEntry(name, mimetype); 0083 } 0084 ok = store->close() && ok; 0085 return ok; 0086 }