summaryrefslogtreecommitdiffstats
path: root/printer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'printer.cpp')
-rw-r--r--printer.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/printer.cpp b/printer.cpp
new file mode 100644
index 000000000..01c1f5546
--- /dev/null
+++ b/printer.cpp
@@ -0,0 +1,48 @@
+#include "printer.h"
+#include "templatelayout.h"
+
+#include <QtWebKitWidgets>
+#include <QPainter>
+
+#define A4_300DPI_WIDTH 2480
+#define A4_300DPI_HIGHT 3508
+
+Printer::Printer(QPrinter *printer)
+{
+ this->printer = printer;
+
+ //override these settings for now.
+ printer->setFullPage(true);
+ printer->setOrientation(QPrinter::Portrait);
+ printer->setPaperSize(QPrinter::A4);
+ printer->setPrintRange(QPrinter::AllPages);
+ printer->setResolution(300);
+}
+
+void Printer::render()
+{
+ QPainter painter;
+ QSize size(A4_300DPI_WIDTH, A4_300DPI_HIGHT);
+ painter.begin(printer);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setRenderHint(QPainter::SmoothPixmapTransform);
+
+ webView->page()->setViewportSize(size);
+
+ int Pages = ceil((float)webView->page()->mainFrame()->contentsSize().rheight() / A4_300DPI_HIGHT);
+ for (int i = 0; i < Pages; i++) {
+ webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer);
+ webView->page()->mainFrame()->scroll(0, A4_300DPI_HIGHT);
+ if (i < Pages - 1)
+ printer->newPage();
+ }
+ painter.end();
+}
+
+void Printer::print()
+{
+ TemplateLayout t;
+ webView = new QWebView();
+ webView->setHtml(t.generate());
+ render();
+}