void MainWindow
::getAllTitles(QPrinter *printer
) {
QString strDate
= date.
toString("d MMM yyyy");
printer
->setPaperSize
(QPrinter::Letter);
// create a font appropriate to page size
titleFont.
setStyleHint(QFont::Courier);
titleFont.setPointSize(20);
bodyFont.
setStyleHint(QFont::Helvetica);
ui->editor->clear();
textFormat.setFont(bodyFont);
titleFormat.setFont(titleFont);
titleFormat.
setFontWeight(QFont::Bold);
boldFormat.
setFontWeight(QFont::Bold);
tFrame->setFrameFormat(tFrameFormat);
acursor.insertFrame(tFrameFormat);
acursor.setPosition(0);
QString hdrtxt
= "<h1 style=\"text-align: center; font-family: \'";
hdrtxt += d->rtitleFont;
hdrtxt += "\'; font-size: 20pt; font-weight: bold;\">";
hdrtxt += "All Book Titles By Title";
hdrtxt += "</h1><br>";
acursor.insertHtml(hdrtxt);
QString dttxt
= "<div style=\"text-align: center; font-family: \'";
dttxt += d->rtitleFont;
dttxt += "\' font-size: 11pt; font-weight: normal;\">";
dttxt += strDate;
dttxt += "</div>";
acursor.insertHtml(dttxt);
acursor.setPosition(tFrame->lastPosition());
acursor.endEditBlock();
acursor.setPosition(tpFrame->lastPosition());
topFrameFormat.setPadding(10);
topFrame->setFrameFormat(topFrameFormat);
titleFrameFormat.setBorder(0);
titleFrame->setFrameFormat(titleFrameFormat);
bodyFrame->setFrameFormat(bodyFrameFormat);
strDML = "SELECT DISTINCT ";
strDML += "Books.Title, Authors.LastName||', '||Authors.FirstName Author, ";
strDML += "MediaType.Media ";
strDML += "FROM ";
strDML += " Books, Authors, MediaType ";
strDML += "WHERE ";
strDML += " Books.AuthKey = Authors.ID AND ";
strDML += " Books.MediaKey = MediaType.ID ";
strDML += "ORDER BY Books.Title, Author ";
qry.exec(strDML);
qry.first();
qry.last();
qry.first();
tblFormat.setColumns(5);
tblFormat.setCellPadding(1);
tblFormat.setCellSpacing(2);
tblFormat.
setPageBreakPolicy(QTextFormat::PageBreak_Auto);
tblFormat.setHeaderRowCount(1);
acursor.insertBlock();
acursor.beginEditBlock();
QTextTable *tableBooks
= acursor.
insertTable(1,
5,tblFormat
);
tableBooks
->format
().
setPageBreakPolicy(QTextFormat::PageBreak_Auto);
acursor = tableBooks->cellAt(0, 0).firstCursorPosition();
acursor = tableBooks->cellAt(0,0).firstCursorPosition();
coltxt = "<tr style=\"height: 15px; margin: 0; padding: 0;\">";
coltxt += "<th style=\"";
coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
coltxt += d->rsectionFont;
coltxt += "'; border-bottom: 2px solid black;\">";
coltxt += "<u> ";
coltxt += "Book Title </u></th>";
acursor.insertHtml(coltxt);
acursor = tableBooks->cellAt(0,1).firstCursorPosition();
coltxt = "<th style=\"";
coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
coltxt += d->rsectionFont;
coltxt += "'; border-bottom: 2px solid black;\"> </th>";
acursor.insertHtml(coltxt);
acursor = tableBooks->cellAt(0,2).firstCursorPosition();
coltxt = "<th style=\"";
coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
coltxt += d->rsectionFont;
coltxt += "'; border-bottom: 2px solid black;\"><u> Author Name </u></th>";
acursor.insertHtml(coltxt);
acursor = tableBooks->cellAt(0,3).firstCursorPosition();
coltxt = "<th style=\"";
coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
coltxt += d->rsectionFont;
coltxt += "'; border-bottom: 2px solid black;\"><u> Media </u></th></tr>";
acursor.insertHtml(coltxt);
int j = 1;
do
{
if ( qry.record().field("Title").value().toString().trimmed() == "" ) break;
tableBooks->insertRows(j,1);
acursor = tableBooks->cellAt(j, 0).firstCursorPosition();
acursor.insertText(qry.record().field("Title").value().toString().trimmed());
acursor = tableBooks->cellAt(j,1).firstCursorPosition();
acursor.insertText(" ");
acursor = tableBooks->cellAt(j,2).firstCursorPosition();
acursor.insertText(qry.record().field("Author").value().toString().trimmed());
acursor = tableBooks->cellAt(j,3).firstCursorPosition();
acursor.insertText(qry.record().field("Media").value().toString().trimmed());
++j;
} while ( qry.next() );
qry.finish();
acursor.setPosition(bodyFrame->lastPosition());
acursor.endEditBlock();
acursor.setPosition(topFrame->lastPosition());
acursor.endEditBlock();
ui->editor->print(printer);
}
Bookmarks