File indexing completed on 2024-05-12 04:43:22

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public
0015  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include "KReportScriptDraw.h"
0019 #include "KReportRenderObjects.h"
0020 
0021 #include <QFont>
0022 #include <QFontMetrics>
0023 
0024 KReportScriptDraw::KReportScriptDraw(QObject *parent)
0025         : QObject(parent)
0026 {
0027     m_curPage = nullptr;
0028 }
0029 
0030 
0031 KReportScriptDraw::~KReportScriptDraw()
0032 {
0033 }
0034 
0035 void KReportScriptDraw::setPage(OROPage *p)
0036 {
0037     m_curPage = p;
0038 }
0039 
0040 void KReportScriptDraw::setOffset(QPointF off)
0041 {
0042     m_curOffset = off;
0043 }
0044 
0045 void KReportScriptDraw::rectangle(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a)
0046 {
0047     if (m_curPage) {
0048         ORORect *r = new ORORect();
0049 
0050         r->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h))));
0051 
0052         QPen pen(QColor(lc), lw);
0053         QColor c(fc);
0054         c.setAlpha(a);
0055         QBrush bru(c);
0056 
0057         r->setBrush(bru);
0058         r->setPen(pen);
0059         m_curPage->insertPrimitive(r);
0060     }
0061 }
0062 
0063 void KReportScriptDraw::ellipse(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a)
0064 {
0065     if (m_curPage) {
0066         OROEllipse *e = new OROEllipse();
0067 
0068         e->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h))));
0069 
0070         QPen pen(QColor(lc), lw);
0071         QColor c(fc);
0072         c.setAlpha(a);
0073         QBrush bru(c);
0074 
0075         e->setBrush(bru);
0076         e->setPen(pen);
0077         m_curPage->insertPrimitive(e);
0078     }
0079 }
0080 
0081 void KReportScriptDraw::line(qreal x1, qreal y1, qreal x2, qreal y2, const QString& lc)
0082 {
0083     if (m_curPage) {
0084         OROLine *ln = new OROLine();
0085 
0086         ln->setStartPoint(KReportItemBase::scenePosition(QPointF(x1, y1) + m_curOffset));
0087         ln->setEndPoint(KReportItemBase::scenePosition(QPointF(x2, y2) + m_curOffset));
0088 
0089         KReportLineStyle ls;
0090         ls.setColor(QColor(lc));
0091         ls.setWeight(1);
0092         ls.setPenStyle(Qt::SolidLine);
0093 
0094         ln->setLineStyle(ls);
0095         m_curPage->insertPrimitive(ln);
0096     }
0097 }
0098 
0099 void 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)
0100 {
0101     if (m_curPage) {
0102         QFont f(fnt, pt);
0103         QRectF r = QFontMetricsF(f).boundingRect(txt);
0104 
0105         KReportTextStyleData ts;
0106         ts.font = f;
0107         ts.backgroundColor = QColor(bc);
0108         ts.foregroundColor = QColor(fc);
0109         ts.backgroundOpacity = o;
0110 
0111         KReportLineStyle ls;
0112         ls.setColor(QColor(lc));
0113         ls.setWeight(lw);
0114         if (lw <= 0)
0115             ls.setPenStyle(Qt::NoPen);
0116         else
0117             ls.setPenStyle(Qt::SolidLine);
0118 
0119 
0120         OROTextBox *tb = new OROTextBox();
0121         tb->setPosition(QPointF(x, y) + m_curOffset);
0122         tb->setSize(r.size());
0123         tb->setTextStyle(ts);
0124         tb->setLineStyle(ls);
0125 
0126         tb->setText(txt);
0127 
0128         m_curPage->insertPrimitive(tb);
0129 
0130     }
0131 }
0132