mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
3a69638366
commit
d4382c7c4b
4 changed files with 38 additions and 22 deletions
15
printer.cpp
15
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "templateedit.h"
|
||||
#include "printoptions.h"
|
||||
#include "printer.h"
|
||||
#include "ui_templateedit.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
@ -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()
|
||||
|
|
|
@ -188,21 +188,6 @@
|
|||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWebView" name="webView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>60</y>
|
||||
<width>251</width>
|
||||
<height>311</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="url">
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
</url>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
|
@ -216,14 +201,20 @@
|
|||
<string>Preview</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>70</y>
|
||||
<width>211</width>
|
||||
<height>291</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>QtWebKitWidgets/QWebView</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
|
Loading…
Add table
Reference in a new issue