From bc0b443afd73e0bc7c18b293d051aa01bf82d99f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 21 Jun 2015 04:59:15 +0200 Subject: Printing: add QPrintPreviewDialog to main dialog Add preview dialog that shows the printer contents before printing. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 6f30f89f5..9949b104d 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -93,6 +93,11 @@ void PrintDialog::onFinished() void PrintDialog::previewClicked(void) { + QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window + | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint + | Qt::WindowTitleHint); + connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *))); + previewDialog.exec(); } void PrintDialog::printClicked(void) @@ -115,5 +120,9 @@ void PrintDialog::printClicked(void) void PrintDialog::onPaintRequested(QPrinter *printerPtr) { + connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); + printer->print(); + progressBar->setValue(0); + disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); } #endif -- cgit v1.2.3-70-g09d2 From 1faa198020de343004a7f1db85a83e6bc0ef8b34 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 21 Jun 2015 06:13:22 +0200 Subject: Printing: print all dives if 'print selected' is unchecked User can choose either to print all dives or print selected dives only. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 2 +- templatelayout.cpp | 20 ++++++++++++++------ templatelayout.h | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/printer.cpp b/printer.cpp index 79f04e4a0..44f0739bc 100644 --- a/printer.cpp +++ b/printer.cpp @@ -56,7 +56,7 @@ void Printer::render() divesPerPage = 2; break; } - int Pages = ceil(getTotalWork() / (float)divesPerPage); + int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); // get all refereces to diveprofile class in the Html template QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile"); diff --git a/templatelayout.cpp b/templatelayout.cpp index 5f47b64a2..81a4d5f03 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -4,11 +4,19 @@ #include "helpers.h" #include "display.h" -int getTotalWork() +int getTotalWork(print_options *printOptions) { - // return the correct number depending on all/selected dives - // but don't return 0 as we might divide by this number - return amount_selected ? amount_selected : 1; + if (printOptions->print_selected) { + // return the correct number depending on all/selected dives + // but don't return 0 as we might divide by this number + return amount_selected ? amount_selected : 1; + } + int dives = 0, i; + struct dive *dive; + for_each_dive (i, dive) { + dives++; + } + return dives; } TemplateLayout::TemplateLayout(print_options *PrintOptions) : @@ -25,7 +33,7 @@ TemplateLayout::~TemplateLayout() QString TemplateLayout::generate() { int progress = 0; - int totalWork = getTotalWork(); + int totalWork = getTotalWork(PrintOptions); QString templateName; QString htmlContent; @@ -45,7 +53,7 @@ QString TemplateLayout::generate() int i; for_each_dive (i, dive) { //TODO check for exporting selected dives only - if (!dive->selected) + if (!dive->selected && PrintOptions->print_selected) continue; Dive d(dive); diveList.append(QVariant::fromValue(d)); diff --git a/templatelayout.h b/templatelayout.h index 21eae1b80..4637a7962 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -5,7 +5,7 @@ #include "mainwindow.h" #include "printoptions.h" -int getTotalWork(); +int getTotalWork(print_options *printOptions); class TemplateLayout : public QObject { Q_OBJECT -- cgit v1.2.3-70-g09d2 From 5981cf170f9878cbe13da98667fd8817160335a6 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 22 Jun 2015 22:46:39 +0200 Subject: Printing: make dive profile scale dependant on the page size and DPI Use setFontPrintScale() to change the font scale of the dive profile as a ratio of the full resolution, font = (pageWidth * dpi) / fontvalue Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer.cpp b/printer.cpp index 44f0739bc..50027c23b 100644 --- a/printer.cpp +++ b/printer.cpp @@ -36,7 +36,7 @@ void Printer::render() // apply printing settings to profile profile->setFrameStyle(QFrame::NoFrame); profile->setPrintMode(true, !printOptions->color_selected); - profile->setFontPrintScale(0.6); + profile->setFontPrintScale(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi * 0.001); profile->setToolTipVisibile(false); prefs.animation_speed = 0; -- cgit v1.2.3-70-g09d2 From fcde03e84948b0c78c2dd7d8a334cd6def5879af Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 23 Jun 2015 00:10:32 +0200 Subject: Printing: choose printing color mode 'color/greyscale' We can have color printouts only if the printer supports color prints, the user selected 'print in colors' from the print dialog and the default printer settings (Operating system wise) is to print in colors, Otherwise the prints will be in greyscale. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/printer.cpp b/printer.cpp index 50027c23b..5c93d2fed 100644 --- a/printer.cpp +++ b/printer.cpp @@ -26,9 +26,25 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter void Printer::render() { - QPointer profile = MainWindow::instance()->graphics(); + // apply user settings + int divesPerPage; + if (printOptions->color_selected && printer->colorMode()) { + printer->setColorMode(QPrinter::Color); + } else { + printer->setColorMode(QPrinter::GrayScale); + } + switch (printOptions->p_template) { + case print_options::ONE_DIVE: + divesPerPage = 1; + break; + case print_options::TWO_DIVE: + divesPerPage = 2; + break; + } + int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); // keep original preferences + QPointer profile = MainWindow::instance()->graphics(); int profileFrameStyle = profile->frameStyle(); int animationOriginal = prefs.animation_speed; double fontScale = profile->getFontPrintScale(); @@ -47,17 +63,6 @@ void Printer::render() painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); - int divesPerPage; - switch (printOptions->p_template) { - case print_options::ONE_DIVE: - divesPerPage = 1; - break; - case print_options::TWO_DIVE: - divesPerPage = 2; - break; - } - int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); - // get all refereces to diveprofile class in the Html template QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile"); -- cgit v1.2.3-70-g09d2 From 3d5caabe4acefd08e27167a9c4220dc5fb22d537 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Wed, 24 Jun 2015 03:55:09 +0200 Subject: Printing: fix two dives per page borders and text font As we use a responsive layout, every UI element must be relative to its parent and its size must be a ratio of the view port to prevent them from displaying outside their containing parents. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/two_dives.html | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/printing_templates/two_dives.html b/printing_templates/two_dives.html index 574579f90..9868bfd11 100644 --- a/printing_templates/two_dives.html +++ b/printing_templates/two_dives.html @@ -5,10 +5,11 @@ background-color: white; padding: 0px; margin: 0px; + font-size: 1.2vw; } h1 { - font-size: 0.9cm; + font-size: 1.2vw; float: left; } @@ -20,49 +21,56 @@ margin-top: 0; margin-bottom: 0; overflow: hidden; - border-width: 0px; page-break-inside: avoid; } .innerContainer { height: 85%; - border-style: solid; padding: 0.5%; margin-top: 1%; margin-bottom: 1%; overflow: hidden; + -webkit-box-sizing: border-box; + box-sizing: border-box; + border:max(0.1vw, 1px); + border-style:solid; } .table_class { overflow: hidden; max-width: 25%; min-width: 25%; - box-shadow: 5px 5px 5px #888888; margin: 1.5%; float: left; + -webkit-box-sizing: border-box; + box-sizing: border-box; + border:max(0.1vw, 1px); + border-style:solid; } .notes_table_class { overflow: hidden; max-width: 100%; min-width: 100%; - box-shadow: 5px 5px 5px #888888; margin: 1.5%; float: left; + -webkit-box-sizing: border-box; + box-sizing: border-box; + border:max(0.1vw, 1px); + border-style:solid; } .fieldTitle { background-color: #CfC7C5; overflow: hidden; + padding:0; } .diveProfile { width: 37%; - height: 70%; + height: 95%; margin: 1.5%; float: right; - border-style: solid; - padding: 3mm; } .diveDetails { @@ -80,9 +88,9 @@ } .textArea { - max-height: 43ex; overflow: hidden !important; text-overflow: ellipsis; + max-height: 10.3vw; } #footer { @@ -98,7 +106,7 @@
- +

Dive No.

@@ -139,7 +147,7 @@
- +

Time.

@@ -184,7 +192,7 @@
- +

Notes

-- cgit v1.2.3-70-g09d2 From ce3d2abd83717abb1b4b5c8a8eecc04ab1d45e66 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Wed, 24 Jun 2015 05:12:45 +0200 Subject: Printing: show warning message for WIP features Show warning message before proceeding to print 'Table' or 'Statistics' print layout. This should be used during the development phase only. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 9949b104d..6e193d9bd 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #define SETTINGS_GROUP "PrintDialog" @@ -93,6 +94,13 @@ void PrintDialog::onFinished() void PrintDialog::previewClicked(void) { + if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) { + QMessageBox msgBox; + msgBox.setText("This feature is not implemented yet"); + msgBox.exec(); + return; + } + QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowTitleHint); @@ -102,6 +110,13 @@ void PrintDialog::previewClicked(void) void PrintDialog::printClicked(void) { + if (printOptions.type == print_options::TABLE || printOptions.type == print_options::STATISTICS) { + QMessageBox msgBox; + msgBox.setText("This feature is not implemented yet"); + msgBox.exec(); + return; + } + QPrintDialog printDialog(&qprinter, this); if (printDialog.exec() == QDialog::Accepted) { switch (printOptions.type) { -- cgit v1.2.3-70-g09d2 From 963e09ad7b01d99537b59037e2cd1fbedf480261 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 26 Jun 2015 04:21:03 +0200 Subject: Printing: add TemplateEdit form to source tree The TemplateEdit class works to customize the tempalate before printing, User can select the font-size, font-type, color-palette, linespacing and editing the template HTML code. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- CMakeLists.txt | 1 + qt-ui/templateedit.cpp | 15 +++ qt-ui/templateedit.h | 22 +++++ qt-ui/templateedit.ui | 262 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 300 insertions(+) create mode 100644 qt-ui/templateedit.cpp create mode 100644 qt-ui/templateedit.h create mode 100644 qt-ui/templateedit.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 534e8e2b6..f4f49f805 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ else() set(SUBSURFACE_PRINTING_SRCS printer.cpp templatelayout.cpp + qt-ui/templateedit.cpp ) set(PRINTING_PKG PrintSupport) set(PRINTING_LIB Qt5::PrintSupport) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp new file mode 100644 index 000000000..1db62b619 --- /dev/null +++ b/qt-ui/templateedit.cpp @@ -0,0 +1,15 @@ +#include "templateedit.h" +#include "ui_templateedit.h" + +TemplateEdit::TemplateEdit(QWidget *parent) : + QDialog(parent), + ui(new Ui::TemplateEdit) +{ + ui->setupUi(this); + this->templateOptions = templateOptions; +} + +TemplateEdit::~TemplateEdit() +{ + delete ui; +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h new file mode 100644 index 000000000..f1003e461 --- /dev/null +++ b/qt-ui/templateedit.h @@ -0,0 +1,22 @@ +#ifndef TEMPLATEEDIT_H +#define TEMPLATEEDIT_H + +#include + +namespace Ui { +class TemplateEdit; +} + +class TemplateEdit : public QDialog +{ + Q_OBJECT + +public: + explicit TemplateEdit(QWidget *parent = 0); + ~TemplateEdit(); + +private: + Ui::TemplateEdit *ui; +}; + +#endif // TEMPLATEEDIT_H diff --git a/qt-ui/templateedit.ui b/qt-ui/templateedit.ui new file mode 100644 index 000000000..26fe15926 --- /dev/null +++ b/qt-ui/templateedit.ui @@ -0,0 +1,262 @@ + + + TemplateEdit + + + + 0 + 0 + 774 + 433 + + + + Edit Template + + + + + 400 + 380 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 300 + 30 + 441 + 331 + + + + 0 + + + + Style + + + + + 10 + 20 + 401 + 171 + + + + + + + + + Font + + + + + + + + Arial + + + + + Impact + + + + + Georgia + + + + + Courier + + + + + Verdana + + + + + + + + + + + + Font size + + + + + + + 9 + + + 18 + + + + + + + + + + + Color pallet + + + + + + + + Almond + + + + + + + + + + + + Line spacing + + + + + + + 1.000000000000000 + + + 3.000000000000000 + + + 0.250000000000000 + + + 1.250000000000000 + + + + + + + + + + + Template + + + + + 0 + 0 + 441 + 301 + + + + Qt::ScrollBarAsNeeded + + + QPlainTextEdit::NoWrap + + + + + + + + 20 + 60 + 251 + 311 + + + + + about:blank + + + + + + + 30 + 30 + 59 + 14 + + + + Preview + + + + + + QWebView + QWidget +
QtWebKitWidgets/QWebView
+
+
+ + + + buttonBox + accepted() + TemplateEdit + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + TemplateEdit + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
-- cgit v1.2.3-70-g09d2 From ff594c65e3597f53164302f79df05c0b5e70980c Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 26 Jun 2015 04:21:31 +0200 Subject: Printing: call TemplateEdit when edit is triggered Edit button should open TemplateEdit dialog. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 7 +++++++ qt-ui/printoptions.h | 1 + 2 files changed, 8 insertions(+) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index e2684b6ed..0609b2b13 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -1,4 +1,5 @@ #include "printoptions.h" +#include "templateedit.h" #include PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt) @@ -97,3 +98,9 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) break; } } + +void PrintOptions::on_editButton_clicked() +{ + TemplateEdit te; + te.exec(); +} diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 13ef4e310..324697762 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -41,6 +41,7 @@ slots: void on_radioTablePrint_clicked(bool check); void on_radioDiveListPrint_clicked(bool check); void on_printTemplate_currentIndexChanged(int index); + void on_editButton_clicked(); }; #endif // PRINTOPTIONS_H -- cgit v1.2.3-70-g09d2 From a600ea5201f55a3182cb24a0553d02aefad2c51b Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 29 Jun 2015 03:16:19 +0200 Subject: Printing: add template_options struct that contains template The template_options struct holds the settings variables in the code. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 2 +- qt-ui/printdialog.h | 2 ++ qt-ui/printoptions.cpp | 5 +++-- qt-ui/printoptions.h | 3 ++- qt-ui/templateedit.cpp | 2 +- qt-ui/templateedit.h | 11 +++++++++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 6e193d9bd..341a84083 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -34,7 +34,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f } // create a print options object and pass our options struct - optionsWidget = new PrintOptions(this, &printOptions); + optionsWidget = new PrintOptions(this, &printOptions, &templateOptions); // create a new printer object printer = new Printer(&qprinter, &printOptions); diff --git a/qt-ui/printdialog.h b/qt-ui/printdialog.h index a34037442..a00c4c5d9 100644 --- a/qt-ui/printdialog.h +++ b/qt-ui/printdialog.h @@ -6,6 +6,7 @@ #include #include "printoptions.h" #include "printer.h" +#include "templateedit.h" class QProgressBar; class PrintOptions; @@ -24,6 +25,7 @@ private: Printer *printer; QPrinter qprinter; struct print_options printOptions; + struct template_options templateOptions; private slots: diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 0609b2b13..a7c520b21 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -2,7 +2,7 @@ #include "templateedit.h" #include -PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt) +PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt) { hasSetupSlots = false; ui.setupUi(this); @@ -11,6 +11,7 @@ PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt) if (!printOpt) return; setup(printOpt); + templateOptions = templateOpt; } void PrintOptions::setup(struct print_options *printOpt) @@ -101,6 +102,6 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) void PrintOptions::on_editButton_clicked() { - TemplateEdit te; + TemplateEdit te(this, templateOptions); te.exec(); } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 324697762..9bacd4e90 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -25,12 +25,13 @@ class PrintOptions : public QWidget { Q_OBJECT public: - explicit PrintOptions(QWidget *parent = 0, struct print_options *printOpt = 0); + explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt); void setup(struct print_options *printOpt); private: Ui::PrintOptions ui; struct print_options *printOptions; + struct template_options *templateOptions; bool hasSetupSlots; private diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 1db62b619..40e14c221 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,7 +1,7 @@ #include "templateedit.h" #include "ui_templateedit.h" -TemplateEdit::TemplateEdit(QWidget *parent) : +TemplateEdit::TemplateEdit(QWidget *parent, struct template_options *templateOptions) : QDialog(parent), ui(new Ui::TemplateEdit) { diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index f1003e461..2790c619b 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -3,6 +3,13 @@ #include +struct template_options { + int font_index; + int color_palette_index; + double font_size; + double line_spacing; +}; + namespace Ui { class TemplateEdit; } @@ -12,11 +19,11 @@ class TemplateEdit : public QDialog Q_OBJECT public: - explicit TemplateEdit(QWidget *parent = 0); + explicit TemplateEdit(QWidget *parent, struct template_options *templateOptions); ~TemplateEdit(); - private: Ui::TemplateEdit *ui; + struct template_options *templateOptions; }; #endif // TEMPLATEEDIT_H -- cgit v1.2.3-70-g09d2 From 71561e720dbfd85b3cb724dd1eb509b0d230d5db Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Mon, 29 Jun 2015 03:24:29 +0200 Subject: Printing: add QSettings for TemplateEdit class TemplateOptions struct must be saved to QSettings after the window is closed, also it must be recalled when initializing the window. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printdialog.cpp | 17 ++++++++++++++++- qt-ui/templateedit.cpp | 26 ++++++++++++++++++++++++++ qt-ui/templateedit.h | 9 +++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 341a84083..23c6f225e 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -23,6 +23,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.landscape = false; printOptions.p_template = print_options::ONE_DIVE; printOptions.type = print_options::DIVELIST; + templateOptions.font_index = 0; + templateOptions.font_size = 9; + templateOptions.color_palette_index = 0; + templateOptions.line_spacing = 1; } else { s.beginGroup(SETTINGS_GROUP); printOptions.type = (print_options::print_type)s.value("type").toInt(); @@ -31,6 +35,10 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.landscape = s.value("landscape").toBool(); printOptions.p_template = (print_options::print_template)s.value("template_selected").toInt(); qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape); + templateOptions.font_index = s.value("font").toInt(); + templateOptions.font_size = s.value("font_size").toDouble(); + templateOptions.color_palette_index = s.value("color_palette").toInt(); + templateOptions.line_spacing = s.value("line_spacing").toDouble(); } // create a print options object and pass our options struct @@ -83,13 +91,20 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f void PrintDialog::onFinished() { - // save the settings QSettings s; s.beginGroup(SETTINGS_GROUP); + + // save print paper settings s.setValue("type", printOptions.type); s.setValue("print_selected", printOptions.print_selected); s.setValue("color_selected", printOptions.color_selected); s.setValue("template_selected", printOptions.p_template); + + // save template settings + s.setValue("font", templateOptions.font_index); + s.setValue("font_size", templateOptions.font_size); + s.setValue("color_palette", templateOptions.color_palette_index); + s.setValue("line_spacing", templateOptions.line_spacing); } void PrintDialog::previewClicked(void) diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 40e14c221..a4236d036 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -7,9 +7,35 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct template_options *templateOpt { ui->setupUi(this); this->templateOptions = templateOptions; + + // restore the settings and init the UI + ui->fontSelection->setCurrentIndex(templateOptions->font_index); + ui->fontsize->setValue(templateOptions->font_size); + ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index); + ui->linespacing->setValue(templateOptions->line_spacing); } TemplateEdit::~TemplateEdit() { delete ui; } + +void TemplateEdit::on_fontsize_valueChanged(int font_size) +{ + templateOptions->font_size = font_size; +} + +void TemplateEdit::on_linespacing_valueChanged(double line_spacing) +{ + templateOptions->line_spacing = line_spacing; +} + +void TemplateEdit::on_fontSelection_currentIndexChanged(int index) +{ + templateOptions->font_index = index; +} + +void TemplateEdit::on_colorpalette_currentIndexChanged(int index) +{ + templateOptions->color_palette_index = index; +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 2790c619b..73a5e9fbb 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -21,6 +21,15 @@ class TemplateEdit : public QDialog public: explicit TemplateEdit(QWidget *parent, struct template_options *templateOptions); ~TemplateEdit(); +private slots: + void on_fontsize_valueChanged(int font_size); + + void on_linespacing_valueChanged(double line_spacing); + + void on_fontSelection_currentIndexChanged(int index); + + void on_colorpalette_currentIndexChanged(int index); + private: Ui::TemplateEdit *ui; struct template_options *templateOptions; -- cgit v1.2.3-70-g09d2 From bc80fc8849a01ac156c5e54ba8ef3fe04e1aaee3 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 2 Jul 2015 22:26:31 +0200 Subject: Printing: pass the template_options struct to TemplateLayout The template_options struct needs to be passed to TemplateLayout constructor. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 5 +++-- printer.h | 4 +++- qt-ui/printdialog.cpp | 2 +- templatelayout.cpp | 5 ++++- templatelayout.h | 5 ++++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/printer.cpp b/printer.cpp index 5c93d2fed..83cc42d18 100644 --- a/printer.cpp +++ b/printer.cpp @@ -6,10 +6,11 @@ #include #include -Printer::Printer(QPrinter *printer, print_options *printOptions) +Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions) { this->printer = printer; this->printOptions = printOptions; + this->templateOptions = templateOptions; dpi = 0; done = 0; } @@ -116,7 +117,7 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { - TemplateLayout t(printOptions); + TemplateLayout t(printOptions, templateOptions); webView = new QWebView(); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); diff --git a/printer.h b/printer.h index cba82e607..4ab65834a 100644 --- a/printer.h +++ b/printer.h @@ -8,6 +8,7 @@ #include "profile/profilewidget2.h" #include "printoptions.h" +#include "templateedit.h" class Printer : public QObject { Q_OBJECT @@ -16,6 +17,7 @@ private: QPrinter *printer; QWebView *webView; print_options *printOptions; + template_options *templateOptions; QSize pageSize; int done; int dpi; @@ -26,7 +28,7 @@ private slots: void templateProgessUpdated(int value); public: - Printer(QPrinter *printer, print_options *printOptions); + Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions); void print(); signals: diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 23c6f225e..9ff29e67b 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -45,7 +45,7 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f optionsWidget = new PrintOptions(this, &printOptions, &templateOptions); // create a new printer object - printer = new Printer(&qprinter, &printOptions); + printer = new Printer(&qprinter, &printOptions, &templateOptions); QVBoxLayout *layout = new QVBoxLayout(this); setLayout(layout); diff --git a/templatelayout.cpp b/templatelayout.cpp index 81a4d5f03..2a5bb8ff7 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -19,10 +19,11 @@ int getTotalWork(print_options *printOptions) return dives; } -TemplateLayout::TemplateLayout(print_options *PrintOptions) : +TemplateLayout::TemplateLayout(print_options *PrintOptions, template_options *templateOptions) : m_engine(NULL) { this->PrintOptions = PrintOptions; + this->templateOptions = templateOptions; } TemplateLayout::~TemplateLayout() @@ -45,6 +46,7 @@ QString TemplateLayout::generate() m_engine->addTemplateLoader(m_templateLoader); Grantlee::registerMetaType(); + Grantlee::registerMetaType(); QVariantHash mapping; QVariantList diveList; @@ -61,6 +63,7 @@ QString TemplateLayout::generate() emit progressUpdated(progress * 100.0 / totalWork); } mapping.insert("dives", diveList); + mapping.insert("template_options", QVariant::fromValue(*templateOptions)); Grantlee::Context c(mapping); diff --git a/templatelayout.h b/templatelayout.h index 4637a7962..a894ce4ca 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -4,19 +4,21 @@ #include #include "mainwindow.h" #include "printoptions.h" +#include "templateedit.h" int getTotalWork(print_options *printOptions); class TemplateLayout : public QObject { Q_OBJECT public: - TemplateLayout(print_options *PrintOptions); + TemplateLayout(print_options *PrintOptions, template_options *templateOptions); ~TemplateLayout(); QString generate(); private: Grantlee::Engine *m_engine; print_options *PrintOptions; + template_options *templateOptions; signals: void progressUpdated(int value); @@ -75,6 +77,7 @@ public: }; Q_DECLARE_METATYPE(Dive) +Q_DECLARE_METATYPE(template_options) GRANTLEE_BEGIN_LOOKUP(Dive) if (property == "number") -- cgit v1.2.3-70-g09d2 From 4a98d92489b3c404ae1d7320c27cadd9446fa5bf Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 2 Jul 2015 22:37:14 +0200 Subject: Printing: export template_options struct to Grantlee engine Add template_options to Grantlee lookup section and export the struct fields. -font: is the font type used, must be selcted from 5 different types. -font-size: is a user selection from 9 - 18 then it is scaled to a range from 1 to 2 of the displaying view port. -color-palette: is the colors used in the template, all used colors must be referenced from here.(not yet implemented) -line-spacing: is the distance between two consecutive lines in the dive notes text. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/templatelayout.h b/templatelayout.h index a894ce4ca..854a16259 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -104,4 +104,25 @@ else if (property == "notes") return object.notes(); GRANTLEE_END_LOOKUP +GRANTLEE_BEGIN_LOOKUP(template_options) +if (property == "font") { + switch (object.font_index) { + case 0: + return "Arial, Helvetica, sans-serif"; + case 1: + return "Impact, Charcoal, sans-serif"; + case 2: + return "Georgia, serif"; + case 3: + return "Courier, monospace"; + case 4: + return "Verdana, Geneva, sans-serif"; + } +} else if (property == "font_size") { + return object.font_size / 9.0; +} else if (property == "line_spacing") { + return object.line_spacing; +} +GRANTLEE_END_LOOKUP + #endif -- cgit v1.2.3-70-g09d2 From 6446b75b9e358bf3c7969b7df302410b39249948 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 4 Jul 2015 16:55:43 +0200 Subject: Printing: edit templates to show template options dynamically Template styles must refere to Grantlee fields to be replaced with user selected settings. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/one_dive.html | 10 ++++++++-- printing_templates/two_dives.html | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/printing_templates/one_dive.html b/printing_templates/one_dive.html index 754dc85bc..87b2976e0 100644 --- a/printing_templates/one_dive.html +++ b/printing_templates/one_dive.html @@ -5,12 +5,14 @@ background-color: white; padding: 0; margin: 0; - font-size: 1.2vw; + font-size: {{ template_options.font_size }}vw; + line-height: {{ template_options.line_spacing }}; + font-family: {{ template_options.font }}; } h1 { - font-size: 1.2vw; float: left; + font-size: {{ template_options.font_size }}vw; } table { @@ -84,6 +86,10 @@ margin: 1.5%; float: left; } + + .textArea { + line-height: {{ template_options.line_spacing }}; + } diff --git a/printing_templates/two_dives.html b/printing_templates/two_dives.html index 9868bfd11..b0ad9ba15 100644 --- a/printing_templates/two_dives.html +++ b/printing_templates/two_dives.html @@ -5,11 +5,13 @@ background-color: white; padding: 0px; margin: 0px; - font-size: 1.2vw; + font-size: {{ template_options.font_size }}vw; + line-height: {{ template_options.line_spacing }}; + font-family: {{ template_options.font }}; } h1 { - font-size: 1.2vw; + font-size: {{ template_options.font_size }}vw; float: left; } @@ -91,6 +93,7 @@ overflow: hidden !important; text-overflow: ellipsis; max-height: 10.3vw; + line-height: {{ template_options.line_spacing }}; } #footer { -- cgit v1.2.3-70-g09d2 From 815072d2ae29811271af197e2330cc331d58f9c6 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 4 Jul 2015 23:54:15 +0200 Subject: Printing: retrieve number of dives per page from the template file Add special data attribute 'data-numberofdives' in the template with the number of dives per page. This is standard HTML5 specification so it won't corrupt the template file. Any template that will be used for printing must contain this attribute to assure correct output. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 14 +++++++------- printing_templates/one_dive.html | 2 +- printing_templates/two_dives.html | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/printer.cpp b/printer.cpp index 83cc42d18..f8a90f96d 100644 --- a/printer.cpp +++ b/printer.cpp @@ -34,13 +34,13 @@ void Printer::render() } else { printer->setColorMode(QPrinter::GrayScale); } - switch (printOptions->p_template) { - case print_options::ONE_DIVE: - divesPerPage = 1; - break; - case print_options::TWO_DIVE: - divesPerPage = 2; - break; + + // get number of dives per page from data-numberofdives attribute in the body of the selected template + bool ok; + divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); + if (!ok) { + divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed + //TODO: show warning } int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); diff --git a/printing_templates/one_dive.html b/printing_templates/one_dive.html index 87b2976e0..d7ae8d477 100644 --- a/printing_templates/one_dive.html +++ b/printing_templates/one_dive.html @@ -92,7 +92,7 @@ } - + {% block main_rows %} {% for dive in dives %}
diff --git a/printing_templates/two_dives.html b/printing_templates/two_dives.html index b0ad9ba15..62502272b 100644 --- a/printing_templates/two_dives.html +++ b/printing_templates/two_dives.html @@ -102,7 +102,7 @@ } - + {% block main_rows %} {% for dive in dives %}
-- cgit v1.2.3-70-g09d2 From c35092f5c9ce30f2b8df4c554302a3e7c8716a07 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 4 Jul 2015 23:02:17 +0200 Subject: Printing: add custom options to the PrintDialog Add: -custom.html template -custom template to print_options struct -options to the options dialog Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printing_templates/custom.html | 50 ++++++++++++++++++++++++++++++++++++++++++ qt-ui/printoptions.cpp | 6 +++++ qt-ui/printoptions.h | 3 ++- qt-ui/printoptions.ui | 5 +++++ templatelayout.cpp | 2 ++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 printing_templates/custom.html diff --git a/printing_templates/custom.html b/printing_templates/custom.html new file mode 100644 index 000000000..52fdb4b49 --- /dev/null +++ b/printing_templates/custom.html @@ -0,0 +1,50 @@ + + + + + +{% block main_rows %} + {% for dive in dives %} +
+
+

This template is empty

+ +
+
+ {% endfor %} +{% endblock %} + + diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index a7c520b21..cd38e3560 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -36,6 +36,9 @@ void PrintOptions::setup(struct print_options *printOpt) case print_options::TWO_DIVE: ui.printTemplate->setCurrentIndex(1); break; + case print_options::CUSTOM: + ui.printTemplate->setCurrentIndex(2); + break; } // general print option checkboxes @@ -97,6 +100,9 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) case 1: printOptions->p_template = print_options::TWO_DIVE; break; + case 2: + printOptions->p_template = print_options::CUSTOM; + break; } } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 9bacd4e90..1d806b116 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -13,7 +13,8 @@ struct print_options { } type; enum print_template { ONE_DIVE, - TWO_DIVE + TWO_DIVE, + CUSTOM } p_template; bool print_selected; bool color_selected; diff --git a/qt-ui/printoptions.ui b/qt-ui/printoptions.ui index 632b9cdaf..7e66d4cb0 100644 --- a/qt-ui/printoptions.ui +++ b/qt-ui/printoptions.ui @@ -140,6 +140,11 @@ Two dives per page + + + Custom template + + diff --git a/templatelayout.cpp b/templatelayout.cpp index 2a5bb8ff7..fcdd22902 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -71,6 +71,8 @@ QString TemplateLayout::generate() templateName = "one_dive.html"; } else if (PrintOptions->p_template == print_options::TWO_DIVE) { templateName = "two_dives.html"; + } else if (PrintOptions->p_template == print_options::CUSTOM) { + templateName = "custom.html"; } Grantlee::Template t = m_engine->loadByName(templateName); if (!t || t->error()) { -- cgit v1.2.3-70-g09d2 From 605e1e2d93996f57b3e48f698d840f517d84a99d Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 06:21:39 +0200 Subject: Printing: add functions that read/write a template Read/write templates from files. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.cpp | 19 +++++++++++++++++++ templatelayout.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/templatelayout.cpp b/templatelayout.cpp index fcdd22902..9a9dc9656 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -89,6 +89,25 @@ QString TemplateLayout::generate() return htmlContent; } +QString TemplateLayout::readTemplate(QString template_name) +{ + QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name); + if (qfile.open(QFile::ReadOnly | QFile::Text)) { + QTextStream in(&qfile); + return in.readAll(); + } + return ""; +} + +void TemplateLayout::writeTemplate(QString template_name, QString grantlee_template) +{ + QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name); + if (qfile.open(QFile::ReadWrite | QFile::Text)) { + qfile.write(grantlee_template.toUtf8().data()); + qfile.close(); + } +} + Dive::Dive() : m_number(-1), dive(NULL) diff --git a/templatelayout.h b/templatelayout.h index 854a16259..3826c6c00 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -14,6 +14,8 @@ public: TemplateLayout(print_options *PrintOptions, template_options *templateOptions); ~TemplateLayout(); QString generate(); + static QString readTemplate(QString template_name); + static void writeTemplate(QString template_name, QString grantlee_template); private: Grantlee::Engine *m_engine; -- cgit v1.2.3-70-g09d2 From a70cea95e8c67805945eda8e874a12f67daebe9f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 06:28:23 +0200 Subject: Printing: refactor the print options class -Remove unneeded parameter to member variable -Check if template_options struct is valid Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 8 ++++---- qt-ui/printoptions.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index cd38e3560..08be76588 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -8,15 +8,15 @@ PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, stru ui.setupUi(this); if (parent) setParent(parent); - if (!printOpt) + if (!printOpt || !templateOpt) return; - setup(printOpt); templateOptions = templateOpt; + printOptions = printOpt; + setup(); } -void PrintOptions::setup(struct print_options *printOpt) +void PrintOptions::setup() { - printOptions = printOpt; // print type radio buttons switch (printOptions->type) { case print_options::DIVELIST: diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 1d806b116..c33addc83 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -27,7 +27,7 @@ class PrintOptions : public QWidget { public: explicit PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt); - void setup(struct print_options *printOpt); + void setup(); private: Ui::PrintOptions ui; -- cgit v1.2.3-70-g09d2 From c44496e23d3e16ec6b5622eea73ae39d991e27bf Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 07:26:39 +0200 Subject: Printing: move template_options to print_options.h Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 2 +- qt-ui/printoptions.h | 7 +++++++ qt-ui/templateedit.cpp | 4 +++- qt-ui/templateedit.h | 10 ++-------- templatelayout.h | 1 - 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 08be76588..f3c6eb14c 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -108,6 +108,6 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) void PrintOptions::on_editButton_clicked() { - TemplateEdit te(this, templateOptions); + TemplateEdit te(this, printOptions, templateOptions); te.exec(); } diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index c33addc83..d96b27a53 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -21,6 +21,13 @@ struct print_options { bool landscape; }; +struct template_options { + int font_index; + int color_palette_index; + double font_size; + double line_spacing; +}; + // should be based on a custom QPrintDialog class class PrintOptions : public QWidget { Q_OBJECT diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index a4236d036..aecfdc434 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -1,12 +1,14 @@ #include "templateedit.h" +#include "printoptions.h" #include "ui_templateedit.h" -TemplateEdit::TemplateEdit(QWidget *parent, struct template_options *templateOptions) : +TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) : QDialog(parent), ui(new Ui::TemplateEdit) { ui->setupUi(this); this->templateOptions = templateOptions; + this->printOptions = printOptions; // restore the settings and init the UI ui->fontSelection->setCurrentIndex(templateOptions->font_index); diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 73a5e9fbb..dc38d11fc 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -3,13 +3,6 @@ #include -struct template_options { - int font_index; - int color_palette_index; - double font_size; - double line_spacing; -}; - namespace Ui { class TemplateEdit; } @@ -19,7 +12,7 @@ class TemplateEdit : public QDialog Q_OBJECT public: - explicit TemplateEdit(QWidget *parent, struct template_options *templateOptions); + explicit TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions); ~TemplateEdit(); private slots: void on_fontsize_valueChanged(int font_size); @@ -33,6 +26,7 @@ private slots: private: Ui::TemplateEdit *ui; struct template_options *templateOptions; + struct print_options *printOptions; }; #endif // TEMPLATEEDIT_H diff --git a/templatelayout.h b/templatelayout.h index 3826c6c00..622f7d7a0 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -4,7 +4,6 @@ #include #include "mainwindow.h" #include "printoptions.h" -#include "templateedit.h" int getTotalWork(print_options *printOptions); -- cgit v1.2.3-70-g09d2 From cc53dc7acf801f022612678f697e6d76c2443153 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 07:29:46 +0200 Subject: Printing: implement QPlainTextEdit in TemplateEdit This is the main area to edit the templates inside Subsurface. Whenever the user edits a template the edited template is saved in custom.html and custom.html is considered the selected printing template. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 1 + qt-ui/templateedit.cpp | 18 ++++++++++++++++++ qt-ui/templateedit.h | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index f3c6eb14c..0e6a0b320 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -110,4 +110,5 @@ void PrintOptions::on_editButton_clicked() { TemplateEdit te(this, printOptions, templateOptions); te.exec(); + setup(); } diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index aecfdc434..82a71ea32 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -15,6 +15,16 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, ui->fontsize->setValue(templateOptions->font_size); ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index); ui->linespacing->setValue(templateOptions->line_spacing); + + if (printOptions->p_template == print_options::ONE_DIVE) { + grantlee_template = TemplateLayout::readTemplate("one_dive.html"); + } else if (printOptions->p_template == print_options::TWO_DIVE) { + grantlee_template = TemplateLayout::readTemplate("two_dives.html"); + } else if (printOptions->p_template == print_options::CUSTOM) { + grantlee_template = TemplateLayout::readTemplate("custom.html"); + } + + ui->plainTextEdit->setPlainText(grantlee_template); } TemplateEdit::~TemplateEdit() @@ -41,3 +51,11 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { templateOptions->color_palette_index = index; } + +void TemplateEdit::on_TemplateEdit_finished(int result) +{ + if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + printOptions->p_template = print_options::CUSTOM; + TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); + } +} diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index dc38d11fc..296005652 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -2,6 +2,7 @@ #define TEMPLATEEDIT_H #include +#include "templatelayout.h" namespace Ui { class TemplateEdit; @@ -23,10 +24,13 @@ private slots: void on_colorpalette_currentIndexChanged(int index); + void on_TemplateEdit_finished(int result); + private: Ui::TemplateEdit *ui; struct template_options *templateOptions; struct print_options *printOptions; + QString grantlee_template; }; #endif // TEMPLATEEDIT_H -- cgit v1.2.3-70-g09d2