2013-07-25 09:52:20 +00:00
|
|
|
#include <QtCore/qmath.h>
|
2013-07-10 16:32:15 +00:00
|
|
|
#include <QDebug>
|
2013-07-10 12:34:57 +00:00
|
|
|
#include <QPainter>
|
2013-07-10 13:04:00 +00:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QApplication>
|
2013-07-25 09:52:20 +00:00
|
|
|
#include <QTableView>
|
|
|
|
#include <QHeaderView>
|
2014-03-07 18:02:37 +00:00
|
|
|
#include <QPointer>
|
2013-07-10 12:34:57 +00:00
|
|
|
#include "mainwindow.h"
|
2013-07-10 19:55:40 +00:00
|
|
|
#include "../dive.h"
|
2013-07-10 21:45:29 +00:00
|
|
|
#include "../display.h"
|
2013-12-04 13:44:31 +00:00
|
|
|
#include "printdialog.h"
|
|
|
|
#include "printlayout.h"
|
2013-07-11 09:45:41 +00:00
|
|
|
#include "models.h"
|
2013-10-03 14:50:40 +00:00
|
|
|
#include "modeldelegates.h"
|
2013-07-10 12:34:57 +00:00
|
|
|
|
|
|
|
PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct options *optionsPtr)
|
|
|
|
{
|
|
|
|
dialog = dialogPtr;
|
|
|
|
printer = printerPtr;
|
|
|
|
printOptions = optionsPtr;
|
2013-07-10 21:48:38 +00:00
|
|
|
|
|
|
|
// table print settings
|
2013-07-25 09:52:20 +00:00
|
|
|
tablePrintHeadingBackground = 0xffeeeeee;
|
|
|
|
tablePrintColumnNames.append(tr("Dive#"));
|
|
|
|
tablePrintColumnNames.append(tr("Date"));
|
|
|
|
tablePrintColumnNames.append(tr("Depth"));
|
|
|
|
tablePrintColumnNames.append(tr("Duration"));
|
|
|
|
tablePrintColumnNames.append(tr("Master"));
|
|
|
|
tablePrintColumnNames.append(tr("Buddy"));
|
|
|
|
tablePrintColumnNames.append(tr("Location"));
|
|
|
|
tablePrintColumnWidths.append(7);
|
|
|
|
tablePrintColumnWidths.append(10);
|
|
|
|
tablePrintColumnWidths.append(10);
|
|
|
|
tablePrintColumnWidths.append(10);
|
|
|
|
tablePrintColumnWidths.append(15);
|
|
|
|
tablePrintColumnWidths.append(15);
|
|
|
|
tablePrintColumnWidths.append(33);
|
2013-10-03 14:50:40 +00:00
|
|
|
// profile print settings
|
2013-11-30 12:38:54 +00:00
|
|
|
const int dw = 20; // base percentage
|
2013-10-03 14:50:40 +00:00
|
|
|
profilePrintColumnWidths.append(dw);
|
|
|
|
profilePrintColumnWidths.append(dw);
|
2013-11-30 13:50:47 +00:00
|
|
|
profilePrintColumnWidths.append(dw - 3);
|
|
|
|
profilePrintColumnWidths.append(dw - 3);
|
|
|
|
profilePrintColumnWidths.append(dw + 6); // fit to 100%
|
2014-02-28 04:09:57 +00:00
|
|
|
const int sr = 12; // smallest row height in pixels
|
2013-11-30 15:37:27 +00:00
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr + 4);
|
2013-10-03 14:50:40 +00:00
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
2013-11-30 12:38:54 +00:00
|
|
|
profilePrintRowHeights.append(sr);
|
|
|
|
profilePrintRowHeights.append(sr);
|
2013-07-10 12:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintLayout::print()
|
|
|
|
{
|
2013-07-10 13:04:00 +00:00
|
|
|
// we call setup each time to check if the printer properties have changed
|
|
|
|
setup();
|
2013-07-10 12:34:57 +00:00
|
|
|
switch (printOptions->type) {
|
|
|
|
case options::PRETTY:
|
2013-09-27 16:06:45 +00:00
|
|
|
printProfileDives(3, 2);
|
2013-07-10 12:34:57 +00:00
|
|
|
break;
|
|
|
|
case options::TWOPERPAGE:
|
2013-09-27 16:06:45 +00:00
|
|
|
printProfileDives(2, 1);
|
2013-07-10 12:34:57 +00:00
|
|
|
break;
|
|
|
|
case options::TABLE:
|
|
|
|
printTable();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 13:04:00 +00:00
|
|
|
void PrintLayout::setup()
|
|
|
|
{
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
screenDpiX = desktop->physicalDpiX();
|
2013-07-16 15:48:37 +00:00
|
|
|
screenDpiY = desktop->physicalDpiY();
|
2013-07-10 13:04:00 +00:00
|
|
|
|
|
|
|
printerDpi = printer->resolution();
|
|
|
|
pageRect = printer->pageRect();
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
scaleX = (qreal)printerDpi / (qreal)screenDpiX;
|
|
|
|
scaleY = (qreal)printerDpi / (qreal)screenDpiY;
|
2013-07-25 09:52:20 +00:00
|
|
|
|
|
|
|
// a printer page scalled to screen DPI
|
|
|
|
scaledPageW = pageRect.width() / scaleX;
|
|
|
|
scaledPageH = pageRect.height() / scaleY;
|
2013-07-10 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 13:13:40 +00:00
|
|
|
// go trought the dive table and find how many dives we are a going to print
|
2013-12-04 23:48:38 +00:00
|
|
|
int PrintLayout::estimateTotalDives() const
|
2013-12-04 13:13:40 +00:00
|
|
|
{
|
2013-12-04 23:48:38 +00:00
|
|
|
int total = 0, i = 0;
|
|
|
|
struct dive *dive;
|
|
|
|
for_each_dive(i, dive) {
|
2013-12-04 13:13:40 +00:00
|
|
|
if (!dive->selected && printOptions->print_selected)
|
|
|
|
continue;
|
2013-12-04 23:48:38 +00:00
|
|
|
total++;
|
2013-12-04 13:13:40 +00:00
|
|
|
}
|
2013-12-04 23:48:38 +00:00
|
|
|
return total;
|
2013-12-04 13:13:40 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 14:50:40 +00:00
|
|
|
/* the used formula here is:
|
|
|
|
* s = (S - (n - 1) * p) / n
|
|
|
|
* where:
|
|
|
|
* s is the length of a single element (unknown)
|
|
|
|
* S is the total available length
|
|
|
|
* n is the number of elements to fit
|
|
|
|
* p is the padding between elements
|
|
|
|
*/
|
|
|
|
#define ESTIMATE_DIVE_DIM(S, n, p) \
|
2014-03-05 20:19:45 +00:00
|
|
|
((S) - ((n) - 1) * (p)) / (n);
|
2013-10-03 14:50:40 +00:00
|
|
|
|
2013-09-27 16:06:45 +00:00
|
|
|
void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
|
2013-07-10 12:34:57 +00:00
|
|
|
{
|
2013-12-04 23:48:38 +00:00
|
|
|
int i, row = 0, col = 0, printed = 0, total = estimateTotalDives();
|
2013-12-04 13:16:20 +00:00
|
|
|
struct dive *dive;
|
|
|
|
if (!total)
|
|
|
|
return;
|
|
|
|
|
2013-09-27 16:06:45 +00:00
|
|
|
// setup a painter
|
2013-10-03 14:50:40 +00:00
|
|
|
QPainter painter;
|
|
|
|
painter.begin(printer);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
painter.scale(scaleX, scaleY);
|
2013-07-12 16:23:47 +00:00
|
|
|
|
2013-09-27 16:06:45 +00:00
|
|
|
// setup the profile widget
|
2014-03-07 15:42:13 +00:00
|
|
|
ProfileWidget2 profile;
|
|
|
|
profile.setFrameStyle(QFrame::NoFrame);
|
|
|
|
// profile->setPrintMode(true, !printOptions->color_selected);
|
2013-09-27 16:06:45 +00:00
|
|
|
// swap rows/col for landscape
|
|
|
|
if (printer->orientation() == QPrinter::Landscape) {
|
|
|
|
int swap = divesPerColumn;
|
|
|
|
divesPerColumn = divesPerRow;
|
|
|
|
divesPerRow = swap;
|
|
|
|
}
|
2014-03-07 15:42:13 +00:00
|
|
|
|
2013-10-03 14:50:40 +00:00
|
|
|
// padding in pixels between two dives. no padding if only one dive per page.
|
|
|
|
const int padDef = 20;
|
|
|
|
const int padW = (divesPerColumn < 2) ? 0 : padDef;
|
|
|
|
const int padH = (divesPerRow < 2) ? 0 : padDef;
|
|
|
|
// estimate dimensions for a single dive
|
|
|
|
const int scaledW = ESTIMATE_DIVE_DIM(scaledPageW, divesPerColumn, padW);
|
|
|
|
const int scaledH = ESTIMATE_DIVE_DIM(scaledPageH, divesPerRow, padH);
|
|
|
|
// padding in pixels between profile and table
|
2013-10-15 09:54:17 +00:00
|
|
|
const int padPT = 5;
|
2013-10-03 14:50:40 +00:00
|
|
|
// create a model and table
|
|
|
|
ProfilePrintModel model;
|
2014-03-07 15:42:13 +00:00
|
|
|
QPointer<QTableView> table(createProfileTable(&model, scaledW));
|
2013-10-03 14:50:40 +00:00
|
|
|
// profilePrintTableMaxH updates after the table is created
|
|
|
|
const int tableH = profilePrintTableMaxH;
|
|
|
|
// resize the profile widget
|
2014-03-07 15:42:13 +00:00
|
|
|
profile.resize(scaledW, scaledH - tableH - padPT);
|
2013-10-05 10:31:08 +00:00
|
|
|
// offset table or profile on top
|
|
|
|
int yOffsetProfile = 0, yOffsetTable = 0;
|
|
|
|
if (printOptions->notes_up)
|
|
|
|
yOffsetProfile = tableH + padPT;
|
|
|
|
else
|
|
|
|
yOffsetTable = scaledH - tableH;
|
2013-10-03 14:50:40 +00:00
|
|
|
|
|
|
|
// plot the dives at specific rows and columns on the page
|
2013-07-12 16:23:47 +00:00
|
|
|
for_each_dive(i, dive) {
|
|
|
|
if (!dive->selected && printOptions->print_selected)
|
|
|
|
continue;
|
2013-09-27 16:06:45 +00:00
|
|
|
if (col == divesPerColumn) {
|
|
|
|
col = 0;
|
|
|
|
row++;
|
|
|
|
if (row == divesPerRow) {
|
|
|
|
row = 0;
|
|
|
|
printer->newPage();
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 08:39:15 +00:00
|
|
|
QTransform origTransform = painter.transform();
|
|
|
|
|
2013-10-03 14:50:40 +00:00
|
|
|
// draw a profile
|
2013-10-16 08:39:15 +00:00
|
|
|
painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetProfile);
|
2014-03-07 15:42:13 +00:00
|
|
|
profile.plotDives( QList<struct dive*>() << dive);
|
|
|
|
profile.render(&painter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
|
2013-10-16 08:39:15 +00:00
|
|
|
painter.setTransform(origTransform);
|
|
|
|
|
2013-10-03 14:50:40 +00:00
|
|
|
// draw a table
|
2013-10-16 08:39:15 +00:00
|
|
|
painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetTable);
|
2013-10-03 14:50:40 +00:00
|
|
|
model.setDive(dive);
|
2013-10-16 08:39:15 +00:00
|
|
|
table->render(&painter);
|
|
|
|
painter.setTransform(origTransform);
|
2013-09-27 16:06:45 +00:00
|
|
|
col++;
|
2013-12-04 13:16:20 +00:00
|
|
|
printed++;
|
|
|
|
emit signalProgress((printed * 100) / total);
|
2013-07-12 16:23:47 +00:00
|
|
|
}
|
2013-07-10 12:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 14:50:40 +00:00
|
|
|
/* we create a table that has a fixed height, but can stretch to fit certain width */
|
|
|
|
QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int tableW)
|
|
|
|
{
|
|
|
|
// setup a new table
|
|
|
|
QTableView *table = new QTableView();
|
|
|
|
QHeaderView *vHeader = table->verticalHeader();
|
|
|
|
QHeaderView *hHeader = table->horizontalHeader();
|
|
|
|
table->setAttribute(Qt::WA_DontShowOnScreen);
|
|
|
|
table->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
table->setFocusPolicy(Qt::NoFocus);
|
|
|
|
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
hHeader->setVisible(false);
|
|
|
|
vHeader->setVisible(false);
|
2014-02-28 04:09:57 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
2014-01-15 08:30:37 +00:00
|
|
|
hHeader->setResizeMode(QHeaderView::Fixed);
|
2013-10-03 14:50:40 +00:00
|
|
|
vHeader->setResizeMode(QHeaderView::Fixed);
|
2014-01-15 08:30:37 +00:00
|
|
|
#else
|
|
|
|
hHeader->setSectionResizeMode(QHeaderView::Fixed);
|
|
|
|
vHeader->setSectionResizeMode(QHeaderView::Fixed);
|
|
|
|
#endif
|
2013-10-03 14:50:40 +00:00
|
|
|
// set the model
|
|
|
|
table->setModel(model);
|
|
|
|
|
|
|
|
/* setup cell span for the table using QTableView::setSpan().
|
|
|
|
* changes made here reflect on ProfilePrintModel::data(). */
|
|
|
|
const int cols = model->columnCount();
|
|
|
|
const int rows = model->rowCount();
|
2013-11-30 12:38:54 +00:00
|
|
|
// info on top
|
|
|
|
table->setSpan(0, 0, 1, 4);
|
|
|
|
table->setSpan(1, 0, 1, 4);
|
|
|
|
// gas used
|
|
|
|
table->setSpan(2, 0, 1, 2);
|
|
|
|
table->setSpan(3, 0, 1, 2);
|
|
|
|
// notes
|
|
|
|
table->setSpan(6, 0, 1, 5);
|
|
|
|
table->setSpan(7, 0, 5, 5);
|
2013-10-03 14:50:40 +00:00
|
|
|
|
|
|
|
/* resize row heights to the 'profilePrintRowHeights' indexes.
|
|
|
|
* profilePrintTableMaxH will then hold the table height. */
|
|
|
|
int i;
|
|
|
|
profilePrintTableMaxH = 0;
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
int h = profilePrintRowHeights.at(i);
|
|
|
|
profilePrintTableMaxH += h;
|
|
|
|
vHeader->resizeSection(i, h);
|
|
|
|
}
|
|
|
|
// resize columns. columns widths are percentages from the table width.
|
|
|
|
int accW = 0;
|
|
|
|
for (i = 0; i < cols; i++) {
|
|
|
|
int pw = qCeil((qreal)(profilePrintColumnWidths.at(i) * tableW) / 100.0);
|
|
|
|
accW += pw;
|
|
|
|
if (i == cols - 1 && accW > tableW) /* adjust last column */
|
|
|
|
pw -= accW - tableW;
|
|
|
|
hHeader->resizeSection(i, pw);
|
|
|
|
}
|
|
|
|
// resize
|
|
|
|
table->resize(tableW, profilePrintTableMaxH);
|
|
|
|
// hide the grid and set a stylesheet
|
2014-01-15 17:52:42 +00:00
|
|
|
table->setItemDelegate(new ProfilePrintDelegate(this));
|
2013-10-03 14:50:40 +00:00
|
|
|
table->setShowGrid(false);
|
|
|
|
table->setStyleSheet(
|
|
|
|
"QTableView { border: none }"
|
2014-02-28 04:09:57 +00:00
|
|
|
"QTableView::item { border: 0px; padding-left: 2px; padding-right: 2px; }");
|
2013-10-03 14:50:40 +00:00
|
|
|
// return
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2013-07-25 09:52:20 +00:00
|
|
|
void PrintLayout::printTable()
|
2013-07-10 12:34:57 +00:00
|
|
|
{
|
2013-12-04 13:18:56 +00:00
|
|
|
struct dive *dive;
|
2013-12-06 16:24:28 +00:00
|
|
|
int done = 0; // percents done
|
2013-12-04 23:48:38 +00:00
|
|
|
int i, row = 0, progress, total = estimateTotalDives();
|
2013-12-04 13:18:56 +00:00
|
|
|
if (!total)
|
|
|
|
return;
|
|
|
|
|
2013-07-25 09:52:20 +00:00
|
|
|
// create and setup a table
|
|
|
|
QTableView table;
|
|
|
|
table.setAttribute(Qt::WA_DontShowOnScreen);
|
|
|
|
table.setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
table.setFocusPolicy(Qt::NoFocus);
|
|
|
|
table.horizontalHeader()->setVisible(false);
|
|
|
|
table.verticalHeader()->setVisible(false);
|
2014-02-28 04:09:57 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
2014-01-15 08:30:37 +00:00
|
|
|
table.horizontalHeader()->setResizeMode(QHeaderView::Fixed);
|
2013-07-25 09:52:20 +00:00
|
|
|
table.verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
2014-01-15 08:30:37 +00:00
|
|
|
#else
|
|
|
|
table.horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
|
|
|
table.verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
#endif
|
2013-07-25 09:52:20 +00:00
|
|
|
table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
// fit table to one page initially
|
2014-02-28 04:09:57 +00:00
|
|
|
table.resize(scaledPageW, scaledPageH);
|
2013-07-25 09:52:20 +00:00
|
|
|
|
2013-10-03 14:50:41 +00:00
|
|
|
// don't show border
|
|
|
|
table.setStyleSheet(
|
2014-02-28 04:09:57 +00:00
|
|
|
"QTableView { border: none }");
|
2013-10-03 14:50:41 +00:00
|
|
|
|
2013-07-25 09:52:20 +00:00
|
|
|
// create and fill a table model
|
|
|
|
TablePrintModel model;
|
|
|
|
addTablePrintHeadingRow(&model, row); // add one heading row
|
|
|
|
row++;
|
2013-12-04 13:18:56 +00:00
|
|
|
progress = 0;
|
2013-07-10 19:55:40 +00:00
|
|
|
for_each_dive(i, dive) {
|
2013-07-10 20:03:01 +00:00
|
|
|
if (!dive->selected && printOptions->print_selected)
|
2013-07-10 19:55:40 +00:00
|
|
|
continue;
|
2013-07-25 09:52:20 +00:00
|
|
|
addTablePrintDataRow(&model, row, dive);
|
|
|
|
row++;
|
2013-12-04 13:18:56 +00:00
|
|
|
progress++;
|
2013-12-06 16:24:28 +00:00
|
|
|
emit signalProgress((progress * 10) / total);
|
2013-07-25 09:52:20 +00:00
|
|
|
}
|
2013-12-06 16:24:28 +00:00
|
|
|
done = 10;
|
2013-07-25 09:52:20 +00:00
|
|
|
table.setModel(&model); // set model to table
|
|
|
|
// resize columns to percentages from page width
|
2013-10-03 14:50:41 +00:00
|
|
|
int accW = 0;
|
|
|
|
int cols = model.columns;
|
|
|
|
int tableW = table.width();
|
2014-02-12 21:24:40 +00:00
|
|
|
for (i = 0; i < model.columns; i++) {
|
2013-10-03 14:50:41 +00:00
|
|
|
int pw = qCeil((qreal)(tablePrintColumnWidths.at(i) * table.width()) / 100.0);
|
|
|
|
accW += pw;
|
|
|
|
if (i == cols - 1 && accW > tableW) /* adjust last column */
|
|
|
|
pw -= accW - tableW;
|
2013-07-25 09:52:20 +00:00
|
|
|
table.horizontalHeader()->resizeSection(i, pw);
|
|
|
|
}
|
|
|
|
// reset the model at this point
|
|
|
|
model.callReset();
|
|
|
|
|
|
|
|
// a list of vertical offsets where pages begin and some helpers
|
|
|
|
QList<unsigned int> pageIndexes;
|
|
|
|
pageIndexes.append(0);
|
|
|
|
|
2013-12-06 16:24:28 +00:00
|
|
|
/* the algorithm bellow processes the table rows in multiple passes,
|
|
|
|
* compensating for loss of space due to moving rows on a new page instead
|
|
|
|
* of truncating them.
|
|
|
|
* there is a 'passes' array defining how much percents of the total
|
|
|
|
* progress each will take. given, the first and last stage of this function
|
|
|
|
* use 10% each, then the sum of passes[] here should be 80%.
|
|
|
|
* two should be enough! */
|
|
|
|
const int passes[] = { 70, 10 };
|
|
|
|
int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings;
|
|
|
|
bool isHeading = false;
|
|
|
|
|
2013-12-07 22:54:16 +00:00
|
|
|
for (unsigned int pass = 0; pass < sizeof(passes) / sizeof(passes[0]); pass++) {
|
2013-12-06 16:24:28 +00:00
|
|
|
progress = headings = accH = 0;
|
|
|
|
total = model.rows - lastAccIndex;
|
2014-02-12 21:24:40 +00:00
|
|
|
for (i = lastAccIndex; i < model.rows; i++) {
|
2013-12-06 16:24:28 +00:00
|
|
|
rowH = table.rowHeight(i);
|
|
|
|
accH += rowH;
|
|
|
|
if (isHeading) {
|
|
|
|
headings += rowH;
|
|
|
|
isHeading = false;
|
|
|
|
}
|
|
|
|
if (accH > scaledPageH) {
|
|
|
|
lastAccIndex = i;
|
|
|
|
pageIndexes.append(pageIndexes.last() + (accH - rowH));
|
|
|
|
addTablePrintHeadingRow(&model, i);
|
|
|
|
isHeading = true;
|
|
|
|
accH = 0;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
tableHeight += table.rowHeight(i);
|
|
|
|
progress++;
|
|
|
|
emit signalProgress(done + (progress * passes[pass]) / total);
|
2013-07-10 16:32:15 +00:00
|
|
|
}
|
2013-12-06 16:24:28 +00:00
|
|
|
done += passes[pass];
|
2013-07-10 16:32:15 +00:00
|
|
|
}
|
2013-12-06 16:24:28 +00:00
|
|
|
done = 90;
|
2013-12-05 12:08:33 +00:00
|
|
|
pageIndexes.append(pageIndexes.last() + accH + headings);
|
2013-07-25 09:52:20 +00:00
|
|
|
table.resize(scaledPageW, tableHeight);
|
2013-07-10 16:32:15 +00:00
|
|
|
|
2013-07-25 09:52:20 +00:00
|
|
|
// attach a painter and render pages by using pageIndexes
|
|
|
|
QPainter painter(printer);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
painter.scale(scaleX, scaleY);
|
2013-12-04 13:18:56 +00:00
|
|
|
total = pageIndexes.size() - 1;
|
|
|
|
progress = 0;
|
2014-02-12 21:24:40 +00:00
|
|
|
for (i = 0; i < total; i++) {
|
2013-07-25 09:52:20 +00:00
|
|
|
if (i > 0)
|
|
|
|
printer->newPage();
|
|
|
|
QRegion region(0, pageIndexes.at(i) - 1,
|
2013-10-15 11:37:31 +00:00
|
|
|
table.width(),
|
|
|
|
pageIndexes.at(i + 1) - pageIndexes.at(i) + 1);
|
2013-07-25 09:52:20 +00:00
|
|
|
table.render(&painter, QPoint(0, 0), region);
|
2013-12-04 13:18:56 +00:00
|
|
|
progress++;
|
2013-12-06 16:24:28 +00:00
|
|
|
emit signalProgress(done + (progress * 10) / total);
|
2013-07-25 09:52:20 +00:00
|
|
|
}
|
2013-07-10 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 09:52:20 +00:00
|
|
|
void PrintLayout::addTablePrintDataRow(TablePrintModel *model, int row, struct dive *dive) const
|
2013-07-10 16:32:15 +00:00
|
|
|
{
|
2013-07-11 09:45:41 +00:00
|
|
|
struct DiveItem di;
|
2014-01-07 03:57:20 +00:00
|
|
|
di.diveId = dive->id;
|
2013-07-25 09:52:20 +00:00
|
|
|
model->insertRow();
|
|
|
|
model->setData(model->index(row, 0), QString::number(dive->number), Qt::DisplayRole);
|
|
|
|
model->setData(model->index(row, 1), di.displayDate(), Qt::DisplayRole);
|
|
|
|
model->setData(model->index(row, 2), di.displayDepth(), Qt::DisplayRole);
|
|
|
|
model->setData(model->index(row, 3), di.displayDuration(), Qt::DisplayRole);
|
|
|
|
model->setData(model->index(row, 4), dive->divemaster, Qt::DisplayRole);
|
|
|
|
model->setData(model->index(row, 5), dive->buddy, Qt::DisplayRole);
|
|
|
|
model->setData(model->index(row, 6), dive->location, Qt::DisplayRole);
|
2013-07-10 21:48:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 09:52:20 +00:00
|
|
|
void PrintLayout::addTablePrintHeadingRow(TablePrintModel *model, int row) const
|
2013-07-10 21:48:38 +00:00
|
|
|
{
|
2013-07-25 09:52:20 +00:00
|
|
|
model->insertRow(row);
|
|
|
|
for (int i = 0; i < model->columns; i++) {
|
|
|
|
model->setData(model->index(row, i), tablePrintColumnNames.at(i), Qt::DisplayRole);
|
|
|
|
model->setData(model->index(row, i), tablePrintHeadingBackground, Qt::BackgroundRole);
|
|
|
|
}
|
2013-07-10 12:34:57 +00:00
|
|
|
}
|