0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

Big pages printing has been changed

This commit is contained in:
Arin Alex 2017-09-08 01:18:35 +03:00
parent 21cdce94e6
commit b6d03ab71c
3 changed files with 91 additions and 10 deletions

View File

@ -50,7 +50,7 @@ PageItemDesignIntf::PageItemDesignIntf(QObject *owner, QGraphicsItem *parent) :
m_topMargin(0), m_bottomMargin(0), m_leftMargin(0), m_rightMargin(0),
m_pageOrientaion(Portrait), m_pageSize(A4), m_sizeChainging(false),
m_fullPage(false), m_oldPrintMode(false), m_resetPageNumber(false),
m_isExtendedInDesignMode(false), m_extendedHeight(1000), m_isTOC(false)
m_isExtendedInDesignMode(false), m_extendedHeight(1000), m_isTOC(false), m_setPageSizeToPrinter(false)
{
setFixedPos(true);
setPossibleResizeDirectionFlags(Fixed);
@ -331,6 +331,19 @@ void PageItemDesignIntf::initColumnsPos(QVector<qreal> &posByColumns, qreal pos,
}
}
bool PageItemDesignIntf::getSetPageSizeToPrinter() const
{
return m_setPageSizeToPrinter;
}
void PageItemDesignIntf::setSetPageSizeToPrinter(bool setPageSizeToPrinter)
{
if (m_setPageSizeToPrinter != setPageSizeToPrinter){
m_setPageSizeToPrinter = setPageSizeToPrinter;
notify("setPageSizeToPrinter", !setPageSizeToPrinter, setPageSizeToPrinter);
}
}
bool PageItemDesignIntf::isTOC() const
{
return m_isTOC;
@ -340,10 +353,8 @@ void PageItemDesignIntf::setIsTOC(bool isTOC)
{
if (m_isTOC != isTOC){
m_isTOC = isTOC;
if (!isLoading()){
notify("pageIsTOC", !isTOC, isTOC);
}
}
}
int PageItemDesignIntf::extendedHeight() const
@ -381,10 +392,8 @@ void PageItemDesignIntf::setResetPageNumber(bool resetPageNumber)
{
if (m_resetPageNumber!=resetPageNumber){
m_resetPageNumber = resetPageNumber;
if (!isLoading()){
notify("resetPageNumber",!m_resetPageNumber,m_resetPageNumber);
}
}
}
void PageItemDesignIntf::updateSubItemsSize(RenderPass pass, DataSourceManager *dataManager)
@ -605,6 +614,46 @@ void PageItemDesignIntf::preparePopUpMenu(QMenu &menu)
if (action->text().compare(tr("Paste")) != 0)
action->setVisible(false);
}
menu.addSeparator();
QAction* action = menu.addAction(tr("Page is TOC"));
action->setCheckable(true);
action->setChecked(isTOC());
action = menu.addAction(tr("Reset page number"));
action->setCheckable(true);
action->setChecked(resetPageNumber());
action = menu.addAction(tr("Full page"));
action->setCheckable(true);
action->setChecked(fullPage());
action = menu.addAction(tr("Set page size to printer"));
action->setCheckable(true);
action->setChecked(getSetPageSizeToPrinter());
// action = menu.addAction(tr("Transparent"));
// action->setCheckable(true);
// action->setChecked(backgroundMode() == TransparentMode);
}
void PageItemDesignIntf::processPopUpAction(QAction *action)
{
if (action->text().compare(tr("Page is TOC")) == 0){
page()->setPropertyToSelectedItems("pageIsTOC",action->isChecked());
}
if (action->text().compare(tr("Reset page number")) == 0){
page()->setPropertyToSelectedItems("resetPageNumber",action->isChecked());
}
if (action->text().compare(tr("Full page")) == 0){
page()->setPropertyToSelectedItems("fullPage",action->isChecked());
}
if (action->text().compare(tr("Set page size to printer")) == 0){
page()->setPropertyToSelectedItems("setPageSizeToPrinter",action->isChecked());
}
}
void PageItemDesignIntf::initPageSize(const PageItemDesignIntf::PageSize &size)
{

View File

@ -56,6 +56,7 @@ class PageItemDesignIntf : public LimeReport::ItemsContainerDesignInft
Q_PROPERTY(bool isExtendedInDesignMode READ isExtendedInDesignMode WRITE setExtendedInDesignMode)
Q_PROPERTY(int extendedHeight READ extendedHeight WRITE setExtendedHeight)
Q_PROPERTY(bool pageIsTOC READ isTOC WRITE setIsTOC)
Q_PROPERTY(bool setPageSizeToPrinter READ getSetPageSizeToPrinter WRITE setSetPageSizeToPrinter )
friend class ReportRender;
public:
enum Orientation { Portrait, Landscape };
@ -129,6 +130,9 @@ public:
bool isTOC() const;
void setIsTOC(bool isTOC);
bool getSetPageSizeToPrinter() const;
void setSetPageSizeToPrinter(bool setPageSizeToPrinter);
signals:
void beforeFirstPageRendered();
void afterLastPageRendered();
@ -144,6 +148,7 @@ protected:
void initPageSize(const QSizeF &size);
QColor selectionMarkerColor(){return Qt::transparent;}
void preparePopUpMenu(QMenu &menu);
void processPopUpAction(QAction *action);
private:
void paintGrid(QPainter *ppainter, QRectF rect);
void initColumnsPos(QVector<qreal>&posByColumns, qreal pos, int columnCount);
@ -163,6 +168,7 @@ private:
bool m_isExtendedInDesignMode;
int m_extendedHeight;
bool m_isTOC;
bool m_setPageSizeToPrinter;
};
typedef QList<PageItemDesignIntf::Ptr> ReportPages;

View File

@ -249,6 +249,15 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer)
bool isFirst = true;
int currenPage = 1;
qreal leftMargin, topMargin, rightMargin, bottomMargin;
printer.getPageMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin, QPrinter::Millimeter);
QRectF printerPageRect = printer.pageRect(QPrinter::Millimeter);
printerPageRect = QRectF(0,0,(printerPageRect.size().width() + rightMargin + leftMargin) * Const::mmFACTOR,
(printerPageRect.size().height() + bottomMargin +topMargin) * Const::mmFACTOR);
foreach(PageItemDesignIntf::Ptr page, pages){
if (
@ -261,6 +270,7 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer)
{
QPointF pagePos = page->pos();
page->setPos(0,0);
renderPage.setPageItem(page);
renderPage.setSceneRect(renderPage.pageItem()->mapToScene(renderPage.pageItem()->rect()).boundingRect());
@ -282,8 +292,10 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer)
QSizeF pageSize = (renderPage.pageItem()->pageOrientation()==PageItemDesignIntf::Landscape)?
QSizeF(renderPage.pageItem()->sizeMM().height(),renderPage.pageItem()->sizeMM().width()):
renderPage.pageItem()->sizeMM();
if (page->getSetPageSizeToPrinter())
printer.setPaperSize(pageSize,QPrinter::Millimeter);
} else {
if (page->getSetPageSizeToPrinter())
printer.setPaperSize((QPrinter::PageSize)renderPage.pageItem()->pageSize());
}
}
@ -295,7 +307,21 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer)
painter = new QPainter(&printer);
}
if (printerPageRect.width() < page->geometry().width()){
qreal pageWidth = page->geometry().width();
QRectF currentPrintingRect = printerPageRect;
while (pageWidth>0){
renderPage.render(painter, printer.pageRect(), currentPrintingRect);
currentPrintingRect.adjust(printerPageRect.size().width(),0,printerPageRect.size().width(),0);
pageWidth -= printerPageRect.size().width();
if (pageWidth>0) printer.newPage();
}
} else {
renderPage.render(painter);
}
page->setPos(pagePos);
}