KReport

KReportScriptDraw.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "KReportScriptDraw.h"
19#include "KReportRenderObjects.h"
20
21#include <QFont>
22#include <QFontMetrics>
23
24KReportScriptDraw::KReportScriptDraw(QObject *parent)
25 : QObject(parent)
26{
27 m_curPage = nullptr;
28}
29
30
31KReportScriptDraw::~KReportScriptDraw()
32{
33}
34
35void KReportScriptDraw::setPage(OROPage *p)
36{
37 m_curPage = p;
38}
39
40void KReportScriptDraw::setOffset(QPointF off)
41{
42 m_curOffset = off;
43}
44
45void KReportScriptDraw::rectangle(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a)
46{
47 if (m_curPage) {
48 ORORect *r = new ORORect();
49
50 r->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h))));
51
52 QPen pen(QColor(lc), lw);
53 QColor c(fc);
54 c.setAlpha(a);
55 QBrush bru(c);
56
57 r->setBrush(bru);
58 r->setPen(pen);
59 m_curPage->insertPrimitive(r);
60 }
61}
62
63void KReportScriptDraw::ellipse(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a)
64{
65 if (m_curPage) {
66 OROEllipse *e = new OROEllipse();
67
68 e->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h))));
69
70 QPen pen(QColor(lc), lw);
71 QColor c(fc);
72 c.setAlpha(a);
73 QBrush bru(c);
74
75 e->setBrush(bru);
76 e->setPen(pen);
77 m_curPage->insertPrimitive(e);
78 }
79}
80
81void KReportScriptDraw::line(qreal x1, qreal y1, qreal x2, qreal y2, const QString& lc)
82{
83 if (m_curPage) {
84 OROLine *ln = new OROLine();
85
86 ln->setStartPoint(KReportItemBase::scenePosition(QPointF(x1, y1) + m_curOffset));
87 ln->setEndPoint(KReportItemBase::scenePosition(QPointF(x2, y2) + m_curOffset));
88
90 ls.setColor(QColor(lc));
91 ls.setWeight(1);
92 ls.setPenStyle(Qt::SolidLine);
93
94 ln->setLineStyle(ls);
95 m_curPage->insertPrimitive(ln);
96 }
97}
98
99void KReportScriptDraw::text(qreal x, qreal y, const QString &txt, const QString &fnt, int pt, const QString &fc, const QString&bc, const QString &lc, qreal lw, int o)
100{
101 if (m_curPage) {
102 QFont f(fnt, pt);
104
105 KReportTextStyleData ts;
106 ts.font = f;
107 ts.backgroundColor = QColor(bc);
108 ts.foregroundColor = QColor(fc);
109 ts.backgroundOpacity = o;
110
112 ls.setColor(QColor(lc));
113 ls.setWeight(lw);
114 if (lw <= 0)
115 ls.setPenStyle(Qt::NoPen);
116 else
117 ls.setPenStyle(Qt::SolidLine);
118
119
120 OROTextBox *tb = new OROTextBox();
121 tb->setPosition(QPointF(x, y) + m_curOffset);
122 tb->setSize(r.size());
123 tb->setTextStyle(ts);
124 tb->setLineStyle(ls);
125
126 tb->setText(txt);
127
128 m_curPage->insertPrimitive(tb);
129
130 }
131}
132
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
The KReportLineStyle class represents line style.
void rectangle(qreal, qreal, qreal, qreal, const QString &, const QString &, qreal, int)
Draw a rectangle.
void ellipse(qreal, qreal, qreal, qreal, const QString &, const QString &, qreal, int)
Draw an ellipse.
void text(qreal, qreal, const QString &, const QString &fnt=QLatin1String("Helvetica"), int pt=12, const QString &fc=QLatin1String("#000000"), const QString &bc=QLatin1String("#ffffff"), const QString &lc=QLatin1String("#ffffff"), qreal lw=0, int o=0)
Draw some text.
void line(qreal, qreal, qreal, qreal, const QString &)
Draw a line.
Defines an ellipse.
Defines a line with a width/weight.
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Defines a rectangle.
A text box primitive it defines a box region and text that will be rendered inside that region,...
void setAlpha(int alpha)
QRectF boundingRect(QChar ch) const const
QSizeF size() const const
SolidLine
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.