diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 79090f9..83adadb 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -61,6 +61,64 @@ private: int m_toPage; }; +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(): m_x(0), m_y(0), m_width(0), m_height(0), m_type(Milimeters){} + + qreal x() const; + void setX(const qreal &x); + + qreal y() const; + void setY(const qreal &y); + + qreal width() const; + void setWidth(const qreal &width); + + qreal height() const; + void setHeight(const qreal &height); + + Type type() const; + void setType(const Type &type); + +private: + qreal m_x; + qreal m_y; + qreal m_width; + qreal m_height; + Type m_type; +}; + +class LIMEREPORT_EXPORT WatermarkSetting{ +public: + WatermarkSetting(const QString& text, const ItemGeometry& geometry, const QFont& font) + : m_text(text), m_font(font), m_opacity(50), m_geomerty(geometry), m_color(QColor(Qt::black)){} + WatermarkSetting(): m_font(QFont()), m_opacity(50), m_geomerty(ItemGeometry()){} + QString text() const; + void setText(const QString &text); + + QFont font() const; + void setFont(const QFont &font); + + int opacity() const; + void setOpacity(const int &opacity); + + ItemGeometry geomerty() const; + void setGeomerty(const ItemGeometry &geomerty); + + QColor color() const; + void setColor(const QColor &color); + +private: + QString m_text; + QFont m_font; + int m_opacity; + ItemGeometry m_geomerty; + QColor m_color; +}; + class DataSourceManager; class ReportEnginePrivate; class PageDesignIntf; @@ -123,6 +181,8 @@ public: ScaleType previewScaleType(); int previewScalePercent(); void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); + void addWatermark(const WatermarkSetting& watermarkSetting); + void clearWatermarks(); signals: void cleared(); void renderStarted(); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 3420639..08ae3b1 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -939,6 +939,16 @@ void ReportEnginePrivate::setPreviewScaleType(const ScaleType &scaleType, int pe m_previewScalePercent = percent; } +void ReportEnginePrivate::addWatermark(const WatermarkSetting &watermarkSetting) +{ + m_watermarks.append(watermarkSetting); +} + +void ReportEnginePrivate::clearWatermarks() +{ + m_watermarks.clear(); +} + PageItemDesignIntf* ReportEnginePrivate::getPageByName(const QString& pageName) { foreach(PageItemDesignIntf* page, m_renderingPages){ @@ -1152,6 +1162,38 @@ void ReportEnginePrivate::paintByExternalPainter(const QString& objectName, QPai emit externalPaint(objectName, painter, options); } +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); + if (watermark){ + watermark->setProperty("content", watermarkSetting.text()); + watermark->setProperty("font",watermark->font()); + watermark->setProperty("watermark",true); + watermark->setProperty("itemLocation",1); + watermark->setProperty("foregroundOpacity", watermarkSetting.opacity()); + watermark->setProperty("fontColor", watermarkSetting.color()); + } + return watermark; + +} + ReportPages ReportEnginePrivate::renderToPages() { int startTOCPage = -1; @@ -1175,7 +1217,20 @@ ReportPages ReportEnginePrivate::renderToPages() m_reportRender->setScriptContext(scriptContext()); m_renderingPages.clear(); foreach (PageDesignIntf* page, m_pages) { + + QVector watermarks; + if (!m_watermarks.isEmpty()){ + foreach(WatermarkSetting watermarkSetting, m_watermarks){ + watermarks.append(createWatermark(page, watermarkSetting)); + } + } + PageItemDesignIntf* rp = createRenderingPage(page->pageItem()); + + + qDeleteAll(watermarks.begin(),watermarks.end()); + watermarks.clear(); + m_renderingPages.append(rp); scriptContext()->baseDesignIntfToScript(rp->objectName(), rp); } @@ -1457,6 +1512,18 @@ void ReportEngine::setPreviewScaleType(const ScaleType &previewScaleType, int pe d->setPreviewScaleType(previewScaleType, percent); } +void ReportEngine::addWatermark(const WatermarkSetting &watermarkSetting) +{ + Q_D(ReportEngine); + d->addWatermark(watermarkSetting); +} + +void ReportEngine::clearWatermarks() +{ + Q_D(ReportEngine); + d->clearWatermarks(); +} + void ReportEngine::setShowProgressDialog(bool value) { @@ -1651,5 +1718,106 @@ void PrintProcessor::initPrinter(PageItemDesignIntf* page) } } +qreal ItemGeometry::x() const +{ + return m_x; +} + +void ItemGeometry::setX(const qreal &x) +{ + m_x = x; +} + +qreal ItemGeometry::y() const +{ + return m_y; +} + +void ItemGeometry::setY(const qreal &y) +{ + m_y = y; +} + +qreal ItemGeometry::width() const +{ + return m_width; +} + +void ItemGeometry::setWidth(const qreal &width) +{ + m_width = width; +} + +qreal ItemGeometry::height() const +{ + return m_height; +} + +void ItemGeometry::setHeight(const qreal &height) +{ + m_height = height; +} + +ItemGeometry::Type ItemGeometry::type() const +{ + return m_type; +} + +void ItemGeometry::setType(const Type &type) +{ + m_type = type; +} + +QString WatermarkSetting::text() const +{ + return m_text; +} + +void WatermarkSetting::setText(const QString &text) +{ + m_text = text; +} + +QFont WatermarkSetting::font() const +{ + return m_font; +} + +void WatermarkSetting::setFont(const QFont &font) +{ + m_font = font; +} + +int WatermarkSetting::opacity() const +{ + return m_opacity; +} + +void WatermarkSetting::setOpacity(const int &opacity) +{ + m_opacity = opacity; +} + +ItemGeometry WatermarkSetting::geomerty() const +{ + return m_geomerty; +} + +void WatermarkSetting::setGeomerty(const ItemGeometry &geomerty) +{ + m_geomerty = geomerty; +} + +QColor WatermarkSetting::color() const +{ + return m_color; +} + +void WatermarkSetting::setColor(const QColor &color) +{ + m_color = color; +} + + }// namespace LimeReport diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 79090f9..83adadb 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -61,6 +61,64 @@ private: int m_toPage; }; +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(): m_x(0), m_y(0), m_width(0), m_height(0), m_type(Milimeters){} + + qreal x() const; + void setX(const qreal &x); + + qreal y() const; + void setY(const qreal &y); + + qreal width() const; + void setWidth(const qreal &width); + + qreal height() const; + void setHeight(const qreal &height); + + Type type() const; + void setType(const Type &type); + +private: + qreal m_x; + qreal m_y; + qreal m_width; + qreal m_height; + Type m_type; +}; + +class LIMEREPORT_EXPORT WatermarkSetting{ +public: + WatermarkSetting(const QString& text, const ItemGeometry& geometry, const QFont& font) + : m_text(text), m_font(font), m_opacity(50), m_geomerty(geometry), m_color(QColor(Qt::black)){} + WatermarkSetting(): m_font(QFont()), m_opacity(50), m_geomerty(ItemGeometry()){} + QString text() const; + void setText(const QString &text); + + QFont font() const; + void setFont(const QFont &font); + + int opacity() const; + void setOpacity(const int &opacity); + + ItemGeometry geomerty() const; + void setGeomerty(const ItemGeometry &geomerty); + + QColor color() const; + void setColor(const QColor &color); + +private: + QString m_text; + QFont m_font; + int m_opacity; + ItemGeometry m_geomerty; + QColor m_color; +}; + class DataSourceManager; class ReportEnginePrivate; class PageDesignIntf; @@ -123,6 +181,8 @@ public: ScaleType previewScaleType(); int previewScalePercent(); void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); + void addWatermark(const WatermarkSetting& watermarkSetting); + void clearWatermarks(); signals: void cleared(); void renderStarted(); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 4c82a0e..ab2679e 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -217,6 +217,8 @@ public: ScaleType previewScaleType(); int previewScalePercent(); void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); + void addWatermark(const WatermarkSetting& watermarkSetting); + void clearWatermarks(); signals: void pagesLoadFinished(); void datasourceCollectionLoadFinished(const QString& collectionName); @@ -303,6 +305,8 @@ private: int m_previewScalePercent; int m_startTOCPage; QColor m_previewPageBackgroundColor; + QVector m_watermarks; + BaseDesignIntf *createWatermark(PageDesignIntf *page, WatermarkSetting watermarkSetting); }; }