From 6e92feffa70a1260adf87e0cf7a47ff93b841c36 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Tue, 3 Sep 2019 12:59:59 +0300 Subject: [PATCH] Added the ability to send page margins to the printer --- limereport/lrpageitemdesignintf.cpp | 58 ++++++++++++++++++++++++++++- limereport/lrpageitemdesignintf.h | 25 ++++++++++++- limereport/lrreportengine.cpp | 8 +++- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index 9d41a71..586f5ee 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -51,7 +51,9 @@ PageItemDesignIntf::PageItemDesignIntf(QObject *owner, QGraphicsItem *parent) : 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_setPageSizeToPrinter(false), - m_endlessHeight(false), m_printable(true), m_pageFooter(0), m_printBehavior(Split) + m_endlessHeight(false), m_printable(true), m_pageFooter(0), m_printBehavior(Split), + m_printerMarginTop(0), m_printerMarginRight(0), m_printerMarginBottom(0), m_printerMarginLeft(0), + m_changePrinterMargins(false) { setFixedPos(true); setPossibleResizeDirectionFlags(Fixed); @@ -65,7 +67,9 @@ PageItemDesignIntf::PageItemDesignIntf(const PageSize pageSize, const QRectF &re m_pageOrientaion(Portrait), m_pageSize(pageSize), m_sizeChainging(false), m_fullPage(false), m_oldPrintMode(false), m_resetPageNumber(false), m_isExtendedInDesignMode(false), m_extendedHeight(1000), m_isTOC(false), m_setPageSizeToPrinter(false), - m_endlessHeight(false), m_printable(true), m_pageFooter(0), m_printBehavior(Split) + m_endlessHeight(false), m_printable(true), m_pageFooter(0), m_printBehavior(Split), + m_printerMarginTop(0), m_printerMarginRight(0), m_printerMarginBottom(0), m_printerMarginLeft(0), + m_changePrinterMargins(false) { setFixedPos(true); setPossibleResizeDirectionFlags(Fixed); @@ -344,6 +348,56 @@ void PageItemDesignIntf::initColumnsPos(QVector &posByColumns, qreal pos, } } +bool PageItemDesignIntf::changePrinterMargins() const +{ + return m_changePrinterMargins; +} + +void PageItemDesignIntf::setChangePrinterMargins(bool value) +{ + m_changePrinterMargins = value; +} + +int PageItemDesignIntf::printerMarginLeft() const +{ + return m_printerMarginLeft; +} + +void PageItemDesignIntf::setPrinterMarginLeft(int printerMarginLeft) +{ + m_printerMarginLeft = printerMarginLeft; +} + +int PageItemDesignIntf::printerMarginBottom() const +{ + return m_printerMarginBottom; +} + +void PageItemDesignIntf::setPrinterMarginBottom(int printerMarginBottom) +{ + m_printerMarginBottom = printerMarginBottom; +} + +int PageItemDesignIntf::printerMarginRight() const +{ + return m_printerMarginRight; +} + +void PageItemDesignIntf::setPrinterMarginRight(int printerMarginRight) +{ + m_printerMarginRight = printerMarginRight; +} + +int PageItemDesignIntf::printerMarginTop() const +{ + return m_printerMarginTop; +} + +void PageItemDesignIntf::setPrinterMarginTop(int printerMarginTop) +{ + m_printerMarginTop = printerMarginTop; +} + void PageItemDesignIntf::setPrintBehavior(const PrintBehavior &printBehavior) { m_printBehavior = printBehavior; diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index f804776..8097926 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -64,6 +64,12 @@ class PageItemDesignIntf : public ItemsContainerDesignInft Q_PROPERTY(QString printerName READ printerName WRITE setPrinterName) Q_PROPERTY(UnitType units READ unitType WRITE setUnitTypeProperty) Q_PROPERTY(PrintBehavior printBehavior READ printBehavior WRITE setPrintBehavior) + Q_PROPERTY(int printerMarginTop READ printerMarginTop WRITE setPrinterMarginTop) + Q_PROPERTY(int printerMarginRight READ printerMarginRight WRITE setPrinterMarginRight) + Q_PROPERTY(int printerMarginBottom READ printerMarginBottom WRITE setPrinterMarginBottom) + Q_PROPERTY(int printerMarginLeft READ printerMarginLeft WRITE setPrinterMarginLeft) + Q_PROPERTY(bool changePrinterMargins READ changePrinterMargins WRITE setChangePrinterMargins) + friend class ReportRender; public: enum Orientation { Portrait = QPrinter::Portrait, Landscape = QPrinter::Landscape }; @@ -169,6 +175,18 @@ public: PrintBehavior printBehavior() const; void setPrintBehavior(const PrintBehavior &printBehavior); + int printerMarginTop() const; + void setPrinterMarginTop(int printerMarginTop); + int printerMarginRight() const; + void setPrinterMarginRight(int printerMarginRight); + int printerMarginBottom() const; + void setPrinterMarginBottom(int printerMarginBottom); + int printerMarginLeft() const; + void setPrinterMarginLeft(int printerMarginLeft); + + bool changePrinterMargins() const; + void setChangePrinterMargins(bool value); + signals: void beforeFirstPageRendered(); void afterLastPageRendered(); @@ -212,8 +230,11 @@ private: QString m_printerName; BandDesignIntf* m_pageFooter; PrintBehavior m_printBehavior; - - + int m_printerMarginTop; + int m_printerMarginRight; + int m_printerMarginBottom; + int m_printerMarginLeft; + bool m_changePrinterMargins; }; typedef QList ReportPages; diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 91db8b8..fd7107c 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -1845,7 +1845,13 @@ void PrintProcessor::initPrinter(PageItemDesignIntf* page) m_printer->setPaperSize(pageSize,QPrinter::Millimeter); } else { m_printer->setFullPage(page->fullPage()); - m_printer->setPageMargins(0,0,0,0, QPrinter::Millimeter); + if (page->changePrinterMargins()){ + m_printer->setPageMargins(page->printerMarginLeft(), + page->printerMarginTop(), + page->printerMarginRight(), + page->printerMarginBottom(), + QPrinter::Millimeter); + } m_printer->setOrientation(static_cast(page->pageOrientation())); if (page->pageSize()==PageItemDesignIntf::Custom){ QSizeF pageSize = (page->pageOrientation()==PageItemDesignIntf::Landscape)?