mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 16:44:39 +03:00
Anchor has been added to ItemGeometry
This commit is contained in:
parent
f1f1e443ac
commit
de5cc0e0ca
@ -64,8 +64,8 @@ private:
|
|||||||
class LIMEREPORT_EXPORT ItemGeometry{
|
class LIMEREPORT_EXPORT ItemGeometry{
|
||||||
public:
|
public:
|
||||||
enum Type{Milimeters, Pixels};
|
enum Type{Milimeters, Pixels};
|
||||||
ItemGeometry(qreal x, qreal y, qreal width, qreal height, Type type = Milimeters)
|
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_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){}
|
ItemGeometry(): m_x(0), m_y(0), m_width(0), m_height(0), m_type(Milimeters){}
|
||||||
|
|
||||||
qreal x() const;
|
qreal x() const;
|
||||||
@ -83,12 +83,16 @@ public:
|
|||||||
Type type() const;
|
Type type() const;
|
||||||
void setType(const Type &type);
|
void setType(const Type &type);
|
||||||
|
|
||||||
|
Qt::Alignment anchor() const;
|
||||||
|
void setAnchor(const Qt::Alignment &anchor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qreal m_x;
|
qreal m_x;
|
||||||
qreal m_y;
|
qreal m_y;
|
||||||
qreal m_width;
|
qreal m_width;
|
||||||
qreal m_height;
|
qreal m_height;
|
||||||
Type m_type;
|
Type m_type;
|
||||||
|
Qt::Alignment m_anchor;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIMEREPORT_EXPORT WatermarkSetting{
|
class LIMEREPORT_EXPORT WatermarkSetting{
|
||||||
@ -119,6 +123,14 @@ private:
|
|||||||
QColor m_color;
|
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 DataSourceManager;
|
||||||
class ReportEnginePrivate;
|
class ReportEnginePrivate;
|
||||||
class PageDesignIntf;
|
class PageDesignIntf;
|
||||||
|
@ -1164,27 +1164,13 @@ void ReportEnginePrivate::paintByExternalPainter(const QString& objectName, QPai
|
|||||||
|
|
||||||
BaseDesignIntf* ReportEnginePrivate::createWatermark(PageDesignIntf* page, WatermarkSetting watermarkSetting)
|
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){
|
if (watermark){
|
||||||
watermark->setProperty("content", watermarkSetting.text());
|
watermark->setProperty("content", watermarkSetting.text());
|
||||||
watermark->setProperty("font",watermark->font());
|
watermark->setProperty("font",watermarkSetting.font());
|
||||||
watermark->setProperty("watermark",true);
|
watermark->setProperty("watermark",true);
|
||||||
watermark->setProperty("itemLocation",1);
|
watermark->setProperty("itemLocation",1);
|
||||||
watermark->setProperty("foregroundOpacity", watermarkSetting.opacity());
|
watermark->setProperty("foregroundOpacity", watermarkSetting.opacity());
|
||||||
@ -1768,6 +1754,16 @@ void ItemGeometry::setType(const Type &type)
|
|||||||
m_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
|
QString WatermarkSetting::text() const
|
||||||
{
|
{
|
||||||
return m_text;
|
return m_text;
|
||||||
@ -1818,6 +1814,70 @@ void WatermarkSetting::setColor(const QColor &color)
|
|||||||
m_color = 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
|
}// namespace LimeReport
|
||||||
|
|
||||||
|
@ -64,8 +64,8 @@ private:
|
|||||||
class LIMEREPORT_EXPORT ItemGeometry{
|
class LIMEREPORT_EXPORT ItemGeometry{
|
||||||
public:
|
public:
|
||||||
enum Type{Milimeters, Pixels};
|
enum Type{Milimeters, Pixels};
|
||||||
ItemGeometry(qreal x, qreal y, qreal width, qreal height, Type type = Milimeters)
|
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_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){}
|
ItemGeometry(): m_x(0), m_y(0), m_width(0), m_height(0), m_type(Milimeters){}
|
||||||
|
|
||||||
qreal x() const;
|
qreal x() const;
|
||||||
@ -83,12 +83,16 @@ public:
|
|||||||
Type type() const;
|
Type type() const;
|
||||||
void setType(const Type &type);
|
void setType(const Type &type);
|
||||||
|
|
||||||
|
Qt::Alignment anchor() const;
|
||||||
|
void setAnchor(const Qt::Alignment &anchor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qreal m_x;
|
qreal m_x;
|
||||||
qreal m_y;
|
qreal m_y;
|
||||||
qreal m_width;
|
qreal m_width;
|
||||||
qreal m_height;
|
qreal m_height;
|
||||||
Type m_type;
|
Type m_type;
|
||||||
|
Qt::Alignment m_anchor;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIMEREPORT_EXPORT WatermarkSetting{
|
class LIMEREPORT_EXPORT WatermarkSetting{
|
||||||
@ -119,6 +123,14 @@ private:
|
|||||||
QColor m_color;
|
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 DataSourceManager;
|
||||||
class ReportEnginePrivate;
|
class ReportEnginePrivate;
|
||||||
class PageDesignIntf;
|
class PageDesignIntf;
|
||||||
|
@ -56,6 +56,24 @@ class PrintRange;
|
|||||||
class ReportDesignWindow;
|
class ReportDesignWindow;
|
||||||
class ReportExporterInterface;
|
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 {
|
class ReportEnginePrivateInterface {
|
||||||
public:
|
public:
|
||||||
virtual PageDesignIntf* appendPage(const QString& pageName="") = 0;
|
virtual PageDesignIntf* appendPage(const QString& pageName="") = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user