mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
8ea849d0c2
commit
b241b7c06a
2 changed files with 39 additions and 7 deletions
|
@ -47,6 +47,7 @@ void PrintDialog::printClicked(void)
|
||||||
// printer.setOutputFileName("print.pdf");
|
// printer.setOutputFileName("print.pdf");
|
||||||
// printer.setOutputFormat(QPrinter::PdfFormat);
|
// printer.setOutputFormat(QPrinter::PdfFormat);
|
||||||
// temporary: use a preview dialog
|
// temporary: use a preview dialog
|
||||||
|
printer.setResolution(300);
|
||||||
QPrintPreviewDialog previewDialog(&printer, this);
|
QPrintPreviewDialog previewDialog(&printer, this);
|
||||||
QObject::connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
|
QObject::connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
|
||||||
previewDialog.exec();
|
previewDialog.exec();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QAbstractTextDocumentLayout>
|
#include <QAbstractTextDocumentLayout>
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "profilegraphics.h"
|
||||||
#include "printlayout.h"
|
#include "printlayout.h"
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
#include "../display.h"
|
#include "../display.h"
|
||||||
|
@ -27,7 +28,6 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op
|
||||||
dialog = dialogPtr;
|
dialog = dialogPtr;
|
||||||
printer = printerPtr;
|
printer = printerPtr;
|
||||||
printOptions = optionsPtr;
|
printOptions = optionsPtr;
|
||||||
// painter = new QPainter(printer);
|
|
||||||
|
|
||||||
// table print settings
|
// table print settings
|
||||||
tableColumnNames.append(tr("Dive#"));
|
tableColumnNames.append(tr("Dive#"));
|
||||||
|
@ -50,11 +50,6 @@ void PrintLayout::print()
|
||||||
{
|
{
|
||||||
// we call setup each time to check if the printer properties have changed
|
// we call setup each time to check if the printer properties have changed
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
// temp / debug
|
|
||||||
printTable();
|
|
||||||
return;
|
|
||||||
// ------------
|
|
||||||
switch (printOptions->type) {
|
switch (printOptions->type) {
|
||||||
case options::PRETTY:
|
case options::PRETTY:
|
||||||
printSixDives();
|
printSixDives();
|
||||||
|
@ -81,9 +76,45 @@ void PrintLayout::setup()
|
||||||
scaleY = (qreal)printerDpi/(qreal)screenDpiY;
|
scaleY = (qreal)printerDpi/(qreal)screenDpiY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// experimental
|
||||||
void PrintLayout::printSixDives() const
|
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
|
void PrintLayout::printTwoDives() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue