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