diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index ac7b5b6..269244e 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -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 &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,9 +353,7 @@ void PageItemDesignIntf::setIsTOC(bool isTOC) { if (m_isTOC != isTOC){ m_isTOC = isTOC; - if (!isLoading()){ - notify("pageIsTOC", !isTOC, isTOC); - } + notify("pageIsTOC", !isTOC, isTOC); } } @@ -381,9 +392,7 @@ void PageItemDesignIntf::setResetPageNumber(bool resetPageNumber) { if (m_resetPageNumber!=resetPageNumber){ m_resetPageNumber = resetPageNumber; - if (!isLoading()){ - notify("resetPageNumber",!m_resetPageNumber,m_resetPageNumber); - } + notify("resetPageNumber",!m_resetPageNumber,m_resetPageNumber); } } @@ -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) { diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index d484492..af023cc 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -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&posByColumns, qreal pos, int columnCount); @@ -163,6 +168,7 @@ private: bool m_isExtendedInDesignMode; int m_extendedHeight; bool m_isTOC; + bool m_setPageSizeToPrinter; }; typedef QList ReportPages; diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index bc3f626..a325cfa 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -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,9 +292,11 @@ 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(); - printer.setPaperSize(pageSize,QPrinter::Millimeter); + if (page->getSetPageSizeToPrinter()) + printer.setPaperSize(pageSize,QPrinter::Millimeter); } else { - printer.setPaperSize((QPrinter::PageSize)renderPage.pageItem()->pageSize()); + if (page->getSetPageSizeToPrinter()) + printer.setPaperSize((QPrinter::PageSize)renderPage.pageItem()->pageSize()); } } @@ -293,9 +305,23 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer) } else { isFirst=false; 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); } - renderPage.render(painter); + page->setPos(pagePos); }