mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:13:25 +00:00
Printing: refactoring printer class
- Render specific number of pages only. - Move printer related code to print(). Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
51e36fa158
commit
4e1a5d954b
2 changed files with 20 additions and 21 deletions
39
printer.cpp
39
printer.cpp
|
@ -31,25 +31,8 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
|
|||
profile->render(painter, pos);
|
||||
}
|
||||
|
||||
void Printer::render()
|
||||
void Printer::render(int Pages = 0)
|
||||
{
|
||||
// apply user settings
|
||||
int divesPerPage;
|
||||
if (printOptions->color_selected && printer->colorMode()) {
|
||||
printer->setColorMode(QPrinter::Color);
|
||||
} else {
|
||||
printer->setColorMode(QPrinter::GrayScale);
|
||||
}
|
||||
|
||||
// get number of dives per page from data-numberofdives attribute in the body of the selected template
|
||||
bool ok;
|
||||
divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
|
||||
if (!ok) {
|
||||
divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed
|
||||
//TODO: show warning
|
||||
}
|
||||
int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage);
|
||||
|
||||
// keep original preferences
|
||||
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
|
||||
int profileFrameStyle = profile->frameStyle();
|
||||
|
@ -59,7 +42,7 @@ void Printer::render()
|
|||
// apply printing settings to profile
|
||||
profile->setFrameStyle(QFrame::NoFrame);
|
||||
profile->setPrintMode(true, !printOptions->color_selected);
|
||||
profile->setFontPrintScale(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi * 0.001);
|
||||
profile->setFontPrintScale(pageSize.width() * 0.001);
|
||||
profile->setToolTipVisibile(false);
|
||||
prefs.animation_speed = 0;
|
||||
|
||||
|
@ -132,5 +115,21 @@ void Printer::print()
|
|||
pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
|
||||
webView->page()->setViewportSize(pageSize);
|
||||
webView->setHtml(t.generate());
|
||||
render();
|
||||
if (printOptions->color_selected && printer->colorMode()) {
|
||||
printer->setColorMode(QPrinter::Color);
|
||||
} else {
|
||||
printer->setColorMode(QPrinter::GrayScale);
|
||||
}
|
||||
// apply user settings
|
||||
int divesPerPage;
|
||||
|
||||
// get number of dives per page from data-numberofdives attribute in the body of the selected template
|
||||
bool ok;
|
||||
divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
|
||||
if (!ok) {
|
||||
divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed
|
||||
//TODO: show warning
|
||||
}
|
||||
int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage);
|
||||
render(Pages);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ private:
|
|||
QSize pageSize;
|
||||
int done;
|
||||
int dpi;
|
||||
void render();
|
||||
void render(int Pages);
|
||||
void putProfileImage(QRect box, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile);
|
||||
|
||||
private slots:
|
||||
|
|
Loading…
Add table
Reference in a new issue