void MainWindow::preview(){
printer.
setOrientation(QPrinter::Portrait);
printer.
setPageMargins(10,
10,
10,
10,
QPrinter::Millimeter);
QPrintPreviewDialog print_preview(&printer, this);
print_preview.setWindowState(Qt::WindowMaximized);
connect(&print_preview,
SIGNAL(paintRequested
(QPrinter*)),
this,
SLOT(paint_pages
(QPrinter*)));
print_preview.exec();
}
void MainWindow
::paint_pages(QPrinter *printer
){ QList<QWebView*> pages;
QWebView *current = 0;
int i = 0;
while(i <= 100){
current = new QWebView();
pages << current;
i = populate_web(current, printer, i);
}
int pc = pages.count();
for(i = 0; i < pc; i++){
if(i != 0) printer->newPage();
pages.at(i)->render(&painter);
}
for(i = 0; i < pc; i++)
delete pages.at(i);
}
int MainWindow
::populate_web(QWebView
*pg,
QPrinter *printer,
int n
){ html += "<table cellspacing=0 border = 1 style='border-collapse: collapse'>";
int page_height
= printer
->paperRect
(QPrinter::Point).
height();
for(++n; n <= 100; n++){
html
+= QString("<tr><td width=200>%1</td><td width=200>%2</td><td width=300>%3</td></tr>").
arg(n
).
arg(n
*n
).
arg(n
*n
*n
);
QString html2
= html
+ "</table></body></html>";
pg->setHtml(html2);
int content_height = pg->page()->mainFrame()->contentsSize().height();
if(content_height + 20 > page_height){
html += "</table>";
html
+= QString("<p>Current value: %1</p>").
arg(n
);
break;
}
}
if(n > 100) html += "</table>";
html += "</body></html>";
pg->setHtml(html);
return n;
}
void MainWindow::preview(){
QPrinter printer;
printer.setPageSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
printer.setPageMargins(10,10,10,10,QPrinter::Millimeter);
QPrintPreviewDialog print_preview(&printer, this);
print_preview.setWindowState(Qt::WindowMaximized);
connect(&print_preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paint_pages(QPrinter*)));
print_preview.exec();
}
void MainWindow::paint_pages(QPrinter *printer){
QList<QWebView*> pages;
QWebView *current = 0;
QPainter painter(printer);
int i = 0;
while(i <= 100){
current = new QWebView();
pages << current;
i = populate_web(current, printer, i);
}
int pc = pages.count();
for(i = 0; i < pc; i++){
if(i != 0) printer->newPage();
pages.at(i)->render(&painter);
}
for(i = 0; i < pc; i++)
delete pages.at(i);
}
int MainWindow::populate_web(QWebView *pg, QPrinter *printer, int n){
QString html = "<html><body>";
html += "<table cellspacing=0 border = 1 style='border-collapse: collapse'>";
int page_height = printer->paperRect(QPrinter::Point).height();
for(++n; n <= 100; n++){
html += QString("<tr><td width=200>%1</td><td width=200>%2</td><td width=300>%3</td></tr>").arg(n).arg(n*n).arg(n*n*n);
QString html2 = html + "</table></body></html>";
pg->setHtml(html2);
int content_height = pg->page()->mainFrame()->contentsSize().height();
if(content_height + 20 > page_height){
html += "</table>";
html += QString("<p>Current value: %1</p>").arg(n);
break;
}
}
if(n > 100) html += "</table>";
html += "</body></html>";
pg->setHtml(html);
return n;
}
To copy to clipboard, switch view to plain text mode
Bookmarks