mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Added the ability to add watermarks to all reports.
This commit is contained in:
parent
f1701aabbd
commit
f1f1e443ac
@ -61,6 +61,64 @@ private:
|
|||||||
int m_toPage;
|
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 DataSourceManager;
|
||||||
class ReportEnginePrivate;
|
class ReportEnginePrivate;
|
||||||
class PageDesignIntf;
|
class PageDesignIntf;
|
||||||
@ -123,6 +181,8 @@ public:
|
|||||||
ScaleType previewScaleType();
|
ScaleType previewScaleType();
|
||||||
int previewScalePercent();
|
int previewScalePercent();
|
||||||
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
|
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
|
||||||
|
void addWatermark(const WatermarkSetting& watermarkSetting);
|
||||||
|
void clearWatermarks();
|
||||||
signals:
|
signals:
|
||||||
void cleared();
|
void cleared();
|
||||||
void renderStarted();
|
void renderStarted();
|
||||||
|
@ -939,6 +939,16 @@ void ReportEnginePrivate::setPreviewScaleType(const ScaleType &scaleType, int pe
|
|||||||
m_previewScalePercent = percent;
|
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)
|
PageItemDesignIntf* ReportEnginePrivate::getPageByName(const QString& pageName)
|
||||||
{
|
{
|
||||||
foreach(PageItemDesignIntf* page, m_renderingPages){
|
foreach(PageItemDesignIntf* page, m_renderingPages){
|
||||||
@ -1152,6 +1162,38 @@ void ReportEnginePrivate::paintByExternalPainter(const QString& objectName, QPai
|
|||||||
emit externalPaint(objectName, painter, options);
|
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()
|
ReportPages ReportEnginePrivate::renderToPages()
|
||||||
{
|
{
|
||||||
int startTOCPage = -1;
|
int startTOCPage = -1;
|
||||||
@ -1175,7 +1217,20 @@ ReportPages ReportEnginePrivate::renderToPages()
|
|||||||
m_reportRender->setScriptContext(scriptContext());
|
m_reportRender->setScriptContext(scriptContext());
|
||||||
m_renderingPages.clear();
|
m_renderingPages.clear();
|
||||||
foreach (PageDesignIntf* page, m_pages) {
|
foreach (PageDesignIntf* page, m_pages) {
|
||||||
|
|
||||||
|
QVector<BaseDesignIntf*> watermarks;
|
||||||
|
if (!m_watermarks.isEmpty()){
|
||||||
|
foreach(WatermarkSetting watermarkSetting, m_watermarks){
|
||||||
|
watermarks.append(createWatermark(page, watermarkSetting));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PageItemDesignIntf* rp = createRenderingPage(page->pageItem());
|
PageItemDesignIntf* rp = createRenderingPage(page->pageItem());
|
||||||
|
|
||||||
|
|
||||||
|
qDeleteAll(watermarks.begin(),watermarks.end());
|
||||||
|
watermarks.clear();
|
||||||
|
|
||||||
m_renderingPages.append(rp);
|
m_renderingPages.append(rp);
|
||||||
scriptContext()->baseDesignIntfToScript(rp->objectName(), rp);
|
scriptContext()->baseDesignIntfToScript(rp->objectName(), rp);
|
||||||
}
|
}
|
||||||
@ -1457,6 +1512,18 @@ void ReportEngine::setPreviewScaleType(const ScaleType &previewScaleType, int pe
|
|||||||
d->setPreviewScaleType(previewScaleType, percent);
|
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)
|
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
|
}// namespace LimeReport
|
||||||
|
|
||||||
|
@ -61,6 +61,64 @@ private:
|
|||||||
int m_toPage;
|
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 DataSourceManager;
|
||||||
class ReportEnginePrivate;
|
class ReportEnginePrivate;
|
||||||
class PageDesignIntf;
|
class PageDesignIntf;
|
||||||
@ -123,6 +181,8 @@ public:
|
|||||||
ScaleType previewScaleType();
|
ScaleType previewScaleType();
|
||||||
int previewScalePercent();
|
int previewScalePercent();
|
||||||
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
|
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
|
||||||
|
void addWatermark(const WatermarkSetting& watermarkSetting);
|
||||||
|
void clearWatermarks();
|
||||||
signals:
|
signals:
|
||||||
void cleared();
|
void cleared();
|
||||||
void renderStarted();
|
void renderStarted();
|
||||||
|
@ -217,6 +217,8 @@ public:
|
|||||||
ScaleType previewScaleType();
|
ScaleType previewScaleType();
|
||||||
int previewScalePercent();
|
int previewScalePercent();
|
||||||
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
|
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
|
||||||
|
void addWatermark(const WatermarkSetting& watermarkSetting);
|
||||||
|
void clearWatermarks();
|
||||||
signals:
|
signals:
|
||||||
void pagesLoadFinished();
|
void pagesLoadFinished();
|
||||||
void datasourceCollectionLoadFinished(const QString& collectionName);
|
void datasourceCollectionLoadFinished(const QString& collectionName);
|
||||||
@ -303,6 +305,8 @@ private:
|
|||||||
int m_previewScalePercent;
|
int m_previewScalePercent;
|
||||||
int m_startTOCPage;
|
int m_startTOCPage;
|
||||||
QColor m_previewPageBackgroundColor;
|
QColor m_previewPageBackgroundColor;
|
||||||
|
QVector<WatermarkSetting> m_watermarks;
|
||||||
|
BaseDesignIntf *createWatermark(PageDesignIntf *page, WatermarkSetting watermarkSetting);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user