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 "KoOdtFrameReportLine.h" 0021 #include "KReportRenderObjects.h" 0022 0023 #include <KoXmlWriter.h> 0024 #include <KReportDpi.h> 0025 #include <KoOdfGraphicStyles.h> 0026 #include <KoGenStyle.h> 0027 #include <KoGenStyles.h> 0028 #include <KReportUnit.h> 0029 0030 #include <QPen> 0031 #include "kreport_debug.h" 0032 0033 KoOdtFrameReportLine::KoOdtFrameReportLine(OROLine *primitive) 0034 : KoOdtFrameReportPrimitive(primitive) 0035 { 0036 } 0037 0038 KoOdtFrameReportLine::~KoOdtFrameReportLine() 0039 { 0040 } 0041 0042 OROLine *KoOdtFrameReportLine::line() const 0043 { 0044 return static_cast<OROLine*>(m_primitive); 0045 } 0046 0047 void KoOdtFrameReportLine::createStyle(KoGenStyles *coll) 0048 { 0049 KoGenStyle ps(KoGenStyle::ParagraphStyle, "paragraph"); 0050 m_paragraphStyleName = coll->insert(ps, "P"); 0051 0052 KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic"); 0053 gs.addProperty("draw:fill", "none"); 0054 gs.addPropertyPt("fo:margin", 0); 0055 gs.addProperty("style:horizontal-pos", "from-left"); 0056 gs.addProperty("style:horizontal-rel", "page"); 0057 gs.addProperty("style:vertical-pos", "from-top"); 0058 gs.addProperty("style:vertical-rel", "page"); 0059 gs.addProperty("style:wrap", "dynamic"); 0060 gs.addPropertyPt("style:wrap-dynamic-threshold", 0); 0061 0062 QPen pen; 0063 qreal weight = line()->lineStyle().weight; 0064 if (weight < 1.0) { 0065 weight = 1.0; 0066 } 0067 pen.setWidthF(weight); 0068 pen.setColor(line()->lineStyle().lineColor); 0069 pen.setStyle(line()->lineStyle().style); 0070 KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen); 0071 0072 m_frameStyleName = coll->insert(gs, "F"); 0073 //kreportDebug()<<*coll; 0074 } 0075 0076 void KoOdtFrameReportLine::createBody(KoXmlWriter *bodyWriter) const 0077 { 0078 // convert to inches 0079 qreal sx = INCH_TO_POINT(line()->startPoint().x() / KReportPrivate::dpiX()); 0080 qreal sy = INCH_TO_POINT(line()->startPoint().y() / KReportPrivate::dpiY()); 0081 qreal ex = INCH_TO_POINT(line()->endPoint().x() / KReportPrivate::dpiX()); 0082 qreal ey = INCH_TO_POINT(line()->endPoint().y() / KReportPrivate::dpiY()); 0083 qreal width = ex - sx; 0084 qreal height = ey - sy; 0085 0086 //kreportDebug()<<line()->startPoint()<<line()->endPoint(); 0087 0088 bodyWriter->startElement("draw:rect"); 0089 bodyWriter->addAttribute("draw:id", itemName()); 0090 bodyWriter->addAttribute("xml:id", itemName()); 0091 bodyWriter->addAttribute("draw:name", itemName()); 0092 bodyWriter->addAttribute("text:anchor-type", "page"); 0093 bodyWriter->addAttribute("text:anchor-page-number", pageNumber()); 0094 bodyWriter->addAttribute("draw:style-name", m_frameStyleName); 0095 bodyWriter->addAttribute("draw:z-index", "3"); 0096 0097 if (height == 0.0 && width >= 0.0) { 0098 // just a horizontal line 0099 bodyWriter->addAttributePt("svg:x", sx); 0100 bodyWriter->addAttributePt("svg:y", sy); 0101 bodyWriter->addAttributePt("svg:width", width); 0102 bodyWriter->addAttributePt("svg:height", 0.0); 0103 } else { 0104 // rotate 0105 qreal l = sqrt(width*width + height*height); 0106 bodyWriter->addAttributePt("svg:width", l); 0107 bodyWriter->addAttributePt("svg:height", 0.0); 0108 qreal sina = height / l; 0109 qreal cosa = width / l; 0110 QTransform rotate(cosa, sina, -sina, cosa, sx, sy); 0111 bodyWriter->addAttribute("draw:transform", KoOdfGraphicStyles::saveTransformation(rotate)); 0112 } 0113 0114 bodyWriter->endElement(); // draw:frame 0115 }