From cc53dc7acf801f022612678f697e6d76c2443153 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 07:29:46 +0200 Subject: [PATCH] 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