KReport

KoOdtFrameReportLine.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 "KoOdtFrameReportLine.h"
21#include "KReportRenderObjects.h"
22
23#include <KoXmlWriter.h>
24#include <KReportDpi.h>
25#include <KoOdfGraphicStyles.h>
26#include <KoGenStyle.h>
27#include <KoGenStyles.h>
28#include <KReportUnit.h>
29
30#include <QPen>
31#include "kreport_debug.h"
32
33KoOdtFrameReportLine::KoOdtFrameReportLine(OROLine *primitive)
34 : KoOdtFrameReportPrimitive(primitive)
35{
36}
37
38KoOdtFrameReportLine::~KoOdtFrameReportLine()
39{
40}
41
42OROLine *KoOdtFrameReportLine::line() const
43{
44 return static_cast<OROLine*>(m_primitive);
45}
46
47void KoOdtFrameReportLine::createStyle(KoGenStyles *coll)
48{
49 KoGenStyle ps(KoGenStyle::ParagraphStyle, "paragraph");
50 m_paragraphStyleName = coll->insert(ps, "P");
51
52 KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic");
53 gs.addProperty("draw:fill", "none");
54 gs.addPropertyPt("fo:margin", 0);
55 gs.addProperty("style:horizontal-pos", "from-left");
56 gs.addProperty("style:horizontal-rel", "page");
57 gs.addProperty("style:vertical-pos", "from-top");
58 gs.addProperty("style:vertical-rel", "page");
59 gs.addProperty("style:wrap", "dynamic");
60 gs.addPropertyPt("style:wrap-dynamic-threshold", 0);
61
62 QPen pen;
63 qreal weight = line()->lineStyle().weight;
64 if (weight < 1.0) {
65 weight = 1.0;
66 }
67 pen.setWidthF(weight);
68 pen.setColor(line()->lineStyle().lineColor);
69 pen.setStyle(line()->lineStyle().style);
70 KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen);
71
72 m_frameStyleName = coll->insert(gs, "F");
73 //kreportDebug()<<*coll;
74}
75
76void KoOdtFrameReportLine::createBody(KoXmlWriter *bodyWriter) const
77{
78 // convert to inches
79 qreal sx = INCH_TO_POINT(line()->startPoint().x() / KReportPrivate::dpiX());
80 qreal sy = INCH_TO_POINT(line()->startPoint().y() / KReportPrivate::dpiY());
81 qreal ex = INCH_TO_POINT(line()->endPoint().x() / KReportPrivate::dpiX());
82 qreal ey = INCH_TO_POINT(line()->endPoint().y() / KReportPrivate::dpiY());
83 qreal width = ex - sx;
84 qreal height = ey - sy;
85
86 //kreportDebug()<<line()->startPoint()<<line()->endPoint();
87
88 bodyWriter->startElement("draw:rect");
89 bodyWriter->addAttribute("draw:id", itemName());
90 bodyWriter->addAttribute("xml:id", itemName());
91 bodyWriter->addAttribute("draw:name", itemName());
92 bodyWriter->addAttribute("text:anchor-type", "page");
93 bodyWriter->addAttribute("text:anchor-page-number", pageNumber());
94 bodyWriter->addAttribute("draw:style-name", m_frameStyleName);
95 bodyWriter->addAttribute("draw:z-index", "3");
96
97 if (height == 0.0 && width >= 0.0) {
98 // just a horizontal line
99 bodyWriter->addAttributePt("svg:x", sx);
100 bodyWriter->addAttributePt("svg:y", sy);
101 bodyWriter->addAttributePt("svg:width", width);
102 bodyWriter->addAttributePt("svg:height", 0.0);
103 } else {
104 // rotate
105 qreal l = sqrt(width*width + height*height);
106 bodyWriter->addAttributePt("svg:width", l);
107 bodyWriter->addAttributePt("svg:height", 0.0);
108 qreal sina = height / l;
109 qreal cosa = width / l;
110 QTransform rotate(cosa, sina, -sina, cosa, sx, sy);
111 bodyWriter->addAttribute("draw:transform", KoOdfGraphicStyles::saveTransformation(rotate));
112 }
113
114 bodyWriter->endElement(); // draw:frame
115}
Defines a line with a width/weight.
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 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.