mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
PrintLayout: fix a potential bug in the recent table print update
There is a weird QPicture dependency; we need to offset a page by headingRowHeightD2, which is half the heading height. The same doesn't make sense if we are rendering the table widget directly to the printer-painter. Moving the offset inside 'pageIndexes' is less desirable. The bug itself manifests when a top margin is set on Win32, while on Linux it's more obvious. On new page start, a fixed height from the last dive on the previous page becomes visible even if the math seems correct. Offsetting both the page index and the vertical position at which the QPicture is placed fixes that. If 'table.render(&painter...)' is used the bug also goes away and our 'pageIndexes' start to make sense again, but we want to use QPicture so that the table is in vector. I don't have a good explanation why this happens! Tested on Ubuntu 12.04 and Win7. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ce42e32bce
commit
050b1b71ff
1 changed files with 10 additions and 9 deletions
|
@ -375,9 +375,8 @@ void PrintLayout::printTable()
|
|||
* 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;
|
||||
int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings, headingRowHeightD2;
|
||||
bool isHeading = false;
|
||||
int headingRowH;
|
||||
|
||||
for (unsigned int pass = 0; pass < sizeof(passes) / sizeof(passes[0]); pass++) {
|
||||
progress = headings = accH = 0;
|
||||
|
@ -386,7 +385,7 @@ void PrintLayout::printTable()
|
|||
rowH = table.rowHeight(i);
|
||||
accH += rowH;
|
||||
if (isHeading) {
|
||||
headingRowH = rowH;
|
||||
headingRowHeightD2 = rowH >> 1;
|
||||
headings += rowH;
|
||||
isHeading = false;
|
||||
}
|
||||
|
@ -408,7 +407,10 @@ void PrintLayout::printTable()
|
|||
pageIndexes.append(pageIndexes.last() + accH + headings);
|
||||
table.resize(pageW, tableHeight);
|
||||
|
||||
// attach a painter and render pages by using pageIndexes
|
||||
/* attach a painter and render pages by using pageIndexes
|
||||
* there is a weird QPicture dependency here; we need to offset a page
|
||||
* by headingRowHeightD2, which is half the heading height. the same doesn't
|
||||
* make sense if we are rendering the table widget directly to the printer-painter. */
|
||||
QPainter painter(printer);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
@ -417,17 +419,16 @@ void PrintLayout::printTable()
|
|||
for (i = 0; i < total; i++) {
|
||||
if (i > 0)
|
||||
printer->newPage();
|
||||
QRegion region(0, pageIndexes.at(i) - 1,
|
||||
table.width(),
|
||||
pageIndexes.at(i + 1) - pageIndexes.at(i) + 1);
|
||||
QRegion region(0, pageIndexes.at(i) + headingRowHeightD2 - 1,
|
||||
table.width(),
|
||||
pageIndexes.at(i + 1) - (pageIndexes.at(i) + headingRowHeightD2) + 1);
|
||||
// vectorize the table first by using QPicture
|
||||
QPicture pic;
|
||||
QPainter picPainter;
|
||||
picPainter.begin(&pic);
|
||||
table.render(&picPainter, QPoint(0, 0), region);
|
||||
picPainter.end();
|
||||
// for page# > 0, we need to offset the target point's Y by twice the heading row height
|
||||
painter.drawPicture(QPoint(0, (i > 0 ? -(headingRowH << 1) : 0)), pic);
|
||||
painter.drawPicture(QPoint(0, headingRowHeightD2), pic);
|
||||
progress++;
|
||||
emit signalProgress(done + (progress * 10) / total);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue