From eb4312c9bafcd30063a113608a7da96f5733d43b Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Wed, 10 Jul 2013 19:32:15 +0300 Subject: Print: initial implementation of the table print PrintLayout for now only handles the table print, while the data output itself is work in progress. For now there is a simple HTML/CSS table logic based on QTextDocument. There is an iterative algorithm which listens for a page increase and adds a heading on top of the new page. Signed-off-by: Lubomir I. Ivanov --- qt-ui/printlayout.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- qt-ui/printlayout.h | 4 +++- 2 files changed, 60 insertions(+), 2 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index be5d955ea..0571f30d3 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -1,6 +1,9 @@ +#include #include #include #include +#include +#include #include "mainwindow.h" #include "printlayout.h" @@ -19,12 +22,18 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op dialog = dialogPtr; printer = printerPtr; printOptions = optionsPtr; + // painter = new QPainter(printer); } void PrintLayout::print() { // we call setup each time to check if the printer properties have changed setup(); + + // temp / debug + printTable(); + return; + // ------------ switch (printOptions->type) { case options::PRETTY: printSixDives(); @@ -63,5 +72,52 @@ void PrintLayout::printTwoDives() void PrintLayout::printTable() { - // nop + QTextDocument doc; + QSizeF pageSize; + pageSize.setWidth(pageRect.width()); + pageSize.setHeight(pageRect.height()); + doc.setPageSize(pageSize); + + QString styleSheet = ""; + // setDefaultStyleSheet() doesn't work here? + QString htmlText = styleSheet + ""; + QString htmlTextPrev; + int pageCountNew = 1, pageCount = 1; + bool insertHeading = true; + + while (pageCount < 3) { // should go trough dives (or selected) instead + if (insertHeading) { + htmlText += insertTableHeadingRow(); + insertHeading = false; + } + doc.setHtml(htmlText); + pageCount = doc.pageCount(); + htmlTextPrev = htmlText; + htmlText += insertTableDataRow(); + doc.setHtml(htmlText); + pageCountNew = doc.pageCount(); + // if the page count increases here we revert and add a heading instead + if (pageCountNew > pageCount) { + htmlText = htmlTextPrev; + doc.setHtml(htmlText); + insertHeading = true; + } + } + htmlText += "
"; + doc.setHtml(htmlText); + doc.print(printer); +} + +QString PrintLayout::insertTableHeadingRow() +{ + return "TITLETITLE 2"; +} + +QString PrintLayout::insertTableDataRow() +{ + return "hellohello"; } diff --git a/qt-ui/printlayout.h b/qt-ui/printlayout.h index 120f50d61..9328030f4 100644 --- a/qt-ui/printlayout.h +++ b/qt-ui/printlayout.h @@ -19,7 +19,7 @@ private: QPrinter *printer; struct options *printOptions; - QPainter painter; + QPainter *painter; int screenDpiX, screenDpiY, printerDpi; qreal scaleX, scaleY; QRect pageRect; @@ -28,6 +28,8 @@ private: void printSixDives(); void printTwoDives(); void printTable(); + QString insertTableHeadingRow(); + QString insertTableDataRow(); }; #endif -- cgit v1.2.3-70-g09d2