summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-07-10 19:32:15 +0300
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-07-10 19:32:15 +0300
commiteb4312c9bafcd30063a113608a7da96f5733d43b (patch)
tree52d87e9f6a9751a21a0b53bc9cceffa7bbea2a0d /qt-ui
parent9dc45af915f2c8bc93703cbcc79ade1d3261e297 (diff)
downloadsubsurface-eb4312c9bafcd30063a113608a7da96f5733d43b.tar.gz
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 <neolit123@gmail.com>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/printlayout.cpp58
-rw-r--r--qt-ui/printlayout.h4
2 files changed, 60 insertions, 2 deletions
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 <QDebug>
#include <QPainter>
#include <QDesktopWidget>
#include <QApplication>
+#include <QTextDocument>
+#include <QAbstractTextDocumentLayout>
#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 = "<style type='text/css'>" \
+ "table { border-width: 1px; border-style: solid; border-color: black; }" \
+ "th { font-weight: bold; font-size: large; padding: 3px 10px 3px 10px; }" \
+ "td { padding: 3px 10px 3px 10px; }" \
+ "</style>";
+ // setDefaultStyleSheet() doesn't work here?
+ QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>";
+ 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 += "</table>";
+ doc.setHtml(htmlText);
+ doc.print(printer);
+}
+
+QString PrintLayout::insertTableHeadingRow()
+{
+ return "<tr><th>TITLE</th><th>TITLE 2</th></tr>";
+}
+
+QString PrintLayout::insertTableDataRow()
+{
+ return "<tr><td>hello</td></tr><tr><td>hello</td></tr>";
}
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