From c79def40b106fbefaa64b0a9f769b6bcb4b9efd5 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Thu, 3 Oct 2013 17:50:41 +0300 Subject: Print: small adjustments to table printing PrintLayout::printTable(): - hide the QTableView widget border using a stylesheet - add a guard to fix the last column extending post the page width due to rounding - use 1 extra pixel instead of 2 when grabbing the page region Signed-off-by: Lubomir I. Ivanov Signed-off-by: Dirk Hohndel --- qt-ui/printlayout.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index 4f741d64e..8224c916b 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -266,6 +266,11 @@ void PrintLayout::printTable() // fit table to one page initially table.resize(scaledPageW, scaledPageH); + // don't show border + table.setStyleSheet( + "QTableView { border: none }" + ); + // create and fill a table model TablePrintModel model; struct dive *dive; @@ -280,8 +285,14 @@ void PrintLayout::printTable() } table.setModel(&model); // set model to table // resize columns to percentages from page width + int accW = 0; + int cols = model.columns; + int tableW = table.width(); for (int i = 0; i < model.columns; i++) { - int pw = qCeil((qreal)(tablePrintColumnWidths.at(i) * table.width()) / 100); + 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; table.horizontalHeader()->resizeSection(i, pw); } // reset the model at this point @@ -318,7 +329,7 @@ void PrintLayout::printTable() printer->newPage(); QRegion region(0, pageIndexes.at(i) - 1, table.width(), - pageIndexes.at(i + 1) - pageIndexes.at(i) + 2); + pageIndexes.at(i + 1) - pageIndexes.at(i) + 1); table.render(&painter, QPoint(0, 0), region); } } -- cgit v1.2.3-70-g09d2