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 "KoOdtFrameReportTextBox.h" 0021 #include "KReportRenderObjects.h" 0022 0023 #include <KoXmlWriter.h> 0024 #include <KoOdfGraphicStyles.h> 0025 #include <KoGenStyle.h> 0026 #include <KoGenStyles.h> 0027 0028 #include <QFont> 0029 #include <QPen> 0030 0031 KoOdtFrameReportTextBox::KoOdtFrameReportTextBox(OROTextBox *primitive) 0032 : KoOdtFrameReportPrimitive(primitive) 0033 { 0034 } 0035 0036 KoOdtFrameReportTextBox::~KoOdtFrameReportTextBox() 0037 { 0038 } 0039 0040 OROTextBox *KoOdtFrameReportTextBox::textBox() const 0041 { 0042 return dynamic_cast<OROTextBox*>(m_primitive); 0043 } 0044 0045 void KoOdtFrameReportTextBox::createStyle(KoGenStyles *coll) 0046 { 0047 QFont font = textBox()->textStyle().font; 0048 0049 KoGenStyle ps(KoGenStyle::ParagraphStyle, "paragraph"); 0050 m_paragraphStyleName = coll->insert(ps, "P"); 0051 0052 // text style 0053 KoGenStyle ts(KoGenStyle::TextStyle, "text"); 0054 ts.addProperty("fo:font-family", font.family()); 0055 ts.addPropertyPt("fo:font-size", font.pointSizeF()); 0056 ts.addProperty("fo:font-weight", font.weight() * 10); 0057 ts.addProperty("fo:color", textBox()->textStyle().foregroundColor.name()); 0058 QString fs; 0059 switch (font.style()) { 0060 case QFont::StyleNormal: fs = "normal"; break; 0061 case QFont::StyleItalic: fs = "italic"; break; 0062 case QFont::StyleOblique: fs = "oblique"; break; 0063 } 0064 ts.addProperty("fo:font-style", fs); 0065 m_textStyleName = coll->insert(ts, "T"); 0066 0067 KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic"); 0068 QPen pen; 0069 pen.setColor(textBox()->lineStyle().lineColor); 0070 pen.setWidthF(textBox()->lineStyle().weight); 0071 pen.setStyle(textBox()->lineStyle().style); 0072 KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen); 0073 gs.addProperty("style:horizontal-pos", "from-left"); 0074 gs.addProperty("style:horizontal-rel", "page"); 0075 gs.addProperty("style:vertical-pos", "from-top"); 0076 gs.addProperty("style:vertical-rel", "page"); 0077 gs.addProperty("fo:background-color", textBox()->textStyle().backgroundColor.name()); 0078 m_frameStyleName = coll->insert(gs, "F"); 0079 } 0080 0081 void KoOdtFrameReportTextBox::createBody(KoXmlWriter *bodyWriter) const 0082 { 0083 bodyWriter->startElement("draw:frame"); 0084 bodyWriter->addAttribute("draw:id", itemName()); 0085 bodyWriter->addAttribute("xml:id", itemName()); 0086 bodyWriter->addAttribute("draw:name", itemName()); 0087 bodyWriter->addAttribute("text:anchor-type", "page"); 0088 bodyWriter->addAttribute("text:anchor-page-number", pageNumber()); 0089 bodyWriter->addAttribute("draw:style-name", m_frameStyleName); 0090 0091 commonAttributes(bodyWriter); 0092 0093 bodyWriter->startElement("draw:text-box"); 0094 0095 bodyWriter->startElement("text:p"); 0096 bodyWriter->addAttribute("text:style-name", m_paragraphStyleName); 0097 bodyWriter->startElement("text:span"); 0098 bodyWriter->addAttribute("text:style-name", m_textStyleName); 0099 bodyWriter->addTextNode(textBox()->text()); 0100 0101 bodyWriter->endElement(); // text:span 0102 bodyWriter->endElement(); // text:p 0103 bodyWriter->endElement(); // draw:text-box 0104 bodyWriter->endElement(); // draw:frame 0105 }