From de5cc0e0ca1bec89fcba1d1358af53ded0e9decb Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Tue, 2 Apr 2019 22:56:12 +0300 Subject: [PATCH] Anchor has been added to ItemGeometry --- include/lrreportengine.h | 16 +++++- limereport/lrreportengine.cpp | 96 ++++++++++++++++++++++++++++------- limereport/lrreportengine.h | 16 +++++- limereport/lrreportengine_p.h | 18 +++++++ 4 files changed, 124 insertions(+), 22 deletions(-) diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 83adadb..75cd41c 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -64,8 +64,8 @@ private: class LIMEREPORT_EXPORT ItemGeometry{ public: enum Type{Milimeters, Pixels}; - ItemGeometry(qreal x, qreal y, qreal width, qreal height, Type type = Milimeters) - :m_x(x), m_y(y), m_width(width), m_height(height), m_type(type){} + ItemGeometry(qreal x, qreal y, qreal width, qreal height, Qt::Alignment anchor, Type type = Milimeters) + :m_x(x), m_y(y), m_width(width), m_height(height), m_type(type), m_anchor(anchor){} ItemGeometry(): m_x(0), m_y(0), m_width(0), m_height(0), m_type(Milimeters){} qreal x() const; @@ -83,12 +83,16 @@ public: Type type() const; void setType(const Type &type); + Qt::Alignment anchor() const; + void setAnchor(const Qt::Alignment &anchor); + private: qreal m_x; qreal m_y; qreal m_width; qreal m_height; Type m_type; + Qt::Alignment m_anchor; }; class LIMEREPORT_EXPORT WatermarkSetting{ @@ -119,6 +123,14 @@ private: QColor m_color; }; +class ItemBuilder{ + virtual void setProperty(QString name, QVariant value) = 0; + virtual QVariant property(QString name) = 0; + virtual void setGeometry(ItemGeometry geometry) = 0; + virtual ItemGeometry geometry() = 0; +}; + + class DataSourceManager; class ReportEnginePrivate; class PageDesignIntf; diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 08ae3b1..ee7473d 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -1164,27 +1164,13 @@ void ReportEnginePrivate::paintByExternalPainter(const QString& objectName, QPai BaseDesignIntf* ReportEnginePrivate::createWatermark(PageDesignIntf* page, WatermarkSetting watermarkSetting) { - QPointF pos; - QSizeF size; - switch (watermarkSetting.geomerty().type()) { - case ItemGeometry::Milimeters: - pos.setX(watermarkSetting.geomerty().x() * LimeReport::Const::mmFACTOR); - pos.setY(watermarkSetting.geomerty().y() * LimeReport::Const::mmFACTOR); - size.setWidth(watermarkSetting.geomerty().width() * LimeReport::Const::mmFACTOR); - size.setHeight(watermarkSetting.geomerty().height() * LimeReport::Const::mmFACTOR); - break; - case ItemGeometry::Pixels: - pos.setX(watermarkSetting.geomerty().x()); - pos.setY(watermarkSetting.geomerty().y()); - size.setWidth(watermarkSetting.geomerty().width()); - size.setHeight(watermarkSetting.geomerty().height()); - break; - } - BaseDesignIntf* watermark = page->addReportItem("TextItem",pos,size); + ItemGeometryHelper geometry(watermarkSetting.geomerty()); + + BaseDesignIntf* watermark = page->addReportItem("TextItem", geometry.mapToPage(*page->pageItem()), geometry.sceneSize()); if (watermark){ watermark->setProperty("content", watermarkSetting.text()); - watermark->setProperty("font",watermark->font()); + watermark->setProperty("font",watermarkSetting.font()); watermark->setProperty("watermark",true); watermark->setProperty("itemLocation",1); watermark->setProperty("foregroundOpacity", watermarkSetting.opacity()); @@ -1768,6 +1754,16 @@ void ItemGeometry::setType(const Type &type) m_type = type; } +Qt::Alignment ItemGeometry::anchor() const +{ + return m_anchor; +} + +void ItemGeometry::setAnchor(const Qt::Alignment &anchor) +{ + m_anchor = anchor; +} + QString WatermarkSetting::text() const { return m_text; @@ -1818,6 +1814,70 @@ void WatermarkSetting::setColor(const QColor &color) m_color = color; } +qreal ItemGeometryHelper::sceneX() +{ + return valueToPixels(m_geometry.x()); +} + +qreal ItemGeometryHelper::sceneY() +{ + return valueToPixels(m_geometry.y()); +} + +qreal ItemGeometryHelper::sceneWidth() +{ + return valueToPixels(m_geometry.width()); +} + +qreal ItemGeometryHelper::sceneHeight() +{ + return valueToPixels(m_geometry.height()); +} + +QPointF ItemGeometryHelper::scenePos() +{ + return (QPointF(sceneX(), sceneY())); +} + +QSizeF ItemGeometryHelper::sceneSize() +{ + return (QSizeF(sceneWidth(), sceneHeight())); +} + +QPointF ItemGeometryHelper::mapToPage(const PageItemDesignIntf &page) +{ + qreal startX = 0; + qreal startY = 0; + + if ( m_geometry.anchor() & Qt::AlignLeft){ + startX = 0; + } else if (m_geometry.anchor() & Qt::AlignRight){ + startX = page.geometry().width(); + } else { + startX = page.geometry().width() / 2; + } + + if ( m_geometry.anchor() & Qt::AlignTop){ + startY = 0; + } else if (m_geometry.anchor() & Qt::AlignBottom){ + startY = page.geometry().height(); + } else { + startY = page.geometry().height() / 2; + } + + return QPointF(startX + sceneX(), startY + sceneY()); +} + +qreal ItemGeometryHelper::valueToPixels(qreal value) +{ + switch (m_geometry.type()) { + case LimeReport::ItemGeometry::Milimeters: + return value * Const::mmFACTOR; + case LimeReport::ItemGeometry::Pixels: + return value; + } +} + }// namespace LimeReport diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 83adadb..75cd41c 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -64,8 +64,8 @@ private: class LIMEREPORT_EXPORT ItemGeometry{ public: enum Type{Milimeters, Pixels}; - ItemGeometry(qreal x, qreal y, qreal width, qreal height, Type type = Milimeters) - :m_x(x), m_y(y), m_width(width), m_height(height), m_type(type){} + ItemGeometry(qreal x, qreal y, qreal width, qreal height, Qt::Alignment anchor, Type type = Milimeters) + :m_x(x), m_y(y), m_width(width), m_height(height), m_type(type), m_anchor(anchor){} ItemGeometry(): m_x(0), m_y(0), m_width(0), m_height(0), m_type(Milimeters){} qreal x() const; @@ -83,12 +83,16 @@ public: Type type() const; void setType(const Type &type); + Qt::Alignment anchor() const; + void setAnchor(const Qt::Alignment &anchor); + private: qreal m_x; qreal m_y; qreal m_width; qreal m_height; Type m_type; + Qt::Alignment m_anchor; }; class LIMEREPORT_EXPORT WatermarkSetting{ @@ -119,6 +123,14 @@ private: QColor m_color; }; +class ItemBuilder{ + virtual void setProperty(QString name, QVariant value) = 0; + virtual QVariant property(QString name) = 0; + virtual void setGeometry(ItemGeometry geometry) = 0; + virtual ItemGeometry geometry() = 0; +}; + + class DataSourceManager; class ReportEnginePrivate; class PageDesignIntf; diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index ab2679e..1432bd2 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -56,6 +56,24 @@ class PrintRange; class ReportDesignWindow; class ReportExporterInterface; + +class ItemGeometryHelper{ +public: + ItemGeometryHelper(const ItemGeometry& geometry) + : m_geometry(geometry){} + qreal sceneX(); + qreal sceneY(); + qreal sceneWidth(); + qreal sceneHeight(); + QPointF scenePos(); + QSizeF sceneSize(); + QPointF mapToPage(const PageItemDesignIntf &page); +private: + qreal valueToPixels(qreal value); +private: + const ItemGeometry& m_geometry; +}; + class ReportEnginePrivateInterface { public: virtual PageDesignIntf* appendPage(const QString& pageName="") = 0;