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 --- qt-ui/templateedit.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 qt-ui/templateedit.h (limited to 'qt-ui/templateedit.h') 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 -- 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/templateedit.h') 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(-) (limited to 'qt-ui/templateedit.h') 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 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/templateedit.h') 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/templateedit.h') 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