From d4382c7c4b802b030bab5e64de4b1641f603d543 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 21:45:27 +0200 Subject: Printing: add preview to TemplateEdit dialog Show QPixmap in QLabel, Use Printer class to render the Preview on the QPixmap. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 15 +++++++++++++++ printer.h | 1 + qt-ui/templateedit.cpp | 9 +++++++++ qt-ui/templateedit.ui | 35 +++++++++++++---------------------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/printer.cpp b/printer.cpp index c5867450f..7cef1104e 100644 --- a/printer.cpp +++ b/printer.cpp @@ -141,3 +141,18 @@ void Printer::print() int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); render(Pages); } + +void Printer::previewOnePage() +{ + if (printMode == PREVIEW) { + TemplateLayout t(printOptions, templateOptions); + + pageSize.setHeight(paintDevice->height()); + pageSize.setWidth(paintDevice->width()); + webView->page()->setViewportSize(pageSize); + webView->setHtml(t.generate()); + + // render only one page + render(1); + } +} diff --git a/printer.h b/printer.h index dee9ba980..b4cf3ac2a 100644 --- a/printer.h +++ b/printer.h @@ -38,6 +38,7 @@ public: Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); ~Printer(); void print(); + void previewOnePage(); signals: void progessUpdated(int value); diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 0a8c4ca92..19f5db609 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,5 +1,6 @@ #include "templateedit.h" #include "printoptions.h" +#include "printer.h" #include "ui_templateedit.h" #include @@ -27,6 +28,14 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, } ui->plainTextEdit->setPlainText(grantlee_template); + + int width = ui->label->width(); + int height = ui->label->height(); + QPixmap map(width * 2, height * 2); + map.fill(QColor::fromRgb(255, 255, 255)); + Printer printer(&map, printOptions, templateOptions, Printer::PREVIEW); + printer.previewOnePage(); + ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); } TemplateEdit::~TemplateEdit() diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui index 26fe15926..fa27eb324 100644 --- a/qt-ui/templateedit.ui +++ b/qt-ui/templateedit.ui @@ -188,21 +188,6 @@ - - - - 20 - 60 - 251 - 311 - - - - - about:blank - - - @@ -216,14 +201,20 @@ Preview + + + + 50 + 70 + 211 + 291 + + + + + + - - - QWebView - QWidget -
QtWebKitWidgets/QWebView
-
-
-- cgit v1.2.3-70-g09d2