[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Need printing guidance - header and footers
From:       "Prashant Shah" <pshah.mumbai () gmail ! com>
Date:       2008-10-29 15:42:28
Message-ID: 2f9dd5d80810290830o73706249ged9218171f123e6e () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


This code will print the html header and footer.

    QRect printer_rect(printer->pageRect());

    ///Setting up the header and calculating the header size
    QTextDocument *document_header = new QTextDocument(this);
    document_header->setPageSize(printer_rect.size());
    document_header->setHtml(company_header);
    QSizeF header_size = document_header->size();

    ///Setting up the footer and calculating the footer size
    QTextDocument *document_footer = new QTextDocument(this);
    document_footer->setPageSize(printer_rect.size());
    document_footer->setHtml(company_footer);
    QSizeF footer_size = document_footer->size();

    ///Calculating the main document size for one page
    QSizeF center_size(printer_rect.width(), (printer->pageRect().height() -
header_size.toSize().height() - footer_size.toSize().height()));

    ///Setting up the center page
    QTextDocument *main_doc = new QTextDocument(this);
    main_doc->setHtml(content);
    main_doc->setPageSize(center_size);

    ///Setting up the rectangles for each section.
    QRect headerRect = QRect(QPoint(0,0), document_header->size().toSize());
    QRect footerRect = QRect(QPoint(0,0), document_footer->size().toSize());
    QRect contentRect = QRect(QPoint(0,0), main_doc->size().toSize());
/// Main content rectangle.
    QRect currentRect = QRect(QPoint(0,0), center_size.toSize());        ///
Current main content rectangle.

    QPainter painter(printer);
    int count = 0;

    while (currentRect.intersects(contentRect))
    {///Loop if the current content rectangle intersects with the main
content rectangle.
        ///Resetting the painter matrix co ordinate system.
        painter.resetMatrix();
        ///Applying negative translation of painter co-ordinate system by
current main content rectangle top y coordinate.
        painter.translate(0, -currentRect.y());
        ///Applying positive translation of painter co-ordinate system by
header hight.
        painter.translate(0, headerRect.height());
        ///Drawing the center content for current page.
        main_doc->drawContents(&painter, currentRect);
        ///Resetting the painter matrix co ordinate system.
        painter.resetMatrix();
        ///Drawing the header on the top of the page
        document_header->drawContents(&painter, headerRect);
        ///Applying positive translation of painter co-ordinate system to
draw the footer
        painter.translate(0, headerRect.height());
        painter.translate(0, center_size.height());
        document_footer->drawContents(&painter, footerRect);

        count++;
        ///Translating the current rectangle to the area to be printed for
the next page
        currentRect.translate(0, currentRect.height());
        ///Inserting a new page if there is till area left to be printed
        if (currentRect.intersects(contentRect))
        {
            printer->newPage();
        }
    }

[Attachment #5 (text/html)]

This code will print the html header and footer.<br><br>&nbsp;&nbsp;&nbsp; \
QRect printer_rect(printer-&gt;pageRect());<br><br>&nbsp;&nbsp;&nbsp; \
///Setting up the header and calculating the header \
size<br>&nbsp;&nbsp;&nbsp; QTextDocument *document_header = new \
QTextDocument(this);<br> &nbsp;&nbsp;&nbsp; \
document_header-&gt;setPageSize(printer_rect.size());<br>&nbsp;&nbsp;&nbsp; \
document_header-&gt;setHtml(company_header);<br>&nbsp;&nbsp;&nbsp; QSizeF \
header_size = document_header-&gt;size();<br><br>&nbsp;&nbsp;&nbsp; \
///Setting up the footer and calculating the footer size<br> \
&nbsp;&nbsp;&nbsp; QTextDocument *document_footer = new \
QTextDocument(this);<br>&nbsp;&nbsp;&nbsp; \
document_footer-&gt;setPageSize(printer_rect.size());<br>&nbsp;&nbsp;&nbsp; \
document_footer-&gt;setHtml(company_footer);<br>&nbsp;&nbsp;&nbsp; QSizeF \
footer_size = document_footer-&gt;size();<br> <br>&nbsp;&nbsp;&nbsp; \
///Calculating the main document size for one page<br>&nbsp;&nbsp;&nbsp; \
QSizeF center_size(printer_rect.width(), (printer-&gt;pageRect().height() - \
header_size.toSize().height() - \
footer_size.toSize().height()));<br><br>&nbsp;&nbsp;&nbsp; ///Setting up \
the center page<br> &nbsp;&nbsp;&nbsp; QTextDocument *main_doc = new \
QTextDocument(this);<br>&nbsp;&nbsp;&nbsp; \
main_doc-&gt;setHtml(content);<br>&nbsp;&nbsp;&nbsp; \
main_doc-&gt;setPageSize(center_size);<br><br>&nbsp;&nbsp;&nbsp; ///Setting \
up the rectangles for each section.<br>&nbsp;&nbsp;&nbsp; QRect headerRect \
= QRect(QPoint(0,0), document_header-&gt;size().toSize());<br> \
&nbsp;&nbsp;&nbsp; QRect footerRect = QRect(QPoint(0,0), \
document_footer-&gt;size().toSize());<br>&nbsp;&nbsp;&nbsp; QRect \
contentRect = QRect(QPoint(0,0), \
main_doc-&gt;size().toSize());&nbsp;&nbsp;&nbsp; /// Main content \
rectangle.<br>&nbsp;&nbsp;&nbsp; QRect currentRect = QRect(QPoint(0,0), \
center_size.toSize());&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /// Current \
main content rectangle.<br> <br>&nbsp;&nbsp;&nbsp; QPainter \
painter(printer);<br>&nbsp;&nbsp;&nbsp; int count = \
0;<br><br>&nbsp;&nbsp;&nbsp; while \
(currentRect.intersects(contentRect))<br>&nbsp;&nbsp;&nbsp; {///Loop if the \
current content rectangle intersects with the main content \
rectangle.<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ///Resetting the \
painter matrix co ordinate system.<br> &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; painter.resetMatrix();<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; ///Applying negative translation of painter co-ordinate \
system by current main content rectangle top y \
coordinate.<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; painter.translate(0, \
-currentRect.y());<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ///Applying \
positive translation of painter co-ordinate system by header hight.<br> \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; painter.translate(0, \
headerRect.height());<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ///Drawing \
the center content for current page.<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; main_doc-&gt;drawContents(&amp;painter, \
currentRect);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ///Resetting the \
painter matrix co ordinate system.<br> &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; painter.resetMatrix();<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; ///Drawing the header on the top of the \
page<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
document_header-&gt;drawContents(&amp;painter, \
headerRect);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ///Applying positive \
translation of painter co-ordinate system to draw the footer<br> \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; painter.translate(0, \
headerRect.height());<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
painter.translate(0, center_size.height());<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; document_footer-&gt;drawContents(&amp;painter, \
footerRect);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; ///Translating the current rectangle to the area to be \
printed for the next page<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
currentRect.translate(0, currentRect.height());<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; ///Inserting a new page if there is till area left to be \
printed<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if \
(currentRect.intersects(contentRect))<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; printer-&gt;newPage();<br> &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic