diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp
index 3a2bfea8..b3851594 100644
--- a/src/common/KReportItemBase.cpp
+++ b/src/common/KReportItemBase.cpp
@@ -1,239 +1,239 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportItemBase.h"
#include "KReportUtils.h"
#include "KReportUtils_p.h"
#include
#include
#include
class Q_DECL_HIDDEN KReportItemBase::Private
{
public:
Private();
~Private();
KPropertySet *set;
KProperty *nameProperty;
KProperty *sizeProperty;
KProperty *positionProperty;
QString oldName;
qreal z = 0;
};
KReportItemBase::Private::Private()
{
set = new KPropertySet();
nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name"));
nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut);
positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position"));
sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size"));
set->addProperty(nameProperty);
set->addProperty(positionProperty);
set->addProperty(sizeProperty);
}
KReportItemBase::Private::~Private()
{
delete set;
}
KReportItemBase::KReportItemBase() : d(new Private())
{
connect(propertySet(), &KPropertySet::propertyChanged,
this, &KReportItemBase::propertyChanged);
}
KReportItemBase::~KReportItemBase()
{
delete d;
}
-bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts)
+bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts)
{
return KReportUtils::parseReportTextStyleData(elemSource, ts);
}
bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls)
{
return KReportUtils::parseReportLineStyleData(elemSource, ls);
}
bool KReportItemBase::parseReportRect(const QDomElement & elemSource)
{
QPointF pos;
QSizeF size;
pos.setX(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:x"), QLatin1String("1cm"))));
pos.setY(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:y"), QLatin1String("1cm"))));
size.setWidth(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:width"), QLatin1String("1cm"))));
size.setHeight(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("1cm"))));
setPosition(pos);
setSize(size);
return true;
}
void KReportItemBase::setUnit(const KReportUnit& u)
{
qDebug() << "Setting page unit to: " << u.symbol();
d->positionProperty->setOption("unit", u.symbol());
d->sizeProperty->setOption("unit", u.symbol());
}
int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler* script)
{
Q_UNUSED(page)
Q_UNUSED(section)
Q_UNUSED(offset)
Q_UNUSED(data)
Q_UNUSED(script)
return 0;
}
int KReportItemBase::renderReportData(OROPage *page, OROSection *section, const QPointF &offset,
KReportDataSource *dataSource, KReportScriptHandler* script)
{
Q_UNUSED(page)
Q_UNUSED(section)
Q_UNUSED(offset)
Q_UNUSED(dataSource)
Q_UNUSED(script)
return 0;
}
QString KReportItemBase::itemDataSource() const
{
return QString();
}
KPropertySet* KReportItemBase::propertySet()
{
return d->set;
}
bool KReportItemBase::supportsSubQuery() const
{
return false;
}
QString KReportItemBase::entityName() const
{
return d->nameProperty->value().toString();
}
void KReportItemBase::setEntityName(const QString& n)
{
d->nameProperty->setValue(n);
}
KProperty* KReportItemBase::nameProperty()
{
return d->nameProperty;
}
QString KReportItemBase::oldName() const
{
return d->oldName;
}
void KReportItemBase::setOldName(const QString& old)
{
d->oldName = old;
}
QPointF KReportItemBase::position() const
{
return d->positionProperty->value().toPointF();
}
QSizeF KReportItemBase::size() const
{
return d->sizeProperty->value().toSizeF();
}
const KPropertySet * KReportItemBase::propertySet() const
{
return d->set;
}
QPointF KReportItemBase::scenePosition(const QPointF &pos)
{
const qreal x = POINT_TO_INCH(pos.x()) * KReportPrivate::dpiX();
const qreal y = POINT_TO_INCH(pos.y()) * KReportPrivate::dpiY();
return QPointF(x, y);
}
QSizeF KReportItemBase::sceneSize(const QSizeF &size)
{
const qreal w = POINT_TO_INCH(size.width()) * KReportPrivate::dpiX();
const qreal h = POINT_TO_INCH(size.height()) * KReportPrivate::dpiY();
return QSizeF(w, h);
}
qreal KReportItemBase::z() const
{
return d->z;
}
void KReportItemBase::setZ(qreal z)
{
d->z = z;
}
void KReportItemBase::setPosition(const QPointF& pos)
{
d->positionProperty->setValue(pos);
}
void KReportItemBase::setSize(const QSizeF& size)
{
d->sizeProperty->setValue(size);
}
QPointF KReportItemBase::positionFromScene(const QPointF& pos)
{
const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX());
const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY());
return QPointF(x, y);
}
QSizeF KReportItemBase::sizeFromScene(const QSizeF& size)
{
qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX());
qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY());
return QSizeF(w, h);
}
void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p)
{
Q_UNUSED(s)
Q_UNUSED(p)
}
diff --git a/src/common/KReportItemBase.h b/src/common/KReportItemBase.h
index 414b8b6f..02020960 100644
--- a/src/common/KReportItemBase.h
+++ b/src/common/KReportItemBase.h
@@ -1,155 +1,155 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2010 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KREPORTITEMBASE_H
#define KREPORTITEMBASE_H
#include "config-kreport.h"
#include "kreport_export.h"
#include "KReportUnit.h"
#include
#include
#include
class OROPage;
class OROSection;
class KReportSize;
class KReportDataSource;
class KReportLineStyle;
#ifdef KREPORT_SCRIPTING
class KReportScriptHandler;
#else
#define KReportScriptHandler void
#endif
class KProperty;
class KPropertySet;
class QDomElement;
-class KRTextStyleData
+class KReportTextStyleData
{
public:
QFont font;
Qt::Alignment alignment;
QColor backgroundColor;
QColor foregroundColor;
int backgroundOpacity;
};
/*
class KReportLineStyle
{
public:
int weight;
QColor lineColor;
Qt::PenStyle style;
};
*/
/**
*/
class KREPORT_EXPORT KReportItemBase : public QObject
{
Q_OBJECT
public:
KReportItemBase();
virtual ~KReportItemBase();
/**
@brief Return the item type as a string. Required by all items
@return Item type
*/
virtual QString typeName() const = 0;
/**
@brief Render the item into a primitive which is used by the second stage renderer
@return the height required by the object
*/
virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
/**
@brief Render a complex item that uses a sub query as a data source
@return the height required by the object
*/
virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler *script);
/**
@brief Override if the item supports a simple data source, such as a field
@return The field name or expression for the data source
*/
virtual QString itemDataSource() const;
/**
@brief Override if the item uses a sub query and linked fields, such as a chart or sub-report
@return True if uses a sub query
*/
virtual bool supportsSubQuery() const;
-
+
KPropertySet* propertySet();
const KPropertySet* propertySet() const;
-
+
void setEntityName(const QString& n);
QString entityName() const;
virtual void setUnit(const KReportUnit& u);
/**
* @brief Return the size in points
*/
QSizeF size() const;
-
+
/**
* @brief Return the position in points
*/
QPointF position() const;
void setPosition(const QPointF &pos);
void setSize(const QSizeF &siz);
-
+
qreal z() const;
void setZ(qreal z);
-
+
//Helper function to map between size/position units
static QPointF scenePosition(const QPointF &pos);
static QSizeF sceneSize(const QSizeF &size);
static QPointF positionFromScene(const QPointF &pos);
static QSizeF sizeFromScene(const QSizeF &size);
protected:
virtual void createProperties() = 0;
bool parseReportRect(const QDomElement &elem);
- static bool parseReportTextStyleData(const QDomElement &, KRTextStyleData*);
+ static bool parseReportTextStyleData(const QDomElement &, KReportTextStyleData*);
static bool parseReportLineStyleData(const QDomElement &, KReportLineStyle*);
-
+
KProperty *nameProperty();
QString oldName() const;
void setOldName(const QString &old);
-
+
Q_SLOT virtual void propertyChanged(KPropertySet &s, KProperty &p);
-
+
private:
Q_DISABLE_COPY(KReportItemBase)
class Private;
Private * const d;
};
#endif
diff --git a/src/common/KReportRenderObjects.cpp b/src/common/KReportRenderObjects.cpp
index c3fe1d8b..3d2a63ac 100644
--- a/src/common/KReportRenderObjects.cpp
+++ b/src/common/KReportRenderObjects.cpp
@@ -1,968 +1,968 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportRenderObjects.h"
#include "KReportUtils_p.h"
#include "kreport_debug.h"
// Helper functions
static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2)
{
return s1->position().x() < s2->position().x();
}
//
// ORODocument
//
class Q_DECL_HIDDEN ORODocument::Private
{
public:
Private();
~Private();
QString title;
QList pages;
QList sections;
KReportPrivate::PageLayout pageLayout;
};
ORODocument::Private::Private()
{
}
ORODocument::Private::~Private()
{
qDeleteAll(pages);
qDeleteAll(sections);
}
ORODocument::ORODocument(const QString& title) : d(new Private())
{
d->title = title;
}
ORODocument::~ORODocument()
{
delete d;
}
void ORODocument::setTitle(const QString &title)
{
d->title = title;
}
OROPage* ORODocument::page(int index)
{
return d->pages.value(index);
}
const OROPage * ORODocument::page(int index) const
{
return d->pages.value(index);
}
void ORODocument::addPage(OROPage* p)
{
if (p == 0) {
return;
}
if (p->document() != 0 && p->document() != this) {
return;
}
p->setDocument(this);
d->pages.append(p);
}
OROSection* ORODocument::section(int pnum)
{
return d->sections.value(pnum);
}
const OROSection * ORODocument::section(int index) const
{
return d->sections.value(index);
}
void ORODocument::addSection(OROSection* s)
{
if (s == 0)
return;
if (s->document() != 0 && s->document() != this) {
return;
}
s->setDocument(this);
d->sections.append(s);
}
void ORODocument::setPageLayout(const QPageLayout & options)
{
d->pageLayout = options;
}
void ORODocument::notifyChange(int pageNo)
{
emit(updated(pageNo));
}
QPageLayout ORODocument::pageLayout() const
{
return d->pageLayout;
}
int ORODocument::pageCount() const
{
return d->pages.count();
}
int ORODocument::sectionCount() const
{
return d->sections.count();
}
QString ORODocument::title() const
{
return d->title;
}
void ORODocument::removePage(OROPage* page)
{
d->pages.removeOne(page);
delete page;
}
void ORODocument::takePage(OROPage* page)
{
d->pages.removeOne(page);
}
void ORODocument::removeSection(OROSection* section)
{
d->sections.removeOne(section);
delete section;
}
void ORODocument::takeSection(OROSection* section)
{
d->sections.removeOne(section);
}
int ORODocument::pageIndex(const OROPage* page) const
{
return d->pages.indexOf(const_cast(page));
}
//
// OROPage
//
class Q_DECL_HIDDEN OROPage::Private
{
public:
Private();
~Private();
ORODocument *document;
QList primitives;
};
OROPage::Private::Private()
{
}
OROPage::Private::~Private()
{
qDeleteAll(primitives);
}
OROPage::OROPage(ORODocument * pDocument)
: d(new Private())
{
d->document = pDocument;
}
OROPage::~OROPage()
{
if (d->document) {
d->document->takePage(this);
}
delete d;
}
int OROPage::pageNumber() const
{
if (d->document) {
return d->document->pageIndex(this);
}
return -1;
}
OROPrimitive* OROPage::primitive(int index)
{
return d->primitives.value(index);
}
const OROPrimitive * OROPage::primitive(int index) const
{
return d->primitives.value(index);
}
void OROPage::insertPrimitive(OROPrimitive* p, int index)
{
//kreportDebug() << "Adding primitive" << p->type() << "to page" << page();
if (p == 0)
return;
p->setPage(this);
if (index == -1) {
d->primitives.append(p);
} else {
d->primitives.insert(index, p);
}
#if 0
//TODO
if (notify) {
if (d->document) {
d->document->notifyChange(pageNumber());
}
}
#endif
}
ORODocument * OROPage::document()
{
return d->document;
}
const ORODocument * OROPage::document() const
{
return d->document;
}
int OROPage::primitiveCount() const
{
return d->primitives.count();
}
void OROPage::setDocument(ORODocument* doc)
{
d->document = doc;
}
void OROPage::removePrimitive(OROPrimitive* primitive)
{
d->primitives.removeOne(primitive);
delete primitive;
}
void OROPage::takePrimitive(OROPrimitive* primitive)
{
d->primitives.removeOne(primitive);
}
//
// OROSection
//
class Q_DECL_HIDDEN OROSection::Private
{
public:
Private();
~Private();
ORODocument * document;
QList primitives;
qint64 row = 0;
int height = 0;
KReportSectionData::Section type = KReportSectionData::None;
QColor backgroundColor = Qt::white;
};
OROSection::Private::Private()
{
}
OROSection::Private::~Private()
{
qDeleteAll(primitives);
primitives.clear();
}
OROSection::OROSection(ORODocument* doc) : d(new Private())
{
d->document = doc;
}
OROSection::~OROSection()
{
if (d->document) {
d->document->takeSection(this);
}
delete d;
}
OROPrimitive* OROSection::primitive(int index)
{
return d->primitives.value(index);
}
const OROPrimitive * OROSection::primitive(int index) const
{
return d->primitives.value(index);
}
void OROSection::addPrimitive(OROPrimitive* primitive)
{
if (primitive == 0)
return;
d->primitives.append(primitive);
}
void OROSection::setHeight(int h)
{
d->height = h;
}
int OROSection::height() const
{
return d->height;
}
void OROSection::setBackgroundColor(const QColor& color)
{
d->backgroundColor = color;
}
QColor OROSection::backgroundColor() const
{
return d->backgroundColor;
}
void OROSection::sortPrimitives(Qt::Orientation orientation)
{
if (orientation == Qt::Horizontal) {
qSort(d->primitives.begin(), d->primitives.end(), xLessThan);
}
}
ORODocument * OROSection::document()
{
return d->document;
}
const ORODocument * OROSection::document() const
{
return d->document;
}
int OROSection::primitiveCount() const
{
return d->primitives.count();
}
void OROSection::setType(KReportSectionData::Section t)
{
d->type = t;
}
KReportSectionData::Section OROSection::type() const
{
return d->type;
}
void OROSection::setDocument(ORODocument* doc)
{
d->document = doc;
}
//
// OROPrimitive
//
class Q_DECL_HIDDEN OROPrimitive::Private
{
public:
OROPage * page = nullptr;
QPointF position;
QSizeF size;
};
OROPrimitive::OROPrimitive()
: d(new Private())
{
}
OROPrimitive::~OROPrimitive()
{
if (d->page) {
d->page->takePrimitive(this);
}
delete d;
}
void OROPrimitive::setPosition(const QPointF& pos)
{
d->position = pos;
}
void OROPrimitive::setSize(const QSizeF & s)
{
d->size = s;
}
OROPage * OROPrimitive::page()
{
return d->page;
}
const OROPage * OROPrimitive::page() const
{
return d->page;
}
QPointF OROPrimitive::position() const
{
return d->position;
}
QSizeF OROPrimitive::size() const
{
return d->size;
}
void OROPrimitive::setPage(OROPage* page)
{
d->page = page;
}
//
// OROTextBox
//
class Q_DECL_HIDDEN OROTextBox::Private
{
public:
Private();
~Private();
QString text;
- KRTextStyleData textStyle;
+ KReportTextStyleData textStyle;
KReportLineStyle lineStyle;
Qt::Alignment alignment;
int flags; // Qt::AlignmentFlag and Qt::TextFlag OR'd
bool wordWrap;
bool canGrow;
bool requiresPostProcessing;
};
OROTextBox::Private::Private()
{
flags = 0;
wordWrap = false;
canGrow = false;
requiresPostProcessing = false;
lineStyle.setColor(Qt::black);
lineStyle.setWeight(0);
lineStyle.setPenStyle(Qt::NoPen);
}
OROTextBox::Private::~Private()
{
}
OROTextBox::OROTextBox() : d(new Private())
{
}
OROTextBox::~OROTextBox()
{
delete d;
}
void OROTextBox::setText(const QString & s)
{
d->text = s;
}
-void OROTextBox::setTextStyle(const KRTextStyleData & ts)
+void OROTextBox::setTextStyle(const KReportTextStyleData & ts)
{
d->textStyle = ts;
}
void OROTextBox::setLineStyle(const KReportLineStyle & ls)
{
d->lineStyle = ls;
}
void OROTextBox::setFont(const QFont & f)
{
d->textStyle.font = f;
}
void OROTextBox::setFlags(int f)
{
d->flags = f;
}
bool OROTextBox::canGrow() const
{
return d->canGrow;
}
int OROTextBox::flags() const
{
return d->flags;
}
KReportLineStyle OROTextBox::lineStyle() const
{
return d->lineStyle;
}
bool OROTextBox::requiresPostProcessing() const
{
return d->requiresPostProcessing;
}
void OROTextBox::setCanGrow(bool grow)
{
d->canGrow = grow;
}
void OROTextBox::setRequiresPostProcessing(bool pp)
{
d->requiresPostProcessing = pp;
}
void OROTextBox::setWordWrap(bool ww)
{
d->wordWrap = ww;
}
QString OROTextBox::text() const
{
return d->text;
}
-KRTextStyleData OROTextBox::textStyle() const
+KReportTextStyleData OROTextBox::textStyle() const
{
return d->textStyle;
}
bool OROTextBox::wordWrap() const
{
return d->wordWrap;
}
OROPrimitive* OROTextBox::clone() const
{
OROTextBox *theClone = new OROTextBox();
theClone->setSize(size());
theClone->setPosition(position());
theClone->setText(text());
theClone->setTextStyle(textStyle());
theClone->setLineStyle(lineStyle());
theClone->setFlags(flags());
theClone->setCanGrow(canGrow());
theClone->setWordWrap(wordWrap());
theClone->setRequiresPostProcessing(requiresPostProcessing());
return theClone;
}
//
// OROLine
//
class Q_DECL_HIDDEN OROLine::Private
{
public:
QPointF endPoint;
KReportLineStyle lineStyle;
};
OROLine::OROLine() : d(new Private())
{
}
OROLine::~OROLine()
{
delete d;
}
void OROLine::setStartPoint(const QPointF & p)
{
setPosition(p);
}
void OROLine::setEndPoint(const QPointF & p)
{
d->endPoint = p;
}
void OROLine::setLineStyle(const KReportLineStyle& style)
{
d->lineStyle = style;
}
QPointF OROLine::endPoint() const
{
return d->endPoint;
}
KReportLineStyle OROLine::lineStyle() const
{
return d->lineStyle;
}
OROPrimitive* OROLine::clone() const
{
OROLine *theClone = new OROLine();
theClone->setStartPoint(position());
theClone->setEndPoint(endPoint());
theClone->setLineStyle(lineStyle());
return theClone;
}
//
// OROImage
//
class Q_DECL_HIDDEN OROImage::Private
{
public:
QImage image;
bool scaled;
Qt::TransformationMode transformFlags;
Qt::AspectRatioMode aspectFlags;
};
OROImage::OROImage() : d(new Private())
{
d->scaled = false;
d->transformFlags = Qt::FastTransformation;
d->aspectFlags = Qt::IgnoreAspectRatio;
}
OROImage::~OROImage()
{
delete d;
}
void OROImage::setImage(const QImage & img)
{
d->image = img;
}
void OROImage::setScaled(bool b)
{
d->scaled = b;
}
void OROImage::setTransformationMode(Qt::TransformationMode transformation)
{
d->transformFlags = transformation;
}
void OROImage::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
{
d->aspectFlags = aspectRatioMode;
}
Qt::AspectRatioMode OROImage::aspectRatioMode() const
{
return d->aspectFlags;
}
QImage OROImage::image() const
{
return d->image;
}
bool OROImage::isScaled() const
{
return d->scaled;
}
Qt::TransformationMode OROImage::transformationMode() const
{
return d->transformFlags;
}
OROPrimitive* OROImage::clone() const
{
OROImage *theClone = new OROImage();
theClone->setSize(size());
theClone->setPosition(position());
theClone->setImage(image());
theClone->setScaled(isScaled());
theClone->setTransformationMode(transformationMode());
theClone->setAspectRatioMode(aspectRatioMode());
return theClone;
}
//
// OROPicture
//
class Q_DECL_HIDDEN OROPicture::Private
{
public:
QPicture picture;
};
OROPicture::OROPicture() : d(new Private())
{
}
OROPicture::~OROPicture()
{
delete d;
}
OROPrimitive* OROPicture::clone() const
{
OROPicture *theClone = new OROPicture();
theClone->setSize(size());
theClone->setPosition(position());
// theClone->setPicture(*(picture()ddddddds));
return theClone;
}
QPicture* OROPicture::picture()
{
return &d->picture;
}
void OROPicture::setPicture(const QPicture& p)
{
d->picture = p;
}
//
// ORORect
//
class Q_DECL_HIDDEN ORORect::Private
{
public:
QPen pen;
QBrush brush;
};
ORORect::ORORect() : d(new Private())
{
}
ORORect::~ORORect()
{
delete d;
}
void ORORect::setRect(const QRectF & r)
{
setPosition(r.topLeft());
setSize(r.size());
}
void ORORect::setPen(const QPen & p)
{
d->pen = p;
}
void ORORect::setBrush(const QBrush & b)
{
d->brush = b;
}
QBrush ORORect::brush() const
{
return d->brush;
}
QPen ORORect::pen() const
{
return d->pen;
}
QRectF ORORect::rect() const
{
return QRectF(position(), size());
}
OROPrimitive* ORORect::clone() const
{
ORORect *theClone = new ORORect();
theClone->setSize(size());
theClone->setPosition(position());
theClone->setPen(pen());
theClone->setBrush(brush());
return theClone;
}
//
// OROEllipse
//
class Q_DECL_HIDDEN OROEllipse::Private
{
public:
QPen pen;
QBrush brush;
};
OROEllipse::OROEllipse() : d(new Private())
{
}
OROEllipse::~OROEllipse()
{
delete d;
}
void OROEllipse::setRect(const QRectF & r)
{
setPosition(r.topLeft());
setSize(r.size());
}
void OROEllipse::setPen(const QPen & p)
{
d->pen = p;
}
void OROEllipse::setBrush(const QBrush & b)
{
d->brush = b;
}
QBrush OROEllipse::brush() const
{
return d->brush;
}
QPen OROEllipse::pen() const
{
return d->pen;
}
QRectF OROEllipse::rect() const
{
return QRectF(position(), size());
}
OROPrimitive* OROEllipse::clone() const
{
OROEllipse *theClone = new OROEllipse();
theClone->setSize(size());
theClone->setPosition(position());
theClone->setPen(pen());
theClone->setBrush(brush());
return theClone;
}
//
// OROCheck
//
class Q_DECL_HIDDEN OROCheckBox::Private
{
public:
OROCheckBox::Type checkType;
bool value;
KReportLineStyle lineStyle;
QColor foregroundColor;
};
OROCheckBox::OROCheckBox() : d(new Private())
{
d->value = false;
}
OROCheckBox::~OROCheckBox()
{
delete d;
}
OROCheckBox::Type OROCheckBox::checkType() const
{
return d->checkType;
}
QColor OROCheckBox::foregroundColor() const
{
return d->foregroundColor;
}
KReportLineStyle OROCheckBox::lineStyle() const
{
return d->lineStyle;
}
void OROCheckBox::setForegroundColor(const QColor& fg)
{
d->foregroundColor = fg;
}
void OROCheckBox::setLineStyle(const KReportLineStyle& ls)
{
d->lineStyle = ls;
}
void OROCheckBox::setValue(bool v)
{
d->value = v;
}
bool OROCheckBox::value() const
{
return d->value;
}
void OROCheckBox::setCheckType(Type type)
{
if (type == Cross || type == Tick || type == Dot) {
d->checkType = type;
} else {
d->checkType = Cross;
}
}
OROPrimitive* OROCheckBox::clone() const
{
OROCheckBox *theClone = new OROCheckBox();
theClone->setSize(size());
theClone->setPosition(position());
theClone->setLineStyle(lineStyle());
theClone->setForegroundColor(foregroundColor());
theClone->setValue(value());
theClone->setCheckType(checkType());
return theClone;
}
diff --git a/src/common/KReportRenderObjects.h b/src/common/KReportRenderObjects.h
index 6f876d03..b2a633d6 100644
--- a/src/common/KReportRenderObjects.h
+++ b/src/common/KReportRenderObjects.h
@@ -1,462 +1,462 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KREPORTRENDEROBJECTS_H
#define KREPORTRENDEROBJECTS_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "KReportDataSource.h"
#include "KReportItemBase.h"
#include "KReportSectionData.h"
#include "KReportLineStyle.h"
class ORODocument;
class OROPage;
class OROPrimitive;
class OROTextBox;
class OROLine;
class OROImage;
class OROSection;
//
// ORODocument
// This object is a single document containing one or more OROPage elements
//
class KREPORT_EXPORT ORODocument : public QObject
{
Q_OBJECT
public:
explicit ORODocument(const QString &title = QString());
~ORODocument();
QString title() const;
void setTitle(const QString &title);
/**
* @brief Return the total number of pages in the document
*
*/
int pageCount() const;
/**
* @brief Return a pointer to a given page
*
* @param index page number to find
* @return OROPage*
*/
OROPage* page(int index);
const OROPage* page(int index) const;
/**
* @brief Adds the supplied page to this document
*
* Ownership of the page is tranferred the document
*
* @param page an OROPage* to be added
*/
void addPage(OROPage* page);
/**
* @brief Returns the index of the supplied page in the document
*
* @param page OROPage* to find
* @return int page index
*/
int pageIndex(const OROPage* page) const;
/**
* @brief Removes the given page from the document
*
* The page is also deleted
*
* @param page OROPage* to delete
*/
void removePage(OROPage* page);
/**
* @brief Takes the page from the document but does not delete it
*
* @param page OROPage* to take from the document
*/
void takePage(OROPage *page);
/**
* @brief Return the total number of sections in the document
*
*/
int sectionCount() const;
/**
* @brief Return a pointer to a given section
*
* @param index section number to find
* @return OROSection*
*/
OROSection* section(int index);
const OROSection* section(int index) const;
/**
* @brief Adds the supplied sectin to the document
*
* Ownership of the section is transferred to the document
*
* @param section OROSection* to add to the document
*/
void addSection(OROSection* section);
/**
* @brief Removes the supplied section from the document
*
* The section will also be deleted
*
* @param section OROSection* to remove and delete
*/
void removeSection(OROSection *section);
/**
* @brief Takes the section from the document but does not delete it
*
* @param page OROSection* to take from the document
*/
void takeSection(OROSection *section);
void setPageLayout(const QPageLayout &layout);
QPageLayout pageLayout() const;
void notifyChange(int pageNo);
Q_SIGNALS:
void updated(int pageNo);
private:
class Private;
Private * const d;
};
//
// OROPage
// This object is a single page in a document and may contain zero or more
// OROPrimitive objects all of which represent some form of mark to made on
// a page.
//
class KREPORT_EXPORT OROPage
{
public:
explicit OROPage(ORODocument * doc = 0);
~OROPage();
ORODocument* document();
const ORODocument* document() const;
void setDocument(ORODocument *doc);
int pageNumber() const; // returns this pages current page number
int primitiveCount() const;
OROPrimitive* primitive(int index);
const OROPrimitive* primitive(int index) const;
void insertPrimitive(OROPrimitive* primitive, int index = -1);
void removePrimitive(OROPrimitive *primitive);
void takePrimitive(OROPrimitive *primitive);
private:
class Private;
Private * const d;
};
//
// OROSection
// This object is a single row in a document and may contain zero or more
// OROPrimitives
//
class KREPORT_EXPORT OROSection
{
public:
explicit OROSection(ORODocument* doc = 0);
~OROSection();
void setHeight(int);
int height() const;
void setBackgroundColor(const QColor& color);
QColor backgroundColor() const;
ORODocument* document();
const ORODocument* document() const;
void setDocument(ORODocument *doc);
void setType(KReportSectionData::Section t);
KReportSectionData::Section type() const;
int primitiveCount() const;
OROPrimitive* primitive(int index);
const OROPrimitive* primitive(int index) const;
void addPrimitive(OROPrimitive* primitive);
void sortPrimitives(Qt::Orientation orientation);
private:
class Private;
Private * const d;
};
//
// OROPrimitive
// This object represents the basic primitive with a position and type.
// Other primitives are subclasses with a defined type and any additional
// information they require to define that primitive.
//
class KREPORT_EXPORT OROPrimitive
{
public:
virtual ~OROPrimitive();
OROPage* page();
const OROPage* page() const;
void setPage(OROPage *page);
QPointF position() const;
void setPosition(const QPointF &pos);
QSizeF size() const;
void setSize(const QSizeF &s);
virtual OROPrimitive* clone() const = 0;
protected:
OROPrimitive();
private:
class Private;
Private * const d;
};
//
// OROTextBox
// This is a text box primitive it defines a box region and text that will
// be rendered inside that region. It also contains information for font
// and positioning of the text.
//
class KREPORT_EXPORT OROTextBox : public OROPrimitive
{
public:
OROTextBox();
virtual ~OROTextBox();
QString text() const;
void setText(const QString &text);
- KRTextStyleData textStyle() const;
- void setTextStyle(const KRTextStyleData&);
+ KReportTextStyleData textStyle() const;
+ void setTextStyle(const KReportTextStyleData&);
KReportLineStyle lineStyle() const;
void setLineStyle(const KReportLineStyle&);
void setFont(const QFont &font);
int flags() const;
void setFlags(int flags);
virtual OROPrimitive* clone() const;
bool requiresPostProcessing() const;
void setRequiresPostProcessing(bool pp);
bool wordWrap() const;
void setWordWrap(bool ww);
bool canGrow() const;
void setCanGrow(bool grow);
private:
class Private;
Private * const d;
};
//
// OROLine
// This primitive defines a line with a width/weight.
//
class KREPORT_EXPORT OROLine : public OROPrimitive
{
public:
OROLine();
virtual ~OROLine();
QPointF startPoint() const {
return position();
};
void setStartPoint(const QPointF &start);
QPointF endPoint() const;
void setEndPoint(const QPointF &end);
KReportLineStyle lineStyle() const;
void setLineStyle(const KReportLineStyle& style);
virtual OROPrimitive* clone() const;
private:
class Private;
Private * const d;
};
//
// OROImage
// This primitive defines an image
//
class KREPORT_EXPORT OROImage: public OROPrimitive
{
public:
OROImage();
virtual ~OROImage();
QImage image() const;
void setImage(const QImage &img);
bool isScaled() const;
void setScaled(bool scaled);
Qt::TransformationMode transformationMode() const;
void setTransformationMode(Qt::TransformationMode transformation);
Qt::AspectRatioMode aspectRatioMode() const;
void setAspectRatioMode(Qt::AspectRatioMode aspect);
virtual OROPrimitive* clone() const;
private:
class Private;
Private * const d;
};
//
// OROPicture
// This primitive defines a picture
//
class KREPORT_EXPORT OROPicture: public OROPrimitive
{
public:
OROPicture();
virtual ~OROPicture();
void setPicture(const QPicture& pic);
QPicture* picture();
virtual OROPrimitive* clone() const;
private:
class Private;
Private * const d;
};
//
// ORORect
// This primitive defines a drawn rectangle
//
class KREPORT_EXPORT ORORect: public OROPrimitive
{
public:
ORORect();
virtual ~ORORect();
QRectF rect() const;
void setRect(const QRectF &rectangle);
QPen pen() const;
void setPen(const QPen &pen);
QBrush brush() const;
void setBrush(const QBrush &brush);
virtual OROPrimitive* clone() const;
private:
class Private;
Private * const d;
};
//
// ORORect
// This primitive defines a drawn rectangle
//
class KREPORT_EXPORT OROEllipse: public OROPrimitive
{
public:
OROEllipse();
virtual ~OROEllipse();
QRectF rect() const;
void setRect(const QRectF &rectangle);
QPen pen() const;
void setPen(const QPen &pen);
QBrush brush() const;
void setBrush(const QBrush &brush);
virtual OROPrimitive* clone() const;
private:
class Private;
Private * const d;
};
class KREPORT_EXPORT OROCheckBox : public OROPrimitive
{
public:
enum Type {
Cross = 1,
Tick,
Dot
};
OROCheckBox();
virtual ~OROCheckBox();
virtual OROPrimitive* clone() const;
void setCheckType(Type type);
Type checkType() const;
void setValue(bool val);
bool value() const;
void setLineStyle(const KReportLineStyle& ls);
KReportLineStyle lineStyle() const;
void setForegroundColor(const QColor& fg);
QColor foregroundColor() const;
private:
class Private;
Private * const d;
};
#endif // __RENDEROBJECTS_H__
diff --git a/src/common/KReportUtils.cpp b/src/common/KReportUtils.cpp
index 1afd0eca..9fc18e81 100644
--- a/src/common/KReportUtils.cpp
+++ b/src/common/KReportUtils.cpp
@@ -1,555 +1,555 @@
/* This file is part of the KDE project
Copyright (C) 2010-2015 Jarosław Staniek
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KReportUtils.h"
#include "KReportUnit.h"
#include "KReportItemBase.h"
#include "KReportLineStyle.h"
#include
#include
#include
#include
QString KReportUtils::attr(const QDomElement &el, const char *attrName,
const QString &defaultValue)
{
const QString val = el.attribute(QLatin1String(attrName));
return val.isEmpty() ? defaultValue : val;
}
QByteArray KReportUtils::attr(const QDomElement &el, const char *attrName,
const QByteArray &defaultValue)
{
const QByteArray val = el.attribute(QLatin1String(attrName)).toLatin1();
return val.isEmpty() ? defaultValue : val;
}
bool KReportUtils::attr(const QDomElement &el, const char *attrName, bool defaultValue)
{
const QString val = el.attribute(QLatin1String(attrName));
return val.isEmpty() ? defaultValue : QVariant(val).toBool();
}
int KReportUtils::attr(const QDomElement &el, const char *attrName, int defaultValue)
{
const QString val = el.attribute(QLatin1String(attrName));
if (val.isEmpty()) {
return defaultValue;
}
bool ok;
const int result = QVariant(val).toInt(&ok);
return ok ? result : defaultValue;
}
qreal KReportUtils::attr(const QDomElement &el, const char *attrName, qreal defaultValue)
{
const QString val = el.attribute(QLatin1String(attrName));
return KReportUnit::parseValue(val, defaultValue);
}
QColor KReportUtils::attr(const QDomElement &el, const char *attrName, const QColor &defaultValue)
{
const QString val = el.attribute(QLatin1String(attrName));
if (val.isEmpty()) {
return defaultValue;
}
return QColor(val);
}
qreal KReportUtils::attrPercent(const QDomElement& el, const char* attrName, qreal defaultValue)
{
QString str(el.attribute(QLatin1String(attrName)));
if (str.isEmpty() || !str.endsWith(QLatin1Char('%'))) {
return defaultValue;
}
str.chop(1);
bool ok;
const qreal result = QVariant(str).toReal(&ok) / 100.0;
if (!ok) {
return defaultValue;
}
return result;
}
Qt::PenStyle KReportUtils::penStyle(const QString& str, Qt::PenStyle defaultValue)
{
const QByteArray s(str.toLatin1());
if (s == "nopen" || s == "none") {
return Qt::NoPen;
} else if (s == "solid") {
return Qt::SolidLine;
} else if (s == "dash" || s == "wave" /*we have nothing better for now*/) {
return Qt::DashLine;
} else if (s == "dot" || s == "dotted") {
return Qt::DotLine;
} else if (s == "dashdot" || s == "dot-dash") {
return Qt::DashDotLine;
} else if (s == "dashdotdot" || s == "dot-dot-dash") {
return Qt::DashDotDotLine;
} else {
return defaultValue;
}
}
Qt::Alignment KReportUtils::verticalAlignment(const QString &str, Qt::Alignment defaultValue)
{
const QByteArray s(str.toLatin1());
if (s == "center") {
return Qt::AlignVCenter;
} else if (s == "top") {
return Qt::AlignTop;
} else if (s == "bottom") {
return Qt::AlignBottom;
} else {
return defaultValue;
}
}
Qt::Alignment KReportUtils::horizontalAlignment(const QString &str, Qt::Alignment defaultValue)
{
const QByteArray s(str.toLatin1());
if (s == "center") {
return Qt::AlignHCenter;
} else if (s == "right") {
return Qt::AlignRight;
} else if (s == "left") {
return Qt::AlignLeft;
} else {
return defaultValue;
}
}
QString KReportUtils::verticalToString(Qt::Alignment alignment)
{
if (alignment.testFlag(Qt::AlignVCenter)) {
return QLatin1String("center");
} else if (alignment.testFlag(Qt::AlignTop)) {
return QLatin1String("top");
} else if (alignment.testFlag(Qt::AlignBottom)) {
return QLatin1String("bottom");
}
return QString();
}
QString KReportUtils::horizontalToString(Qt::Alignment alignment)
{
if (alignment.testFlag(Qt::AlignHCenter)) {
return QLatin1String("center");
} else if (alignment.testFlag(Qt::AlignLeft)) {
return QLatin1String("left");
} else if (alignment.testFlag(Qt::AlignRight)) {
return QLatin1String("right");
}
return QString();
}
QRectF KReportUtils::readRectAttributes(const QDomElement &el, const QRectF &defaultValue)
{
QRectF val;
val.setX(attr(el, "svg:x", defaultValue.x()));
val.setY(attr(el, "svg:y", defaultValue.y()));
val.setWidth(attr(el, "svg:width", defaultValue.width()));
val.setHeight(attr(el, "svg:height", defaultValue.height()));
return val;
}
int KReportUtils::readPercent(const QDomElement& el, const char* name, int defaultPercentValue, bool *ok)
{
Q_ASSERT(name);
QString percent(el.attribute(QLatin1String(name)));
if (percent.isEmpty()) {
if (ok)
*ok = true;
return defaultPercentValue;
}
if (!percent.endsWith(QLatin1Char('%'))) {
if (ok)
*ok = false;
return 0;
}
percent.chop(1);
if (ok)
*ok = true;
return percent.toInt(ok);
}
//! @return string representation of @a value, cuts of zeros; precision is set to 2
static QString roundValueToString(qreal value)
{
QString s(QString::number(value, 'g', 2));
if (s.endsWith(QLatin1String(".00")))
return QString::number(qRound(value));
return s;
}
//! Used by readFontAttributes()
static QFont::Capitalization readFontCapitalization(const QByteArray& fontVariant, const QByteArray& textTransform)
{
if (fontVariant == "small-caps")
return QFont::SmallCaps;
if (textTransform == "uppercase")
return QFont::AllUppercase;
if (textTransform == "lowercase")
return QFont::AllLowercase;
if (textTransform == "capitalize")
return QFont::Capitalize;
// default, "normal"
return QFont::MixedCase;
}
void KReportUtils::readFontAttributes(const QDomElement& el, QFont *font)
{
Q_ASSERT(font);
const QFont::Capitalization cap = readFontCapitalization(
attr(el, "fo:font-variant", QByteArray()), attr(el, "fo:text-transform", QByteArray()));
font->setCapitalization(cap);
// weight
const QByteArray fontWeight(attr(el, "fo:font-weight", QByteArray()));
int weight = -1;
if (fontWeight == "bold") {
weight = QFont::Bold;
}
if (fontWeight == "normal") {
weight = QFont::Normal;
}
else if (!fontWeight.isEmpty()) {
// Remember : Qt and CSS/XSL doesn't have the same scale. It's 100-900 instead of Qt's 0-100
// See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#font-weight
// and http://www.w3.org/TR/CSS2/fonts.html#font-boldness
bool ok;
qreal boldness = fontWeight.toUInt(&ok);
if (ok) {
boldness = qMin(boldness, 900.0);
boldness = qMax(boldness, 100.0);
weight = (boldness - 100.0) * 0.12375 /*== 99/800*/; // 0..99
}
}
if (weight >= 0) {
font->setWeight(weight);
}
font->setItalic(attr(el, "fo:font-style", QByteArray()) == "italic");
font->setFixedPitch(attr(el, "style:font-pitch", QByteArray()) == "fixed");
font->setFamily(attr(el, "fo:font-family", font->family()));
font->setKerning(attr(el, "style:letter-kerning", font->kerning()));
// underline
const QByteArray underlineType(attr(el, "style:text-underline-type", QByteArray()));
font->setUnderline(!underlineType.isEmpty() && underlineType != "none"); // double or single (we don't recognize them)
// stricken-out
const QByteArray strikeOutType(attr(el, "style:text-line-through-type", QByteArray()));
font->setStrikeOut(!strikeOutType.isEmpty() && strikeOutType != "none"); // double or single (we don't recognize them)
//! @todo support fo:font-size-rel?
//! @todo support fo:font-size in px
font->setPointSizeF(KReportUtils::attr(el, "fo:font-size", font->pointSizeF()));
// letter spacing
// §7.16.2 of [XSL] http://www.w3.org/TR/xsl11/#letter-spacing
font->setLetterSpacing(QFont::PercentageSpacing,
100.0 * KReportUtils::attrPercent(el, "fo:letter-spacing", font->letterSpacing()));
}
void KReportUtils::writeFontAttributes(QDomElement *el, const QFont &font)
{
Q_ASSERT(el);
switch (font.capitalization()) {
case QFont::SmallCaps:
el->setAttribute(QLatin1String("fo:font-variant"), QLatin1String("small-caps"));
break;
case QFont::MixedCase:
// default: "normal", do not save
break;
case QFont::AllUppercase:
el->setAttribute(QLatin1String("fo:text-transform"), QLatin1String("uppercase"));
break;
case QFont::AllLowercase:
el->setAttribute(QLatin1String("fo:text-transform"), QLatin1String("lowercase"));
break;
case QFont::Capitalize:
el->setAttribute(QLatin1String("fo:text-transform"), QLatin1String("capitalize"));
break;
}
// Remember : Qt and CSS/XSL doesn't have the same scale. It's 100-900 instead of Qt's 0-100
// See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#font-weight
// and http://www.w3.org/TR/CSS2/fonts.html#font-boldness
if (font.weight() == QFont::Light) {
el->setAttribute(QLatin1String("fo:font-weight"), 200);
}
else if (font.weight() == QFont::Normal) {
// Default
//el->setAttribute("fo:font-weight", "normal"); // 400
}
else if (font.weight() == QFont::DemiBold) {
el->setAttribute(QLatin1String("fo:font-weight"), 600);
}
else if (font.weight() == QFont::Bold) {
el->setAttribute(QLatin1String("fo:font-weight"), QLatin1String("bold")); // 700
}
else if (font.weight() == QFont::Black) {
el->setAttribute(QLatin1String("fo:font-weight"), 900);
}
else {
el->setAttribute(QLatin1String("fo:font-weight"), qBound(10, font.weight(), 90) * 10);
}
// italic, default is "normal"
if (font.italic()) {
el->setAttribute(QLatin1String("fo:font-style"), QLatin1String("italic"));
}
// pitch, default is "variable"
if (font.fixedPitch()) {
el->setAttribute(QLatin1String("style:font-pitch"), QLatin1String("fixed"));
}
if (!font.family().isEmpty()) {
el->setAttribute(QLatin1String("fo:font-family"), font.family());
}
// kerning, default is "true"
el->setAttribute(QLatin1String("style:letter-kerning"), QLatin1String(font.kerning() ? "true" : "false"));
// underline, default is "none"
if (font.underline()) {
el->setAttribute(QLatin1String("style:text-underline-type"), QLatin1String("single"));
}
// stricken-out, default is "none"
if (font.strikeOut()) {
el->setAttribute(QLatin1String("style:text-line-through-type"), QLatin1String("single"));
}
el->setAttribute(QLatin1String("fo:font-size"), font.pointSize());
// letter spacing, default is "normal"
// §7.16.2 of [XSL] http://www.w3.org/TR/xsl11/#letter-spacing
if (font.letterSpacingType() == QFont::PercentageSpacing) {
// A value of 100 will keep the spacing unchanged; a value of 200 will enlarge
// the spacing after a character by the width of the character itself.
if (font.letterSpacing() != 100.0) {
el->setAttribute(QLatin1String("fo:letter-spacing"), roundValueToString(font.letterSpacing()) + QLatin1Char('%'));
}
}
else {
// QFont::AbsoluteSpacing
// A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing.
el->setAttribute(QLatin1String("fo:letter-spacing"), roundValueToString(font.letterSpacing()));
}
}
void KReportUtils::buildXMLRect(QDomElement *entity, const QPointF &pos, const QSizeF &size)
{
Q_ASSERT(entity);
KReportUtils::setAttribute(entity, pos);
KReportUtils::setAttribute(entity, size );
}
-void KReportUtils::buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts)
+void KReportUtils::buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KReportTextStyleData &ts)
{
Q_ASSERT(doc);
Q_ASSERT(entity);
QDomElement element = doc->createElement(QLatin1String("report:text-style"));
element.setAttribute(QLatin1String("fo:background-color"), ts.backgroundColor.name());
element.setAttribute(QLatin1String("fo:foreground-color"), ts.foregroundColor.name());
element.setAttribute(QLatin1String("fo:background-opacity"), QString::number(ts.backgroundOpacity) + QLatin1Char('%'));
KReportUtils::writeFontAttributes(&element, ts.font);
entity->appendChild(element);
}
void KReportUtils::buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls)
{
Q_ASSERT(doc);
Q_ASSERT(entity);
QDomElement element = doc->createElement(QLatin1String("report:line-style"));
element.setAttribute(QLatin1String("report:line-color"), ls.color().name());
element.setAttribute(QLatin1String("report:line-weight"), ls.weight());
QString l;
switch (ls.penStyle()) {
case Qt::NoPen:
l = QLatin1String("nopen");
break;
case Qt::SolidLine:
l = QLatin1String("solid");
break;
case Qt::DashLine:
l = QLatin1String("dash");
break;
case Qt::DotLine:
l = QLatin1String("dot");
break;
case Qt::DashDotLine:
l = QLatin1String("dashdot");
break;
case Qt::DashDotDotLine:
l = QLatin1String("dashdotdot");
break;
default:
l = QLatin1String("solid");
}
element.setAttribute(QLatin1String("report:line-style"), l);
entity->appendChild(element);
}
void KReportUtils::addPropertyAsAttribute(QDomElement* e, KProperty* p)
{
Q_ASSERT(e);
Q_ASSERT(p);
const QString name = QLatin1String("report:") + QLatin1String(p->name().toLower());
switch (p->value().type()) {
case QVariant::Int :
e->setAttribute(name, p->value().toInt());
break;
case QVariant::Double:
e->setAttribute(name, p->value().toDouble());
break;
case QVariant::Bool:
e->setAttribute(name, p->value().toInt());
break;
default:
e->setAttribute(name, p->value().toString());
break;
}
}
void KReportUtils::setAttribute(QDomElement *e, const QString &attribute, double value)
{
Q_ASSERT(e);
QString s;
s.setNum(value, 'f', DBL_DIG);
e->setAttribute(attribute, s + QLatin1String("pt"));
}
void KReportUtils::setAttribute(QDomElement *e, const QPointF &value)
{
Q_ASSERT(e);
KReportUtils::setAttribute(e, QLatin1String("svg:x"), value.x());
KReportUtils::setAttribute(e, QLatin1String("svg:y"), value.y());
}
void KReportUtils::setAttribute(QDomElement *e, const QSizeF &value)
{
Q_ASSERT(e);
KReportUtils::setAttribute(e, QLatin1String("svg:width"), value.width());
KReportUtils::setAttribute(e, QLatin1String("svg:height"), value.height());
}
-bool KReportUtils::parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts)
+bool KReportUtils::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts)
{
Q_ASSERT(ts);
if (elemSource.tagName() != QLatin1String("report:text-style"))
return false;
ts->backgroundColor = QColor(elemSource.attribute(QLatin1String("fo:background-color"), QLatin1String("#ffffff")));
ts->foregroundColor = QColor(elemSource.attribute(QLatin1String("fo:foreground-color"), QLatin1String("#000000")));
bool ok;
ts->backgroundOpacity = KReportUtils::readPercent(elemSource, "fo:background-opacity", 100, &ok);
if (!ok) {
return false;
}
KReportUtils::readFontAttributes(elemSource, &ts->font);
return true;
}
bool KReportUtils::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls)
{
Q_ASSERT(ls);
if (elemSource.tagName() == QLatin1String("report:line-style")) {
ls->setColor(QColor(elemSource.attribute(QLatin1String("report:line-color"), QLatin1String("#ffffff"))));
ls->setWeight(elemSource.attribute(QLatin1String("report:line-weight"), QLatin1String("0.0")).toDouble());
QString l = elemSource.attribute(QLatin1String("report:line-style"), QLatin1String("nopen"));
if (l == QLatin1String("nopen")) {
ls->setPenStyle(Qt::NoPen);
} else if (l == QLatin1String("solid")) {
ls->setPenStyle(Qt::SolidLine);
} else if (l == QLatin1String("dash")) {
ls->setPenStyle(Qt::DashLine);
} else if (l == QLatin1String("dot")) {
ls->setPenStyle(Qt::DotLine);
} else if (l == QLatin1String("dashdot")) {
ls->setPenStyle(Qt::DashDotLine);
} else if (l == QLatin1String("dashdotdot")) {
ls->setPenStyle(Qt::DashDotDotLine);
}
return true;
}
return false;
}
#if 0
bool KReportUtils::parseReportRect(const QDomElement & elemSource, KReportPosition *pos, KReportSize *size)
{
Q_ASSERT(pos);
Q_ASSERT(size);
// QStringList sl;
// QDomNamedNodeMap map = elemSource.attributes();
// for (int i=0; i < map.count(); ++i ) {
// sl << map.item(i).nodeName();
// }
QPointF _pos;
QSizeF _siz;
_pos.setX(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:x"), QLatin1String("1cm"))));
_pos.setY(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:y"), QLatin1String("1cm"))));
_siz.setWidth(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:width"), QLatin1String("1cm"))));
_siz.setHeight(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("1cm"))));
pos->setPointPos(_pos);
size->setPointSize(_siz);
return true;
}
#endif
class PageIds : private QHash
{
public:
PageIds() {}
QPageSize::PageSizeId id(const QString &key) {
if (isEmpty()) {
for (int i = 0; i < QPageSize::LastPageSize; ++i) {
QString key(QPageSize::key(static_cast(i)));
if (key.isEmpty()) {
break;
}
insert(key, static_cast(i));
}
}
return value(key);
}
};
Q_GLOBAL_STATIC(PageIds, s_pageIds)
QPageSize::PageSizeId KReportUtils::pageSizeId(const QString &key)
{
return s_pageIds->id(key);
}
QPageSize KReportUtils::pageSize(const QString &key)
{
return QPageSize(s_pageIds->id(key));
}
diff --git a/src/common/KReportUtils.h b/src/common/KReportUtils.h
index 49e0d301..953c158a 100644
--- a/src/common/KReportUtils.h
+++ b/src/common/KReportUtils.h
@@ -1,131 +1,131 @@
/* This file is part of the KDE project
Copyright (C) 2010-2015 Jarosław Staniek
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KREPORTUTILS_H
#define KREPORTUTILS_H
#include "kreport_export.h"
#include
#include
#include
#include
class QDomDocument;
class QDomElement;
class QFont;
class QPointF;
class KProperty;
class KReportPosition;
class KReportSize;
-class KRTextStyleData;
+class KReportTextStyleData;
class KReportLineStyle;
namespace KReportUtils
{
KREPORT_EXPORT QString attr(const QDomElement &el, const char *attrName,
const QString &defaultValue = QString());
KREPORT_EXPORT QByteArray attr(const QDomElement &el, const char *attrName,
const QByteArray &defaultValue = QByteArray());
KREPORT_EXPORT bool attr(const QDomElement &el, const char *attrName, bool defaultValue = false);
KREPORT_EXPORT int attr(const QDomElement &el, const char *attrName, int defaultValue = 0);
KREPORT_EXPORT qreal attr(const QDomElement &el, const char *attrName, qreal defaultValue = 0.0);
KREPORT_EXPORT QColor attr(const QDomElement &el, const char *attrName, const QColor &defaultValue = QColor());
//! @return percent value converted to qreal, e.g. 1.0 for "100%", 0.505 for "50.5%".
//! @a defaultValue is returned if there is not "%" suffix or no proper number.
KREPORT_EXPORT qreal attrPercent(const QDomElement& el, const char* attrName, qreal defaultValue = 0.0);
//! @return pen style from @a str or @a defaultValue
//! Values from ODF 1.2 19.493 style:line-style are also recognized.
KREPORT_EXPORT Qt::PenStyle penStyle(const QString &str, Qt::PenStyle defaultValue);
//! @return vertical alignment flag from @a str or @a defaultValue
KREPORT_EXPORT Qt::Alignment verticalAlignment(const QString &str, Qt::Alignment defaultValue);
//! @return horizontal alignment flag from @a str or @a defaultValue
KREPORT_EXPORT Qt::Alignment horizontalAlignment(const QString &str, Qt::Alignment defaultValue);
//! @return vertical alignment flag name from @a alignment
KREPORT_EXPORT QString verticalToString(Qt::Alignment alignment);
//! @return horizontal alignment flag from @a alignment
KREPORT_EXPORT QString horizontalToString(Qt::Alignment alignment);
//! @return rectangle value read from svg:x, svg:y, svg:width, svg:height attributes of @a el.
//! If any of the arguments are missing, @a defaultValue is returned.
KREPORT_EXPORT QRectF readRectAttributes(const QDomElement &el, const QRectF &defaultValue = QRectF());
//! @return percent value for element @a name. If the element is missing, returns @a defaultPercentValue.
//! If @a ok is not 0, *ok is set to the result.
KREPORT_EXPORT int readPercent(const QDomElement & el, const char* name, int defaultPercentValue, bool *ok);
//! Reads all font attributes for element @a el into @a font.
//! @todo add unit tests
KREPORT_EXPORT void readFontAttributes(const QDomElement& el, QFont* font);
//! Writes all attributes of font @a font into element @a el.
//! @todo add unit tests
KREPORT_EXPORT void writeFontAttributes(QDomElement *el, const QFont &font);
//! Writes attributes for the rect position @p pos, @p siz
KREPORT_EXPORT void buildXMLRect(QDomElement *entity, const QPointF &pos, const QSizeF &size);
//! Writes attributes for text style @p ts
- KREPORT_EXPORT void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts);
+ KREPORT_EXPORT void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KReportTextStyleData &ts);
//! Writes attributes for line style @p ls
KREPORT_EXPORT void buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls);
//! Writes attributes for the property @p p
KREPORT_EXPORT void addPropertyAsAttribute(QDomElement* e, KProperty* p);
//! Writes @p attribute to element @p e, @p value is stored in points with unit 'pt'
KREPORT_EXPORT void setAttribute(QDomElement *e, const QString &attribute, double value);
//! Writes point @p value as attributes to element @p e
KREPORT_EXPORT void setAttribute(QDomElement *e, const QPointF &value);
//! Writes size @p value as attributes to element @p e
KREPORT_EXPORT void setAttribute(QDomElement *e, const QSizeF &value);
//! Reads attributes from @p elemSource into text style @p ts
- KREPORT_EXPORT bool parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts);
+ KREPORT_EXPORT bool parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts);
//! Reads attributes from @p elemSource into line style @p ls
KREPORT_EXPORT bool parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls);
//! Reads attributes from @p elemSource into rect @p pos, @p siz
KREPORT_EXPORT bool parseReportRect(const QDomElement & elemSource, KReportPosition *pos, KReportSize *size);
//! @return page size ID for page key (the PPD standard mediaOption keyword, e.g. "A4")
//! @note It's an efficient workaround because QPageSize misses this function.
KREPORT_EXPORT QPageSize::PageSizeId pageSizeId(const QString &key);
//! Like QPageSize::PageSizeId pageSizeId(const QString &key) but returns entire QPageSize object.
KREPORT_EXPORT QPageSize pageSize(const QString &key);
} // KReportUtils
#endif
diff --git a/src/items/field/KReportItemField.cpp b/src/items/field/KReportItemField.cpp
index d516e2a6..855e3f6b 100644
--- a/src/items/field/KReportItemField.cpp
+++ b/src/items/field/KReportItemField.cpp
@@ -1,288 +1,288 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportItemField.h"
#include "KReportRenderObjects.h"
#include "kreportplugin_debug.h"
#ifdef KREPORT_SCRIPTING
#include "renderer/scripting/KReportScriptHandler.h"
#endif
#include
#include
#include
#include
#include
KReportItemField::KReportItemField()
{
createProperties();
}
KReportItemField::KReportItemField(const QDomNode & element)
{
createProperties();
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name")));
m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value")));
setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble());
m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align")));
m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align")));
m_canGrow->setValue(element.toElement().attribute(QLatin1String("report:can-grow")));
m_wordWrap->setValue(element.toElement().attribute(QLatin1String("report:word-wrap")));
parseReportRect(element.toElement());
for (int i = 0; i < nl.count(); i++) {
node = nl.item(i);
n = node.nodeName();
if (n == QLatin1String("report:text-style")) {
- KRTextStyleData ts;
+ KReportTextStyleData ts;
if (parseReportTextStyleData(node.toElement(), &ts)) {
m_backgroundColor->setValue(ts.backgroundColor);
m_foregroundColor->setValue(ts.foregroundColor);
m_backgroundOpacity->setValue(ts.backgroundOpacity);
m_font->setValue(ts.font);
}
} else if (n == QLatin1String("report:line-style")) {
KReportLineStyle ls;
if (parseReportLineStyleData(node.toElement(), &ls)) {
m_lineWeight->setValue(ls.weight());
m_lineColor->setValue(ls.color());
m_lineStyle->setValue(static_cast(ls.penStyle()));
}
} else {
kreportpluginWarning() << "while parsing field element encountered unknown element: " << n;
}
}
}
KReportItemField::~KReportItemField()
{
}
void KReportItemField::createProperties()
{
QStringList keys, strings;
m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source"));
m_controlSource->setOption("extraValueAllowed", QLatin1String("true"));
m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field"));
keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right");
strings << tr("Left") << tr("Center") << tr("Right");
m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment"));
keys.clear();
strings.clear();
keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom");
strings << tr("Top") << tr("Center") << tr("Bottom");
m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment"));
m_font = new KProperty("font", QApplication::font(), tr("Font"));
m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color"));
m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color"));
m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity"));
m_backgroundOpacity->setOption("max", 100);
m_backgroundOpacity->setOption("min", 0);
m_backgroundOpacity->setOption("unit", QLatin1String("%"));
m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight"));
m_lineWeight->setOption("step", 1.0);
m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color"));
m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), QString(), KProperty::LineStyle);
m_wordWrap = new KProperty("word-wrap", QVariant(false), tr("Word Wrap"));
m_canGrow = new KProperty("can-grow", QVariant(false), tr("Can Grow"));
//! @todo I do not think we need these
#if 0 //Field Totals
m_trackTotal = new KProperty("trackTotal", QVariant(false), futureI18n("Track Total"));
m_trackBuiltinFormat = new KProperty("trackBuiltinFormat", QVariant(false), futureI18n("Track Builtin Format"));
_useSubTotal = new KProperty("useSubTotal", QVariant(false), futureI18n("Use Sub Total"_));
_trackTotalFormat = new KProperty("trackTotalFormat", QString(), futureI18n("Track Total Format"));
#endif
propertySet()->addProperty(m_controlSource);
propertySet()->addProperty(m_itemValue);
propertySet()->addProperty(m_horizontalAlignment);
propertySet()->addProperty(m_verticalAlignment);
propertySet()->addProperty(m_font);
propertySet()->addProperty(m_backgroundColor);
propertySet()->addProperty(m_foregroundColor);
propertySet()->addProperty(m_backgroundOpacity);
propertySet()->addProperty(m_lineWeight);
propertySet()->addProperty(m_lineColor);
propertySet()->addProperty(m_lineStyle);
propertySet()->addProperty(m_wordWrap);
propertySet()->addProperty(m_canGrow);
//_set->addProperty ( _trackTotal );
//_set->addProperty ( _trackBuiltinFormat );
//_set->addProperty ( _useSubTotal );
//_set->addProperty ( _trackTotalFormat );
}
int KReportItemField::textFlags() const
{
int flags;
QString t;
t = m_horizontalAlignment->value().toString();
if (t == QLatin1String("center"))
flags = Qt::AlignHCenter;
else if (t == QLatin1String("right"))
flags = Qt::AlignRight;
else
flags = Qt::AlignLeft;
t = m_verticalAlignment->value().toString();
if (t == QLatin1String("center"))
flags |= Qt::AlignVCenter;
else if (t == QLatin1String("bottom"))
flags |= Qt::AlignBottom;
else
flags |= Qt::AlignTop;
if (m_wordWrap->value().toBool() == true) {
flags |= Qt::TextWordWrap;
}
return flags;
}
-KRTextStyleData KReportItemField::textStyle() const
+KReportTextStyleData KReportItemField::textStyle() const
{
- KRTextStyleData d;
+ KReportTextStyleData d;
d.backgroundColor = m_backgroundColor->value().value();
d.foregroundColor = m_foregroundColor->value().value();
d.font = m_font->value().value();
d.backgroundOpacity = m_backgroundOpacity->value().toInt();
return d;
}
QString KReportItemField::itemDataSource() const
{
return m_controlSource->value().toString();
}
void KReportItemField::setItemDataSource(const QString& t)
{
if (m_controlSource->value() != t) {
m_controlSource->setValue(t);
}
//kreportpluginDebug() << "Field: " << entityName() << "is" << itemDataSource();
}
KReportLineStyle KReportItemField::lineStyle() const
{
KReportLineStyle ls;
ls.setWeight(m_lineWeight->value().toReal());
ls.setColor(m_lineColor->value().value());
ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt());
return ls;
}
// RTTI
QString KReportItemField::typeName() const
{
return QLatin1String("field");
}
int KReportItemField::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler *script)
{
OROTextBox * tb = new OROTextBox();
tb->setPosition(scenePosition(position()) + offset);
tb->setSize(sceneSize(size()));
tb->setFont(font());
tb->setFlags(textFlags());
tb->setTextStyle(textStyle());
tb->setLineStyle(lineStyle());
tb->setCanGrow(m_canGrow->value().toBool());
tb->setWordWrap(m_wordWrap->value().toBool());
QString str;
QString ids = itemDataSource();
if (!ids.isEmpty()) {
#ifdef KREPORT_SCRIPTING
if (ids.left(1) == QLatin1String("=") && script) { //Everything after = is treated as code
if (!ids.contains(QLatin1String("PageTotal()"))) {
QVariant v = script->evaluate(ids.mid(1));
str = v.toString();
} else {
str = ids.mid(1);
tb->setRequiresPostProcessing(true);
}
} else
#else
Q_UNUSED(script);
#endif
if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string
str = ids.mid(1);
} else {
str = data.toString();
}
} else {
str = m_itemValue->value().toString();
}
tb->setText(str);
//Work out the size of the text
if (tb->canGrow()) {
QRect r;
if (tb->wordWrap()) {
//Grow vertically
QFontMetrics metrics(font());
QRect temp(tb->position().x(), tb->position().y(), tb->size().width(), 5000); // a large vertical height
r = metrics.boundingRect(temp, tb->flags(), str);
} else {
//Grow Horizontally
QFontMetrics metrics(font());
QRect temp(tb->position().x(), tb->position().y(), 5000, tb->size().height()); // a large vertical height
r = metrics.boundingRect(temp, tb->flags(), str);
}
tb->setSize(r.size() + QSize(4,4));
}
if (page) {
page->insertPrimitive(tb);
}
if (section) {
OROPrimitive *clone = tb->clone();
clone->setPosition(scenePosition(position()));
section->addPrimitive(clone);
}
int height = scenePosition(position()).y() + tb->size().height();
//If there is no page to add the item to, delete it now because it wont be deleted later
if (!page) {
delete tb;
}
return height;
}
diff --git a/src/items/field/KReportItemField.h b/src/items/field/KReportItemField.h
index c7c00850..491abbeb 100644
--- a/src/items/field/KReportItemField.h
+++ b/src/items/field/KReportItemField.h
@@ -1,87 +1,87 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KREPORTITEMFIELD_H
#define KREPORTITEMFIELD_H
#include "KReportItemBase.h"
#include
class QDomNode;
namespace Scripting
{
class Field;
}
class KReportItemField : public KReportItemBase
{
Q_OBJECT
public:
KReportItemField();
explicit KReportItemField(const QDomNode & element);
virtual ~KReportItemField();
virtual QString typeName() const;
virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
virtual QString itemDataSource() const;
protected:
KProperty * m_controlSource;
KProperty * m_horizontalAlignment;
KProperty * m_verticalAlignment;
KProperty * m_font;
//KProperty * m_trackTotal;
//KProperty * m_trackBuiltinFormat;
//KProperty * _useSubTotal;
//KProperty * _trackTotalFormat;
KProperty * m_foregroundColor;
KProperty * m_backgroundColor;
KProperty* m_backgroundOpacity;
KProperty* m_lineColor;
KProperty* m_lineWeight;
KProperty* m_lineStyle;
KProperty* m_wordWrap;
KProperty* m_canGrow;
KProperty* m_itemValue;
//bool builtinFormat;
//QString format;
QStringList fieldNames(const QString &);
KReportLineStyle lineStyle() const;
- KRTextStyleData textStyle() const;
+ KReportTextStyleData textStyle() const;
int textFlags() const;
QFont font() const {
return m_font->value().value();
}
void setItemDataSource(const QString&);
private:
virtual void createProperties();
friend class Scripting::Field;
};
#endif
diff --git a/src/items/label/KReportItemLabel.cpp b/src/items/label/KReportItemLabel.cpp
index a2ba567c..35bf35e7 100644
--- a/src/items/label/KReportItemLabel.cpp
+++ b/src/items/label/KReportItemLabel.cpp
@@ -1,209 +1,209 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportItemLabel.h"
#include "KReportRenderObjects.h"
#include "kreportplugin_debug.h"
#include
#include
#include
#include
KReportItemLabel::KReportItemLabel()
{
createProperties();
}
KReportItemLabel::KReportItemLabel(const QDomNode & element)
{
createProperties();
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name")));
m_text->setValue(element.toElement().attribute(QLatin1String("report:caption")));
setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble());
m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align")));
m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align")));
parseReportRect(element.toElement());
for (int i = 0; i < nl.count(); i++) {
node = nl.item(i);
n = node.nodeName();
if (n == QLatin1String("report:text-style")) {
- KRTextStyleData ts;
+ KReportTextStyleData ts;
if (parseReportTextStyleData(node.toElement(), &ts)) {
m_backgroundColor->setValue(ts.backgroundColor);
m_foregroundColor->setValue(ts.foregroundColor);
m_backgroundOpacity->setValue(ts.backgroundOpacity);
m_font->setValue(ts.font);
}
} else if (n == QLatin1String("report:line-style")) {
KReportLineStyle ls;
if (parseReportLineStyleData(node.toElement(), &ls)) {
m_lineWeight->setValue(ls.weight());
m_lineColor->setValue(ls.color());
m_lineStyle->setValue(static_cast(ls.penStyle()));
}
} else {
kreportpluginWarning() << "while parsing label element encountered unknown element: " << n;
}
}
}
KReportItemLabel::~KReportItemLabel()
{
}
QString KReportItemLabel::text() const
{
return m_text->value().toString();
}
void KReportItemLabel::setText(const QString& t)
{
m_text->setValue(t);
}
void KReportItemLabel::createProperties()
{
m_text = new KProperty("caption", QLatin1String("Label"), tr("Caption"));
QStringList keys, strings;
keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right");
strings << tr("Left") << tr("Center") << tr("Right");
m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment"));
keys.clear();
strings.clear();
keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom");
strings << tr("Top") << tr("Center") << tr("Bottom");
m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment"));
m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Font"));
m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color"));
m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color"));
m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity"));
m_backgroundOpacity->setOption("max", 100);
m_backgroundOpacity->setOption("min", 0);
m_backgroundOpacity->setOption("unit", QLatin1String("%"));
m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight"));
m_lineWeight->setOption("step", 1.0);
m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color"));
m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), QString(), KProperty::LineStyle);
propertySet()->addProperty(m_text);
propertySet()->addProperty(m_horizontalAlignment);
propertySet()->addProperty(m_verticalAlignment);
propertySet()->addProperty(m_font);
propertySet()->addProperty(m_backgroundColor);
propertySet()->addProperty(m_foregroundColor);
propertySet()->addProperty(m_backgroundOpacity);
propertySet()->addProperty(m_lineWeight);
propertySet()->addProperty(m_lineColor);
propertySet()->addProperty(m_lineStyle);
}
Qt::Alignment KReportItemLabel::textFlags() const
{
Qt::Alignment align;
QString t;
t = m_horizontalAlignment->value().toString();
if (t == QLatin1String("center"))
align = Qt::AlignHCenter;
else if (t == QLatin1String("right"))
align = Qt::AlignRight;
else
align = Qt::AlignLeft;
t = m_verticalAlignment->value().toString();
if (t == QLatin1String("center"))
align |= Qt::AlignVCenter;
else if (t == QLatin1String("bottom"))
align |= Qt::AlignBottom;
else
align |= Qt::AlignTop;
return align;
}
-KRTextStyleData KReportItemLabel::textStyle() const
+KReportTextStyleData KReportItemLabel::textStyle() const
{
- KRTextStyleData d;
+ KReportTextStyleData d;
d.backgroundColor = m_backgroundColor->value().value();
d.foregroundColor = m_foregroundColor->value().value();
d.font = m_font->value().value();
d.backgroundOpacity = m_backgroundOpacity->value().toInt();
return d;
}
KReportLineStyle KReportItemLabel::lineStyle() const
{
KReportLineStyle ls;
ls.setWeight(m_lineWeight->value().toReal());
ls.setColor(m_lineColor->value().value());
ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt());
return ls;
}
// RTTI
QString KReportItemLabel::typeName() const
{
return QLatin1String("label");
}
int KReportItemLabel::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler *script)
{
Q_UNUSED(data)
Q_UNUSED(script)
OROTextBox * tb = new OROTextBox();
tb->setPosition(scenePosition(position()) + offset);
tb->setSize(sceneSize(size()));
tb->setFont(font());
tb->setText(text());
tb->setFlags(textFlags());
tb->setTextStyle(textStyle());
tb->setLineStyle(lineStyle());
if (page) {
page->insertPrimitive(tb);
}
if (section) {
OROPrimitive *clone = tb->clone();
clone->setPosition(scenePosition(position()));
section->addPrimitive(clone);
}
if (!page) {
delete tb;
}
return 0; //Item doesn't stretch the section height
}
diff --git a/src/items/label/KReportItemLabel.h b/src/items/label/KReportItemLabel.h
index 3a4ba2c2..c47878c4 100644
--- a/src/items/label/KReportItemLabel.h
+++ b/src/items/label/KReportItemLabel.h
@@ -1,72 +1,72 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KReportItemLabel_H
#define KReportItemLabel_H
#include "KReportItemBase.h"
#include
class QDomNode;
namespace Scripting
{
class Label;
}
/**
*/
class KReportItemLabel : public KReportItemBase
{
Q_OBJECT
public:
KReportItemLabel();
explicit KReportItemLabel(const QDomNode & element);
virtual ~KReportItemLabel();
virtual QString typeName() const;
virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
protected:
KProperty *m_text;
KProperty *m_horizontalAlignment;
KProperty *m_verticalAlignment;
KProperty *m_font;
KProperty *m_foregroundColor;
KProperty *m_backgroundColor;
KProperty *m_backgroundOpacity;
KProperty *m_lineColor;
KProperty *m_lineWeight;
KProperty *m_lineStyle;
QString text() const;
QFont font() const {
return m_font->value().value();
}
Qt::Alignment textFlags() const;
void setText(const QString&);
- KRTextStyleData textStyle() const;
+ KReportTextStyleData textStyle() const;
KReportLineStyle lineStyle() const;
private:
virtual void createProperties();
friend class Scripting::Label;
};
#endif
diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp
index 43b51804..32bf0ca0 100644
--- a/src/items/text/KReportItemText.cpp
+++ b/src/items/text/KReportItemText.cpp
@@ -1,320 +1,320 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportItemText.h"
#include "KReportRenderObjects.h"
#include "kreportplugin_debug.h"
#include
#include
#include
#include
#include
#include
#include
KReportItemText::KReportItemText()
: KReportItemText(QDomNode())
{
}
KReportItemText::KReportItemText(const QDomNode & element) : m_bottomPadding(0.0)
{
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
createProperties();
nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name")));
m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value")));
setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble());
m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align")));
m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align")));
m_bottomPadding = element.toElement().attribute(QLatin1String("report:bottom-padding")).toDouble();
parseReportRect(element.toElement());
for (int i = 0; i < nl.count(); i++) {
node = nl.item(i);
n = node.nodeName();
if (n == QLatin1String("report:text-style")) {
- KRTextStyleData ts;
+ KReportTextStyleData ts;
if (parseReportTextStyleData(node.toElement(), &ts)) {
m_backgroundColor->setValue(ts.backgroundColor);
m_foregroundColor->setValue(ts.foregroundColor);
m_backgroundOpacity->setValue(ts.backgroundOpacity);
m_font->setValue(ts.font);
}
} else if (n == QLatin1String("report:line-style")) {
KReportLineStyle ls;
if (parseReportLineStyleData(node.toElement(), &ls)) {
m_lineWeight->setValue(ls.weight());
m_lineColor->setValue(ls.color());
m_lineStyle->setValue(static_cast(ls.penStyle()));
}
} else {
kreportpluginWarning() << "while parsing field element encountered unknown element: " << n;
}
}
}
KReportItemText::~KReportItemText()
{
}
Qt::Alignment KReportItemText::textFlags() const
{
Qt::Alignment align;
QString t;
t = m_horizontalAlignment->value().toString();
if (t == QLatin1String("center"))
align = Qt::AlignHCenter;
else if (t == QLatin1String("right"))
align = Qt::AlignRight;
else
align = Qt::AlignLeft;
t = m_verticalAlignment->value().toString();
if (t == QLatin1String("center"))
align |= Qt::AlignVCenter;
else if (t == QLatin1String("bottom"))
align |= Qt::AlignBottom;
else
align |= Qt::AlignTop;
return align;
}
void KReportItemText::createProperties()
{
//connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) );
QStringList keys, strings;
//_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" );
m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source"));
m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field"));
keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right");
strings << tr("Left") << tr("Center") << tr("Right");
m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment"));
keys.clear();
strings.clear();
keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom");
strings << tr("Top") << tr("Center") << tr("Bottom");
m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment"));
m_font = new KProperty("font", QApplication::font(), tr("Font"));
m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color"));
m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color"));
m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight"));
m_lineWeight->setOption("step", 1.0);
m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color"));
m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), QString(), KProperty::LineStyle);
m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity"));
m_backgroundOpacity->setOption("max", 100);
m_backgroundOpacity->setOption("min", 0);
m_backgroundOpacity->setOption("unit", QLatin1String("%"));
propertySet()->addProperty(m_controlSource);
propertySet()->addProperty(m_itemValue);
propertySet()->addProperty(m_horizontalAlignment);
propertySet()->addProperty(m_verticalAlignment);
propertySet()->addProperty(m_font);
propertySet()->addProperty(m_backgroundColor);
propertySet()->addProperty(m_foregroundColor);
propertySet()->addProperty(m_backgroundOpacity);
propertySet()->addProperty(m_lineWeight);
propertySet()->addProperty(m_lineColor);
propertySet()->addProperty(m_lineStyle);
}
QString KReportItemText::itemDataSource() const
{
return m_controlSource->value().toString();
}
qreal KReportItemText::bottomPadding() const
{
return m_bottomPadding;
}
void KReportItemText::setBottomPadding(qreal bp)
{
if (m_bottomPadding != bp) {
m_bottomPadding = bp;
}
}
-KRTextStyleData KReportItemText::textStyle() const
+KReportTextStyleData KReportItemText::textStyle() const
{
- KRTextStyleData d;
+ KReportTextStyleData d;
d.backgroundColor = m_backgroundColor->value().value();
d.foregroundColor = m_foregroundColor->value().value();
d.font = m_font->value().value();
d.backgroundOpacity = m_backgroundOpacity->value().toInt();
return d;
}
KReportLineStyle KReportItemText::lineStyle() const
{
KReportLineStyle ls;
ls.setWeight(m_lineWeight->value().toReal());
ls.setColor(m_lineColor->value().value());
ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt());
return ls;
}
// RTTI
QString KReportItemText::typeName() const
{
return QLatin1String("text");
}
int KReportItemText::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler *script)
{
Q_UNUSED(script);
QString qstrValue;
QString cs = itemDataSource();
if (!cs.isEmpty()) {
if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string
qstrValue = cs.mid(1);
} else {
qstrValue = data.toString();
}
} else {
qstrValue = m_itemValue->value().toString();
}
QPointF pos = scenePosition(position());
QSizeF siz = sceneSize(size());
pos += offset;
QRectF trf(pos, siz);
qreal intStretch = trf.top() - offset.y();
if (qstrValue.length()) {
QRectF rect = trf;
int pos = 0;
QChar separator;
QRegularExpression re(QLatin1String("\\s"));
QPrinter prnt(QPrinter::HighResolution);
QFontMetrics fm(font(), &prnt);
// int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10;
int intRectWidth = (int)((size().width() / 72) * prnt.resolution());
int intLineCounter = 0;
qreal intBaseTop = trf.top();
qreal intRectHeight = trf.height();
while (qstrValue.length()) {
QRegularExpressionMatch match = re.match(qstrValue);
int idx = match.capturedStart(pos);
if (idx == -1) {
idx = qstrValue.length();
separator = QLatin1Char('\n');
} else
separator = qstrValue.at(idx);
if (fm.boundingRect(qstrValue.left(idx)).width() < intRectWidth || pos == 0) {
pos = idx + 1;
if (separator == QLatin1Char('\n')) {
QString line = qstrValue.left(idx);
qstrValue.remove(0, idx + 1);
pos = 0;
rect.setTop(intBaseTop + (intLineCounter * intRectHeight));
rect.setBottom(rect.top() + intRectHeight);
OROTextBox * tb = new OROTextBox();
tb->setPosition(rect.topLeft());
tb->setSize(rect.size());
tb->setFont(font());
tb->setText(line);
tb->setFlags(textFlags());
tb->setTextStyle(textStyle());
tb->setLineStyle(lineStyle());
if (page) {
page->insertPrimitive(tb);
}
if (section) {
OROTextBox *tb2 = dynamic_cast(tb->clone());
if (tb2) {
tb2->setPosition(scenePosition(position()));
section->addPrimitive(tb2);
}
}
if (!page) {
delete tb;
}
intStretch += intRectHeight;
intLineCounter++;
}
} else {
QString line = qstrValue.left(pos - 1);
qstrValue.remove(0, pos);
pos = 0;
rect.setTop(intBaseTop + (intLineCounter * intRectHeight));
rect.setBottom(rect.top() + intRectHeight);
OROTextBox * tb = new OROTextBox();
tb->setPosition(rect.topLeft());
tb->setSize(rect.size());
tb->setFont(font());
tb->setText(line);
tb->setFlags(textFlags());
tb->setTextStyle(textStyle());
tb->setLineStyle(lineStyle());
if (page) {
page->insertPrimitive(tb);
} else {
delete tb;
}
intStretch += intRectHeight;
intLineCounter++;
}
}
intStretch += (m_bottomPadding / 100.0);
}
return intStretch; //Item returns its required section height
}
diff --git a/src/items/text/KReportItemText.h b/src/items/text/KReportItemText.h
index e6ebffdc..b469b9f3 100644
--- a/src/items/text/KReportItemText.h
+++ b/src/items/text/KReportItemText.h
@@ -1,82 +1,82 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KREPORTITEMTEXT_H
#define KREPORTITEMTEXT_H
#include "KReportItemBase.h"
#include
class QDomNode;
namespace Scripting
{
class Text;
}
/**
*/
class KReportItemText : public KReportItemBase
{
Q_OBJECT
public:
KReportItemText();
explicit KReportItemText(const QDomNode & element);
virtual ~KReportItemText();
virtual QString typeName() const;
virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
virtual QString itemDataSource() const;
protected:
KProperty* m_controlSource;
KProperty* m_horizontalAlignment;
KProperty* m_verticalAlignment;
KProperty* m_font;
KProperty* m_foregroundColor;
KProperty* m_backgroundColor;
KProperty* m_backgroundOpacity;
KProperty* m_lineColor;
KProperty* m_lineWeight;
KProperty* m_lineStyle;
KProperty* m_itemValue;
qreal m_bottomPadding;
Qt::Alignment textFlags() const;
QFont font() const {
return m_font->value().value();
}
void setBottomPadding(qreal bp);
qreal bottomPadding() const;
- KRTextStyleData textStyle() const;
+ KReportTextStyleData textStyle() const;
KReportLineStyle lineStyle() const;
private:
virtual void createProperties();
friend class Scripting::Text;
};
#endif
diff --git a/src/plugins/barcode/codeean.cpp b/src/plugins/barcode/codeean.cpp
index 7704dcb5..58f5e9f3 100644
--- a/src/plugins/barcode/codeean.cpp
+++ b/src/plugins/barcode/codeean.cpp
@@ -1,842 +1,842 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the implementation of the Code EAN and similar
* formats for rendering purposes. All this code assumes a 100dpi
* rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include "KReportRenderObjects.h"
static const int LEFTHAND_ODD = 0;
static const int LEFTHAND_EVEN = 1;
static const int RIGHTHAND = 2;
static const int _encodings[10][3][7] = {
/* LEFTHAND_ODD */ /* LEFTHAND_EVEN */ /* RIGHTHAND */
{ { 0, 0, 0, 1, 1, 0, 1}, { 0, 1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, 1, 0 } }, // 0
{ { 0, 0, 1, 1, 0, 0, 1}, { 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0 } }, // 1
{ { 0, 0, 1, 0, 0, 1, 1}, { 0, 0, 1, 1, 0, 1, 1 }, { 1, 1, 0, 1, 1, 0, 0 } }, // 2
{ { 0, 1, 1, 1, 1, 0, 1}, { 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1, 0 } }, // 3
{ { 0, 1, 0, 0, 0, 1, 1}, { 0, 0, 1, 1, 1, 0, 1 }, { 1, 0, 1, 1, 1, 0, 0 } }, // 4
{ { 0, 1, 1, 0, 0, 0, 1}, { 0, 1, 1, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1, 1, 0 } }, // 5
{ { 0, 1, 0, 1, 1, 1, 1}, { 0, 0, 0, 0, 1, 0, 1 }, { 1, 0, 1, 0, 0, 0, 0 } }, // 6
{ { 0, 1, 1, 1, 0, 1, 1}, { 0, 0, 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1, 0, 0 } }, // 7
{ { 0, 1, 1, 0, 1, 1, 1}, { 0, 0, 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0 } }, // 8
{ { 0, 0, 0, 1, 0, 1, 1}, { 0, 0, 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 1, 0, 0 } } // 9
};
static const int odd = LEFTHAND_ODD;
static const int even = LEFTHAND_EVEN;
static const int _parity[10][6] = {
{ odd, odd, odd, odd, odd, odd }, // 0
{ odd, odd, even, odd, even, even }, // 1
{ odd, odd, even, even, odd, even }, // 2
{ odd, odd, even, even, even, odd }, // 3
{ odd, even, odd, odd, even, even }, // 4
{ odd, even, even, odd, odd, even }, // 5
{ odd, even, even, even, odd, odd }, // 6
{ odd, even, odd, even, odd, even }, // 7
{ odd, even, odd, even, even, odd }, // 8
{ odd, even, even, odd, even, odd } // 9
};
static const int _upcparenc[10][2][6] = {
/* PARITY 0 */ /* PARITY 1 */
{ { even, even, even, odd, odd, odd }, { odd, odd, odd, even, even, even } }, // 0
{ { even, even, odd, even, odd, odd }, { odd, odd, even, odd, even, even } }, // 1
{ { even, even, odd, odd, even, odd }, { odd, odd, even, even, odd, even } }, // 2
{ { even, even, odd, odd, odd, even }, { odd, odd, even, even, even, odd } }, // 3
{ { even, odd, even, even, odd, odd }, { odd, even, odd, odd, even, even } }, // 4
{ { even, odd, odd, even, even, odd }, { odd, even, even, odd, odd, even } }, // 5
{ { even, odd, odd, odd, even, even }, { odd, even, even, even, odd, odd } }, // 6
{ { even, odd, even, odd, even, odd }, { odd, even, odd, even, odd, even } }, // 7
{ { even, odd, even, odd, odd, even }, { odd, even, odd, even, even, odd } }, // 8
{ { even, odd, odd, even, odd, even }, { odd, even, even, odd, even, odd } } // 9
};
//
//! @todo New Renderer Functions
////////////////////////////////////////////////////////
void renderCodeEAN13(OROPage * page, const QRectF & r, const QString & _str, int align)
{
int val[13];
// initialize all the values just so we can be predictable
for (int i = 0; i < 13; ++i)
val[i] = -1;
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 12 && _str.length() != 13)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar)_str.at(i)).digitValue();
if (val[i] == -1)
return;
}
// calculate and append the checksum value
int old_sum = val[12]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 12; ++i) {
checksum += val[i] * ((i % 2) ? 3 : 1);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[12] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar 1/100 inch
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
if (quiet_zone < 10)
quiet_zone = 10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 2;
// L = 95X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (95.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
if (align == 1) { // center
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
} else if (align > 1) // right
quiet_zone = draw_width - (L + quiet_zone);
// else if(align < 1) {} // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_parity[val[0]][i]][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.07));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render last set
for (int i = 0; i < 6; ++i) {
int b = val[i+7];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.07));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString parstr = QString::fromLatin1("%1").arg(val[0]);
QString leftstr = QString().sprintf("%d%d%d%d%d%d",
val[1], val[2], val[3], val[4], val[5], val[6]);
QString rightstr = QString().sprintf("%d%d%d%d%d%d",
val[7], val[8], val[9], val[10], val[11], val[12]);
QFont font(QLatin1String("Arial"), 6);
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left(), r.top() + draw_height - 0.12));
tb->setSize(QSizeF(quiet_zone - 0.02, 0.12));
tb->setFont(font);
tb->setText(parstr);
tb->setFlags(Qt::AlignRight | Qt::AlignTop);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.07));
tb->setSize(QSizeF(0.42, 0.1));
tb->setFont(font);
tb->setText(leftstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.5, (r.top() + draw_height) - 0.07));
tb->setSize(QSizeF(0.42, 0.1));
tb->setFont(font);
tb->setText(rightstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
}
void renderCodeUPCA(OROPage * page, const QRectF & r, const QString & _str, int align)
{
int val[13];
// initialize all the values just so we can be predictable
for (int i = 0; i < 13; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 11 && _str.length() != 12)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
val[0] = 0;
for (int i = 0; i < _str.length(); ++i) {
val[i+1] = ((QChar)_str.at(i)).digitValue();
if (val[i+1] == -1)
return;
}
// calculate and append the checksum value
int old_sum = val[12]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 12; ++i) {
checksum += val[i] * ((i % 2) ? 3 : 1);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[12] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 2;
// L = 95X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (95.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
if (align == 1) { // center
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
} else if (align > 1) // right
quiet_zone = draw_width - (L + quiet_zone);
// else if(align < 1) {} // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_parity[val[0]][i]][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - (i == 0 ? 0 : 0.07)));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render last set
for (int i = 0; i < 6; ++i) {
int b = val[i+7];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - (i == 5 ? 0 : 0.07)));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString parstr = QString::number(val[1]);
QString chkstr = QString::number(val[12]);
QString leftstr = QString().sprintf("%d%d%d%d%d",
val[2], val[3], val[4], val[5], val[6]);
QString rightstr = QString().sprintf("%d%d%d%d%d",
val[7], val[8], val[9], val[10], val[11]);
QFont font(QLatin1String("Arial"), 6);
- KRTextStyleData ts;
+ KReportTextStyleData ts;
ts.backgroundColor = Qt::white;
ts.font = font;
ts.foregroundColor = Qt::black;
ts.backgroundOpacity = 100;
ts.alignment = Qt::AlignRight | Qt::AlignTop;
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left(), r.top() + draw_height - 12));
tb->setSize(QSizeF(quiet_zone - 2, 12));
tb->setTextStyle(ts);
tb->setText(parstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 10, (r.top() + draw_height) - 7));
tb->setSize(QSizeF(35, 10));
tb->setTextStyle(ts);
tb->setText(leftstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 50, (r.top() + draw_height) - 7));
tb->setSize(QSizeF(35, 10));
tb->setTextStyle(ts);
tb->setText(rightstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + L + 2, (r.top() + draw_height) - 12));
tb->setSize(QSizeF(8, 12));
tb->setTextStyle(ts);
tb->setText(chkstr);
page->insertPrimitive(tb);
}
void renderCodeEAN8(OROPage * page, const QRectF & r, const QString & _str, int align)
{
int val[8];
// initialize all the values just so we can be predictable
for (int i = 0; i < 8; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 7 && _str.length() != 8)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar)_str.at(i)).digitValue();
if (val[i] == -1)
return;
}
// calculate and append the checksum value
int old_sum = val[7]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 7; ++i) {
checksum += val[i] * ((i % 2) ? 1 : 3);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[7] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
if (quiet_zone < 10)
quiet_zone = 10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 0.02;
// L = 60X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (67.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
if (align == 1) { // center
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
} else if (align > 1) // right
quiet_zone = draw_width - (L + quiet_zone);
// else if(align < 1) {} // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 4; ++i) {
int b = val[i];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][LEFTHAND_ODD][w]) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.06));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render last set
for (int i = 0; i < 4; ++i) {
int b = val[i+4];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.06));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString leftstr = QString().sprintf("%d%d%d%d",
val[0], val[1], val[2], val[3]);
QString rightstr = QString().sprintf("%d%d%d%d",
val[4], val[5], val[6], val[7]);
QFont font(QLatin1String("Arial"), 6);
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.06));
tb->setSize(QSizeF(0.28, 0.10));
tb->setFont(font);
tb->setText(leftstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.36, (r.top() + draw_height) - 0.06));
tb->setSize(QSizeF(0.28, 0.10));
tb->setFont(font);
tb->setText(rightstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
}
void renderCodeUPCE(OROPage * page, const QRectF & r, const QString & _str, int align)
{
int val[8];
// initialize all the values just so we can be predictable
for (int i = 0; i < 8; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 8)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar)_str.at(i)).digitValue();
if (val[i] == -1)
return;
}
// calculate and append the checksum value
// because everything is so messed up we don't calculate
// the checksum and require that it be passed in already
// however we do have to verify that the first digit is
// either 0 or 1 as that is our parity
if (val[0] != 0 && val[0] != 1)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 0.10;
if (quiet_zone < 0.10)
quiet_zone = 0.10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 2;
// L = 51X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (51.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
if (align == 1) { // center
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
} else if (align > 1) // right
quiet_zone = draw_width - (L + quiet_zone);
// else if(align < 1) {} // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_upcparenc[val[7]][val[0]][i]][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 7));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString parstr = QString::number(val[0]);
QString chkstr = QString::number(val[7]);
QString leftstr = QString().sprintf("%d%d%d%d%d%d",
val[1], val[2], val[3], val[4], val[5], val[6]);
QFont font(QLatin1String("Arial"), 6);
- KRTextStyleData ts;
+ KReportTextStyleData ts;
ts.backgroundColor = Qt::white;
ts.font = font;
ts.foregroundColor = Qt::black;
ts.backgroundOpacity = 100;
ts.alignment = Qt::AlignRight | Qt::AlignTop;
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left(), r.top() + draw_height - 12));
tb->setSize(QSizeF(quiet_zone - 2, 12));
tb->setTextStyle(ts);
tb->setText(parstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 3, (r.top() + draw_height) - 7));
tb->setSize(QSizeF(42, 10));
tb->setTextStyle(ts);
tb->setText(leftstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + L + 2, r.top() + draw_height - 12));
tb->setSize(QSizeF(8, 12));
tb->setTextStyle(ts);
tb->setText(chkstr);
page->insertPrimitive(tb);
}
diff --git a/src/renderer/scripting/KReportScriptDraw.cpp b/src/renderer/scripting/KReportScriptDraw.cpp
index d78edbb1..f65fe9d8 100644
--- a/src/renderer/scripting/KReportScriptDraw.cpp
+++ b/src/renderer/scripting/KReportScriptDraw.cpp
@@ -1,132 +1,132 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportScriptDraw.h"
#include "KReportRenderObjects.h"
#include
#include
KReportScriptDraw::KReportScriptDraw(QObject *parent)
: QObject(parent)
{
m_curPage = 0;
}
KReportScriptDraw::~KReportScriptDraw()
{
}
void KReportScriptDraw::setPage(OROPage *p)
{
m_curPage = p;
}
void KReportScriptDraw::setOffset(QPointF off)
{
m_curOffset = off;
}
void KReportScriptDraw::rectangle(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a)
{
if (m_curPage) {
ORORect *r = new ORORect();
r->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h))));
QPen pen(QColor(lc), lw);
QColor c(fc);
c.setAlpha(a);
QBrush bru(c);
r->setBrush(bru);
r->setPen(pen);
m_curPage->insertPrimitive(r);
}
}
void KReportScriptDraw::ellipse(qreal x, qreal y, qreal w, qreal h, const QString& lc, const QString& fc, qreal lw, int a)
{
if (m_curPage) {
OROEllipse *e = new OROEllipse();
e->setRect(QRectF(KReportItemBase::scenePosition(QPointF(x, y)) + m_curOffset, KReportItemBase::sceneSize(QSizeF(w, h))));
QPen pen(QColor(lc), lw);
QColor c(fc);
c.setAlpha(a);
QBrush bru(c);
e->setBrush(bru);
e->setPen(pen);
m_curPage->insertPrimitive(e);
}
}
void KReportScriptDraw::line(qreal x1, qreal y1, qreal x2, qreal y2, const QString& lc)
{
if (m_curPage) {
OROLine *ln = new OROLine();
ln->setStartPoint(KReportItemBase::scenePosition(QPointF(x1, y1) + m_curOffset));
ln->setEndPoint(KReportItemBase::scenePosition(QPointF(x2, y2) + m_curOffset));
KReportLineStyle ls;
ls.setColor(QColor(lc));
ls.setWeight(1);
ls.setPenStyle(Qt::SolidLine);
ln->setLineStyle(ls);
m_curPage->insertPrimitive(ln);
}
}
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)
{
if (m_curPage) {
QFont f(fnt, pt);
QRectF r = QFontMetrics(f).boundingRect(txt);
- KRTextStyleData ts;
+ KReportTextStyleData ts;
ts.font = f;
ts.backgroundColor = QColor(bc);
ts.foregroundColor = QColor(fc);
ts.backgroundOpacity = o;
KReportLineStyle ls;
ls.setColor(QColor(lc));
ls.setWeight(lw);
if (lw <= 0)
ls.setPenStyle(Qt::NoPen);
else
ls.setPenStyle(Qt::SolidLine);
OROTextBox *tb = new OROTextBox();
tb->setPosition(QPointF(x, y) + m_curOffset);
tb->setSize(r.size());
tb->setTextStyle(ts);
tb->setLineStyle(ls);
tb->setText(txt);
m_curPage->insertPrimitive(tb);
}
}
diff --git a/src/wrtembed/KReportDesignerItemBase.cpp b/src/wrtembed/KReportDesignerItemBase.cpp
index 53f4a13e..0c78d2e7 100644
--- a/src/wrtembed/KReportDesignerItemBase.cpp
+++ b/src/wrtembed/KReportDesignerItemBase.cpp
@@ -1,118 +1,118 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportDesignerItemBase.h"
#include "KReportItemBase.h"
#include "KReportUtils.h"
#include
#include
#include
class Q_DECL_HIDDEN KReportDesignerItemBase::Private
{
public:
Private();
~Private();
KReportDesigner *reportDesigner;
KReportItemBase *item;
QString renderText;
};
KReportDesignerItemBase::Private::Private()
{
}
KReportDesignerItemBase::Private::~Private()
{
}
KReportDesignerItemBase::~KReportDesignerItemBase()
{
delete d;
}
KReportDesignerItemBase::KReportDesignerItemBase(KReportDesigner *r, KReportItemBase *b) : d(new Private())
{
d->reportDesigner = r;
d->item = b;
}
void KReportDesignerItemBase::buildXML(QGraphicsItem * item, QDomDocument *doc, QDomElement *parent)
{
KReportDesignerItemBase *re = 0;
re = dynamic_cast(item);
if (re) {
re->buildXML(doc, parent);
}
}
void KReportDesignerItemBase::buildXMLRect(QDomDocument *doc, QDomElement *entity, KReportItemBase *i)
{
Q_UNUSED(doc);
KReportUtils::buildXMLRect(entity, i->position(), i->size());
}
-void KReportDesignerItemBase::buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts)
+void KReportDesignerItemBase::buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KReportTextStyleData &ts)
{
KReportUtils::buildXMLTextStyle(doc, entity, ts);
}
void KReportDesignerItemBase::buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls)
{
KReportUtils::buildXMLLineStyle(doc, entity, ls);
}
QString KReportDesignerItemBase::dataSourceAndObjectTypeName(const QString& dataSource, const QString& objectTypeName) const
{
return QString::fromLatin1("%1: %2").arg(dataSource).arg(objectTypeName);
}
// static
void KReportDesignerItemBase::addPropertyAsAttribute(QDomElement* e, KProperty* p)
{
KReportUtils::addPropertyAsAttribute(e, p);
}
KReportDesigner * KReportDesignerItemBase::designer() const
{
return d->reportDesigner;
}
void KReportDesignerItemBase::setDesigner(KReportDesigner* rd)
{
d->reportDesigner = rd;
}
KReportItemBase *KReportDesignerItemBase::item() const
{
return d->item;
}
QString KReportDesignerItemBase::renderText() const
{
return d->renderText;
}
void KReportDesignerItemBase::setRenderText(const QString& text)
{
d->renderText = text;
}
diff --git a/src/wrtembed/KReportDesignerItemBase.h b/src/wrtembed/KReportDesignerItemBase.h
index 4e967beb..0c42dd76 100644
--- a/src/wrtembed/KReportDesignerItemBase.h
+++ b/src/wrtembed/KReportDesignerItemBase.h
@@ -1,88 +1,88 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains all the Report Entity classes. Each one is a
* derivative of ReportEntity, which in turn is derived from QCanvasItem.
*/
#ifndef KREPORTDESIGNERITEMBASE_H
#define KREPORTDESIGNERITEMBASE_H
#include
#include "KReportItemBase.h"
class QDomDocument;
class QDomElement;
class KReportDesigner;
class KReportPosition;
class KReportSize;
//
// ReportEntity
//
class KREPORT_EXPORT KReportDesignerItemBase
{
public:
virtual ~KReportDesignerItemBase();
static void buildXML(QGraphicsItem * item, QDomDocument *doc, QDomElement *parent);
virtual void buildXML(QDomDocument *doc, QDomElement *parent) = 0;
static void buildXMLRect(QDomDocument *doc, QDomElement *entity, KReportItemBase *i);
- static void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KRTextStyleData &ts);
+ static void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KReportTextStyleData &ts);
static void buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls);
virtual KReportDesignerItemBase* clone() = 0;
virtual void move(const QPointF&) = 0;
KReportDesigner* designer() const;
void setDesigner(KReportDesigner* rd);
static void addPropertyAsAttribute(QDomElement* e, KProperty* p);
protected:
explicit KReportDesignerItemBase(KReportDesigner*, KReportItemBase*);
QString dataSourceAndObjectTypeName(const QString& dataSource, const QString& objectTypeName) const;
/**
* @brief Updates the text that is shown for the item in the report designer
* If itemDataSource is set then it is preferred over itemStaticValue
* itemType is appended to the end of the text
*
* @param itemDataSource source field property
* @param itemStaticValue value property
* @param itemType type of item
* @return void
*/
void updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType);
KReportItemBase *item() const;
void setRenderText(const QString &text);
QString renderText() const;
private:
Q_DISABLE_COPY(KReportDesignerItemBase)
class Private;
Private * const d;
};
#endif