Print: provide means for profile layouting

printlayout.cpp(h):

This patch cleans some test code and adds the function
printProfileDives() that accepts a number of dives
per rows and columns. It can technically fit any number
of dives on a page given the page size allows it. Both
landscape and portrait layouts are supported.

It now replaces the old methods:
printTwoDives()
printSixDives()

Space is reserved for data tables that will be placed
bellow profiles on a later stage.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2013-09-27 19:06:45 +03:00 committed by Dirk Hohndel
parent e81bbc1dab
commit df8107830e
2 changed files with 45 additions and 32 deletions

View file

@ -26,6 +26,7 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op
{ {
dialog = dialogPtr; dialog = dialogPtr;
printer = printerPtr; printer = printerPtr;
painter = NULL;
printOptions = optionsPtr; printOptions = optionsPtr;
// table print settings // table print settings
@ -52,10 +53,10 @@ void PrintLayout::print()
setup(); setup();
switch (printOptions->type) { switch (printOptions->type) {
case options::PRETTY: case options::PRETTY:
printSixDives(); printProfileDives(3, 2);
break; break;
case options::TWOPERPAGE: case options::TWOPERPAGE:
printTwoDives(); printProfileDives(2, 1);
break; break;
case options::TABLE: case options::TABLE:
printTable(); printTable();
@ -80,52 +81,65 @@ void PrintLayout::setup()
scaledPageH = pageRect.height() / scaleY; scaledPageH = pageRect.height() / scaleY;
} }
// experimental void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
void PrintLayout::printSixDives() const
{ {
ProfileGraphicsView *profile = mainWindow()->graphics(); // setup a painter
QPainter painter; painter = new QPainter();
painter.begin(printer); painter->begin(printer);
painter.setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
// painter.setRenderHint(QPainter::HighQualityAntialiasing); painter->setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::SmoothPixmapTransform); painter->scale(scaleX, scaleY);
painter.scale(scaleX, scaleY);
// setup the profile widget
ProfileGraphicsView *profile = mainWindow()->graphics();
profile->clear(); profile->clear();
profile->setPrintMode(true, !printOptions->color_selected); profile->setPrintMode(true, !printOptions->color_selected);
QSize originalSize = profile->size(); QSize originalSize = profile->size();
profile->resize(scaledPageW, scaledPageH); // swap rows/col for landscape
if (printer->orientation() == QPrinter::Landscape) {
int swap = divesPerColumn;
divesPerColumn = divesPerRow;
divesPerRow = swap;
}
// estimate profile and table height and resize the widget
const int scaledW = scaledPageW / divesPerColumn;
const int scaledH = scaledPageH / divesPerRow;
/* make the table 1/3 of the reserved height. potentially this could depend
* on orientation and other parameters as well. */
const int tableHeight = scaledH / 3;
profile->resize(scaledW, scaledH - tableHeight);
int i; // plot the dives at specific rows and columns
int i, row = 0, col = 0;
struct dive *dive; struct dive *dive;
bool firstPage = true;
for_each_dive(i, dive) { for_each_dive(i, dive) {
if (!dive->selected && printOptions->print_selected) if (!dive->selected && printOptions->print_selected)
continue; continue;
// don't create a new page if still on first page if (col == divesPerColumn) {
if (!firstPage) col = 0;
row++;
if (row == divesPerRow) {
row = 0;
printer->newPage(); printer->newPage();
else }
firstPage = false; }
profile->plot(dive, true); profile->plot(dive, true);
QPixmap pm = QPixmap::grabWidget(profile); QPixmap pm = QPixmap::grabWidget(profile);
QTransform transform; painter->drawPixmap(scaledW * col, scaledH * row, pm);
transform.rotate(270); /* TODO: table should be drawn here, preferably by another function */
pm = QPixmap(pm.transformed(transform)); col++;
painter.drawPixmap(0, 0, pm);
} }
painter.end();
// cleanup
painter->end();
delete painter;
painter = NULL;
profile->setPrintMode(false); profile->setPrintMode(false);
profile->resize(originalSize); profile->resize(originalSize);
profile->clear(); profile->clear();
profile->plot(current_dive, true); profile->plot(current_dive, true);
} }
void PrintLayout::printTwoDives() const
{
// nop
}
void PrintLayout::printTable() void PrintLayout::printTable()
{ {
// create and setup a table // create and setup a table

View file

@ -19,9 +19,9 @@ public:
private: private:
PrintDialog *dialog; PrintDialog *dialog;
QPrinter *printer; QPrinter *printer;
QPainter *painter;
struct options *printOptions; struct options *printOptions;
QPainter *painter;
int screenDpiX, screenDpiY, printerDpi, scaledPageW, scaledPageH; int screenDpiX, screenDpiY, printerDpi, scaledPageW, scaledPageH;
qreal scaleX, scaleY; qreal scaleX, scaleY;
QRect pageRect; QRect pageRect;
@ -31,8 +31,7 @@ private:
unsigned int tablePrintHeadingBackground; unsigned int tablePrintHeadingBackground;
void setup(); void setup();
void printSixDives() const; void printProfileDives(int divesPerRow, int divesPerColumn);
void printTwoDives() const;
void printTable(); void printTable();
void addTablePrintDataRow(TablePrintModel *model, int row, struct dive *dive) const; void addTablePrintDataRow(TablePrintModel *model, int row, struct dive *dive) const;
void addTablePrintHeadingRow(TablePrintModel *model, int row) const; void addTablePrintHeadingRow(TablePrintModel *model, int row) const;