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 +++++++ 1 file changed, 7 insertions(+) (limited to 'qt-ui/printoptions.cpp') 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(); +} -- 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(-) (limited to 'qt-ui/printoptions.cpp') 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 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 (limited to 'qt-ui/printoptions.cpp') 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 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(-) (limited to 'qt-ui/printoptions.cpp') 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(-) (limited to 'qt-ui/printoptions.cpp') 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(+) (limited to 'qt-ui/printoptions.cpp') 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