diff options
author | Anton Lundin <glance@acc.umu.se> | 2019-09-06 23:17:49 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-09-11 17:21:50 +0100 |
commit | fcf5333bf2caf8eb34e31b9f7cd1d72bf4797115 (patch) | |
tree | ebc665a52913fba7c420cf629ff61934cbc30804 /desktop-widgets/printdialog.cpp | |
parent | 18644c89f66091bdde23c7e491c763b49ff4fe2a (diff) | |
download | subsurface-fcf5333bf2caf8eb34e31b9f7cd1d72bf4797115.tar.gz |
Add the ability to export print template as html
This way we can view the html generated from a print template, for
debugging, validation or printing via your favorite browser.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Diffstat (limited to 'desktop-widgets/printdialog.cpp')
-rw-r--r-- | desktop-widgets/printdialog.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/desktop-widgets/printdialog.cpp b/desktop-widgets/printdialog.cpp index 4c863fbea..f0c8f4df8 100644 --- a/desktop-widgets/printdialog.cpp +++ b/desktop-widgets/printdialog.cpp @@ -7,6 +7,7 @@ #include <QProgressBar> #include <QPrintPreviewDialog> #include <QPrintDialog> +#include <QFileDialog> #include <QShortcut> #include <QSettings> #include <QMessageBox> @@ -108,10 +109,14 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QPushButton *previewButton = new QPushButton(tr("&Preview")); connect(previewButton, SIGNAL(clicked(bool)), this, SLOT(previewClicked())); + QPushButton *exportHtmlButton = new QPushButton(tr("Export Html")); + connect(exportHtmlButton, SIGNAL(clicked(bool)), this, SLOT(exportHtmlClicked())); + QDialogButtonBox *buttonBox = new QDialogButtonBox; buttonBox->addButton(QDialogButtonBox::Cancel); buttonBox->addButton(printButton, QDialogButtonBox::AcceptRole); buttonBox->addButton(previewButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(exportHtmlButton, QDialogButtonBox::AcceptRole); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); @@ -181,6 +186,25 @@ void PrintDialog::previewClicked(void) previewDialog.exec(); } +void PrintDialog::exportHtmlClicked(void) +{ + createPrinterObj(); + QString saveFileName = printOptions.p_template; + QString filename = existing_filename ?: prefs.default_filename; + QFileInfo fi(filename); + filename = fi.absolutePath().append(QDir::separator()).append(saveFileName); + QString htmlExportFilename = QFileDialog::getSaveFileName(this, tr("Filename to export html to"), + filename, tr("Html file") + " (*.html)"); + if (!htmlExportFilename.isEmpty()) { + QFile file(htmlExportFilename); + file.open(QIODevice::WriteOnly); + connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); + file.write(printer->exportHtml().toUtf8()); + file.close(); + close(); + } +} + void PrintDialog::printClicked(void) { createPrinterObj(); |