diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2013-07-12 19:23:47 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-07-18 12:00:12 -0700 |
commit | b241b7c06a970578152154313c9c10627882c292 (patch) | |
tree | f0b35d8da5e758314c8f02534a4ca804c090fc4f | |
parent | 8ea849d0c29de3af33ca7a2354eeb30a34afe1f4 (diff) | |
download | subsurface-b241b7c06a970578152154313c9c10627882c292.tar.gz |
Print: add experimental code for printing profiles
PrintLayout::printSixDives() goes trough all dives
and prints their profiles on full portrait pages.
This method is based on resizing the ProfileGraphicsView
widget, plotting each dive and then 'grabbing' it using
QPixmap::grabWidget().
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
-rw-r--r-- | qt-ui/printdialog.cpp | 1 | ||||
-rw-r--r-- | qt-ui/printlayout.cpp | 45 |
2 files changed, 39 insertions, 7 deletions
diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 542590707..f4bf16d05 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -47,6 +47,7 @@ void PrintDialog::printClicked(void) // printer.setOutputFileName("print.pdf"); // printer.setOutputFormat(QPrinter::PdfFormat); // temporary: use a preview dialog + printer.setResolution(300); QPrintPreviewDialog previewDialog(&printer, this); QObject::connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *))); previewDialog.exec(); diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index 471b8f847..935a4cc91 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -5,6 +5,7 @@ #include <QTextDocument> #include <QAbstractTextDocumentLayout> #include "mainwindow.h" +#include "profilegraphics.h" #include "printlayout.h" #include "../dive.h" #include "../display.h" @@ -27,7 +28,6 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op dialog = dialogPtr; printer = printerPtr; printOptions = optionsPtr; - // painter = new QPainter(printer); // table print settings tableColumnNames.append(tr("Dive#")); @@ -50,11 +50,6 @@ void PrintLayout::print() { // we call setup each time to check if the printer properties have changed setup(); - - // temp / debug - printTable(); - return; - // ------------ switch (printOptions->type) { case options::PRETTY: printSixDives(); @@ -81,9 +76,45 @@ void PrintLayout::setup() scaleY = (qreal)printerDpi/(qreal)screenDpiY; } +// experimental void PrintLayout::printSixDives() const { - // nop + ProfileGraphicsView *profile = mainWindow()->graphics(); + QPainter painter; + painter.begin(printer); + painter.setRenderHint(QPainter::Antialiasing); + // painter.setRenderHint(QPainter::HighQualityAntialiasing); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.scale(scaleX, scaleY); + + profile->clear(); + profile->setPrintMode(true); + QSize originalSize = profile->size(); + profile->resize(pageRect.height()/scaleY, pageRect.width()/scaleX); + + int i; + struct dive *dive; + bool firstPage = true; + for_each_dive(i, dive) { + if (!dive->selected && printOptions->print_selected) + continue; + // don't create a new page if still on first page + if (!firstPage) + printer->newPage(); + else + firstPage = false; + profile->plot(dive, true); + QPixmap pm = QPixmap::grabWidget(profile); + QTransform transform; + transform.rotate(270); + pm = QPixmap(pm.transformed(transform)); + painter.drawPixmap(0, 0, pm); + } + painter.end(); + profile->setPrintMode(false); + profile->resize(originalSize); + profile->clear(); + profile->plot(current_dive, true); } void PrintLayout::printTwoDives() const |