Print: cleanup for PrintLayout::printTable()

also includes:
- experiment with colored background for headings
- experiment with 'left' alignment for headings
('th' tag CSS does not support 'text-align')
- whitespace fixes

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2013-07-10 23:03:01 +03:00
parent 9a99aa4c58
commit 8fcba14753

View file

@ -78,11 +78,24 @@ void PrintLayout::printTable()
pageSize.setHeight(pageRect.height()); pageSize.setHeight(pageRect.height());
doc.setPageSize(pageSize); doc.setPageSize(pageSize);
QString styleSheet = "<style type='text/css'>" \ QString styleSheet(
"table { border-width: 1px; border-style: solid; border-color: black; }" \ "<style type='text/css'>" \
"th { font-weight: bold; font-size: large; padding: 3px 10px 3px 10px; }" \ "table {" \
"td { padding: 3px 10px 3px 10px; }" \ " border-width: 1px;" \
"</style>"; " border-style: solid;" \
" border-color: black;" \
"}" \
"th {" \
" background-color: #eeeeee;" \
" font-weight: bold;" \
" font-size: large;" \
" padding: 6px 10px 6px 10px;" \
"}" \
"td {" \
" padding: 3px 10px 3px 10px;" \
"}" \
"</style>"
);
// setDefaultStyleSheet() doesn't work here? // setDefaultStyleSheet() doesn't work here?
QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>"; QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>";
QString htmlTextPrev; QString htmlTextPrev;
@ -92,10 +105,8 @@ void PrintLayout::printTable()
int i; int i;
struct dive *dive; struct dive *dive;
for_each_dive(i, dive) { for_each_dive(i, dive) {
pageCount = pageCountNew; if (!dive->selected && printOptions->print_selected)
if (!dive->selected && printOptions->print_selected) {
continue; continue;
}
if (insertHeading) { if (insertHeading) {
htmlText += insertTableHeadingRow(); htmlText += insertTableHeadingRow();
insertHeading = false; insertHeading = false;
@ -103,6 +114,7 @@ void PrintLayout::printTable()
htmlTextPrev = htmlText; htmlTextPrev = htmlText;
htmlText += insertTableDataRow(dive); htmlText += insertTableDataRow(dive);
doc.setHtml(htmlText); doc.setHtml(htmlText);
pageCount = pageCountNew;
pageCountNew = doc.pageCount(); pageCountNew = doc.pageCount();
/* if the page count increases after adding this row we 'revert' /* if the page count increases after adding this row we 'revert'
* and add a heading instead. */ * and add a heading instead. */
@ -119,7 +131,7 @@ void PrintLayout::printTable()
QString PrintLayout::insertTableHeadingRow() QString PrintLayout::insertTableHeadingRow()
{ {
return "<tr><th>TITLE</th><th>TITLE 2</th></tr>"; return "<tr><th align='left'>TITLE</th><th align='left'>TITLE 2</th></tr>";
} }
QString PrintLayout::insertTableDataRow(struct dive *dive) QString PrintLayout::insertTableDataRow(struct dive *dive)