KReport

KoOdtFrameReportTextBox.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 "KoOdtFrameReportTextBox.h"
21#include "KReportRenderObjects.h"
22
23#include <KoXmlWriter.h>
24#include <KoOdfGraphicStyles.h>
25#include <KoGenStyle.h>
26#include <KoGenStyles.h>
27
28#include <QFont>
29#include <QPen>
30
31KoOdtFrameReportTextBox::KoOdtFrameReportTextBox(OROTextBox *primitive)
32 : KoOdtFrameReportPrimitive(primitive)
33{
34}
35
36KoOdtFrameReportTextBox::~KoOdtFrameReportTextBox()
37{
38}
39
40OROTextBox *KoOdtFrameReportTextBox::textBox() const
41{
42 return dynamic_cast<OROTextBox*>(m_primitive);
43}
44
45void KoOdtFrameReportTextBox::createStyle(KoGenStyles *coll)
46{
47 QFont font = textBox()->textStyle().font;
48
49 KoGenStyle ps(KoGenStyle::ParagraphStyle, "paragraph");
50 m_paragraphStyleName = coll->insert(ps, "P");
51
52 // text style
53 KoGenStyle ts(KoGenStyle::TextStyle, "text");
54 ts.addProperty("fo:font-family", font.family());
55 ts.addPropertyPt("fo:font-size", font.pointSizeF());
56 ts.addProperty("fo:font-weight", font.weight() * 10);
57 ts.addProperty("fo:color", textBox()->textStyle().foregroundColor.name());
58 QString fs;
59 switch (font.style()) {
60 case QFont::StyleNormal: fs = "normal"; break;
61 case QFont::StyleItalic: fs = "italic"; break;
62 case QFont::StyleOblique: fs = "oblique"; break;
63 }
64 ts.addProperty("fo:font-style", fs);
65 m_textStyleName = coll->insert(ts, "T");
66
67 KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic");
68 QPen pen;
69 pen.setColor(textBox()->lineStyle().lineColor);
70 pen.setWidthF(textBox()->lineStyle().weight);
71 pen.setStyle(textBox()->lineStyle().style);
72 KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen);
73 gs.addProperty("style:horizontal-pos", "from-left");
74 gs.addProperty("style:horizontal-rel", "page");
75 gs.addProperty("style:vertical-pos", "from-top");
76 gs.addProperty("style:vertical-rel", "page");
77 gs.addProperty("fo:background-color", textBox()->textStyle().backgroundColor.name());
78 m_frameStyleName = coll->insert(gs, "F");
79}
80
81void KoOdtFrameReportTextBox::createBody(KoXmlWriter *bodyWriter) const
82{
83 bodyWriter->startElement("draw:frame");
84 bodyWriter->addAttribute("draw:id", itemName());
85 bodyWriter->addAttribute("xml:id", itemName());
86 bodyWriter->addAttribute("draw:name", itemName());
87 bodyWriter->addAttribute("text:anchor-type", "page");
88 bodyWriter->addAttribute("text:anchor-page-number", pageNumber());
89 bodyWriter->addAttribute("draw:style-name", m_frameStyleName);
90
91 commonAttributes(bodyWriter);
92
93 bodyWriter->startElement("draw:text-box");
94
95 bodyWriter->startElement("text:p");
96 bodyWriter->addAttribute("text:style-name", m_paragraphStyleName);
97 bodyWriter->startElement("text:span");
98 bodyWriter->addAttribute("text:style-name", m_textStyleName);
99 bodyWriter->addTextNode(textBox()->text());
100
101 bodyWriter->endElement(); // text:span
102 bodyWriter->endElement(); // text:p
103 bodyWriter->endElement(); // draw:text-box
104 bodyWriter->endElement(); // draw:frame
105}
A text box primitive it defines a box region and text that will be rendered inside that region,...
QString family() const const
qreal pointSizeF() const const
Style style() const const
Weight weight() const const
void setColor(const QColor &color)
void setStyle(Qt::PenStyle style)
void setWidthF(qreal width)
QString & insert(qsizetype position, QChar ch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.