[PATCH 4/4] Print: small adjustments to table printing
Lubomir I. Ivanov
neolit123 at gmail.com
Thu Oct 3 07:50:41 UTC 2013
From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
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 <neolit123 at gmail.com>
---
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 4f741d6..8224c91 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);
}
}
--
1.7.11.msysgit.0
More information about the subsurface
mailing list